1

Well I have this GeoJSON file :

{"type": "FeatureCollection", "features": [{"id": "1", "type": "Feature", "geometry":{"type":"Point","coordinates":[-5.8039556,35.7903036]},"properties": {"gid":"1","name":"Tanger Ville","link":"C:\\xampp\\htdocs\\final4\\img","layer":"Points"}}, {"id": "2", "type": "Feature", "geometry":{"type":"Point","coordinates":[-5.8053745,35.7896316]},"properties": {"gid":"2","name":null,"link":"C:\\xampp\\htdocs\\final4\\img","layer":"Points"}}, {"id": "3", "type": "Feature", "geometry":{"type":"Point","coordinates":[-5.8035001,35.7894603]},"properties": {"gid":"3","name":"Tanger Ville","link":"C:\\xampp\\htdocs\\final4\\img","layer":"Points"}}, {"id": "4", "type": "Feature", "geometry":{"type":"Point","coordinates":[-5.8026494,35.7909747]},"properties": {"gid":"4","name":"Tanger Ville","link":"C:\\xampp\\htdocs\\final4\\img","layer":"Points"}}, {"id": "6", "type": "Feature", "geometry":{"type":"Point","coordinates":[-5.8000892,35.7912068]},"properties": {"gid":"6","name":"Tanger Ville","link":"C:\\xampp\\htdocs\\final4\\img","layer":"Points"}}, {"id": "5", "type": "Feature", "geometry":{"type":"Point","coordinates":[-5.8034242,35.7892276]},"properties": {"gid":"5","name":"Tanger Ville","link":"C:\\xampp\\htdocs\\final4\\img","layer":"Points"}}, {"id": "7", "type": "Feature", "geometry":{"type":"Point","coordinates":[-5.8055798,35.7912481]},"properties": {"gid":"7","name":null,"link":"C:\\xampp\\htdocs\\final4\\img","layer":"Points"}}, {"id": "8", "type": "Feature", "geometry":{"type":"Point","coordinates":[-5.8046302,35.7890426]},"properties": {"gid":"8","name":null,"link":"C:\\xampp\\htdocs\\final4\\img","layer":"Points"}}]}

I want to retrieve only the coordinates , I used this function but It didn't work

var features = point_layer.getSource().getFeatures();
                features.forEach((feature) => {
                console.log(feature.getCoordinates());
                });

it says " feature.getCoordinates is not a function" .

The main purpose is to get the coordinates to campare them to pixel clicked on map.

2

In getting coordinates from features you must first get geometry by getGeometry() and then get coordinates from geometry by getCoordinates():

var coordinates = feature.getGeometry().getCoordinates();
  • so now I can get the coordinates of all points I have ? – Nabil Faska Jul 31 at 12:50
  • Of all the points in the feature. Why don't you try it? – TomazicM Jul 31 at 12:54
  • I already did , trying to display them as console log , but I got nothing shown – Nabil Faska Jul 31 at 12:57
  • What you get if you log feature.getGeometry()? – TomazicM Jul 31 at 13:00
  • nothing ! but I thought logging feature.getGeometry().getCoordinates will show an array of coordinates – Nabil Faska Jul 31 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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