使用标记对象而不是数组时,群集谷歌地图引脚

时间:2013-06-12 15:02:30

标签: google-maps-api-3 markerclusterer

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

所以我想把我的别针聚集在一起。

我开始使用a google maps clusterer library 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函数的对象

1 个答案:

答案 0 :(得分:0)

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