π Area Selection
@@ -367,16 +376,16 @@
π Quick Presets
map.on('mousemove', onMouseMove);
map.on('mouseup', onMouseUp);
- // Prevent default selection behavior
- map.dragging.disable();
- map.on('mousedown', function() { map.dragging.disable(); });
- map.on('mouseup', function() { map.dragging.enable(); });
+
}
- // Mouse event handlers for area selection
+ // Mouse event handlers for area selection (Shift+drag to select)
function onMouseDown(e) {
+ if (!e.originalEvent.shiftKey) return;
+
isSelecting = true;
startPoint = e.latlng;
+ map.dragging.disable();
if (selectionRectangle) {
map.removeLayer(selectionRectangle);
@@ -408,6 +417,7 @@ π Quick Presets
if (!isSelecting || !startPoint) return;
isSelecting = false;
+ map.dragging.enable();
const bounds = L.latLngBounds(startPoint, e.latlng);
// Update form fields
@@ -598,6 +608,69 @@ π Quick Presets
});
});
+ // Search for a location using Nominatim
+ async function searchLocation() {
+ const query = document.getElementById('searchInput').value.trim();
+ const status = document.getElementById('searchStatus');
+
+ if (!query) {
+ status.textContent = 'Enter a location to search';
+ return;
+ }
+
+ status.textContent = 'Searching...';
+
+ try {
+ const response = await fetch(
+ `https://nominatim.openstreetmap.org/search?q=${encodeURIComponent(query)}&format=json&limit=1`
+ );
+ const data = await response.json();
+
+ if (!data || data.length === 0) {
+ status.textContent = 'Location not found';
+ return;
+ }
+
+ const result = data[0];
+ const bbox = result.boundingbox; // [south, north, west, east]
+ const south = parseFloat(bbox[0]);
+ const north = parseFloat(bbox[1]);
+ const west = parseFloat(bbox[2]);
+ const east = parseFloat(bbox[3]);
+
+ // Update form fields
+ document.getElementById('north').value = north.toFixed(6);
+ document.getElementById('south').value = south.toFixed(6);
+ document.getElementById('east').value = east.toFixed(6);
+ document.getElementById('west').value = west.toFixed(6);
+
+ // Draw rectangle and fit map
+ const bounds = L.latLngBounds([south, west], [north, east]);
+
+ if (selectionRectangle) {
+ map.removeLayer(selectionRectangle);
+ }
+
+ selectionRectangle = L.rectangle(bounds, {
+ color: '#3498db',
+ weight: 2,
+ fill: true,
+ fillOpacity: 0.2
+ }).addTo(map);
+
+ map.fitBounds(bounds, { padding: [20, 20] });
+
+ status.textContent = `Found: ${result.display_name.substring(0, 50)}...`;
+ document.getElementById('selectionInfo').classList.remove('hidden');
+ updateBoundsDisplay(bounds);
+ calculateStats();
+ generateCommand();
+
+ } catch (err) {
+ status.textContent = 'Search failed: ' + err.message;
+ }
+ }
+
// Initialize everything
initMap();