Search code examples
javascripthere-apiheremaps

Here Maps: Currently visible markers


I have a HERE maps based javascript map on a website with a list of markers. When the user zooms and pans the map, the mapviewchangeend event is triggered.

In that event, how can I find out which markers are currently visible?

The H.Maps object has a getObjectsWithin method, but that one needs a polygon - which I don't know how to obtain.


Solution

  • As polygon you should use the bounds from ViewModel's getLookAtData method:

    map.addEventListener('mapviewchangeend', (e) => {
      let bounds = map.getViewModel().getLookAtData().bounds;
      map.getObjectsWithin(bounds, (objects) => {
        console.log(objects);
      })
    })
    

    For more information check the H.map.ViewModel.getObjectsWithin documentation.