从数组中删除标记后更新markercluster [英] update markercluster after removing markers from array
问题描述
我有两个数组,其中一个是所有标记(称为标记),另一个是与搜索条件匹配的标记称为current_markers)。这些都是从第一个数组中找到的。
然后我在屏幕上绘制current_markers。
然而,我发现那么markerclusterer库不会基于这个变化进行更新。
那么我怎样才能更新markerclusterer?
是否有可能将markerclusterer分配给一个变量并调用更新函数?
您应该将标记对象存储在var然后取消设置地图,如下所示:
var markerCluster = new MarkerClusterer(map,markers);
/// ...稍后在
markerCluster.setMap(null);
完成此操作后,您可以初始化新的MarkerClusterer
添加新标记
更新
谷歌地图的UI插件这里有一些额外的代码。我甚至在类 reset_markercluster
ofcourse的按钮上添加了一个点击,这只是示出如何使用它来调用地图
var _map,_markerCluster;
$ b $(函数(){
$('#map_canvas')。gmap()。bind('init',function(event,map){
_map = map ; //此时,您可以在需要调用地图时调用_map
//在这里构建标记...
_markerCluster = new MarkerClusterer(_map,标记); //你也可以使用map来代替_map,因为它在这个函数中仍然存在
$(button.reset_markercluster)。click(function(e ){
e.preventDefault();
_markerCluster.setMap(null); //删除之前添加的markerCluster
//在这里重建您的标记...
_markerCluster = new MarkerClusterer(_map,newMarkers);
});
});
I am currently using markercluster plugin with jquery ui maps.
I have two arrays one of all markers (called markers) and one of markers that match search criteria (called current_markers). These are fitered from the first array.
I then draw the current_markers on screen.
I am finding however that the markerclusterer library is not updating based on this change.
So how can I update the markerclusterer?
Is it possible to assign the markerclusterer to a variable and call an update function?
You should store the marker object in a var and then unset the map as following:
var markerCluster = new MarkerClusterer(map, markers);
/// ... later on
markerCluster.setMap(null);
after you've done this, you could init a new MarkerClusterer
with new markers
Update
since you are using google maps ui plugin here's some additional code. I've added a click even on a button with class reset_markercluster
ofcourse this is just to show how to use it to call the map
var _map, _markerCluster;
$(function() {
$('#map_canvas').gmap().bind('init', function(event, map) {
_map = map; // at this point you can call _map whenever you need to call the map
// build up your markers here ...
_markerCluster = new MarkerClusterer(_map, markers); // you could also use map instead of _map here cause it's still present in this function
});
$("button.reset_markercluster").click(function(e) {
e.preventDefault();
_markerCluster.setMap(null); // remove's the previous added markerCluster
// rebuild you markers here ...
_markerCluster = new MarkerClusterer(_map, newMarkers);
});
});
这篇关于从数组中删除标记后更新markercluster的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!