How to get the coordinates of a polygon in OpenLay

2019-08-10 01:07发布

问题:

I have tried to add a click handler to the map, but am not sure how to tell when the polygon has finished drawing. Is there a simple function to get the polygon coordinates on draw end ?

回答1:

You can probably adapt https://stackoverflow.com/a/24835176/228885 for your purposes. As mentioned in another answer feature.once('change', ...) might be another way to go. I expect in that case you would pick the last element from the feature passed to the handler. Then you would extract the coordinates out of it and off you go.

TLDR; Listen add or change of features, extract coordinate.