jquery – 在地图的元素外侧鼠标悬停时更改谷歌地图v3标记的颜色

前端之家收集整理的这篇文章主要介绍了jquery – 在地图的元素外侧鼠标悬停时更改谷歌地图v3标记的颜色前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在尝试这样做,以便当一个html元素被鼠标悬停在谷歌地图上的标记的颜色代码时,api v3将会改变.

这是谷歌地图代码

  1. $(document).ready(function(){
  2. var markers;
  3. var map;
  4. var infowindow = new google.maps.InfoWindow();
  5. var bounds = new google.maps.LatLngBounds();
  6. markers = new Array();
  7. var mapOptions = {
  8. zoom: 0,//Set to 0 because we are using auto formatting w/ bounds
  9. disableDefaultUI: true,zoomControl: true,mapTypeId: google.maps.MapTypeId.ROADMAP,};
  10. map = new google.maps.Map(document.getElementById("map"),mapOptions);
  11. map.fitBounds(bounds);
  12. $("#map_list ul li").each(function(index) {
  13. var markerLatLng = new google.maps.LatLng($(this).children(".marker_lat").text(),$(this).children(".marker_long").text());
  14. var marker = new google.maps.Marker({
  15. position: markerLatLng,map: map,animation: google.maps.Animation.DROP,title : $(this).children(".marker_title").text(),brief: $(this).children(".marker_brief").text(),icon: 'http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld='+$(this).children(".marker_number").text()+'|00aeef|000000'
  16. });
  17. markers.push(marker);
  18. //add to bounds for auto center and zoom
  19. bounds.extend(markerLatLng);
  20. });
  21. });

它是从网页中的html动态构建标记,如下所示:

我怎样才能这样做,当我将鼠标移到#map_list ul li上时,它会将颜色代码00aeef更改为ff0000?

最佳答案
Example translated from Mike Williams’ v2 tutorial(只需更改侧栏中HTML元素鼠标悬停时的标记图标).

鼠标悬停/鼠标移动时更改标记代码

  1. // A function to create the marker and set up the event window function
  2. function createMarker(latlng,name,html,color) {
  3. var contentString = html;
  4. var marker = new google.maps.Marker({
  5. position: latlng,icon: gicons[color],title: name,zIndex: Math.round(latlng.lat()*-100000)<<5
  6. });
  7. google.maps.event.addListener(marker,'click',function() {
  8. infowindow.setContent(contentString);
  9. infowindow.open(map,marker);
  10. });
  11. // Switch icon on marker mouSEOver and mouSEOut
  12. google.maps.event.addListener(marker,"mouSEOver",function() {
  13. marker.setIcon(gicons["yellow"]);
  14. });
  15. google.maps.event.addListener(marker,"mouSEOut",function() {
  16. marker.setIcon(gicons["blue"]);
  17. });
  18. gmarkers.push(marker);
  19. // add a line to the side_bar html
  20. var marker_num = gmarkers.length-1;
  21. side_bar_html += '

Example using KML/geoxml3

猜你在找的jQuery相关文章