In Vue2
I am trying to change the google maps default marker to a custom Image. created custom markers showing on the map but, when I draw the poly-line between them default red color markers get place above the custom marker. I couldn't hide or replace the default markers.
suggested answer here is for way-points marker not start and end of a poly-line.
I uses vue2-google-maps
package.
this is a screenshot of the map
this is the template
<template>
<div>
<GmapMap
:center="center"
:zoom="zoom"
map-type-id="roadmap"
style="width: 100%; height: 300px"
ref="map"
>
<GmapMarker
v-for="(m, index) in markers"
:key="index"
:ref="`marker${index}`"
:position="m.position"
:clickable="true"
:icon="m.icon"
/>
<DirectionsRenderer
v-if='start!=null'
travelMode="DRIVING"
:origin="origin"
:destination="destionation"/>
</GmapMap>
</div>
</template>
and this is the script part
<script>
import DirectionsRenderer from './DirectionsRenderer.js'
export default{
components: {DirectionsRenderer},
data:()=>({
markers:[],
center:{lat:49.2831066, lng:-123.1031387},
zoom:10,
start:null,
end:null,
}),
computed: {
origin() {
if (!this.start) return null;
return { query: this.start };
},
destionation() {
if (!this.end) return null;
return { query: this.end };
}
},
methods:{
drawRoute(){
this.start = this.order.from.formatted_address;
this.end = this.order.to.formatted_address;
},
setBounds(){
const bounds = new google.maps.LatLngBounds()
for (let m of this.markers) {
bounds.extend(m.position)
}
this.$refs.map.fitBounds(bounds)
},
init(){
this.markers=[
{
position: {lat:49.2831066 ,lng:-123.1031387},
icon:
{
url: '/images/icons/pickup.png',
size: {width: 60, height: 60, f: 'px', b: 'px',},
scaledSize: {width: 20, height: 20, f: 'px', b: 'px',},
}
},
{
position: {lat:49.2544622,lng:-123.1053708},
icon:{
url: '/images/icons/destination.png',
size: {width: 60, height: 60, f: 'px', b: 'px',},
scaledSize: {width: 20, height: 20, f: 'px', b: 'px',},
}
}
];
}
this.setBounds();
},
created(){
this.init();
}
}
</script>
and this is DirectionsRenderer.js
script
import { MapElementFactory } from "vue2-google-maps";
export default MapElementFactory({
name: "directionsRenderer",
ctr() {
return google.maps.DirectionsRenderer;
},
events: [],
mappedProps: {},
props: {
origin: { type: Object },
destination: { type: Object },
travelMode: { type: String }
},
afterCreate(directionsRenderer) {
let directionsService = new google.maps.DirectionsService();
this.$watch(
() => [this.origin, this.destination, this.travelMode],
() => {
let { origin, destination, travelMode } = this;
if (!origin || !destination || !travelMode) return;
directionsService.route(
{
origin,
destination,
travelMode
},
(response, status) => {
if (status !== "OK") return;
directionsRenderer.setDirections(response);
}
);
}
);
}
});
directionsRenderer.setDirections(response);
in bellow snipet draw a line with default markers at the beginning and end of the line.
directionsService.route(
{
origin,
destination,
travelMode
},
(response, status) => {
if (status !== "OK") return;
directionsRenderer.setDirections(response);
}
);
any idea how can I solve this problem?