-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changing Color of Way points. #96
Comments
Hi @Hokino ! There is no way to custom waypoints style now with any waypoint params in GoogleMapAPI - directions#Waypoints. 😞 But I have found this post, you can create your own polylines to replace exist polylines from result. I have try and it seems to be successful. Hope to help you.
<agm-map [latitude]="lat" [longitude]="lng" (mapReady)="onMapReady($event)">
<agm-direction
[origin]="origin"
[destination]="destination"
[waypoints]="waypoints"
[renderOptions]="renderOptions"
(onResponse)="onResponse($event)"
>
</agm-direction>
</agm-map>
import { Component } from '@angular/core';
import { Polyline, PolylineOptions, GoogleMap } from '@agm/core/services/google-maps-types';
declare var google: any;
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent {
public lat = 24.799448;
public lng = 120.979021;
public origin: any = 'Taichung Railway Station, Taiwan';
public destination: any = 'Wenxin Forest Park, Taiwan';
public waypoints: Array<any> = [
{ location: 'Chung Shan Medical University, Taiwan', stopover: true },
{ location: 'National Chung Hsing University, Taiwan', stopover: true },
];
// Hide origin polylines
public renderOptions = { suppressPolylines: true };
// Custom polylines
public polylines: Array<Polyline> = [];
// Current map
public map: GoogleMap;
// Save GoogleMap instance
public onMapReady(event: GoogleMap) {
this.map = event;
}
public async onResponse(event: any) {
// Default style
const polylineOptions: PolylineOptions = {
strokeWeight: 6,
strokeOpacity: 0.55,
};
// Polylines strokeColor
const colors = ['#0000FF', '#FF0000', '#0000FF'];
// Clear exist polylines
this.polylines.forEach(polyline => polyline.setMap(null));
const { legs } = event.routes[0];
legs.forEach((leg, index) => {
leg.steps.forEach(step => {
const nextSegment = step.path;
const stepPolyline: Polyline = new google.maps.Polyline(polylineOptions);
// Custom color
stepPolyline.setOptions({ strokeColor: colors[index] });
nextSegment.forEach(next => stepPolyline.getPath().push(next));
this.polylines.push(stepPolyline);
stepPolyline.setMap(this.map);
});
});
}
} Your suggestion is great, it can be a new feature. 🙂 Ref |
Hi @explooosion I have another question. Say that the directions are circular. So for the same previous example, if A -> B -> C -> A (D). If we are going in a loop where the origin matches the destination is there a way to prevent the A from becoming labelled with a D pin. Where Im thinking that maybe i could have a click event that modifies the z-index of the marker selected that would send it to the back. So maybe swap the two values? That way once a user clicks once marker A would be visible and then on another click marker D would be visible? Does that seem like the correct solution? I looked into marker cluster and spider marker solutions but those dont look like they will work for my purposes. |
This comment has been minimized.
This comment has been minimized.
Good Morning @Hokino I have same problem with markers and option stopover in direction, thanks for the solution. Att, |
Suppose I have an Origin of A and Destination of D with a way point of B and C.
Is it possible to change the stroke color of the waypoint section of the agm-direction.
Something like:
waypoints: [
{
icon: 'your-icon-url',
label: 'marker label',
opacity: 0.8,
polylineOptions: {
strokeColor: '0080ff',
strokeWeight: 6,
strokeOpacity: 0.55
}
},
],
For example could I have :
A -> B (default blue)
B -> C (red)
C -> D (default blue)
I have tried to do multiple directions so that each of the above routes (a -> b, b -> c, c -> d) are its own direction and setting the strokeColor in the renderOptions. But then the markers are not automatically showing as a,b,c,d. Rather they are showing up like this.
Please tell me if such a functionality already exists.
Thanks!
The text was updated successfully, but these errors were encountered: