google maps v3 API mouseover with polygons?

后端 未结 4 1813
难免孤独
难免孤独 2021-01-31 09:20

I\'m building a map using the google v3 api because it is way faster. Essentially, it\'s a map of an area with about 30 cities with polygons over the regions. When a user hovers

相关标签:
4条回答
  • 2021-01-31 10:18

    The following works:

    google.maps.event.addListener(polygon,"mouseover",function(){
     this.setOptions({fillColor: "#00FF00"});
    }); 
    
    google.maps.event.addListener(polygon,"mouseout",function(){
     this.setOptions({fillColor: "#FF0000"});
    });
    
    0 讨论(0)
  • 2021-01-31 10:18

    In Google Maps API V3, I have a rollover for a polygon with the below code. I do not like that I have to unset and reset the map each rollover, but, at this point in time, this is how I achieved a mouseover.

    I am interested in any comments on how to improve this code.

    var polyShape     = new google.maps.Polygon({paths:polyData,strokeColor:"#aa0",strokeOpacity:0.5,strokeWeight:1,fillColor:"#cc0",fillOpacity: 0.25});
    var polyShapeOver = new google.maps.Polygon({paths:polyData,strokeColor:"#cc0",strokeOpacity:0.5,strokeWeight:1,fillColor:"#ff0",fillOpacity: 0.25}); 
    
    polyShape.setMap(map);
    
    google.maps.event.addListener(polyShape,"mouseover",function(){
      this.setMap(null);
      polyShapeOver.setMap(map);
    }); 
    
    google.maps.event.addListener(polyShapeOver,"mouseout",function(){
      this.setMap(null);
      polyShape.setMap(map);
    });
    
    0 讨论(0)
  • 2021-01-31 10:18

    Maps API V3 events are defined per object. Doing a search on the V3 reference page reveals that Marker is the only object with definitions for mouseover and mouseout. So yes, you appear to be correct.

    By the way, there are people doing this, but it looks pretty involved:

    http://groups.google.com/group/Google-Maps-API/browse_thread/thread/4ddc4f5888994563

    0 讨论(0)
  • 2021-01-31 10:22

    mouseover and mouseout are now implemented in V3 Polyline.

    0 讨论(0)
提交回复
热议问题