mirror of
https://github.com/zvx-echo6/central.git
synced 2026-05-21 18:14:44 +02:00
fix(gui): region picker render + click-to-draw
Bug A: Maps render blank on /setup/adapters for FIRMS and USGS because Leaflet computed zero dimensions before container layout settled. Fix: add setTimeout invalidateSize() after map creation. Bug B: No click-to-draw functionality - only drag corners. Fix: add L.Control.Draw for rectangle drawing with CREATED event handler to replace existing rectangle. Both fixes applied to: - setup_adapters.html (wizard inline JS) - _region_picker.html (standalone edit page) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
616452c1df
commit
8c18dc8482
2 changed files with 91 additions and 5 deletions
|
|
@ -59,6 +59,10 @@
|
||||||
maxZoom: 18
|
maxZoom: 18
|
||||||
}).addTo(map);
|
}).addTo(map);
|
||||||
|
|
||||||
|
// Ensure map renders correctly even if container has not
|
||||||
|
// finished laying out at init time
|
||||||
|
setTimeout(function() { map.invalidateSize(); }, 100);
|
||||||
|
|
||||||
// Create initial rectangle
|
// Create initial rectangle
|
||||||
const bounds = L.latLngBounds(
|
const bounds = L.latLngBounds(
|
||||||
L.latLng(savedSouth, savedWest),
|
L.latLng(savedSouth, savedWest),
|
||||||
|
|
@ -69,11 +73,34 @@
|
||||||
map.fitBounds(bounds.pad(0.1));
|
map.fitBounds(bounds.pad(0.1));
|
||||||
|
|
||||||
// Create editable rectangle
|
// Create editable rectangle
|
||||||
const rectangle = L.rectangle(bounds, {
|
let rectangle = L.rectangle(bounds, {
|
||||||
color: '#3388ff',
|
color: '#3388ff',
|
||||||
weight: 2,
|
weight: 2,
|
||||||
fillOpacity: 0.2
|
fillOpacity: 0.2
|
||||||
}).addTo(map);
|
});
|
||||||
|
|
||||||
|
// Set up Leaflet.draw for click-to-draw
|
||||||
|
const drawnItems = new L.FeatureGroup();
|
||||||
|
drawnItems.addLayer(rectangle);
|
||||||
|
map.addLayer(drawnItems);
|
||||||
|
|
||||||
|
const drawControl = new L.Control.Draw({
|
||||||
|
draw: {
|
||||||
|
rectangle: { shapeOptions: { color: '#3388ff', weight: 2,
|
||||||
|
fillOpacity: 0.2 } },
|
||||||
|
polyline: false,
|
||||||
|
polygon: false,
|
||||||
|
circle: false,
|
||||||
|
marker: false,
|
||||||
|
circlemarker: false
|
||||||
|
},
|
||||||
|
edit: {
|
||||||
|
featureGroup: drawnItems,
|
||||||
|
edit: false,
|
||||||
|
remove: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
map.addControl(drawControl);
|
||||||
|
|
||||||
// Make rectangle editable
|
// Make rectangle editable
|
||||||
rectangle.editing.enable();
|
rectangle.editing.enable();
|
||||||
|
|
@ -96,13 +123,33 @@
|
||||||
// Listen for rectangle edit events
|
// Listen for rectangle edit events
|
||||||
rectangle.on('edit', updateInputs);
|
rectangle.on('edit', updateInputs);
|
||||||
|
|
||||||
|
// When user draws a new rectangle, replace the existing one
|
||||||
|
map.on(L.Draw.Event.CREATED, function(e) {
|
||||||
|
drawnItems.clearLayers();
|
||||||
|
rectangle = e.layer;
|
||||||
|
rectangle.setStyle({ color: '#3388ff', weight: 2,
|
||||||
|
fillOpacity: 0.2 });
|
||||||
|
drawnItems.addLayer(rectangle);
|
||||||
|
rectangle.editing.enable();
|
||||||
|
rectangle.on('edit', updateInputs);
|
||||||
|
updateInputs();
|
||||||
|
});
|
||||||
|
|
||||||
// Reset button
|
// Reset button
|
||||||
document.getElementById('region-reset-btn').addEventListener('click', function() {
|
document.getElementById('region-reset-btn').addEventListener('click', function() {
|
||||||
const originalBounds = L.latLngBounds(
|
const originalBounds = L.latLngBounds(
|
||||||
L.latLng(savedSouth, savedWest),
|
L.latLng(savedSouth, savedWest),
|
||||||
L.latLng(savedNorth, savedEast)
|
L.latLng(savedNorth, savedEast)
|
||||||
);
|
);
|
||||||
rectangle.setBounds(originalBounds);
|
drawnItems.clearLayers();
|
||||||
|
rectangle = L.rectangle(originalBounds, {
|
||||||
|
color: '#3388ff',
|
||||||
|
weight: 2,
|
||||||
|
fillOpacity: 0.2
|
||||||
|
});
|
||||||
|
drawnItems.addLayer(rectangle);
|
||||||
|
rectangle.editing.enable();
|
||||||
|
rectangle.on('edit', updateInputs);
|
||||||
updateInputs();
|
updateInputs();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -174,17 +174,44 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||||
maxZoom: 18
|
maxZoom: 18
|
||||||
}).addTo(map);
|
}).addTo(map);
|
||||||
|
|
||||||
|
// Ensure map renders correctly even if container has not
|
||||||
|
// finished laying out at init time
|
||||||
|
setTimeout(function() { map.invalidateSize(); }, 100);
|
||||||
|
|
||||||
const bounds = L.latLngBounds(
|
const bounds = L.latLngBounds(
|
||||||
L.latLng(savedSouth, savedWest),
|
L.latLng(savedSouth, savedWest),
|
||||||
L.latLng(savedNorth, savedEast)
|
L.latLng(savedNorth, savedEast)
|
||||||
);
|
);
|
||||||
map.fitBounds(bounds.pad(0.1));
|
map.fitBounds(bounds.pad(0.1));
|
||||||
|
|
||||||
const rectangle = L.rectangle(bounds, {
|
let rectangle = L.rectangle(bounds, {
|
||||||
color: '#3388ff',
|
color: '#3388ff',
|
||||||
weight: 2,
|
weight: 2,
|
||||||
fillOpacity: 0.2
|
fillOpacity: 0.2
|
||||||
}).addTo(map);
|
});
|
||||||
|
|
||||||
|
// Set up Leaflet.draw for click-to-draw
|
||||||
|
const drawnItems = new L.FeatureGroup();
|
||||||
|
drawnItems.addLayer(rectangle);
|
||||||
|
map.addLayer(drawnItems);
|
||||||
|
|
||||||
|
const drawControl = new L.Control.Draw({
|
||||||
|
draw: {
|
||||||
|
rectangle: { shapeOptions: { color: '#3388ff', weight: 2,
|
||||||
|
fillOpacity: 0.2 } },
|
||||||
|
polyline: false,
|
||||||
|
polygon: false,
|
||||||
|
circle: false,
|
||||||
|
marker: false,
|
||||||
|
circlemarker: false
|
||||||
|
},
|
||||||
|
edit: {
|
||||||
|
featureGroup: drawnItems,
|
||||||
|
edit: false,
|
||||||
|
remove: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
map.addControl(drawControl);
|
||||||
|
|
||||||
rectangle.editing.enable();
|
rectangle.editing.enable();
|
||||||
|
|
||||||
|
|
@ -204,6 +231,18 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||||
rectangle.on('edit', updateInputs);
|
rectangle.on('edit', updateInputs);
|
||||||
updateInputs();
|
updateInputs();
|
||||||
|
|
||||||
|
// When user draws a new rectangle, replace the existing one
|
||||||
|
map.on(L.Draw.Event.CREATED, function(e) {
|
||||||
|
drawnItems.clearLayers();
|
||||||
|
rectangle = e.layer;
|
||||||
|
rectangle.setStyle({ color: '#3388ff', weight: 2,
|
||||||
|
fillOpacity: 0.2 });
|
||||||
|
drawnItems.addLayer(rectangle);
|
||||||
|
rectangle.editing.enable();
|
||||||
|
rectangle.on('edit', updateInputs);
|
||||||
|
updateInputs();
|
||||||
|
});
|
||||||
|
|
||||||
// Fix map size when details is opened
|
// Fix map size when details is opened
|
||||||
const details = container.closest('details');
|
const details = container.closest('details');
|
||||||
if (details) {
|
if (details) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue