L.polygon(leafletCoords, {color: "blue", weight: 1}).addTo(map);
}
+ // fly to a view that fits all matches in frame
+ let flyBounds = null;
+ if (matches.length) {
+ let minLat = Infinity;
+ let minLon = Infinity;
+ let maxLat = -Infinity;
+ let maxLon = -Infinity;
+ for (const feature of matches) {
+ // extract flat coordinates of all positive polygons
+ const coordinates = feature.geometry.coordinates.flatMap(poly => poly[0]);
+ const longitudes = coordinates.map(([lon, lat]) => lon);
+ const latitudes = coordinates.map(([lon, lat]) => lat);
+ minLat = Math.min(minLat, ...latitudes);
+ minLon = Math.min(minLon, ...longitudes);
+ maxLat = Math.max(maxLat, ...latitudes);
+ maxLon = Math.max(maxLon, ...longitudes);
+ }
+ flyBounds = L.latLngBounds(L.latLng(minLat, minLon), L.latLng(maxLat, maxLon));
+ }
+
+ console.log(flyBounds);
overlay.style["display"] = "none";
+ if (flyBounds !== null) {
+ map.flyToBounds(flyBounds);
+ }
}
const map = L.map("map");