In the case the GDPR plugin replaces the SP Page Builder OpenStreetMap addon with:
<div class="gdprlock-placeholder gdprlock-placeholder-action">...</div>
And after consent, you want to show the map without page reload.
You can put the code below into the custom script section of the desired category, take care to change the Open Street Map coordinates and details based on your map.
| Code: |
(function () {
var phs = document.querySelectorAll(".gdprlock-placeholder.gdprlock-placeholder-action");
if (!phs.length) return;
phs.forEach(function (ph, idx) {
if (ph.__osm_done) return;
ph.__osm_done = true;
var wrapper = document.createElement("div");
wrapper.className = "sppb-addon-openstreetmap-wrapper";
var content = document.createElement("div");
content.className = "sppb-addon-content";
var mapEl = document.createElement("div");
mapEl.id = "sppb-addon-osm-gdpr-" + Date.now() + "-" + idx;
mapEl.className = "sppb-addon-openstreetmap";
mapEl.setAttribute(
"data-location",
JSON.stringify([
{
address: "Edersee Chalet<br>Sommerseite 26<br>34513 Waldeck",
latitude: "51.2143649",
longitude: "9.0133005",
custom_icon: ""
}
])
);
mapEl.setAttribute("data-mapstyle", "OpenStreetMap.Mapnik");
mapEl.setAttribute("data-mapzoom", "15");
mapEl.setAttribute("data-mousescroll", "1");
mapEl.setAttribute("data-dragging", "1");
mapEl.setAttribute("data-zoomcontrol", "1");
mapEl.setAttribute("data-attribution", "1");
content.appendChild(mapEl);
wrapper.appendChild(content);
ph.parentNode.insertBefore(wrapper, ph);
ph.parentNode.removeChild(ph);
if (mapEl._leaflet_id) {
try { delete mapEl._leaflet_id; } catch (e) { mapEl._leaflet_id = null; }
}
if (typeof window.initOpenStreetMap === "function") {
window.initOpenStreetMap(wrapper);
}
});
})();
|