0

I have to draw a polygon on a vector layer on a simple OpenLayers OSM map (WebMercator). What I know:

  1. the center (lat/lon) of this polygon
  2. the lengths (in meters) of each side.

I can pre-calculate the mercator coordinates of each vertice at a given position (for example lat/lon 0,0) and save them on a DB.

To do so, I'm using libraries I cannot use in my application backend.

But what I need is to move this polygon around the world keeping the right dimensions in meters: the user needs to view on the map the real size of that object.

So, is there any way to reproject the moved object in the new location? Or at least to create a new geometry each time in the new position by simply know the sides lengths?

1

I suppose you are using the draw and translate interactions.

On the 'drawend' event, clone your polygon, transform it to EPSG:4326 and save it for later.

On the 'translating' event, get the first coordinate from the dragged feature and transform it to EPSG:4326. Then translate the stored polygon with the delta of it's first coordinate and the new coordinate above. Clone the stored polygon, transform it to the map projection and replace the geometry in the dragged feature with it.

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.