var mbAttr = 'Map data © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, ' +
'Imagery © <a href="https://www.mapbox.com/">Mapbox</a>'
// please replace this with your own mapbox token!
var token = 'my_token_here';
var mapboxUrl = 'https://api.mapbox.com/styles/v1/mapbox/streets-v10/tiles/{z}/{x}/{y}@2x?access_token=' + token;
var OpenStreetMap_Mapnick=L.tileLayer(mapboxUrl, {id: 'mapbox/light-v9', attribution: mbAttr})
var map = L.map('mapid', {
center: [45.43538, 12.33297],
zoom: 14,
layers: [OpenStreetMap_Mapnick]
});
var control = L.control.layers(null, null).addTo(map);
for (let i = 1; i <= 7; i++) {
new L.GPX('gpx/MuVe_7D/MuVe_7D_T'+i+'.gpx', {
async: true,
marker_options: {
startIconUrl: 'assets/pins/Pin_ATG.png',
endIconUrl: 'assets/pins/Pin_CUR.png',
shadowUrl: 'assets/pins/Pin_shadow.png'
}
}).on('loaded', function(e) {
var gpx = e.target;
control.addOverlay(gpx, 'gpr_GPX'+i);
}).addTo(map);
}
$("#GPX1").click(function(event) {
event.preventDefault();
if(map.hasLayer(gpr_GPX1)) {
$(this).removeClass('selected');
map.removeLayer(gpr_GPX1);
} else {
map.addLayer(gpr_GPX1);
$(this).addClass('selected');
}
});
How can I solve it? I
I am using this snippet of code to show/hide layers but it doesn't work. The curious fact about it is that if I plot a POI the show/hide functionality from the link works, it seems I am doing something wrong defining the layers.
Thanks!