1

OpenLayer - 6.4.3

Need to calculate LENGTH and WIDTH of current EXTENT in miles.

Then add x miles to the calculated LENGTH and WIDTH.

Then get the new extent from new LENGTH and WIDTH with same center as initial extent.

const extent_initial = this.map.getView().calculateExtent(this.map.getSize());

// get the Length and width in miles from 'extent_inital' 

// add x miles to Length and Width 
// so Length_new = Length + x , Width_new = Width + x
// Calculate new Extent with Length_new and Width_new and extent_inital center


Thanks in advance

Kishor Kunal
  • 267
  • 1
  • 6

1 Answers1

1

The accuracy of what you want will depend on the projection you are using an the size of the extent in that projection.

enter image description here While this is a rectangle when projected, due to the shape of the earth the width at the top (latitude 60 north) in miles is only half the width at the bottom (equator).

So this will work best for a small extent where the scale is close to constant. Calculate the scale in miles at the center of the extent, then you can get the width and height of the center lines in miles.

const center = ol.extent.getCenter(extent_initial);

const pointResolutionInMiles = ol.proj.getPointResolution(this.map.getView().getProjection(), 1, center, 'ft')  / 5280;

const widthInMiles = ol.extent.getWidth(extent_initial) * pointResolutionInMiles;

const heightInMiles = ol.extent.getHeight(extent_initial) * pointResolutionInMiles;

To create a new extent you can buffer the initial extent in each direction (top, bottom, left, right) so to increase width and height by x you need a buffer of x / 2 miles at each edge, which must be converted back to projection units:

const extent_new = ol.extent.buffer(extent_initial, (x / 2) / pointResolutionInMiles);
Mike
  • 16,042
  • 2
  • 14
  • 30