0👍
You can do it with the below steps:
- declare your paths and initial polygonOptions:
polygon: {
paths: [{
lat: 1.380,
lng: 103.800
}, {
lat: 1.380,
lng: 103.810
}, {
lat: 1.390,
lng: 103.810
}, {
lat: 1.390,
lng: 103.800
}],
polygonOptions: {
strokeColor: 'transparent',
}
- Map those values in the parameters inside
<gmap-polygon
. You can then put methods onmouseover
andmouseout
events.
<gmap-polygon :paths="polygon.paths" :editable="true" :options="polygon.polygonOptions" @mouseover="changePolygonMouseOver($event)" @mouseout="changePolygonMouseOut()" ref="google_map_polygon">
</gmap-polygon>
- Call the polygon object using
this.$refs.google_map_polygon.$polygonObject
then use thesetOptions()
to set the polygonOptions during the mouseover and mouseout events. On mouseOut you can use the initial value of your polygonOptionsthis.polygon.polygonOptions
:
methods: {
changePolygonMouseOver: function() {
this.$refs.google_map_polygon.$polygonObject.setOptions({
strokeColor: 'red',
})
},
changePolygonMouseOut: function() {
console.log("mouseOut")
this.$refs.google_map_polygon.$polygonObject.setOptions(this.polygon.polygonOptions)
}
}
Here’s the working code.
Source:stackexchange.com