Question

I have a Geojson Linestring file that I would like to style. I load it with L.mapbox.featureLayer() but I guess there is no styling option. I try to load it with L.geoJson but does not find the way to do it through url:

var myStyle = {
"color": "#ff7800",
"weight": 5,
"opacity": 0.65
};
L.geoJson(myGeojson, {
style: myStyle
}).addTo(map);

What should I add to load the Geojson from url?

Was it helpful?

Solution

L.geoJSON takes an object, not a URL. You can use jQuery's getJSON to load the data, then call L.geoJSON when it's ready:

$.getJSON("orders.json", function(data) {
    L.geoJson(data, {
        style: myStyle
    }).addTo(map);
}

See http://api.jquery.com/jquery.getjson/ for more details.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top