Comments (6)
Hey polsola.
I saw your issue just now, sorry.
I don't know a lot nuxt, but indeed it seems there is issues related to nuxt due to the underlaying gmap library of this component. there is a small trick in the link on the README that gives a hint how to solve it. I cannot do any thing more for you on this topic.
Please let me know if this solves your issue.
from vue2-gmap-custom-marker.
I also thing you issue may be due to SSR that doesn't compute marker on gmap properly.
You may try to render them on client side for a test and if it is related to SSR, you may share me any technical detail that would help to solve your issue.
from vue2-gmap-custom-marker.
Hello Eric,
Do not worry, thanks for the help!
I've tried now to import it without plugin and with the workaround, with this there's no error, but the position still doesn't refresh, here's how it looks now:
<template>
<div>
<GmapMap
:center="center"
:zoom="8"
style="width: 100%; height: 600px"
>
<gmap-custom-marker
:key="vehicle.id"
v-for="vehicle in vehicles"
:marker="vehicle.position"
>
<div class="vehicle-marker">
<img :src="vehicle.avatar" />
</div>
</gmap-custom-marker>
</GmapMap>
</div>
</template>
<style lang="scss">
.vehicle-marker {
width: 100px;
height: 100px;
background-color: red;
img {
width: 64px;
display: block;
}
}
</style>
<script>
import * as VueGoogleMaps from 'vue2-google-maps'
import GmapCustomMarker from 'vue2-gmap-custom-marker'
import Vue from 'vue'
Vue.use(VueGoogleMaps, {
load: {
key: '#'
}
})
export default {
layout: 'ridereact',
components: {
'gmap-custom-marker': GmapCustomMarker
},
head() {
return {
title: `${this.$t('menu.map')}`,
}
},
data() {
return {
center: {lat:41.385063, lng:2.173404},
vehicles: [
{
id: 1,
avatar: '#',
position: {
lat: 41.385063,
lng: 2.173404
}
},{
id: 2,
avatar: '#',
position: {
lat: 41.930290,
lng: 2.254350
}
}
]
}
},
mounted() {
setInterval(function () {
this.vehicles.forEach(vehicle => {
var newLat = vehicle.position.lat += (Math.floor(Math.random() * 11) >= 6) ? 0.005 : -0.005
var newLng = vehicle.position.lng += (Math.floor(Math.random() * 11) >= 6) ? 0.005 : -0.005
vehicle.position.lat = newLat
vehicle.position.lng = newLng
console.log('Vehicle', vehicle.id, vehicle.position.lat, vehicle.position.lng)
});
}.bind(this), 2000)
}
}
</script>
I'm gonna try to create the same without Nuxt.js to see if this works as expected
from vue2-gmap-custom-marker.
Hello again Eric,
Weird thing, if I set both of the markers (normal & custom) the position updates correctly on both, here's the template now:
<GmapMap
:center="center"
:zoom="8"
style="width: 100%; height: 600px"
>
<GmapMarker
:key="`vehicle-${vehicle.id}`"
v-for="vehicle in vehicles"
:position="vehicle.position"
/>
<gmap-custom-marker
:key="vehicle.id"
v-for="vehicle in vehicles"
:marker="vehicle.position"
:offsetY="-10"
>
<div class="vehicle-marker">
<img :src="vehicle.avatar" />
</div>
</gmap-custom-marker>
</GmapMap>
from vue2-gmap-custom-marker.
I am back from holiday, I'll have a look into your issue soon.
from vue2-gmap-custom-marker.
Hey @polsola ,
Here is a working code
<template>
<div>
{{vehicles}}
<GmapMap :center="center" :zoom="8" style="width: 100%; height: 600px">
<gmap-custom-marker
:key="vehicle.id"
v-for="vehicle in vehicles"
:marker="vehicle.position"
>
<div class="vehicle-marker">
<img :src="vehicle.avatar" />
</div>
</gmap-custom-marker>
</GmapMap>
</div>
</template>
<style>
.vehicle-marker {
width: 100px;
height: 100px;
background-color: red;
}
.vehicle-marker img {
width: 64px;
display: block;
}
</style>
<script>
import * as VueGoogleMaps from "vue2-google-maps";
import GmapCustomMarker from "vue2-gmap-custom-marker";
import Vue from "vue";
Vue.use(VueGoogleMaps, {
load: {
key: '#'
}
});
export default {
layout: "ridereact",
components: {
"gmap-custom-marker": GmapCustomMarker
},
head() {
return {
title: `${this.$t("menu.map")}`
};
},
data() {
return {
center: { lat: 41.385063, lng: 2.173404 },
vehicles: [
{
id: 1,
avatar: "#",
position: {
lat: 41.385063,
lng: 2.173404
}
},
{
id: 2,
avatar: "#",
position: {
lat: 41.93029,
lng: 2.25435
}
}
]
};
},
mounted() {
setInterval(
function() {
this.vehicles.forEach(vehicle => {
var newLat = vehicle.position.lat +(Math.floor(Math.random() * 11) >= 6 ? 0.05 : -0.05)
var newLng = vehicle.position.lng + (Math.floor(Math.random() * 11) >= 6 ? 0.05 : -0.05)
vehicle.position = {
lat: newLat,
lng: newLng
}
console.log(
"Vehicle",
vehicle.id,
vehicle.position.lat,
vehicle.position.lng
);
});
}.bind(this),
2000
);
}
};
</script>
I just assigned an object reference to the marker position instead of setting individual raw position number values. This let vue reactive system continue to work properly.
Also, don't forget to clean your set interval in a vue destroy method for exemple if you want to avoid strange behaviors and memory leaks.
Hope this helps
from vue2-gmap-custom-marker.
Related Issues (20)
- Marker offsets completely off with new latest update HOT 2
- The custom marker doesn't display in the exact LatLng HOT 1
- Other google maps items getting activated on click. HOT 1
- Render 4k marker on map with cluster HOT 4
- zIndex HOT 4
- HotFix: typeerror: cannot read property 'repaint' of undefined at vuecomponent.zindex HOT 2
- vue-google-maps is no longer maintained HOT 6
- Can not using gmap custom maker in nuxt 2.0 typescript HOT 1
- Rotate Marker HOT 2
- GmapInfoWindow does not work HOT 3
- How to animate gmap custom marker
- [Feature request] How to animation gmap customer marker HOT 9
- Cluster image dont work HOT 2
- How to drag the marker? HOT 2
- How to get extra info in a cluster HOT 3
- Custom marker popup going off screen HOT 2
- Making this library for vue3-google-map HOT 4
- incompatibility with [email protected] cluster and custom marker HOT 5
- Displaced markers on page change in Nuxt HOT 3
- ERROR in ./node_modules/vue2-gmap-custom-marker/node_modules/gmap-vue/dist/main.js HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vue2-gmap-custom-marker.