In diesem Dokument erfahren Sie, wie Sie das Erscheinungsbild einer Karte anpassen und die Datensichtbarkeit und die Ansichtsoptionen steuern. Sie haben dazu folgende Möglichkeiten:
- Cloudbasierte Kartenstile verwenden
- Optionen für den Kartenstil direkt in Ihrem Code festlegen
Karte mit cloudbasiertem Gestalten von Karteninhalten stylen
Wenn Sie einen Kartenstil auf Ihre JavaScript-Karte für die Freigabe von Fahrten anwenden möchten, geben Sie beim Erstellen der JourneySharingMapView
eine mapId
und eine beliebige andere mapOptions
an.
In den folgenden Beispielen wird gezeigt, wie Sie einen Kartenstil mit einer Karten-ID anwenden.
JavaScript
const mapView = new google.maps.journeySharing.JourneySharingMapView({
element: document.getElementById('map_canvas'),
locationProviders: [locationProvider],
mapOptions: {
mapId: 'YOUR_MAP_ID'
}
// Any other styling options.
});
TypeScript
const mapView = new google.maps.journeySharing.JourneySharingMapView({
element: document.getElementById('map_canvas'),
locationProviders: [locationProvider],
mapOptions: {
mapId: 'YOUR_MAP_ID'
}
// Any other styling options.
});
Karten direkt in Ihrem eigenen Code stylen
Sie können den Kartenstil auch anpassen, indem Sie beim Erstellen der JourneySharingMapView
Kartenoptionen festlegen. In den folgenden Beispielen wird gezeigt, wie Sie eine Karte mithilfe von Kartenoptionen gestalten. Weitere Informationen zu den verfügbaren Kartenoptionen finden Sie in der Google Maps JavaScript API-Referenz unter mapOptions
.
JavaScript
const mapView = new google.maps.journeySharing.JourneySharingMapView({
element: document.getElementById('map_canvas'),
locationProviders: [locationProvider],
mapOptions: {
styles: [
{
"featureType": "road.arterial",
"elementType": "geometry",
"stylers": [
{ "color": "#CCFFFF" }
]
}
]
}
});
TypeScript
const mapView = new google.maps.journeySharing.JourneySharingMapView({
element: document.getElementById('map_canvas'),
locationProviders: [locationProvider],
mapOptions: {
styles: [
{
"featureType": "road.arterial",
"elementType": "geometry",
"stylers": [
{ "color": "#CCFFFF" }
]
}
]
}
});
Informationen auf der Karte anzeigen
Mithilfe einer InfoWindow
können Sie zusätzliche Informationen zu einer Fahrzeug- oder Standortmarkierung anzeigen. Weitere Informationen finden Sie unter InfoWindow
.
Im folgenden Beispiel wird gezeigt, wie Sie eine InfoWindow
erstellen und an eine Fahrzeugmarkierung anhängen:
JavaScript
// 1. Create an info window.
const infoWindow = new google.maps.InfoWindow(
{disableAutoPan: true});
locationProvider.addListener('update', e => {
const stopsCount = e.trip.remainingWaypoints.length;
infoWindow.setContent(
`Your vehicle is ${stopsCount} stops away.`);
// 2. Attach the info window to a vehicle marker.
// This property can return multiple markers.
const marker = mapView.vehicleMarkers[0];
infoWindow.open(mapView.map, marker);
});
// 3. Close the info window.
infoWindow.close();
TypeScript
// 1. Create an info window.
const infoWindow = new google.maps.InfoWindow(
{disableAutoPan: true});
locationProvider.addListener('update', (e: google.maps.journeySharing.FleetEngineTripLocationProviderUpdateEvent) => {
const stopsCount = e.trip.remainingWaypoints.length;
infoWindow.setContent(
`Your vehicle is ${stopsCount} stops away.`);
// 2. Attach the info window to a vehicle marker.
// This property can return multiple markers.
const marker = mapView.vehicleMarkers[0];
infoWindow.open(mapView.map, marker);
});
// 3. Close the info window.
infoWindow.close();
Automatische Anpassung deaktivieren
Sie können verhindern, dass der Darstellungsbereich der Karte automatisch an das Fahrzeug und die voraussichtliche Route angepasst wird, indem Sie die automatische Anpassung deaktivieren. Im folgenden Beispiel wird gezeigt, wie Sie die automatische Anpassung deaktivieren, wenn Sie die Kartenansicht für die Freigabe von Fahrten konfigurieren.
JavaScript
const mapView = new
google.maps.journeySharing.JourneySharingMapView({
element: document.getElementById('map_canvas'),
locationProviders: [locationProvider],
automaticViewportMode:
google.maps.journeySharing
.AutomaticViewportMode.NONE,
...
});
TypeScript
const mapView = new
google.maps.journeySharing.JourneySharingMapView({
element: document.getElementById('map_canvas'),
locationProviders: [locationProvider],
automaticViewportMode:
google.maps.journeySharing
.AutomaticViewportMode.NONE,
...
});