2016-08-18 83 views
0

我是vuejs的新手。我正在使用vue-google-maps來顯示標記,我想知道如何更改標記圖標。我試圖添加圖標到標記標記,但它不起作用。下面我的代碼:如何更改vue-google-maps中的標記圖標

在我的模板,我有:

<marker :position.sync="m.position" :icon.sync="m.icon" v-for="m in markers"></marker> 

,這裏是我的腳本:

export default { 
data: function data() { 
    return { 
    center: { lat: 33.533818415851705, lng: -3.746186887500016 }, 
    zoom: 7, 
    markers: [{position: { lat: 34.263, lng: -6.582 }, icon:"../assets/marker-icon.png"}] 
    };}}; 

有人能指導我嗎?

回答

2

看看bug here

,誘騙here

document.addEventListener('DOMContentLoaded', function() { 
 
\t VueGoogleMap.load({ 
 
    \t key: 'AIzaSyAF2ndm4PTn52sqO8E2NW3bAULQu2-IQaw' 
 
    }); 
 

 
    Vue.component('marker', VueGoogleMap.Marker); 
 
    Vue.component('map', VueGoogleMap.Map); 
 

 
    var map = new Vue({ 
 
    el: '#map', 
 
    data: { 
 
     center: { 
 
     lat: 41.6005450, 
 
     lng: -93.609 
 
     }, 
 
     markers: [{ 
 
     position: { 
 
      lat: 41.585095, 
 
      lng: -93.624523 
 
     } 
 
     }] 
 
    }, 
 
    }); 
 
});
<body> 
 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.21/vue.js"></script> 
 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.6.1/lodash.min.js"></script> 
 
    <script src="https://rawgit.com/GuillaumeLeclerc/vue-google-maps/master/dist/vue-google-maps.js"></script> 
 
    <div id="map"> 
 
    <map :icon="{path:'M55.296 -56.375v40.32q0 1.8 -1.224 3.204t-3.096 2.178 -3.726 1.152 -3.474 0.378 -3.474 -0.378 -3.726 -1.152 -3.096 -2.178 -1.224 -3.204 1.224 -3.204 3.096 -2.178 3.726 -1.152 3.474 -0.378q3.78 0 6.912 1.404v-19.332l-27.648 8.532v25.524q0 1.8 -1.224 3.204t-3.096 2.178 -3.726 1.152 -3.474 0.378 -3.474 -0.378 -3.726 -1.152 -3.096 -2.178 -1.224 -3.204 1.224 -3.204 3.096 -2.178 3.726 -1.152 3.474 -0.378q3.78 0 6.912 1.404v-34.812q0 -1.116 0.684 -2.034t1.764 -1.278l29.952 -9.216q0.432 -0.144 1.008 -0.144 1.44 0 2.448 1.008t1.008 2.448z'}" style="height:500px;width:500px;display:block;" :center="center" :zoom="7"> 
 
     <marker v-for="m in markers" :position.sync="m.position" :clickable="true" :draggable="true" @g-click="center=m.center"> 
 
     </marker> 
 
    </map> 
 
    </div> 
 
</body>

+0

感謝@Shaig它現在。我剛剛編輯了這些:標記:[{position:{lat:34.263,lng:-6.582},icon:「../ assets/marker-icon.png」}]:[{position:{lat:34.263, lng:-6.582},圖標:{url:「../assets/marker-icon.png」}}]。 –

+0

我很高興它幫助@MariaMinh! –