1

我正在管理这个网站:http : //www.gprprojecten.nl 基本上我正在做的是从网络服务中获取数据流并对其进行处理。之后我对这些数据做了各种各样的事情,包括在谷歌地图上显示所有项目。问题是,随着项目数量的增长,(自定义)引脚开始重叠(不可见,不可点击)。

所以我想聚集我的别针。

我开始使用A32.blog作为起点来开发谷歌地图集群库。

但是现在出现了一个问题。由于我选择了一个名为filter.js的客户端过滤器系统,我依赖于使用谷歌地图的这种方式,它使用对象而不是集群器库中使用的标记数组。

下面是我结合 filter.js 用来生成地图的代码:

var googleMap = {
center_lat_lng: [52.14, 5.3],
map: null,
markers: {},
addMarker: function (project) {
    var that = this;
    var image = new google.maps.MarkerImage('@Url.Content("~/Content/img/marker.png")',
        new google.maps.Size(63, 27),
        new google.maps.Point(0, 0),
        new google.maps.Point(23, 27));
    var marker = new google.maps.Marker({
        position: new google.maps.LatLng(project.loclat, project.loclong),
        map: this.map,
        title: project.gebouwnaam,
        icon: image
    });

    marker.info_window_content = "<div class=\"gmapcontentwindow\"><h4>" + project.gebouwnaam + "</h4><img src=\"" + project.thumburl + "\" alt=\"" + project.gebouwnaam + "\" /><div class=\"gebouwdata\"><span class=\"date\">" + project.publicatiedatum + "</span><h5>" + project.plaats + "</h5><span>" + project.gebruiksfunctie + " | " + project.gebouwcategorie + "</span><span>" + project.licentiehouder + "</span><span class=\"stars " + project.rating + "\"></span>"
    if (project.akkoorddoorexpert == "True") {
        marker.info_window_content += "<span class=\"expert\"></span>"
    }
    var forwardUrl = '@Url.Content("~/Home/Details/")';
    marker.info_window_content += "<span  class=\"forward\"><a href=\"" + forwardUrl + project.id + "\" title=\"Bekijk " + project.gebouwnaam + " in detail\">Lees meer >></b></a></span></div></div>"
    this.markers[project.id] = marker

    google.maps.event.addListener(marker, 'click', function () {
        that.infowindow.setContent(marker.info_window_content)
        that.infowindow.open(that.map, marker);
    });
},

updateMarkers: function (filtering_result) {
    var google_map = this;
    $.each(google_map.markers, function () { this.setMap(null); })
    $.each(filtering_result, function () {
        google_map.markers[this.id].setMap(google_map.map);
    });
},

init: function () {
    var options = {
        center: new google.maps.LatLng(this.center_lat_lng[0], this.center_lat_lng[1]),
        zoom: 8,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    this.map = new google.maps.Map(document.getElementById("gmap"), options)

    this.infowindow = new google.maps.InfoWindow({

    });
    //var markersarray = $(this.markers).toArray();
    //console.log(markersarray);
    //doet het nog niet???
    //http://a32.me/2012/05/handling-huge-amount-of-markers-on-google-maps-with-clusters/
    //var markerCluster = new MarkerClusterer(this.map, markersarray, {
    //  gridSize: 10,
    //  minimumClusterSize: 2
    //});
}
};

project 是一个从 filter.js 传递给 init 函数的对象

4

1 回答 1

0

您需要将 Marker Clusterer 添加到全局范围或在对象中保留对它的引用。

于 2013-06-17T17:09:23.130 回答