Asked by nanoteilchen on 2017-01-06T15:10:05Z
Reply on StackOverflowI'm working on a map with mapbox/leaflet. In a file I have the position of different companies. Every company should have the same (mapbox) icon, but I cant define it in the file (eg. I have to add marker-symbol, marker-size, etc afterwords). Therefore, I'm first loading the file with the jquery-function "getJSON", add the properties and load it into a featureLayer. But then, the events "layeradd" and "popupopen" will never be fired whereas "click" works fine. Do you have any ideas?
Loading per url - no standard-marker-image possible:
powerplantlayer = new L.mapbox.featureLayer().loadURL("data/companies.geojson");
powerplantlayer.on("click", onPowerplantClick);
powerplantlayer.on('layeradd popupopen', function(e) {
//IS EXECUTED
});
powerplantlayer.addTo(map);
Loading per variable - events layeradd popupopen not called.
$.getJSON( "data/reactors.geojson", function( reactorjson ) {
//add markers to json-file
$.each( reactorjson['features'], function( key, val ) {
val['properties']['marker-color'] = '#ad1a17';
val['properties']['marker-symbol'] = 'monument';
val['properties']['marker-size'] = 'large';
});
// load featurelayer
powerplantlayer = new L.mapbox.featureLayer().setGeoJSON(reactorjson);
powerplantlayer.on("click", onPowerplantClick);
powerplantlayer.on('layeradd popupopen', function(e) {
// IS NEVER CALLED
});
powerplantlayer.addTo(map);
});
Reply on StackOverflow