custom marker for vue2-google-maps

可紊 提交于 2020-01-23 01:58:07

问题


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?


回答1:


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')}" />



回答2:


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',},
    },
  };
},


来源:https://stackoverflow.com/questions/51800404/custom-marker-for-vue2-google-maps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!