0

Wondering if anyone knows how to get multiple geometries of what a user has drawn on an openlayers 3 map.

At the moment i am using

        var coords = feature.getGeometry().getCoordinates();

Is there a openlayers method to get the geometries of all the polygons/points etc. drawn?

hope that makes sense

1 Answer 1

1

I guess you use a vector layer to place the geometry objects a user has drawn (lines, points, polygons etc) Then you need to call:

var feats = vector.getSource().getFeatures(); //You have a Collection of features console.log("feats",feats); //now you may iterate through your features feats.forEach(function(feat){ //and you may get the coordinates for each individual feature var coordinates = feat.getGeometry().getCoordinates(); });

Here is a fiddle to demostrate. Draw some vectors on the map and then press the "get all features" button

1
  • Thanks for the reply man! I managed to get it working just before but in a different way for anyone interested as well. I had the coordinates saving to a variable. So decided to use an array to store all the point the user had click, on each new press it would add the point to the array. Not at a computer but can post code later if anyone interested.
    – cmca
    Oct 10, 2016 at 14:07

Your Answer

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

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