Vue.use(VueGoogleMaps, {
load: {
key: ''
},
});
new Vue({
el: '#root',
computed:{
icon(){
if (this.resized)
return {
url:"https://i.ibb.co/bdykLz4/test.png",
size: { width: 100, height: 100, f: "px", b: "px" },
scaledSize: { width: 50, height: 50, f: "px", b: "px" }
}
else
return {
url:"https://i.ibb.co/bdykLz4/test.png"
}
}
},
data: {
resized:true,
startLocation: {
lat: 38.7126659,
lng: -9.3051496
},
coordinates: {
0: {
full_name: 'Point 1',
lat: 38.7226659,
lng: -9.3151496
},
1: {
full_name: 'Point 2',
lat: 38.7136659,
lng: -9.3061496
}
},
},
methods: {
getPosition: function(marker) {
return {
lat: parseFloat(marker.lat),
lng: parseFloat(marker.lng)
}
},
}
});
<script src="https://xkjyeah.github.io/vue-google-maps/vue-google-maps.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<body>
<div id="root">
<gmap-map ref="mymap" :center="startLocation" :zoom="14" style="width: 100%; height: 500px">
<gmap-marker v-for="(item, key) in coordinates" :key="key" :position="getPosition(item)" :icon="icon"/>
</gmap-map>
Resized: <input type="checkbox" id="checkbox" v-model="resized" >
</div>
</body>
I am trying to use custom markers with vue2-google-maps, and found a strange behaviour.
If I use a png image for example 100x100 pixels and set the properties to resize it to 50x50 pixels, when I start to zoom out, the marker start to move away from the coordinates.
If I did not use the resize property, there is no problem.
I have searched a lot about this issue and canĀ“t find anything.
I had prepared a JSFiddle, just uncheck the checkbox and everything is ok during the zoom out, but if you let the checkbox marked and start to zoom out, you will see that the mark goes to the ocean, when it should be on Portugal.
The difference on the object passed to the icon property is:
when checked:
{
url:"https://i.ibb.co/bdykLz4/test.png",
size: { width: 100, height: 100, f: "px", b: "px" },
scaledSize: { width: 50, height: 50, f: "px", b: "px" }
}
when unchecked:
{
url:"https://i.ibb.co/bdykLz4/test.png",
}
Here is the fiddle: https://jsfiddle.net/5dw83v7g/3/
UPDATE: If I keep "size" and "scaledSize" the same, the problem disapears
best regards,
TIA
You have to change your code like this:
and use thisin your body:
I used this code here.
Please rate me if it was helpful. Thanks a lot.