在Google地图中切换标记

时间:2014-06-20 12:57:31

标签: javascript google-maps google-maps-api-3

我创建了一个带有切换按钮的热图。我无法为叠加标记创建切换按钮。请参阅下面我的代码所在的位置。任何建议将不胜感激。请注意我是编码的初学者。感谢。

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Heatmaps</title>
    <style>
      html, body, #map-canvas {
        height: 100%;
        margin: 0px;
        padding: 0px
      }
      #panel {
        position: absolute;
        top: 5px;
        left: 50%;
        margin-left: -180px;
        z-index: 5;
        background-color: #fff;
        padding: 5px;
        border: 1px solid #999;
      }
    </style>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=visualization"></script>
    <script>    
// Adding 500 Data Points
var map, pointarray, heatmap;

var taxiData = [
  new google.maps.LatLng(48.123662,-1.643964),
  new google.maps.LatLng(46.634315,2.169605),
  new google.maps.LatLng(42.554742,9.424047),
  new google.maps.LatLng(48.858082,2.406691),
  new google.maps.LatLng(45.774601,3.084719),
  new google.maps.LatLng(43.696036,7.26559),
  new google.maps.LatLng(44.24778,6.899449),
  new google.maps.LatLng(44.37775,4.696981),
  new google.maps.LatLng(47.229136,4.864319),
  new google.maps.LatLng(46.629681,-1.859237),
  new google.maps.LatLng(46.094375,6.101822),
  new google.maps.LatLng(48.567923,7.754859),
  new google.maps.LatLng(44.849198,-0.541271),
  new google.maps.LatLng(43.617936,1.496382),
  new google.maps.LatLng(46.765741,5.532997),
  new google.maps.LatLng(47.255505,-1.516551),
  new google.maps.LatLng(43.527036,-1.472729),
  new google.maps.LatLng(46.634315,2.169605),
  new google.maps.LatLng(45.362713,5.591349),
  new google.maps.LatLng(49.884875,2.312979),
  new google.maps.LatLng(48.847309,2.38938),
  new google.maps.LatLng(48.839293,2.237662),
  new google.maps.LatLng(46.675392,5.160472),
  new google.maps.LatLng(48.881233,2.375416),
  new google.maps.LatLng(43.8462,6.509824),
  new google.maps.LatLng(43.537399,6.464099),
  new google.maps.LatLng(42.697283,9.450881),
  new google.maps.LatLng(48.859741,2.356039),
  new google.maps.LatLng(43.286828,-0.398901),
  new google.maps.LatLng(47.478419,-0.563166),
  new google.maps.LatLng(47.564024,1.457195),
  new google.maps.LatLng(47.35243,-0.765284),
  new google.maps.LatLng(48.838542,2.251592),
  new google.maps.LatLng(48.884131,2.377569),
  new google.maps.LatLng(43.538834,5.404427),
  new google.maps.LatLng(43.62706,3.861149),
  new google.maps.LatLng(46.094375,6.101822),
  new google.maps.LatLng(43.365911,5.786789),
  new google.maps.LatLng(48.601986,7.783522),
  new google.maps.LatLng(47.311948,-1.562837),
  new google.maps.LatLng(48.782467,2.056275),
  new google.maps.LatLng(44.841249,-0.584617),
  new google.maps.LatLng(43.985009,6.761768),
  new google.maps.LatLng(48.833802,2.231579),
  new google.maps.LatLng(48.848392,2.420592),
  new google.maps.LatLng(43.489477,-1.483008),
  new google.maps.LatLng(47.099943,-1.126837),
  new google.maps.LatLng(44.811935,-0.557277),
  new google.maps.LatLng(48.881229,2.332641),
  new google.maps.LatLng(43.365911,5.786789),
  new google.maps.LatLng(45.649392,5.859076),
  new google.maps.LatLng(48.042408,7.412067),
  new google.maps.LatLng(48.119265,-1.686494),
  new google.maps.LatLng(47.096348,-1.296771),
  new google.maps.LatLng(46.233528,6.43959),
  new google.maps.LatLng(48.843394,2.241663),
  new google.maps.LatLng(49.376983,3.314011),
  new google.maps.LatLng(48.871061,2.328756),
  new google.maps.LatLng(44.733952,-0.527327),
  new google.maps.LatLng(48.224227,-0.873659),
  new google.maps.LatLng(48.794639,2.378953),
  new google.maps.LatLng(48.341818,2.56375),
  new google.maps.LatLng(45.984127,4.719295),
  new google.maps.LatLng(48.839293,2.237662),
  new google.maps.LatLng(50.467366,2.994484),
  new google.maps.LatLng(48.702575,2.069613),
  new google.maps.LatLng(48.88908,2.348273),
  new google.maps.LatLng(47.369173,0.710714),
  new google.maps.LatLng(46.148348,6.082363),
  new google.maps.LatLng(45.255739,5.85841),
  new google.maps.LatLng(48.832222,2.355556),
  new google.maps.LatLng(46.904064,6.352804),
  new google.maps.LatLng(45.016902,0.107567),
  new google.maps.LatLng(48.963963,1.931649),
  new google.maps.LatLng(50.633557,3.080825),
  new google.maps.LatLng(44.812114,-0.572571),
  new google.maps.LatLng(43.721714,7.257167),
  new google.maps.LatLng(48.629989,2.316041),
  new google.maps.LatLng(46.840121,0.544357),
  new google.maps.LatLng(50.732621,3.048188),
  new google.maps.LatLng(48.075871,-1.837195),
  new google.maps.LatLng(48.856803,2.384695),
  new google.maps.LatLng(43.604626,1.444205),
  new google.maps.LatLng(43.543483,3.699367),
  new google.maps.LatLng(43.541147,5.44595),
  new google.maps.LatLng(43.582739,7.048461),
  new google.maps.LatLng(48.823742,2.138747),
  new google.maps.LatLng(48.894501,2.348031),
  new google.maps.LatLng(50.640762,3.028105),
  new google.maps.LatLng(45.016902,0.107567),
  new google.maps.LatLng(48.812765,2.505835),
  new google.maps.LatLng(49.861383,3.266843),
  new google.maps.LatLng(45.93329,6.72161),
  new google.maps.LatLng(47.242722,6.014451),
  new google.maps.LatLng(45.995656,6.93152),
  new google.maps.LatLng(49.116356,-1.072664),
  new google.maps.LatLng(43.698172,7.277086),
  new google.maps.LatLng(50.515557,2.89949),
  new google.maps.LatLng(45.568432,5.167227),
  new google.maps.LatLng(41.11574,1.242462),
  new google.maps.LatLng(48.870025,2.227772),
  new google.maps.LatLng(43.575798,7.105431),
  new google.maps.LatLng(43.831638,4.352155),
  new google.maps.LatLng(48.853298,2.342974),
  new google.maps.LatLng(48.873476,2.331369),
  new google.maps.LatLng(47.904009,1.899794),
  new google.maps.LatLng(47.324054,5.039088),
  new google.maps.LatLng(48.88908,2.348273),
  new google.maps.LatLng(50.515557,2.89949),
  new google.maps.LatLng(46.141102,6.155885),
  new google.maps.LatLng(48.888153,3.328836),
  new google.maps.LatLng(48.822966,2.341676),
  new google.maps.LatLng(43.661683,3.922025),
  new google.maps.LatLng(45.594835,3.024943),
  new google.maps.LatLng(50.255477,3.916604),
  new google.maps.LatLng(48.837459,2.305306),
  new google.maps.LatLng(49.685167,4.769419),
  new google.maps.LatLng(44.164912,4.621838),
  new google.maps.LatLng(48.829325,2.345814),
  new google.maps.LatLng(48.855359,2.445231),
  new google.maps.LatLng(48.179176,6.445136),
  new google.maps.LatLng(43.539447,5.446254),
  new google.maps.LatLng(49.044499,2.108901),
  new google.maps.LatLng(48.73408,1.37073),
  new google.maps.LatLng(50.600347,3.052344),
  new google.maps.LatLng(48.87922,2.287978),
  new google.maps.LatLng(43.273183,5.430614),
  new google.maps.LatLng(48.808026,2.192418),
  new google.maps.LatLng(48.945108,2.149682),
  new google.maps.LatLng(47.861361,5.332175),
  new google.maps.LatLng(41.39402,2.139957),
  new google.maps.LatLng(43.571167,-0.930737),
  new google.maps.LatLng(44.335488,2.633824),
  new google.maps.LatLng(43.509078,-1.522487),
  new google.maps.LatLng(43.432038,2.169639),
  new google.maps.LatLng(47.35243,-0.765284),
  new google.maps.LatLng(48.808026,2.192418),
  new google.maps.LatLng(45.18943,5.716541),
  new google.maps.LatLng(45.269575,5.866406),
  new google.maps.LatLng(43.381993,-0.341715),
  new google.maps.LatLng(48.809224,2.300583),
  new google.maps.LatLng(46.678024,5.521458),
  new google.maps.LatLng(43.055106,-0.432195),
  new google.maps.LatLng(48.755071,2.308439),
  new google.maps.LatLng(49.400139,2.80382),
  new google.maps.LatLng(48.55475,2.003027),
  new google.maps.LatLng(48.865074,2.346438),
  new google.maps.LatLng(45.95165,6.10581),
  new google.maps.LatLng(45.777969,4.827925),
  new google.maps.LatLng(45.766823,4.83624),
  new google.maps.LatLng(43.118996,6.007346),
  new google.maps.LatLng(43.118996,6.007346),
  new google.maps.LatLng(45.18943,5.716541),
  new google.maps.LatLng(46.19535,6.298984),
  new google.maps.LatLng(48.903045,2.281309),
  new google.maps.LatLng(47.899183,-4.097376),
  new google.maps.LatLng(45.389805,-0.590545),
  new google.maps.LatLng(48.991379,2.051722),
  new google.maps.LatLng(45.747795,4.881128),
  new google.maps.LatLng(43.50386,5.733533),
  new google.maps.LatLng(45.911217,6.163627),
  new google.maps.LatLng(43.663739,7.14882),
  new google.maps.LatLng(50.613811,3.04236),
  new google.maps.LatLng(45.18943,5.716541),
  new google.maps.LatLng(45.415284,6.634407),
  new google.maps.LatLng(44.005968,5.115916),
  new google.maps.LatLng(48.852845,1.874855),
  new google.maps.LatLng(48.596155,2.294114),
  new google.maps.LatLng(45.750018,4.886358),
  new google.maps.LatLng(47.512678,5.176868),
  new google.maps.LatLng(43.462224,4.934523),
  new google.maps.LatLng(46.077695,6.407744),
  new google.maps.LatLng(48.834738,2.321883),
  new google.maps.LatLng(48.85764,7.334788),
  new google.maps.LatLng(48.886837,2.409455),
  new google.maps.LatLng(45.255908,5.90436),
  new google.maps.LatLng(48.461481,7.503148),
  new google.maps.LatLng(43.785493,7.231573),
  new google.maps.LatLng(47.31847,5.042767),
  new google.maps.LatLng(44.777547,-0.647259),
  new google.maps.LatLng(47.740128,7.344742),
  new google.maps.LatLng(43.118996,6.007346),
  new google.maps.LatLng(49.19316,2.468739),
  new google.maps.LatLng(48.843491,2.351834),
  new google.maps.LatLng(46.258296,-0.341284),
  new google.maps.LatLng(45.160562,1.544387),
  new google.maps.LatLng(44.857522,0.118771),
  new google.maps.LatLng(43.595603,1.448128),
  new google.maps.LatLng(45.761436,4.83572),
  new google.maps.LatLng(48.34564,5.688499),
  new google.maps.LatLng(48.34564,5.688499),
  new google.maps.LatLng(48.835035,2.505075),
  new google.maps.LatLng(49.36404,6.151245),
  new google.maps.LatLng(45.889481,6.797537),
  new google.maps.LatLng(48.837044,2.398231),
  new google.maps.LatLng(43.557341,1.376799),
  new google.maps.LatLng(47.249231,6.390369),
  new google.maps.LatLng(45.743772,4.849373),
  new google.maps.LatLng(48.34564,5.688499),
  new google.maps.LatLng(48.34564,5.688499),
  new google.maps.LatLng(48.34564,5.688499),
  new google.maps.LatLng(45.889513,6.797366),
  new google.maps.LatLng(48.01578,0.160927),
  new google.maps.LatLng(42.585238,2.442451),
  new google.maps.LatLng(45.935889,6.630435),
  new google.maps.LatLng(48.840276,2.295195),
  new google.maps.LatLng(45.752177,4.840407),
  new google.maps.LatLng(50.418715,1.633277),
  new google.maps.LatLng(45.389805,-0.590545),
  new google.maps.LatLng(45.179993,5.691712),
  new google.maps.LatLng(48.806897,2.422771),
  new google.maps.LatLng(43.64152,7.009186),
  new google.maps.LatLng(44.843641,-0.586002),
  new google.maps.LatLng(43.598156,1.330154),
  new google.maps.LatLng(45.802264,3.263245),
  new google.maps.LatLng(48.895973,2.2772),
  new google.maps.LatLng(49.125624,2.209586),
  new google.maps.LatLng(48.73204,6.236217),
  new google.maps.LatLng(48.512694,-4.068346),
  new google.maps.LatLng(48.892075,2.294136),
  new google.maps.LatLng(45.572325,5.918308),
  new google.maps.LatLng(42.6058,3.034722),
  new google.maps.LatLng(49.115841,2.419535),
  new google.maps.LatLng(49.242612,4.035363),
  new google.maps.LatLng(46.455822,-0.691506),
  new google.maps.LatLng(46.57319,0.364371),
  new google.maps.LatLng(43.590745,1.44569),
  new google.maps.LatLng(47.31847,5.042767),
  new google.maps.LatLng(45.508278,2.922375),
  new google.maps.LatLng(48.708526,2.125599),
  new google.maps.LatLng(44.377632,5.025705),
  new google.maps.LatLng(48.848545,2.319217),
  new google.maps.LatLng(48.787471,2.529378),
  new google.maps.LatLng(46.257632,6.108669),
  new google.maps.LatLng(47.05698,6.604106),
  new google.maps.LatLng(42.585238,2.442451),
  new google.maps.LatLng(43.716642,7.26113),
  new google.maps.LatLng(45.18395,5.714772),
];

