I'm trying to make a simple interactive map of Germany. I'm using mapbox.js (2.4.0) and have it set up like this:
var map;
var currLayer, citiesLayer, riversLayer;
$(document).on("ready", function() {
L.mapbox.accessToken = '';
map = L.mapbox.map('map', 'vantuch.d55cb2a1', {zoomControl: true, scrollWheelZoom: true}).
setView([51.0621,10.9863], 6);
// CALL AJAX REQUEST FOR TESTING
findCities();
findRivers();
findCityPlaces();
});
I am calling AJAX functions to set up a L.geojson layer after success like this:
/* functions for setting up MARKERS (find_river_places) */
function showMarkers(map, geojson, selectType) {
geojsonLayer = L.geoJson(geojson, {
// setting up markers
});
currLayer = geojsonLayer;
map.addLayer(geojsonLayer);
}
function showCitiesMarkers(map, geojson) {
geojsonLayer = L.geoJson(geojson, {
pointToLayer: function(feature, latlng) {
var marker;
//return new L.CircleMarker(latlng, {radius: 5, fillOpacity: 1.0}).bindPopup(popup);
marker = new L.Marker(latlng, {
icon: new L.DivIcon({
className: 'circle-border-city',
html: '<div>' +
'<span class="circle-marker-city">' + feature.properties.name +
'</span>' + '</div>'
})
});
return marker;
}
});
citiesLayer = geojsonLayer;
map.addLayer(geojsonLayer);
}
What I want to do is to have layers for rivers and cities always on the top of other layers (user should be able to turn them on or off), no matter which function is called the first. But they're always rendered at the bottom.
I thought that citiesLayer.bringToFront() after adding other layers should work. But after testing it in the console it does nothing. So what am I doing wrong, or is there a better way to do this ?