Z tego dokumentu dowiesz się, jak dostosować wygląd mapy oraz kontrolować widoczność danych i opcje widoku. Możesz to zrobić na te sposoby:
- Korzystanie z definiowania stylów map w Google Cloud
 - Ustawianie opcji stylu mapy bezpośrednio we własnym kodzie
 
Nadawanie stylu mapie za pomocą definiowania stylów map w Google Cloud
Aby zastosować styl mapy do mapy udostępniania przejazdów w JavaScript, podczas tworzenia JourneySharingMapView określ mapId i inne mapOptions.
Poniższe przykłady pokazują, jak zastosować styl mapy z identyfikatorem mapy.
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.
});
Nadawanie stylu mapom bezpośrednio w kodzie
Możesz też dostosować styl mapy, ustawiając opcje mapy podczas tworzenia JourneySharingMapView. Poniższe przykłady pokazują, jak stylować mapę za pomocą opcji mapy. Więcej informacji o opcjach mapy, które możesz ustawić, znajdziesz w mapOptions w dokumentacji interfejsu Google Maps JavaScript API.
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" }
        ]
      }
    ]
  }
});
Wyświetlanie informacji na mapie
Wyświetl dodatkowe informacje o pojeździe lub znaczniku lokalizacji za pomocą elementu InfoWindow. Więcej informacji znajdziesz w sekcji InfoWindow.
Ten przykład pokazuje, jak utworzyć InfoWindow i dołączyć go do znacznika pojazdu:
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();
Wyłączanie automatycznego dopasowywania
Możesz wyłączyć automatyczne dopasowywanie, aby mapa nie dopasowywała automatycznie widoku do pojazdu i przewidywanej trasy. Poniższy przykład pokazuje, jak wyłączyć automatyczne dopasowywanie podczas konfigurowania widoku mapy udostępniania trasy.
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,
  ...
});