2

I am making my way through learning Mapbox and Mapbox.js. I have loaded my GeoJSON data from a URL:

var featureLayer = L.mapbox.featureLayer()
.loadURL('./data_frag.geojson')
.addTo(map);

Now I am trying to parse out the lat and lon coordinates. It makes sense to me to try something like:

var longitude = featureLayer.geometry.coordinates[0];
var latitude = featureLayer.geometry.coordinates[1];

but that is not right.

Should I be using the feature layer or the GeoJSON layer for this?

2

1 Answer 1

2

L.mapbox.featureLayer() has a getGeoJSON method. For the first feature in the GeoJSON FeatureCollection:

var longitude = (featureLayer.getGeoJSON()).features[0].geometry.coordinates[0];
var latitude = (featureLayer.getGeoJSON()).features[0].geometry.coordinates[1];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.