custom marker for vue2-google-maps

2020-07-18 02:14发布

I am trying to add my own images for a custom marker in vue2-google-maps without success. I know this is a bug and when I add an :icon="{url:'../assets/my_image'}" in tag the marker disappears. Has anyone managed to make it work?

2条回答
孤傲高冷的网名
2楼-- · 2020-07-18 02:39

Just in case if you like to scale the size of the custom marker to look better in retina screen:

in <template>

<GmapMarker
  v-for="(m, index) in markers"
  :key="index"
  :ref="`marker${index}`"
  :position="m.position"
  :clickable="true"
  :draggable="true"
  :icon="markerOptions" />

in script

const mapMarker = require('~/assets/images/layout/map-marker.png');
data() {
  return {
    markerOptions: {
      url: mapMarker,
      size: {width: 60, height: 90, f: 'px', b: 'px',},
      scaledSize: {width: 30, height: 45, f: 'px', b: 'px',},
    },
  };
},
查看更多
Bombasti
3楼-- · 2020-07-18 02:47

You need to load the image in this case, like this:

:icon="{ url: require('../../assets/img/marker-a.png')}"

An example:

<GmapMarker
  v-for="(m, index) in markers"
  :key="index"
  :ref="`marker${index}`"
  :position="m.position"
  :clickable="true"
  :draggable="true"
  :icon="{ url: require('../../assets/img/marker-a.png')}" />
查看更多
登录 后发表回答