linuxoid
linuxoid

Reputation: 1447

HERE Maps JavaScript API: how to get info from click on cluster marker

Following these 2 docs:

https://developer.here.com/documentation/examples/maps-js/clustering/custom-cluster-theme

https://developer.here.com/documentation/maps/3.1.30.3/dev_guide/topics/clustering.html

I have a cluster of markers. But the target data from clicking on the cluster marker is different from that from clicking on the noise marker.

  1. How can I get data from the cluster and noise markers on click to show in a bubble without overriding the theme? How do I distinguish which one was clicked: cluster or noise? Because if I simply do this:
clusteredDataProvider.addEventListener('tap', function(event) {
  let data = event.target.getData();
  console.log(data)
});

the data I need will be in data.c.a.data from cluster and in data.a.data from noise.

  1. How do I stop the ridiculous zoom-in and zoom-out effect when clicking on a cluster marker? Because if the map is set to zoom 2 and the noise markers are on zoom 16, when you click on the cluster marker it starts zooming all the way from 2 to 16 and then straight back to 2 without even a chance of loading the maps. This is awful. How can I stop it?

Thank you.

Upvotes: 0

Views: 648

Answers (1)

linuxoid
linuxoid

Reputation: 1447

  1. The only way which works so far is only with overriding the theme and getting a random point on clicking the cluster, the random point data is the same object as the noise data. Can't figure out how to do that without that.

  2. To stop that insane zoom in and out on clicking markers, I've added:

let zoom = map.getZoom();

map.setCenter(position, zoom > 6 ? true : false);

if (zoom < 7) {
    map.setZoom(7, true);
}

It's the animated centering followed by animated zooming which does that. So I'm centering the map without animation at the lowest zoom and then animate zoom in. I animate centering only when the zoom is at below the cluster marker level.

Upvotes: 0

Related Questions