Extract GeoJSON data into AJAX Call Flyer

So, I'm trying to publish a MapBox with a Leaflet and want to add some tokens from an external data source using an AJAX call. In particular, I collect all Wi-Fi points in New York using this dataset . I see where he says that I can upload Wi-Fi places to JSON, but I'm still trying to teach myself how to encode and don't know what to do from there.

Here is an example that MapBox provides using .js located in your site directory. What would it look like if I made an AJAX call instead?

<script src="museums.js"></script>
<script type="text/javascript">
// Define a GeoJSON data layer with data
var geojsonLayer = new L.GeoJSON();

// Display the name property on click
geojsonLayer.on('featureparse', function (e) {
    if (e.properties && e.properties.name){
    e.layer.bindPopup(e.properties.name);
}
});

geojsonLayer.addGeoJSON(data);

// Add the GeoJSON layer
map.addLayer(geojsonLayer);
</script>
+5
source share
1 answer

wifi, , json URL: wifi spot

, json GEOJSON (Wikipedia)...

, URL-, GEOJSON, jQuery Ajax :

$.ajax({
    type: "POST",
    url: "https://nycopendata.socrata.com/api/views/ehc4-fktp/rows.json",
    dataType: 'json',
    success: function (response) {

        geojsonLayer = L.geoJson(response, {
            style: yourLeafletStyle
        }).addTo(map);
    }
});

+7

All Articles