admin管理员组

文章数量:1356954

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?

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?

Share Improve this question edited Mar 19, 2014 at 18:22 Inclanfunk asked Mar 12, 2014 at 15:45 InclanfunkInclanfunk 1471 gold badge1 silver badge6 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

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./jquery.getjson/ for more details.

本文标签: javascriptHow to load LgeoJson from urlStack Overflow