I can't seem to figure this one out and I'm assuming that this is a problem of code intendation? I have a button that on click in Leaflet should change the basemap layer.
// Basemap Button - Left panel
L.Control.Watermark = L.Control.extend({
onAdd: function(map) {
var Basemap = L.DomUtil.create('img');
Basemap.src = 'basemap.png';
Basemap.style.width = '65px';
Basemap.style.top = '-90px';
Basemap.style.left = '10px';
Basemap.addEventListener('click', function() {
// Change the basemap layer of the map to the OpenStreetMap Street View layer
var osmStreetViewLayer = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors'});
return Basemap;
},
});
L.control.watermark({ position: 'topleft' }).addTo(map);
The issue seems to be on closing "});" ?
Returns error on });
The revised code fixed the error, plus some further considerations to make the basemap toggle, in case someone tries a similar project:
// Basemap Button - Left panel
L.Control.Watermark = L.Control.extend({
onAdd: function(map) {
var Basemap = L.DomUtil.create('img');
Basemap.src = 'basemap.png';
Basemap.style.width = '65px';
Basemap.style.top = '-40px';
Basemap.style.left = '10px';
Basemap.title = 'Change Basemap'; // Add this line to set the title attribute
Basemap.addEventListener('click', function() {
if (map.hasLayer(osmStreetViewLayer)) {
// Remove the OpenStreetMap Street View layer and add back the original layer
map.removeLayer(osmStreetViewLayer);
map.addLayer(originalLayer);
} else {
// Remove the original layer and add the OpenStreetMap Street View layer
map.removeLayer(originalLayer);
osmStreetViewLayer.addTo(map);
}
});
return Basemap;
},
});
Via Active questions tagged javascript - Stack Overflow https://ift.tt/57kRQXl
Comments
Post a Comment