function initialize() {
  var mapOptions = {
    zoom: 6,
    center: new google.maps.LatLng(48.123662,-1.643964),
    mapTypeId: google.maps.MapTypeId.SATELLITE
  };

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

  var pointArray = new google.maps.MVCArray(taxiData);

  heatmap = new google.maps.visualization.HeatmapLayer({
    data: pointArray
  });

  heatmap.setMap(map);

  var locations = [
      ['A.S. Adventure',49.07659,6.10424],
['AU MONTAGNARD',45.838842,1.257624],
['DAVENTURE EN AVENTURE',45.777281,3.067718],
['ESCAPE FROM HOME',45.771264,3.119802],
['ARMURERIE O.D.B',41.939344,8.720587],
['ALTITUDE',48.092798,7.37046],
['AM SPORT SA - INTERSPORT',48.582835,7.741074],
['AU VIEUX CAMPEUR  STRASBOURG',48.582643,7.744637],
['LA GODILLE-SARL / SPORT 2000',48.043285,7.163224],
['LOISIRS SA - INTERSPORT',47.240609,5.986948],
['SA PATRICK SPORTS',48.076367,7.358422],
['SPORT AVENTURES EURL',46.902426,6.357662],
['SPORT ET LOISIRS',49.091438,0.603859],
['WEIGEL SPORTS SARL - INTERSPORT',47.748221,7.337235],
['ALENSPORT - INTERSPORT',48.358839,0.126044],
['MONT BLANC EXPEDITIONS',47.217126,-1.548982],
['ROCHE VENDEE SPORT - INTERSPORT',46.680958,-1.428781],
['AU VIEUX CAMPEUR PARIS',48.849482,2.345298],
['ALTIPLANO',45.088065,5.559912],
['AU VIEUX CAMPEUR ALBERTVILLE',45.677655,6.391796],
['AU VIEUX CAMPEUR LYON',45.756506,4.842133],
['AU VIEUX CAMPEUR SALLANCHES',45.926874,6.639903],
['AU VIEUX CAMPEUR THONON',46.361794,6.459379],
['BERNARD AMOUDRUZ - INTERSPORT',46.202469,6.270037],
['CARIBOU INTERSPORT',45.780777,4.832583],
['COQUOZ SPORT - INTERSPORT',45.921605,6.867754],
['ESPACE MONTAGNE',45.184985,5.771235],
['ESPACE MONTAGNE ANNECY/SPORT 2000',45.936839,6.09028],
['EXPE SPELEMAT',45.450626,4.385943],
['EXPE SPELEMAT',45.062254,5.342146],
['EXPE SPELEMAT',45.767309,4.849234],
['FLAMMIER SPORTS - INTERSPORT',46.067247,6.312707],
['FRASTEYA - SPORT 2000',45.573478,5.955496],
['GOZZI SPORTS',45.362951,5.590641],
['JUGLARET SPORTS SPORT 2000',45.621758,6.774616],
['KILLY SPORT',45.449795,6.979823],
['LE RALLYE - INTERSPORT',45.59453,5.897181],
['LIMONY SPORT SARL - INTERSPORT',45.343875,4.820178],
['MONT BLANC PLAGE SPORTS',45.936305,6.632563],
['MONTAGNES',45.686305,6.568867],
['MONTANIA',45.564878,5.92176],
['MONTAZ SPORTS',45.564608,5.966328],
['MONTEGRE SPORTS',46.071608,6.324332],
['NOGE SPORT - INTERSPORT',45.61695,6.767076],
['PIGUET SPORT- INTERSPORT',46.06054,6.579441],
['REVE DE CIME PARMELAN',45.90411,6.130793],
['S.ABONDANCE - INTERSPORT',45.534469,6.633496],
['SARL RANDO STOCK',45.271111,5.890022],
['SKI ET MONTAGNE / SPORT 2000',45.381142,6.721651],
['SKI SET LA NORMA',45.201273,6.69523],
['SNELL SPORT',45.920732,6.866883],
['SOQUET SPORT - SPORT 2000',45.829237,6.596708],
['SPORT 2000 ANTHY',46.349528,6.437412],
['SPORTECH',45.98172,6.925596],
['SPORTS ALPINS SA - INTERSPORT',45.925299,6.869781],
['TABERT - INTERSPORT',46.194546,6.768534],
['TROC SPORT',45.539641,5.990066],
['ALPIMAT',44.901605,6.632996],
['ALPINA SPORT SARL',43.292455,5.379883],
['ALTICOOP',43.714589,7.262607],
['AU VIEUX CAMPEUR MARSEILLE',43.274218,5.390667],
['BADO SPORT 2000',44.92272,4.908711],
['EXPE SPELEMAT',43.292516,5.382688],
['EXPE SPELEMAT - LA RANDONNEE',43.707764,7.285802],
['GRAVICIME',44.92272,4.908711],
['GUIGAL SPORT - INTERSPORT',45.359865,4.702148],
['LAVENTURE',43.126875,5.820168],
['LA MONTAGNE MARSEILLE',43.287535,5.383852],
['LA RANDONNEE',43.604006,3.873753],
['LE YETI SARL PISCO',43.65905,3.903715],
['MILLON MONTAGNE EURL',44.660839,6.05896],
['NEVE SPORT - SPORT 2000',45.120053,6.113892],
['SPORTS ET MONTAGNE',43.949238,4.810937],
['VERTIKALP',44.555602,4.738101],
['AB SKI / TWINNER',42.503838,2.017524],
['ANETO SPORT / SKI SET',42.999929,0.168227],
['AU VIEUX CAMPEUR TOULOUSE',43.552094,1.50238],
['CASSIGNOL - INTERSPORT',44.031043,1.346924],
['DP SPORT - INTERSPORT',43.319284,-0.346597],
['ESP. CULTUREL SPORT&LOISIRS LECLERC',43.197621,-0.617766],
['EXPE SPELEMAT',43.605298,3.874303],
['Extrême Latitude',43.497069,-1.493851],
['FREDDY SPORT - INTERSPORT',42.745317,0.563609],
['GALLINERA SPORT',42.503838,2.017524],
['GAM SPORT - INTERSPORT',43.237619,0.070005],
['IGLOO SAS SPORTS - INTERSPORT',43.605604,1.447318],
['INTERSPORT MONTAGNE',42.844216,-0.130779],
['LE REFUGE - PATAGONIA',43.634781,2.243348],
['MILLE SPORTS / Sport 2000',42.674823,2.942569],
['MONTAGNE SPORT LE REFUGE',44.838769,-0.572475],
['ONTARIO SPORT',43.504128,1.395169],
['RIBES SPORT',42.986457,1.144016],
['RUNNING ALTITUDE',43.077753,-0.018655],
['SARL DEGEILH SARRAT BOUTIQUE',42.82124,0.327632],
['SPORT 2000 LONS',43.314287,-0.398382],
['SPORT DISTRIBUTION LABEGE - INTERSPORT',43.616194,1.50238],
['SPORT ET LOISIRS MERIDIEN SPORT',43.242477,0.009326],
['SPORTING CASTAGNE - INTERSPORT',42.873012,-0.002733],
['SPORTS AVENTURE',44.834924,-0.576301],
['STARSKI',42.844216,-0.130779],
['T DE LE RUE - INTERSPORT',42.765975,0.24323],
['TAPIE DIFFUSION EURL - INTERSPORT',43.14494,0.403094],
['TELEMARK PYRENEES',42.720191,1.838971],
['TOB PLEIN AIR - INTERSPORT',46.208668,-1.099443],
['TRIATHLON SPORTS - INTERSPORT',43.645696,0.573071],
['TWINNER LAVELANET',42.923812,1.836026],
['ESPORT SENSACIO',42.543295,1.517122],
['OLYMPIA ESPORTS',42.509984,1.531707],
['DAVENTURE EN AVENTURE',45.776959,3.067596],
['ALTITUDE',48.092798,7.37046],
['AM SPORT SA - INTERSPORT',48.582835,7.741074],
['AU VIEUX CAMPEUR  STRASBOURG',48.582643,7.744637],
['HOFF SPORT - TWINNER',48.454696,7.502258],
['LA GODILLE-SARL / SPORT 2000',48.043285,7.163224],
['LOISIRS SA - INTERSPORT',47.240215,5.987463],
['SA PATRICK SPORTS',48.076367,7.358422],
['SPORT AVENTURES EURL',46.901224,6.362022],
['WEIGEL SPORTS SARL - INTERSPORT',47.741349,7.345685],
['CAP RANDO',46.829082,-1.891302],
['MONT BLANC EXPEDITIONS',47.218504,-1.544658],
['AU VIEUX CAMPEUR PARIS',48.849482,2.345298],
['ALTIPLANO',45.034479,5.530929],
['AU VIEUX CAMPEUR ALBERTVILLE',45.670293,6.357697],
['AU VIEUX CAMPEUR LYON',45.756506,4.842133],
['AU VIEUX CAMPEUR SALLANCHES',45.926874,6.639903],
['BERNARD AMOUDRUZ - INTERSPORT',46.202469,6.270037],
['CARIBOU INTERSPORT',45.780777,4.832583],
['CYCLES JUNGBLUT',46.20055,5.233022],
['ESPACE MONTAGNE ANNECY/SPORT 2000',45.614078,5.993451],
['FRASTEYA - SPORT 2000',45.614078,5.993451],
['GOZZI SPORTS',45.362951,5.590641],
['LA RANDONNEE - CENTRALE PRO',45.180836,5.726793],
['MONT BLANC PLAGE SPORTS',45.936305,6.632563],
['MONTAGNES',45.695403,6.585103],
['MONTANIA',45.570027,5.929571],
['MONTAZ SPORTS',45.564608,5.966328],
['PIGUET SPORT- INTERSPORT',46.06054,6.579441],
['S.ABONDANCE - INTERSPORT',45.537953,6.681683],
['SARL RANDO STOCK',45.271111,5.890022],
['SKI ET MONTAGNE / SPORT 2000',45.381142,6.721651],
['SNELL SPORT',45.920732,6.866883],
['TABERT - INTERSPORT',46.182957,6.743969],
['ALPINA SPORT SARL',43.292455,5.379883],
['ALTICOOP',43.714085,7.262102],
['AU VIEUX CAMPEUR MARSEILLE',43.274218,5.390667],
['FABER - INTERSPORT MONTAGNE',44.387244,6.651621],
['LA RANDONNEE',43.604006,3.873753],
['LE YETI SARL PISCO',43.65905,3.903715],
['AU VIEUX CAMPEUR TOULOUSE',43.55651,1.503754],
['CASSIGNOL - INTERSPORT',44.031043,1.346924],
['GAM SPORT 00802 000',43.237619,0.070005],
['LAFONT SPORTS',43.00622,-0.101355],
['LE REFUGE - PATAGONIA',43.634781,2.243348],
['MER ET MONTAGNE SARL/SPORT 2000',43.237619,0.070005],
['MILLE SPORTS / Sport 2000',42.674823,2.942569],
['MONTAGNE SPORT LE REFUGE',44.838769,-0.572475],
['OLMES SPORTS - TWINNER LAVELANET',42.923655,1.835994],
['ONTARIO SPORT',43.504128,1.395169],
['PAUL ANDRIEUX 00778 000',42.765975,0.24323],
['RUNNING ALTITUDE',43.077753,-0.018655],
['SARL DEGEILH SARRAT BOUTIQUE',42.82124,0.327632],
['SPORT 2000 LONS',43.314287,-0.398382],
['SPORT ET LOISIRS MERIDIEN SPORT',43.242477,0.009326],
['SPORTING CASTAGNE 00481 000',42.873012,-0.002733],
['SPORTS AVENTURE',44.834924,-0.576301],
['STARSKI',42.844216,-0.130779],
['T DE LE RUE 00759 000',42.765975,0.24323],
['TAPIE DIFFUSION EURL - 00394 000',43.14494,0.403094],
['TELEMARK PYRENEES',42.720191,1.838971],
['TRIATHLON SPORTS - INTERSPORT',43.645696,0.573071]

    ];

    var infowindow = new google.maps.InfoWindow();

    var iconBase = '';
    var marker, i;
    var markers = new Array();

    for (i = 0; i < locations.length; i++) {  
      marker = new google.maps.Marker({
        position: new google.maps.LatLng(locations[i][1], locations[i][2]),
        map: map,
        icon: iconBase + ''
      });

      markers.push(marker);

      google.maps.event.addListener(marker, 'click', (function(marker, i) {
        return function() {
          infowindow.setContent(locations[i][0]);
          infowindow.open(map, marker);
        }
      })(marker, i));
    }

    function AutoCenter() {
      //  Create a new viewpoint bound
      var bounds = new google.maps.LatLngBounds();
      //  Go through each...
      $.each(markers, function (index, marker) {
      bounds.extend(marker.position);
      });
      //  Fit these bounds to the map
      map.fitBounds(bounds);
    }
    AutoCenter();

}

function toggleHeatmap() {
  heatmap.setMap(heatmap.getMap() ? null : map);
}

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

    </script>
  </head>

  <body>
    <div id="panel">
      <button onclick="toggleHeatmap()">Toggle Heatmap</button>
    </div>
    <div id="map-canvas"></div>
  </body>
</html>

1 个答案:

答案 0 :(得分:1)

使您的标记数组全局化。然后将您的toggleHeatmap函数更改为此类

function toggleHeatmap() {

if(heatmap.getMap() != null) {
    heatmap.setMap(null);
    for (var i = 0; i < markers.length; i++) {
        markers[i].setMap(null);
    }
} else {
    heatmap.setMap(map)
    for (var i = 0; i < markers.length; i++) {
        markers[i].setMap(map);
    }
}
}