2

I'm struggling to get OpenLayers to check whether a coord is within a layer's extent. It took me a while to get it to even check something, but it only ever returns false, even when passing it the center of the extent so I'm clearly doing something wrong.

https://jsfiddle.net/mr_magpie/w405punq/2/

let poly = [-6.2212531, 53.3257768, -6.3122428, 53.3643417];

console.log(ol.extent.getCenter(poly));
console.log(ol.extent.containsCoordinate(poly, ol.extent.getCenter(poly)));
console.log(ol.extent.containsXY(poly, ol.extent.getCenter(poly)));
console.log(ol.extent.containsExtent(poly, ol.extent.getCenter(poly)));

These (as far as I can tell) are the methods to check points/extents but I can't seem to get any working. This prev question is what I tried to get working https://stackoverflow.com/a/34949094

I'm displaying different TileLayers over a map as overlays and if a point is outside a certain layer's extent then I don't want to display that layer so I want to check whether a point is within or outside a given extent.

Any ideas? Many thanks

mr_magpie
  • 23
  • 2

1 Answers1

1

An extent should be in the form [minX, minY, maxX, maxY]

[-6.2212531, 53.3257768, -6.3122428, 53.3643417] is not valid

[-6.3122428, 53.3257768, -6.2212531, 53.3643417] is valid

Mike
  • 16,042
  • 2
  • 14
  • 30
  • I knew it was a bloody stupid mistake. I'd read the docs regarding extents and had (thought) I'd checked that properly. I half assumed it was OK as when I set that extent on my map as boundaries, it did stop it scrolling past, at what I thought were correct points. Thanks ever so much! – mr_magpie Dec 01 '22 at 13:45