google maps v3 API mouseover with polygons?

后端 未结 4 1911
难免孤独
难免孤独 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

    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);
    });
    

提交回复
热议问题