Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/384.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 谷歌地图聚类标记_Javascript_Google Maps_Google Maps Api 3_Google Maps Markers_Markerclusterer - Fatal编程技术网

Javascript 谷歌地图聚类标记

Javascript 谷歌地图聚类标记,javascript,google-maps,google-maps-api-3,google-maps-markers,markerclusterer,Javascript,Google Maps,Google Maps Api 3,Google Maps Markers,Markerclusterer,我正在尝试在我的地图上添加集群,我正在使用的代码工作正常,但是上面没有clustring,我不知道如何将集群添加到此代码中 (function (namespace, $, undefined) { // map the namespace to that var that = namespace; var markers = []; var dealers = []; var googleMap; var tmpDealer = "";

我正在尝试在我的地图上添加集群,我正在使用的代码工作正常,但是上面没有clustring,我不知道如何将集群添加到此代码中

(function (namespace, $, undefined) {

    // map the namespace to that
    var that = namespace;

    var markers = [];
    var dealers = [];
    var googleMap;
    var tmpDealer = "";

   function AddMarkers(aar, map, show) {
        if (aar.length > 0) {
            var image = '/Files/Templates/Designs/Mobler/images/MapMarker.png';
            for (var i = 0; i < aar.length; i++) {
                markers.push( new google.maps.Marker({
                    position: new google.maps.LatLng(parseFloat( aar[i].Latitude),parseFloat(aar[i].Longitude)),
                    map: map,
                    title: aar[i].Name,
                    icon: image,
                    DealerId: aar[i].DealerId,
                    DealerPage: aar[i].Area
                }));
            }
            for (var i = 0; i < markers.length; i++) {
                if (show) {
                    google.maps.event.addListener(markers[i], "click", function () {

                      tmpDealer = this.DealerPage;
                      MoblerLandingPage.SetCookie("/Default.aspx" + tmpDealer, false);
                      MoblerLandingPage.SetAreaName("/Default.aspx?AreaID=" + this.DealerPage, function() {
                        setTimeout(function() {
                            var area = $.cookie("MoblerAreaName");
                            document.location = "http://" + document.domain + "/" + area;
                        }, 250);
                      });
                    });
                } else {
                    google.maps.event.addListener(markers[i], "click", that.onMarkerClick)
                }
            }
        }
    }


    var InfoBoxOptions2 = {
       content: ""
      , disableAutoPan: false
      , maxWidth: 0
      , pixelOffset: new google.maps.Size(-75, -5)
      , zIndex: null
      , boxClass: "DealerMapInfoBox"
      , closeBoxMargin: "5px"
      , closeBoxURL: "/Files/Templates/Designs/SmagOgBehag/images/infoBoxClose.png"
      , infoBoxClearance: new google.maps.Size(1, 1)
      , isHidden: false
      , pane: "floatPane"
      , enableEventPropagation: false
      , alignBottom : true
    };
    var infoBox2 = new InfoBox(InfoBoxOptions2);



    that.Initialize = function(mapId, dealerArray, show){
        dealers = dealerArray;

        var mapOptions = {
            center: new google.maps.LatLng(56.22, 11.32),
            zoom: 7,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        if(!show){
        var mapOptions = {
            center: new google.maps.LatLng(56.22, 11.32),
            zoom: 5,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };

        }
        googleMap = new google.maps.Map(document.getElementById(mapId), mapOptions);



        if(dealerArray.constructor === Array && dealerArray.length > 0){
            AddMarkers(dealers, googleMap, show);


        }

        if(!show){

            google.maps.event.addListener(googleMap, 'click', function () {
                infoBox2.close();
            });
        }
    }

    that.onMarkerClick = function(){

        var marker = this;
        infoBox2.content_ = $('#Dealer' + marker.DealerId + ' li a').html();
        infoBox2.open(marker.map, marker);
    }

    that.ShowDealerOnMap = function(dealerId) {
        for (var i = 0; i < markers.length; i++) {
            if (markers[i].DealerId == dealerId) {
            var marker = markers[i];
            marker.map.setZoom(15);
            marker.map.panTo(marker.getPosition())
            infoBox2.content_ = $('#Dealer' + marker.DealerId).html()
            infoBox2.open(marker.map, marker);
            }
        }
    }
(函数(名称空间,$,未定义){
//将名称空间映射到该名称空间
var=namespace;
var标记=[];
var交易商=[];
谷歌地图;
var tmpDealer=“”;
功能添加标记(aar、地图、显示){
如果(aar.length>0){
var image='/Files/Templates/Designs/Mobler/images/MapMarker.png';
对于(变量i=0;i0){
AddMarkers(经销商、谷歌地图、展会);
}
如果(!show){
google.maps.event.addListener(googleMap,'click',函数(){
infoBox2.close();
});
}
}
that.onMarkerClick=函数(){
var标记=这个;
infoBox2.content_35;=$('#Dealer'+marker.DealerId+'li a').html();
infoBox2.打开(marker.map,marker);
}
that.ShowDealerOnMap=函数(dealerId){
对于(var i=0;i
请参见:

您可以创建基于矩形或基于正方形的簇。

您是否查看了?您可以看到一个使用
MarkerClusterer的工作示例

//Create your map
var center = new google.maps.LatLng(37.4419, -122.1419);
var options = {
  'zoom': 13,
  'center': center,
  'mapTypeId': google.maps.MapTypeId.ROADMAP
};

var map = new google.maps.Map(document.getElementById("map"), options);

//Create the clusterer and its options
var mcOptions = {gridSize: 50, maxZoom: 15};
var markers = [...]; // Create the markers you want to add and collect them into a array.
//Add the clusterer to the map, and the markers to the clusterer.
var mc = new MarkerClusterer(map, markers, mcOptions);
请注意,如果没有很多标记,则必须更改一些选项才能看到群集器工作。更改群集器工作的
maxZoom
,以及网格的大小(
gridSize
选项)。

有关所有选项的完整列表,请参阅

您没有创建marker clusterer。请参阅我尝试了它,但无法使其工作……您可以尝试用我的代码给我举一个小例子吗?我对您的代码不是很熟悉,但通常,您所要做的只是在地图初始化之后定义
mcOptions
,然后,定义填充包含所有标记的数组后,
mc