במאמר הזה מוסבר איך להתאים אישית את המראה והסגנון של מפה, ואיך לשלוט באפשרויות של חלון התצוגה ובחשיפה של נתונים. אפשר לעשות זאת בדרכים הבאות:
- שימוש בעיצוב מפות מבוסס-ענן
- הגדרת אפשרויות של סגנון המפה ישירות בקוד שלכם
עיצוב המפה באמצעות עיצוב מפות מבוסס-ענן
כדי להחיל סגנון מפה על מפה של שיתוף נתוני נסיעה ב-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
במאמרי העזרה של 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" }
]
}
]
}
});
הצגת מידע במפה
הצגת מידע נוסף על כלי רכב או על סמן מיקום באמצעות 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,
...
});