ehog
ehog

Reputation: 75

Current screen bounding box in OpenLayers 3

I have a map that contains a lot of features that are added dynamically.

I want to detech the last added point if it is on the screen, or not. And when it is, i want to play a short notofication sound.

Like this:

if (ol.extent.containsCoordinate(map.getExtent(), ol.proj.transform([parseFloat(data.lon), parseFloat(data.lat)], 'EPSG:4326', 'EPSG:3857')))
{
  var audio = new Audio('tick.wav');
  audio.play();
}

But I cannot find any method to get the current bounding of the screen in the docs of OpenLayers 3.

Upvotes: 1

Views: 1411

Answers (1)

ehog
ehog

Reputation: 75

I found the solution, this is missing from the docs.

if (ol.extent.containsCoordinate(map.getView().calculateExtent(map.getSize()), ol.proj.transform([parseFloat(data.lon), parseFloat(data.lat)], 'EPSG:4326', 'EPSG:3857')))
{
  var audio = new Audio('tick.wav');
  audio.play();
}

Upvotes: 2

Related Questions