开发者

Reload points on Google Maps dynamically

开发者 https://www.devze.com 2023-01-24 15:05 出处:网络
I´m using a jquery plugin (Gmap) to load a google map , and several markers on it. I need to refresh the markers(like changing a cate开发者_StackOverflow中文版gory or something from a drop down menu

I´m using a jquery plugin (Gmap) to load a google map , and several markers on it.

I need to refresh the markers(like changing a cate开发者_StackOverflow中文版gory or something from a drop down menu) and charge some other points on the same map without reloading the whole thing (only the markers)

How can i do this?, thanks!


You could create an array of marker arrays, if you know what I'm talking about. Iterate over each marker, and use the setMap() method to remove it from/place it on the map.

var active = 0,
    map = *map*,
    markers = [
      [*marker1*, *marker2*],
      [*marker3*, *marker4*],
    ];

function setActive( m, map ){

  // remove active markers
  for( var i=0; i<markers[active].length; i++){
    markers[active][i].setMap(null);
  }

  // place new markers
  for( var i=0; i<markers[active].length; i++){
    markers[m][i].setMap(map);
  }

  active = m;
}

// Show the second row of markers:
setActive( 1, map );
0

精彩评论

暂无评论...
验证码 换一张
取 消