jsonmapsleafletusps

Leaflet create map / polygon from USPS EDDM route JSON data


I am green with leaflet, having difficulty finding information on how to create the polygons and information on the map from JSON data from the post office EDDM API

Here is some sample data https://gis.usps.com/arcgis/rest/services/EDDM/selectZIP/GPServer/routes/execute?f=json&env%3AoutSR=4326&ZIP=33510&Rte_Box=R&UserName=EDDM

I am creating something like this, I just need to figure out how to get the JSON data to display on the map. Just looking for a place to start with it.
http://www.imagemedia.com/emap/emap.html

All I have is a blank map started with the following code

    var BING_KEY = 'XXXXXXXXX';
    var map = L.map('map').setView([27.956046, -82.312629], 15);
    var bingLayer = L.tileLayer.bing(BING_KEY).addTo(map);

Solution

  • It seems that you can easily grab the features.geometry.path from that data source and push it inside a leaflet geoJSON layer without much hassle. It seems that data is MultiLineString:

    var uspsGeoJSON = L.geoJson().addTo(map);
    
    uspsGeoJSON.addData({
        "type": "Feature",
        "properties": usps_features["attributes"],
        "geometry": {
            "type": "MultiLineString",
            "coordinates": usps_features["geometry"]["paths"]
        }
    });
    

    This should get you started:

    http://jsfiddle.net/nb3ue10p/