Skip to content Skip to sidebar Skip to footer

Load Geojson Into Layer From A Url?

I'm using Mapbox 2.1 and I'm trying to build a chloropleth map from a GeoJSON source, working from this example: https://www.mapbox.com/mapbox.js/example/v1.0.0/choropleth/ However

Solution 1:

You can use ajax to snag the data from your own site

Here is a jquery way of doing it.

$.ajax({
dataType: "json", //you shouldn't need to declare geojsonurl: "data/district.geojson",
success: function(data) {
    //whatever you want to do with the data, alternatively you could use a closer around the ajax request to capture the data into a variable depending on how you have your code organized
}
}).error(function(e) {
     console.log(e)
});

Post a Comment for "Load Geojson Into Layer From A Url?"