0

I'm new to Javascript and hence I'm a little lost. I am able to read from a GeoJSON file; however, I do not understand how to iterate through the file to get the Lat-Long of the points, and then display those points as markers in Leaflet. I am hoping to also use the plugin Awesome Markers (based on font-awesome, for Leaflet)

This is a sample of my GeoJSON file:

    { "type": "FeatureCollection",
      "features": [
         { "type": "Feature", "properties": { "Street Nam": "Aljunied Avenue 2", " Block": "118 Aljunied Avenue 2", " Postal Co": "380118", " Latitude": 1.320440, "Longitude": 103.887575 }, 
           "geometry": { "type": "Point", "coordinates": [ 103.887575, 1.320440 ] } }
      ,
      { "type": "Feature", "properties": { "Street Nam": "Aljunied Crescent", " Block": "97A Aljunied Crescent", " Postal Co": "381097", " Latitude": 1.321107, "Longitude": 103.886127 }, 
        "geometry": { "type": "Point", "coordinates": [ 103.886127, 1.321107 ] } }
    ]
    }

Thank you for your attention and time =)

4

2 回答 2

1

Process the geojson as described in the leaflet documentation. Specify a pointToLayer function which creates a marker with an awesome icon:

L.geoJson(geoJson, {
    pointToLayer: function (feature, latlng) {
        return L.marker(latlng, 
            {icon: L.AwesomeMarkers.icon( 
                 << options based on feature.properties >> 
             )});
    }
}).addTo(map);
于 2013-03-31T22:16:14.950 回答
0

After reading the file, you should have a javascript object that represents all the data in the file:

var geoData = JSON.parse(fileContents);
var features = geoData.features;

and so on. The parsed data will be converted to objects or arrays depending on whether they are key/value dictionaries or just lists. So from the above

var feature = geoData.features[0];

will get you a reference to the first feature object in the list. If you write

console.log(geoData);

and run with any recent browser you should be able to see an expandable description of the data to help make sense of it all.

于 2013-03-30T20:33:47.060 回答