Andersen
Andersen

Reputation: 93

Move given point by X,Y meters Openlayers

I currently need to calculate a new point (Longitude and Latitude) from a given point and an X and Y offset in meters in Openlayers. I tried using the translate function already available on the ol/geom/Point class but the result does not look correct as the result position is different then expected.

My question is if there's any other way on ol to calculate the desired position. I'm using ol 6.0.3.

Thanks.

Upvotes: 0

Views: 1481

Answers (1)

Viglino Jean-Marc
Viglino Jean-Marc

Reputation: 1421

Web Mercator is not metric... distance at the pole is infinite...

For small distances, you have to calculate the resolution at the point:

import {getPointResolution} from '../src/ol/proj.js';
let pointRes = getPointResolution(map.getView().getProjection(), 1, point);
let dx = 500 / pointRes;
point.translate(dx, 0);

For larger distance you have to compute the distance on the sphere along a great circle. You can look at ol-ext lib to compute the destination point given an initial point, a distance and a bearing: using ol_sphere_computeDestinationPoint function.

Upvotes: 1

Related Questions