Skip to content

Commit b1f1a3e

Browse files
authored
Merge pull request #64 from OpenWebconcept/feature/OWC-165
OWC-165 fix for map not working well when you switch back from geodat…
2 parents aa09b3f + 16eebe8 commit b1f1a3e

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

src/admin/class-admin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public static function admin_enqueue_scripts() {
131131
// Only include the script on the kaarten edit pages.
132132
$screen = get_current_screen();
133133

134-
if ( ! in_array( $screen->id, [ 'owc_ok_datalayer' ], true ) ) {
134+
if ( ! in_array( $screen->id, [ 'owc_ok_datalayer', 'owc_ok_location' ], true ) ) {
135135
return;
136136
}
137137

src/scripts/openstreetmap-geodata.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,36 @@
11
import L from "leaflet";
22

3-
// Create the map with the specified configuration.
3+
let map;
4+
5+
// Create the map with the specified configuration on the page load.
46
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() {
534
// Check if there is a div with the ID 'map-geodata'.
635
if ( ! document.getElementById( 'map-geodata' ) ) {
736
return;
@@ -29,7 +58,7 @@ window.onload = function() {
2958
"enableBoxZoomControl": true
3059
}
3160

32-
const map = new L.Map('map-geodata', {
61+
map = new L.Map('map-geodata', {
3362
center: [config.centerY, config.centerX],
3463
zoom: config.defaultZoom,
3564
minZoom: config.minimumZoom,

0 commit comments

Comments
 (0)