Bevor Sie Routen-Polylinien oder ‑Markierungen anpassen können, müssen Sie zuerst die Optionen zur Anpassung der Benutzeroberfläche initialisieren.
Optionen zur Anpassung der Benutzeroberfläche initialisieren
Der empfohlene Callback zum anfänglichen Festlegen der Optionen für die UI-Anpassung wird in GMTCMapViewDelegate
deklariert. Der mapViewDidInitialize
-Callback wird ausgelöst, wenn das GMTCMapView
-Objekt bereit ist, die Karte zu rendern.
Der Style-Coordinator wurde initialisiert, aber es sind keine UI-Elemente vorhanden.
Swift
/** ViewController.swift */
class ViewController: UIViewController, GMTCMapViewDelegate {
// MARK: - GMTCMapViewDelegate
func mapViewDidInitialize(_ mapview: GMTCMapView) {
// Set the UI customization options here.
}
}
Objective-C
/** ViewController.m */
@interface ViewController () <GMTCMapViewDelegate>
#pragma mark GMTCMapViewDelegate
- (void)mapViewDidInitialize:(GMTCMapView *)mapview {
// Set the UI customization options here.
}
Polylinien anpassen
Die Anpassung von Polylinien wird mit GMTCConsumerMapStyleCoordinator#setPolylineStyleOptions(_:polylineType:)
festgelegt.
Im folgenden Beispiel wird gezeigt, wie Sie Optionen für den Polylinienstil festlegen:
Polylinien-Typen
Sie können die folgenden Polylinien anpassen:
GMTCPolylineType.activeRoute
: Die Route, die das Fahrzeug zum nächsten Punkt des Fahrgasts nimmt, unabhängig davon, ob es sich um den Abhol- oder den Zielort handelt.GMTCPolylineType.remainingRoute
: Das Segment der Fahrt, das nach Abschluss derGMTCPolylineType.activeRoute
durch das Fahrzeug verbleibt.
Beide Arten werden während einer gemeinsamen Reise angezeigt.
Polylinienattribute
Die Eigenschaften, die Sie für jede Polylinie anpassen können, sind eine Teilmenge der Eigenschaften, die in Google Maps PolylineOptions
verfügbar sind.
Die Eigenschaften des Consumer SDK GMTCPolylineStyleOptions
haben die folgenden Merkmale:
- Mit einem Initialisierer erstellt.
- Kann unveränderlich oder veränderlich sein, wenn Sie benutzerdefinierte Werte für eine beliebige Property angeben möchten.
- Standardwerte haben.
Sie können die folgenden Attribute anpassen:
color
width
isVisible
: Wenn Sie eine Polylinie deaktivieren möchten, setzen SieisVisible
auffalse
.isTrafficEnabled
: Dieses Attribut ist standardmäßig auffalse
festgelegt.
Beispiel
Swift
/** MapViewController.swift */
private func updatePolylineUIOptions() {
// Get the GMTCConsumerMapStyleCoordinator
let consumerMapStyleCoordinator = mapView.consumerMapStyleCoordinator
// The polyline type that you would like to set custom UI options for.
let customizablePolylineType = GMTCPolylineType.activeRoute
// Initializing polyline options with default values (immutable version).
let polylineStyleOptions = GMTCPolylineStyleOptions()
consumerMapStyleCoordinator.setPolylineStyleOptions(
polylineStyleOptions, polylineType: customizablePolylineType)
// Initializing polyline options with custom values (mutable version).
let mutablePolylineStyleOptions = GMTCMutablePolylineStyleOptions()
mutablePolylineStyleOptions.isVisible = true
mutablepolylineStyleOptions.strokeWidth = 8.0
mutablepolylineStyleOptions.strokeColor = .blue
mutablepolylineStyleOptions.zIndex = 1000
mutablepolylineStyleOptions.isGeodesic = true
mutablePolylineStyleOptions.isTrafficEnabled = true
mutablePolylineStyleOptions.setTrafficColorFor(.slow, color: .yellow)
mutablePolylineStyleOptions.setTrafficColorFor(.trafficJam, color: .purple)
consumerMapStyleCoordinator.setPolylineStyleOptions(
mutablePolylineStyleOptions, polylineType: customizablePolylineType)
// Reset polyline options to default values.
consumerMapStyleCoordinator.setPolylineStyleOptions(
nil, polylineType: customizablePolylineType)
}
Objective-C
/** MapViewController.m */
- (void)updatePolylineUIOptions {
// Get the GMTCConsumerMapStyleCoordinator
GMTCConsumerMapStyleCoordinator *consumerMapStyleCoordinator = [_mapView consumerMapStyleCoordinator];
// The polyline type that you would like to set custom UI options for.
GMTCPolylineType customizablePolylineType = GMTCPolylineTypeActiveRoute;
// Initializing polyline options with default values (immutable version).
GMTCPolylineStyleOptions *polylineStyleOptions = [[GMTCPolylineStyleOptions alloc] init];
[consumerMapStyleCoordinator setPolylineStyleOptions:polylineStyleOptions
polylineType:customizablePolylineType];
// Initializing polyline options with custom values (mutable version).
GMTCMutablePolylineStyleOptions *mutablePolylineStyleOptions = [[GMTCMutablePolylineStyleOptions alloc] init];
mutablePolylineStyleOptions.isVisible = YES;
mutablepolylineStyleOptions.strokeWidth = 8.0;
mutablepolylineStyleOptions.strokeColor = [UIColor blueColor];
mutablepolylineStyleOptions.zIndex = 1000;
mutablepolylineStyleOptions.isGeodesic = YES;
mutablePolylineStyleOptions.isTrafficEnabled = YES;
[mutablePolylineStyleOptions setTrafficColorForSpeed:GMTSSpeedTypeSlow color:[UIColor yellowColor]];
[mutablePolylineStyleOptions setTrafficColorForSpeed:GMTSSpeedTypeTrafficJam color:[UIColor purpleColor]];
[consumerMapStyleCoordinator setPolylineStyleOptions:mutablePolylineStyleOptions
polylineType:customizablePolylineType];
// Reset polyline options to default values.
[consumerMapStyleCoordinator setPolylineStyleOptions:nil
polylineType:customizablePolylineType];
}
Polylinien mit Verkehrsdaten
Die Verkehrsebene der Polylinie ist standardmäßig deaktiviert. Wenn Sie die Funktion mit polylineStyleOptions.isTrafficEnabled = true
aktivieren, werden Segmente, die Abschnitte mit nicht normalem Traffic darstellen, als Route gezeichnet.
Die Verkehrslage wird durch eine von vier Geschwindigkeiten dargestellt:
GMTSSpeedType.noData
GMTSSpeedType.normal
GMTSSpeedType.slow
GMTSSpeedType.trafficJam
Mit setTrafficColorFor(_:color:)
können Sie die Farbe anpassen, die für die einzelnen Geschwindigkeitsklassen verwendet wird.