In a mapbox application that I am building, I am loading multiple markers onto the page depending on the users geolocation, the problem is though that I need certain markers to be above others, but the markers are not respecting the zIndex
that I set. Here is my code.
function addMarker(type, radius, height, lat, long, id, special, name) {
var circle_options;
switch (type) {
case marker.RESTRICTED:
circle_options = {
color: '#D90000',
fillColor: '#D90000', // Fill color
fillOpacity: 0.4, // Fill opacity
stroke: false,
zIndexOffSet: -1
};
break;
case marker.NOT_RECOMMENDED:
circle_options = {
color: '#FF8000',
fillColor: '#FF8000', // Fill color
fillOpacity: 0.75, // Fill opacity
stroke: false,
zIndexOffSet: 1000
};
break;
case marker.USER_RECOMMENDED:
circle_options = {
color: '#9FCC1C',
fillColor: '#9FCC1C', // Fill color
fillOpacity: 0.75, // Fill opacity
stroke: false,
zIndexOffSet: 1000
};
break;
case marker.APPROVED:
circle_options = {
color: '#006ADC',
fillColor: '#006ADC', // Fill color
fillOpacity: 0.75,
stroke: false,
zIndexOffSet: 1000
};
break;
}
var mark = L.circle([
lat, long
], radius * 1609.34, circle_options);
if (nav.currentPage() == 'location-details') {
if (mapElement) {
mapElement.setView([lat, long], zoomMap[radius])
mapElement.removeLayer(use);
mapElement.removeLayer(ic);
}
}
else if (nav.currentPage() == 'home') {
mark.objectId = id;
circles.push(mark);
}
mark.on('click', function (e) {
var self = id;
circles.some(function (item) {
if (self == item.objectId) {
nav.navigate('location-details', false, item.objectId);
return true;
}
});
})
mark.addTo(mapElement)
}
bringToFront()
andbringToBack()
methods. But it does not allow you to precisely control the z-index, see this feature request. And Vincent is right about the order : see With JavaScript, can I change the Z index/layer of an SVG <g> element? – Exeat