谷歌地图集群和richmarker [英] google map cluster and richmarker

查看:131
本文介绍了谷歌地图集群和richmarker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是关于Google Map的集群和Rails上的ruby上的richmarker

The question is about google map's cluster and richmarker on ruby on rails

最近,我正在使用Ruby on Rails开发Web应用程序, 昨天我发现了一个至关重要的问题,这是我的JavaScript:

Recently I am developing a web application with Ruby on Rails, I found a vital problem yesterday, here is my javascript:

//Build initialize Gmap and build markers on it
//initialize array
var map_infos = [];
//receive marker data from controller
map_infos = gon.map_infos; 

function initialize() {
    var mapOptions = {
        zoom: 8,
        center: new google.maps.LatLng(25.026, 121.523)
    };

    var map = new google.maps.Map(document.getElementById('map'), mapOptions);

//rmarker setting
    var rmarkers = [];
    for(var i = 0; i < map_infos.length; i++){
    var rmarker = new RichMarker({
        position: new google.maps.LatLng(
            map_infos[i]["marker_lat"], 
            map_infos[i]["marker_lng"]
        ),
        content: '<div class="marker_background"><img src="'+map_infos[i]["friend_icon"]+'" class="friend_icon" /></div>',
        map: map
    }).setShadow('5px -3px 3px #555');
    rmarkers.push(rmarker);
    }
    var markerCluster = new MarkerClusterer(map, rmarkers);
}

google.maps.event.addDomListener(window, 'load', initialize);

但是在上述情况下,群集功能不起作用! 它仍然显示每个标记!

But in the case above cluster function doesn't work! It still show every single marker!

所以我将richmarker更改为如下所示的google默认标记:

So I change richmarker to the google default marker like below:

var rmarker = new google.maps.Marker({
    for(var i = 0; i < map_infos.length; i++){
    var marker = new google.maps.Marker({
        position: new google.maps.LatLng(
        map_infos[i]["marker_lat"], 
        map_infos[i]["marker_lng"]
    ),
    map: map
    });
    markers.push(marker);
    }
    var markerCluster = new MarkerClusterer(map, rmarkers);
});

集群现在可以使用!

所以问题是:

如何同时使用Richmarker和集群?

How can I user richmarker and cluster in the meantime?

推荐答案

我只是在尝试做同样的事情,并且通过使用以下代码(在Angular中,它应该与您足够相似)使它第一次工作也许您需要将更多属性传递给RichMarker?

I was just trying to do the same thing and got it to work the first time through using the following code (in Angular but should be similar enough to you) maybe you need to pass more properties to the RichMarker?

$scope.dynMarkers.push(
          new RichMarker({
                        map: $scope.map, 
                        position: position,
                        draggable: false,
                        flat: true,
                        anchor: RichMarkerPosition.MIDDLE,
                        content: '<div>some map marker</div>',
                    }));

然后:

$scope.markerClusterer = new MarkerClusterer($scope.map, $scope.dynMarkers, {
            gridSize: 25
        });

这篇关于谷歌地图集群和richmarker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