简体   繁体   English

Markerclusterer-基于连续标记数组中的特定ID触发特定标记的点击事件

[英]Markerclusterer - Triggering click event of a specific marker based on it's 'id' within a continuous marker array

Before implementing MarkerClusterer, I've been able to trigger the click event of specific markers (which then brings up a panel specific to that marker) by first loading up the marker array like this: 在实施MarkerClusterer之前,我已经能够通过首先加载如下标记数组来触发特定标记的click事件(然后弹出特定于该标记的面板):

markers[marker.id] = marker;

(Where marker.id is a property set when drawing the marker from the JSON, that corresponds to a user record in my database) (其中marker.id是从JSON绘制标记时设置的属性,与我数据库中的用户记录相对应)

Then calling: 然后调用:

google.maps.event.trigger(markers[id], 'click');

(Where 'id' is the user's id I want to click the marker for) (“ id”是我要为其单击标记的用户的ID)

Now that I want to use MarkerClusterer however, it won't cluster using the array loading method I use above, I assume because there are then 'gaps' in my marker array as I don't draw markers for all users. 现在,我想使用MarkerClusterer,它不会使用我上面使用的数组加载方法进行聚类,我认为是因为在我的标记数组中存在“空白”,因为我没有为所有用户绘制标记。

...MarkerClusterer works when I load my marker array like this: ...当我像这样加载标记数组时,MarkerClusterer可以工作:

markers.push(marker);

I assume this gives a continuous array without gaps that MarkerClusterer can read... but now I can't trigger the correct marker's click by it's index in the array. 我假设这提供了一个连续的数组,没有MarkerClusterer可以读取的间隙...但是现在我无法通过其在数组中的索引来触发正确的标记单击。

So it seems I need a way of finding the .indexOf a marker in the continuous marker array based on marker.id... 因此,似乎我需要一种方法在基于marker.id的连续标记数组中找到.indexOf标记...

Any help would be much appreciated. 任何帮助将非常感激。

You have at least 2 options: 您至少有2个选择:

  1. iterate through the "continuous" array of markers looking for the one that has the correct id (inefficient, requires additional processing with large numbers of markers), then trigger the click event on that. 遍历标记的“连续”数组以查找具有正确ID(效率低下,需要使用大量标记进行额外处理)的标记,然后触发该事件的click事件。
  2. create your associative array also, use it for triggering the click event (inefficient, requires memory for an additional array) 还创建您的关联数组,将其用于触发click事件(效率低下,需要额外的内存来存储数组)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM