问题
I am trying to make clusters of H.map.DomMarker
, which are using H.map.DomIcon
with the HTML code. But the native Here Map clustering doesn't work. Only if I use simple H.map.Icon
, but as this is rendered as a canvas
layer, I cannot use my own markers.
Is there any way how to get clusters on DomIcon
?
Edit: Also, is there any way how to get list of markers inside cluster?
Thanks Dan
回答1:
This should be possible using the code from Map clustering with custom theme, because the clustering itself is agnostic to the resulting icon.
The first key part of the clustering in the example is to create a collection of H.clustering.DataPoint(item.latitude, item.longitude, null, item)
which contains lat, lon. The clustering is based on those coordinates, and on the algorithm configuration.
The other key part is the theme itself which contains two function definitions:
getClusterPresentation
which is responsible for returning theH.map.Marker
of points clustered togethergetNoisePresentation
which is responsible for returning theH.map.Marker
of non clustered points
Since H.map.DomMarker
is a H.map.Marker
, having the two above functions returning H.map.DomMarker
should work.
Is there any way how to get list of markers inside cluster
Yes. When you create the marker for the cluster, in getClusterPresentation
, you get the points which are being clustered together (see cluster.forEachDataPoint
function). And before, when you create the datapoints, you had the chance to store data in it. So it is a good time to get data from those datapoints being clustered together, and reference it in the cluster marker if necessary.
Hope it makes sense!
Additionally
[...] if I use simple H.map.Icon, but as this is rendered as a canvas layer, I cannot use my own markers
Actually you can do all of the above with H.map.Icon
and markers rendered in the canvas. Some things are a bit less obvious though, like setting a pointer cursor when hovering on a cluster or a noisepoint.
来源:https://stackoverflow.com/questions/52724857/clustering-for-domicon