City Block Mapper — Final (with per-block match distances)
⟲
Undo
if (minDist < minDistance) { minDistance = minDist; nearestPoly = polygon; } }); if (nearestPoly && minDistance < 0.2) { // ~200 m threshold matched.push({ optimizedPoint: point, polygon: nearestPoly, distance: minDistance }); } else { matched.push({ optimizedPoint: point, polygon: null, distance: null }); } }); // Highlight matched polygons and show result summary polygons.forEach(p => p.setOptions({ strokeColor: '#0078ff', fillColor: '#0078ff' })); matched.forEach((pair, idx) => { if (pair.polygon) { pair.polygon.setOptions({ strokeColor: pair.distance > 0.2 ? 'red' : 'green', fillColor: pair.distance > 0.2 ? 'red' : 'green' }); const label = new google.maps.InfoWindow({ content: `#${idx + 1}`, position: pair.polygon.getPath().getAt(0) }); label.open(map); setTimeout(() => label.close(), 4000); } }); console.log("Matched", matched); return matched; } /* =========================== PREVIEW MATCH HANDLER ============================ */ document.getElementById('previewMatch').addEventListener('click', () => { if (polygons.length === 0 || optimizedRoute.length === 0) { alert("Please ensure both polygons and optimized coordinates are loaded."); return; } const matches = matchOptimizedToPolygons(optimizedRoute); alert(`Preview complete — ${matches.filter(m => m.polygon).length} matched polygons.`); }); /* =========================== APPLY OPTIMIZED ORDER HANDLER ============================ */ document.getElementById('applyOptimizedOrder').addEventListener('click', () => { if (optimizedRoute.length === 0) { alert("Please load or generate an optimized route first."); return; } const matches = matchOptimizedToPolygons(optimizedRoute); const matchedPolygons = matches .filter(m => m.polygon) .map(m => m.polygon); // Reorder polygons array based on optimized route order polygons = matchedPolygons; // Repaint polygons with new order polygons.forEach((p, i) => { p.setOptions({ strokeColor: '#0078ff', fillColor: '#0078ff' }); const label = new google.maps.InfoWindow({ content: `#${i + 1}`, position: p.getPath().getAt(0) }); label.open(map); setTimeout(() => label.close(), 3000); }); alert("Optimized order applied successfully!"); }); /* =========================== INIT ============================ */ window.onload = initMap;