Reputation: 165
I want to add border around the car image on click of the marker. how can i do it?
<gmap-marker
:key="index"
v-for="(m, index) in markers"
:position="{
lat: m.location.latitude,
lng: m.location.longitude,
}"
:icon="markerOptions"
>
</gmap-marker>
</gmap-cluster>
markerOptions: {
url: require('~/assets/images/car.svg'),
scaledSize: { width: 50, height: 50, f: 'px', b: 'px' },
},
Upvotes: -1
Views: 363
Reputation: 2977
You can do this by using 2 types of icons - one with your current car icon then another car icon with border.To do this, here are the steps:
data: {
center: {
lat: 10.0,
lng: 10.0
},
icon: 'http://maps.google.com/mapfiles/kml/shapes/donut.png',
newIcon: 'http://maps.google.com/mapfiles/kml/shapes/target.png',
Then you also make a variable for a selected marker flag inside data with value null
:
selectedMarker: null
Inside <google-marker/>
put a method value in your @click
then pass the marker and the key:
@click="markerClicked(m, key)"
Then on the methods, declare the markerClicked
then pass the key
to the selectedMarker
you declared earlier. This will hold the value of the key of the selected marker:
markerClicked: function(marker, key) {
this.selectedMarker = key
},
<google-marker/>
put a method value in your :icon
. This will handle which icon you will show.
:icon=getIcon(key)
Then on the methods, declare the getIcon
passing the key. Then you will check if the selectedMarker
is equal to this key. If yes, this means that this is the active marker and you will show a new Icon which has the border and if it is not equal, you will just show the marker without border.
getIcon: function(key) {
if (this.selectedMarker == key) {
return this.newIcon
}else{
return this.icon
}
}
Here's a working code.
Upvotes: 0