עיצוב מפה

בחירת פלטפורמה: Android iOS JavaScript

במאמר הזה נסביר איך להתאים אישית את המראה והסגנון של מפה, ואיך לשלוט באפשרויות של נראות הנתונים וחלון התצוגה. אפשר לעשות זאת בדרכים הבאות:

  • שימוש בעיצוב מפות מבוסס-ענן
  • הגדרת אפשרויות של סגנון המפה ישירות בקוד שלכם

עיצוב המפה באמצעות עיצוב מפות מבוסס-ענן

כדי להחיל סגנון מפה על מפה של שיתוף מסלול נסיעה ב-JavaScript, צריך לציין mapId וmapOptions אחרים כשיוצרים את JourneySharingMapView.

בדוגמאות הבאות אפשר לראות איך להחיל סגנון מפה באמצעות מזהה מפה.

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.
});

עיצוב מפות ישירות בקוד שלכם

אפשר גם להתאים אישית את עיצוב המפה על ידי הגדרת אפשרויות המפה כשיוצרים את האובייקט JourneySharingMapView. בדוגמאות הבאות אפשר לראות איך מעצבים מפה באמצעות אפשרויות המפה. מידע נוסף על האפשרויות להגדרת המפה מופיע במאמר בנושא mapOptions במאמרי העזרה של ה-API של Google Maps JavaScript.

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" }
        ]
      }
    ]
  }
});

הצגת מידע במפה

הצגת מידע נוסף על רכב או על סמן מיקום באמצעות InfoWindow. מידע נוסף זמין במאמר InfoWindow.

בדוגמה הבאה אפשר לראות איך ליצור InfoWindow ולצרף אותו לסמן של רכב:

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();

השבתת ההתאמה האוטומטית

כדי שהמפה לא תתאים אוטומטית את אזור התצוגה לרכב ולמסלול הצפוי, אפשר להשבית את ההתאמה האוטומטית. בדוגמה הבאה מוסבר איך להשבית את ההתאמה האוטומטית כשמגדירים את תצוגת המפה של שיתוף המסלול.

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,
  ...
});

המאמרים הבאים

התאמה אישית של סמנים