最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to load L.geoJson from url? - Stack Overflow

programmeradmin6浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论