jeudi 26 mars 2015

Leaflet Geojson Styling


How can external Geojson feeds be styled in leaflet? To add my external feed I'm using the snip below:



var mygeojson = new L.geoJson();
mygeojson.addTo(map);

$.ajax({
dataType: "json",
url: "https://linktomyexternalgeojsonurl",
success: function(data) {
$(data.features).each(function(key, data) {
mygeojson.addData(data);
});
}
}).error(function() {});


The Leaflet website offers examples here http://ift.tt/1cHvWyf but when following the map breaks and does not display any marker. I am clearly doing something wrong and it is likely very simple and obvious to anyone but me.


Leaflet example:



var myStyle = {
"color": "#ff7800",
"weight": 5,
"opacity": 0.65
};

L.geoJson(myLines, {
style: myStyle
}).addTo(map);


My implementation of the Leaflet example:



var myStyle = {
"color": "#ff7800",
"weight": 5,
"opacity": 0.65
};

var mygeojson = new L.geoJson({
style: myStyle})
mygeojson.addTo(map);

$.ajax({
dataType: "json",
url: "https://linktomyexternalgeojsonurl",
success: function(data) {
$(data.features).each(function(key, data) {
mygeojson.addData(data);
});
}
}).error(function() {});




Aucun commentaire:

Enregistrer un commentaire