Gmap.js如何隐藏(不删除)标记。在任何地方都找不到

时间:2014-07-04 22:24:01

标签: jquery google-maps google-maps-markers

使用*gmap.js
我正在尝试创建一个过滤器,以显示某些包含特定标记的Google地图标记。

我在这里设置了一个小演示jsFiddle - > http://jsfiddle.net/2PP5a/1/

gmap.js似乎没有显示如何" HIDE"标记。他们展示了如何" DELETE"但不要隐藏一旦你隐藏了标记,你怎么把它带回来?

我不知道从哪里开始。任何意见,将不胜感激。谢谢!

$(document).ready(function(){

$("#ex2").slider({});

  map = new GMaps({
    el: '#map',
    lat: 29.5714305,
    lng: -98.6744044,
    zoom:10,
    zoomControl : true,
    zoomControlOpt: {
        style : 'BIG',
        position: 'TOP'
    },
    panControl : false,
    streetViewControl : false,
    mapTypeControl: false,
    overviewMapControl: false
  }); 

var orangex = '|FFa500|000000';
var bluex = '|0000FF|FFFFFF';
var redx = '|FF0000|FFFFFF';
var xcol;



    $('.markers li a').each(function(){
        var $this = $(this),
        latlng = $this.data('latlng').split(','),
        color = $this.data('color'),
        place = $this.data('place'),
        myval = $this.data('val'),
        titlex = $this.data('title');

     // if(isNaN(latx)) { alert('not a number'); } else { alert('yep its a number');}
        if(color=='orange') {xcol = orangex;} 
        else if (color=='blue') {xcol = bluex;}
      else if (color=='red') {xcol = redx;}
      else {xcol=orangex;}

        map.addMarker({
            lat: latlng[0],
            lng: latlng[1],
            tag:[color, myval, place],
            icon: "http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=" + myval + xcol,
            title: titlex
        });
    });
});

1 个答案:

答案 0 :(得分:2)

removeMarkers - 方法清除markers - 集合,当您使用此方法时,标记将不再可访问。

迭代标记并将map - 属性设置为null或map-instance:

//hide all markers:
$.each(map.markers,function(){this.setMap(null)});
//show all markers:
$.each(map.markers,function(){this.setMap(map.map)});
相关问题