|
1 | 1 | import L from "leaflet"; |
2 | 2 |
|
3 | | -// Create the map with the specified configuration. |
| 3 | +let map; |
| 4 | + |
| 5 | +// Create the map with the specified configuration on the page load. |
4 | 6 | window.onload = function() { |
| 7 | + // Initialize the map. |
| 8 | + initializeMap(); |
| 9 | +} |
| 10 | + |
| 11 | +// Re-initialize map when switching radio button location_geometry_geodata_type |
| 12 | +document.querySelectorAll('input[name="location_geometry_geodata_type"]').forEach(input => { |
| 13 | + input.addEventListener( 'change', function () { |
| 14 | + // Check if value is 'marker'. |
| 15 | + if (this.value === 'marker') { |
| 16 | + // Remove existing map if exists |
| 17 | + if (map) { |
| 18 | + map.remove(); |
| 19 | + } |
| 20 | + |
| 21 | + // Show your map container |
| 22 | + document.getElementById( 'map-geodata' ).style.display = 'block'; |
| 23 | + |
| 24 | + // Tell Leaflet to recalculate the map size |
| 25 | + setTimeout( function () { |
| 26 | + initializeMap(); |
| 27 | + }, 50 ); |
| 28 | + } |
| 29 | + } ); |
| 30 | +}); |
| 31 | + |
| 32 | + |
| 33 | +function initializeMap() { |
5 | 34 | // Check if there is a div with the ID 'map-geodata'. |
6 | 35 | if ( ! document.getElementById( 'map-geodata' ) ) { |
7 | 36 | return; |
@@ -29,7 +58,7 @@ window.onload = function() { |
29 | 58 | "enableBoxZoomControl": true |
30 | 59 | } |
31 | 60 |
|
32 | | - const map = new L.Map('map-geodata', { |
| 61 | + map = new L.Map('map-geodata', { |
33 | 62 | center: [config.centerY, config.centerX], |
34 | 63 | zoom: config.defaultZoom, |
35 | 64 | minZoom: config.minimumZoom, |
|
0 commit comments