i am trying to integrate a map into my wordpress site using following code. To be more specific i am using this code inside a "html block" of the Block Editor.
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css"
integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A=="
crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"
integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA=="
crossorigin=""></script>
<script src="https://www.akzisemauer-berlin.de/map/js/leaflet.ajax.min.js"></script>
<div id="map" style="width:100%; height: 400px; ">
</div>
<script>
var map = L.map('map', {
zoomControl:true, maxZoom:18, minZoom:1
}).setView([52.513660,13.417072], 12);
L.tileLayer('http://a.tiles.wmflabs.org/bw-mapnik/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
minZoom: 1,
maxZoom: 28,
}).addTo(map);
//Akzisemauer-wand
function akziseWallStyle(feature) {
return {
color: wall_color(feature.properties.bezirk),
weight: 3,
};
}
function wall_color(bezirk) {
if(bezirk === "Friedrichshain-Kreuzberg") return "#e5b813"; else
return "#666666";
}
var akzise_wall = new L.GeoJSON.AJAX("https://www.akzisemauer-berlin.de/map/data/akzise_wall.geojson",{
style:akziseWallStyle});
akzise_wall.addTo(map);
//Akzisemauer-Tore
// markerpopup function
function markerpopup(feature, layer) {
if (feature.properties && feature.properties.name) {
layer.bindPopup(feature.properties.name);
}
}
var akziseGateFHXBStyle = {
radius: 8,
fillColor: "#e5b813",
color: "#000",
weight: 0.3,
opacity: 1,
fillOpacity: 0.8
}
var akzise_gates_FHXB = new L.GeoJSON.AJAX("https://www.akzisemauer-berlin.de/map/data/akzise_gates_FHXB.geojson", {
pointToLayer: function (feature, latlng) {
return L.circleMarker(latlng, akziseGateFHXBStyle)
}}, {
onEachFeature: markerpopup
});
akzise_gates_FHXB.addTo(map);
var akziseGatePBMIStyle = {
radius: 8,
fillColor: "#666666",
color: "#000",
weight: 0.3,
opacity: 1,
fillOpacity: 0.8
}
var akzise_gates_PBMI = new L.GeoJSON.AJAX("https://www.akzisemauer-berlin.de/map/data/akzise_gates_PBMI.geojson", {
pointToLayer: function (feature, latlng) {
return L.circleMarker(latlng, akziseGatePBMIStyle)
}}, {
onEachFeature: markerpopup
});
akzise_gates_PBMI.addTo(map);
testmarker = new L.CircleMarker([ 52.513660,13.417072], { radius: 10, color: 'green', }).bindPopup(String("DOES THIS WORK??")).addTo(map);
// Bezirksgrenzen
var bezirkStyle = {
"color": "#717171",
"weight": 0,
"fillOpacity": 0.4
};
var bezirksgrenzen = new L.GeoJSON.AJAX("https://www.akzisemauer-berlin.de/map/data/bezirksgrenzen_simp.geojson",{
style:bezirkStyle});
bezirksgrenzen.addTo(map);
setInterval(function () {
map.invalidateSize();
}, 100);
</script>
(i use the invalidatesize function to fix a bug where maptiles would not load properly, check here)
I am using the point_to_layer function to style the points (akzisemauer_gates) which works fine but i cannot get the popups to work - neither the two akzise_gates_* features nor the testmarker.
what i tried:
when i skip the styling of the point features and go back to the standard marker the popups work as intended.
when i try out the same code in jsfiddle the popups work (it fails to load my geojson`s, probably for unrelated reasons, but the testmarker works), so i assume the problem is wordpress related
somebody maybe has experience with leaflet behaviour inside wordpress?