Javascript 一次放下一个记号笔

Javascript 一次放下一个记号笔,javascript,ajax,google-maps,google-maps-api-3,Javascript,Ajax,Google Maps,Google Maps Api 3,我正在使用Google Maps Api v3,我试图在地图上一次删除一个标记,就像但我无法让它工作一样,这是我的代码,所有标记都是同时删除的 var map; var markers = []; function initialize() { var latlng = new google.maps.LatLng(52.520816, 13.410186); var options = { zoom: 5, center: latlng,

我正在使用Google Maps Api v3,我试图在地图上一次删除一个标记,就像但我无法让它工作一样,这是我的代码,所有标记都是同时删除的

var map;
var markers = [];

function initialize() { 
    var latlng = new google.maps.LatLng(52.520816, 13.410186);

    var options = {
        zoom: 5,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    map = new google.maps.Map(document.getElementById("map-canvas"), options);
}

initialize();

function loadMarkers() {  

    $.ajax({
       url: 'js/poi.php',
       type: 'GET',
       dataType : "json",
       success: function (data) {

            var latlngbounds = new google.maps.LatLngBounds();      


            $.each(data, function(index, point) {

                var marker = new google.maps.Marker({
                    position: new google.maps.LatLng(point.Lat, point.Lng),
                    animation: google.maps.Animation.DROP,
                    icon: 'img/marker.png'

                });


                markers.push(marker);
                latlngbounds.extend(marker.position);

            });

            var markerCluster = new MarkerClusterer(map, markers);
            map.fitBounds(latlngbounds);

        }

    });
}

loadMarkers();
我尝试在每个标记上使用超时,但我猜loadMarkers();我会马上把它们扔了

    setTimeout(function() {

        var marker = new google.maps.Marker({
            position: new google.maps.LatLng(point.Lat, point.Lng),
            animation: google.maps.Animation.DROP,
            icon: 'img/marker.png'

        });

    }, point.Id * 200);
有没有办法解决这个问题

编辑:poi.php文件列出我表格中的所有点,并按如下方式输出:

[
{"Id":"1","Lat":"52.511467","Lgn":"13.447179"},
{"Id":"2","Lat":"52.549061","Lgn":"13.422975"},
{"Id":"3","Lat":"52.497622","Lgn":"13.396110"},
{"Id":"4","Lat":"52.517683","Lgn":"13.394393"}
]
  • 将标记添加到地图时,将其添加到聚类器
  • 调整边界以在添加标记时显示标记
  • 修正了JSON中的输入错误(不知道这是否是个问题)
  • 将标记添加到地图时,将其添加到聚类器
  • 调整边界以在添加标记时显示标记
  • 修正了JSON中的输入错误(不知道这是否是个问题)
  • 将标记添加到地图时,将其添加到聚类器
  • 调整边界以在添加标记时显示标记
  • 修正了JSON中的输入错误(不知道这是否是个问题)
  • 将标记添加到地图时,将其添加到聚类器
  • 调整边界以在添加标记时显示标记
  • 修正了JSON中的输入错误(不知道这是否是个问题)

  • 首先使用以下值创建标记:

       var marker = new google.maps.Marker({
                position: new google.maps.LatLng(point.Lat, point.Lng),
                map: null,
                visible:false
        });
    
    设置一个用于超时计数器的变量,并在地图缩放更改时始终重置此变量(强制重新聚类的原因)

    观察标记的
    map\u changed
    -事件,以便在先前的聚集标记已从群集中移除时应用动画

    google.maps.event.addListener(marker,'map_changed',function(){
          var marker=this,map=this.getMap();
          //the marker has been clustered
          if(!this.getMap()){     
            this.setValues({visible:false});
          }
          //the marker is not a part of a cluster
          else{
            //the marker has been clustered before, set visible and animation with a delay
            if(!this.getVisible()){
                var counter=this.getMap().get('counter')+1;
                //set the new counter-value
                this.getMap().set('counter',counter);
                setTimeout(function(){marker.setValues({animation:google.maps.Animation.DROP,
                                                        visible:true});},
                           200*counter)
            }
          }
    
    
    });
    

    结果:

    首先使用以下值创建标记:

       var marker = new google.maps.Marker({
                position: new google.maps.LatLng(point.Lat, point.Lng),
                map: null,
                visible:false
        });
    
    设置一个用于超时计数器的变量,并在地图缩放更改时始终重置此变量(强制重新聚类的原因)

    观察标记的
    map\u changed
    -事件,以便在先前的聚集标记已从群集中移除时应用动画

    google.maps.event.addListener(marker,'map_changed',function(){
          var marker=this,map=this.getMap();
          //the marker has been clustered
          if(!this.getMap()){     
            this.setValues({visible:false});
          }
          //the marker is not a part of a cluster
          else{
            //the marker has been clustered before, set visible and animation with a delay
            if(!this.getVisible()){
                var counter=this.getMap().get('counter')+1;
                //set the new counter-value
                this.getMap().set('counter',counter);
                setTimeout(function(){marker.setValues({animation:google.maps.Animation.DROP,
                                                        visible:true});},
                           200*counter)
            }
          }
    
    
    });
    

    结果:

    首先使用以下值创建标记:

       var marker = new google.maps.Marker({
                position: new google.maps.LatLng(point.Lat, point.Lng),
                map: null,
                visible:false
        });
    
    设置一个用于超时计数器的变量,并在地图缩放更改时始终重置此变量(强制重新聚类的原因)

    观察标记的
    map\u changed
    -事件,以便在先前的聚集标记已从群集中移除时应用动画

    google.maps.event.addListener(marker,'map_changed',function(){
          var marker=this,map=this.getMap();
          //the marker has been clustered
          if(!this.getMap()){     
            this.setValues({visible:false});
          }
          //the marker is not a part of a cluster
          else{
            //the marker has been clustered before, set visible and animation with a delay
            if(!this.getVisible()){
                var counter=this.getMap().get('counter')+1;
                //set the new counter-value
                this.getMap().set('counter',counter);
                setTimeout(function(){marker.setValues({animation:google.maps.Animation.DROP,
                                                        visible:true});},
                           200*counter)
            }
          }
    
    
    });
    

    结果:

    首先使用以下值创建标记:

       var marker = new google.maps.Marker({
                position: new google.maps.LatLng(point.Lat, point.Lng),
                map: null,
                visible:false
        });
    
    设置一个用于超时计数器的变量,并在地图缩放更改时始终重置此变量(强制重新聚类的原因)

    观察标记的
    map\u changed
    -事件,以便在先前的聚集标记已从群集中移除时应用动画

    google.maps.event.addListener(marker,'map_changed',function(){
          var marker=this,map=this.getMap();
          //the marker has been clustered
          if(!this.getMap()){     
            this.setValues({visible:false});
          }
          //the marker is not a part of a cluster
          else{
            //the marker has been clustered before, set visible and animation with a delay
            if(!this.getVisible()){
                var counter=this.getMap().get('counter')+1;
                //set the new counter-value
                this.getMap().set('counter',counter);
                setTimeout(function(){marker.setValues({animation:google.maps.Animation.DROP,
                                                        visible:true});},
                           200*counter)
            }
          }
    
    
    });
    

    结果:

    感谢您的代码,如果标记未聚集,效果会很好。我尝试先只对未聚集的标记设置动画,然后,如果用户单击标记组,则对其中的标记设置动画。我担心启动时太多的标记动画会减慢网站的速度。我正在用你的提琴测试这个,如果我修复了它,我会在这里发布我尝试过了,但是我不能首先设置未聚集标记的动画,只有当用户点击它时才设置聚集标记的动画。任何帮助都会很好。感谢代码,如果标记没有聚集,效果会很好。我正在尝试首先仅为未聚集的标记设置动画,然后,如果用户单击标记组,则为其中的标记设置动画。我担心启动时太多的标记动画会减慢网站的速度。我正在用你的提琴测试这个,如果我修复了它,我会在这里发布我尝试过了,但是我不能首先设置未聚集标记的动画,只有当用户点击它时才设置聚集标记的动画。任何帮助都会很好。感谢代码,如果标记没有聚集,效果会很好。我正在尝试首先仅为未聚集的标记设置动画,然后,如果用户单击标记组,则为其中的标记设置动画。我担心启动时太多的标记动画会减慢网站的速度。我正在用你的提琴测试这个,如果我修复了它,我会在这里发布我尝试过了,但是我不能首先设置未聚集标记的动画,只有当用户点击它时才设置聚集标记的动画。任何帮助都会很好。感谢代码,如果标记没有聚集,效果会很好。我正在尝试首先仅为未聚集的标记设置动画,然后,如果用户单击标记组,则为其中的标记设置动画。我担心启动时太多的标记动画会减慢网站的速度。我正在用你的提琴测试这个,如果我修复了它,我会在这里发布我尝试过了,但是我不能首先设置未聚集标记的动画,只有当用户点击它时才设置聚集标记的动画。任何帮助都会很好。