התאמה אישית של ממשק המשתמש ב-iOS

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

המדריך הזה מתאר את האפשרויות שה-SDK מספק נכס consumerMapStyleCoordinator. הנכס הזה זמין דרך הכיתה GMTCMapView. הוא כולל רק את הרכיבים של ממשק המשתמש, ומניח אפליקציית צריכה פעילה. למידע על הגדרת הקצה העורפי הדרושים ל-SDK לצרכנים, תחילת העבודה עם Fleet Engine.

מתבצע אתחול של אפשרויות ההתאמה האישית של ממשק המשתמש

הקריאה החוזרת (callback) המומלצת ששימשה בהתחלה להגדרה של אפשרויות ההתאמה האישית של ממשק המשתמש הוצהרה ב-GMTCMapViewDelegate. mapViewDidInitialize הקריאה החוזרת (callback) מופעלת כשהאובייקט GMTCMapView מוכן לעיבוד המפה. מתאם הסגנונות מופעל, אך לא קיימים רכיבי ממשק משתמש.

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

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

בדוגמה הבאה משתמשים ב-GMTCMapView להתאמה אישית של סגנונות של סמנים. כדי להגדיר את סוג הסמן ואת המאפיינים שלו, צריך להשתמש ב setMarkerStyleOptions(_:markerType:) אפשרויות הסמנים המותאמים אישית שלך מבטלות את ערכי ברירת המחדל שצוינו על ידי Consumer SDK.

Swift

/** ViewController.swift */

private func changeMarkerStyle(
  markerStyleOptions: GMTCMarkerStyleOptions?,
  markerType: GMTCCustomizableMarkerType
) {
  let styleCoordinator = mapView.consumerMapStyleCoordinator
  styleCoordinator.setMarkerStyleOptions(markerStyleOptions, markerType: markerType)
}

/** To restore the default values, call setMarkerStyleOptions(_:markerType:) using nil for the GMTCMarkerStyleOptions parameter.
Here is an example of retrieving the active GMTCMarkerStyleOptions. */

private func retrieveMarkerStyle(markerType: GMTCCustomizableMarkerType) {
  let styleCoordinator = mapView.consumerMapStyleCoordinator

  // The 'markerStyleOptions' contains the stored style options for this marker type.
  let markerStyleOptions = styleCoordinator.markerStyleOptions(for: markerType)
}

Objective-C

/** ViewController.h */

- (void)changeMarkerStyle:(nullable GMTCMarkerStyleOptions *)markerStyleOptions
               markerType:(GMTCCustomizableMarkerType)markerType {
  GMTCConsumerMapStyleCoordinator *styleCoordinator = _mapView.consumerMapStyleCoordinator;
  [styleCoordinator setMarkerStyleOptions:markerStyleOptions markerType:markerType];
}

/** To restore the default values, call setMarkerStyleOptions:markerStyleOptions:markerType: using nil for the GMTCMarkerStyleOptions parameter.
Here is an example of retrieving the active GMTCMarkerStyleOptions. */

- (void)retrieveMarkerStyle:(GMTCCustomizableMarkerType)markerType {
  GMTCConsumerMapStyleCoordinator *styleCoordinator = _mapView.consumerMapStyleCoordinator;

  // The 'markerStyleOptions' contains the stored style options for this marker type.
  GMTCMarkerStyleOptions *markerStyleOptions = [styleCoordinator markerStyleOptionsForType:markerType];
}

סוגי סמנים

הסמנים הבאים זמינים להתאמה אישית:

  • GMTCCustomizableMarkerType.unknown
  • GMTCCustomizableMarkerType.tripPickupPoint
  • GMTCCustomizableMarkerType.tripDropoffPoint
  • GMTCCustomizableMarkerType.tripVehicle
  • GMTCCustomizableMarkerType.intermediateDestination

שימוש ב-GMTCCustomizableMarkerType.tripPickupPoint, GMTCCustomizableMarkerType.intermediateDestination, ו-GMTCCustomizableMarkerType.tripDropoffPoint כדי להתאים אישית את ציוני הדרך התקדמות הנסיעה וההזמנה.

אפשר להשתמש ב-GMTCCustomizableMarkerType.tripVehicle כדי להתאים אישית את סמל הרכב במהלך הנסיעה והתקדמות ההזמנה. סמל הסמן לא משתנה בהתאם לסוג הרכב בנסיעה עצמה.

אפשרויות עט סימון

המאפיינים המותאמים אישית שזמינים לכל סמן הם קבוצת משנה של נכסים שסופקו על ידי מפות Google MarkerOptions ערכת ה-SDK לצרכן GMTCMarkerStyleOptions הם נוצרים באמצעות מאתחל, ואי אפשר לשנות אותם לאחר בנייתם. ערכי ברירת מחדל סופקו לכל נכס, כך שיש לציין רק ערכים מותאמים אישית.

המאפיינים הבאים זמינים להתאמה אישית:

  • groundAnchor
  • isVisible
  • iconView
  • icon
  • zIndex
  • isFlat

הגדרה של isVisible כ-False זהה ל'כיבוי' הסמן. יש לספק מספיק נתונים כדי לאפשר לכם להשתמש ברכיב ממשק משתמש משלכם במקומו.

דוגמה

Swift

/** MapViewController.swift */

private func updateMarkerUIOptions() {
  // Get the GMTCConsumerMapStyleCoordinator
  let consumerMapStyleCoordinator = mapView.consumerMapStyleCoordinator

  // The marker type that you would like to set custom UI options for.
  let customizableMarkerType = GMTCCustomizableMarkerType.tripVehicle

  // Initializing marker options.
  let markerStyleOptions = GMTCMutableMarkerStyleOptions()
  markerStyleOptions.groundAnchor = kGMSMarkerDefaultGroundAnchor
  markerStyleOptions.icon = icon
  markerStyleOptions.zIndex = 100
  markerStyleOptions.isFlat = false
  markerStyleOptions.isVisible = true

  consumerMapStyleCoordinator.setMarkerStyleOptions(markerStyleOptions, markerType: customizableMarkerType)

  // Reset marker options to default values.
  consumerMapStyleCoordinator.setMarkerStyleOptions(nil, markerType: customizableMarkerType)
}

Objective-C

/** MapViewController.m */

- (void)updateMarkerUIOptions {
  // Get the GMTCConsumerMapStyleCoordinator
  GMTCConsumerMapStyleCoordinator *consumerMapStyleCoordinator = [_mapView consumerMapStyleCoordinator];

  // The marker type that you would like to set custom UI options for.
  GMTCCustomizableMarkerType customizableMarkerType = GMTCCustomizableMarkerTypeTripVehicle;

  // Initializing marker options.
  GMTCMutableMarkerStyleOptions *markerStyleOptions =
      [[GMTCMutableMarkerStyleOptions alloc] init];
  markerStyleOptions.groundAnchor = kGMSMarkerDefaultGroundAnchor;
  markerStyleOptions.icon = icon;
  markerStyleOptions.zIndex = 100;
  markerStyleOptions.isFlat = NO;
  markerStyleOptions.isVisible = YES;

  [consumerMapStyleCoordinator setMarkerStyleOptions:markerStyleOptions markerType:customizableMarkerType];

  // Reset marker options to default values.
  [consumerMapStyleCoordinator setMarkerStyleOptions:nil markerType:customizableMarkerType];
}

עדכונים דינמיים של זמני הגעה משוערים לסמני איסוף

כדי ליצור סמן לאיסוף שמציג באופן דינמי את זמן ההגעה המשוער המעודכן מדי פעם, לעדכן את אפשרויות הסגנון של הסמן עבור GMTCCustomizableMarkerType.tripPickupPoint.

דוגמה

Swift

/** MapViewController.swift */

/// Updates the ETA every minute by creating a Timer that repeats every minute.
private func schedulePickupMarkerStyleUpdates() {
  Timer.scheduledTimer(
    timeInterval: 60.0,  // Update marker ETA every minute.
    target: self,
    selector: #selector(updatePickupMarkerETA),
    userInfo: nil,
    repeats: true)
}

/// Updates the marker options for GMTCCustomizableMarkerType.tripPickupPoint for the current time.
@objc private func updatePickupMarkerETA() {
  let consumerMapStyleCoordinator = mapView.consumerMapStyleCoordinator
  let previousOptions = consumerMapStyleCoordinator.markerStyleOptions(for: .tripPickupPoint)

  // Get updated ETA icon.
  let updatedETAIcon = pickupIconForCurrentTime()

  let markerStyleOptions = GMTCMutableMarkerStyleOptions()
  markerStyleOptions.groundAnchor = kGMSMarkerDefaultGroundAnchor
  markerStyleOptions.icon = updatedETAIcon
  markerStyleOptions.zIndex = 100
  markerStyleOptions.isFlat = false
  markerStyleOptions.isVisible = true

  consumerMapStyleCoordinator.setMarkerStyleOptions(markerStyleOptions, markerType: .tripPickupPoint)
}

Objective-C

/** MapViewController.m */

/** Updates the ETA every minute by creating an NSTimer that repeats every minute. */
- (void)schedulePickupMarkerStyleUpdates {
  [NSTimer scheduledTimerWithTimeInterval:60.0 // Update marker ETA every minute.
                                   target:self
                                 selector:@selector(updatePickupMarkerETA)
                                 userInfo:nil
                                  repeats:YES];
}

/** Updates the marker options for GMTCCustomizableMarkerTypeTripPickupPoint for the current time. */
- (void)updatePickupMarkerETA {
  GMTCConsumerMapStyleCoordinator *consumerMapStyleCoordinator = [_mapView consumerMapStyleCoordinator];
  GMTCMarkerStyleOptions *previousOptions = [consumerMapStyleCoordinator markerStyleOptionsForType:GMTCCustomizableMarkerTypeTripPickupPoint];

  // Get updated ETA icon.
  UIImage *updatedETAIcon = [self pickupIconForCurrentTime];

  GMTCMutableMarkerStyleOptions *markerStyleOptions =
                               [[GMTCMutableMarkerStyleOptions alloc] init];
  markerStyleOptions.groundAnchor = kGMSMarkerDefaultGroundAnchor;
  markerStyleOptions.icon = updatedETAIcon;
  markerStyleOptions.zIndex = 100;
  markerStyleOptions.isFlat = NO;
  markerStyleOptions.isVisible = YES;

  [consumerMapStyleCoordinator setMarkerStyleOptions:markerStyleOptions markerType:GMTCCustomizableMarkerTypeTripPickupPoint];
}

קווים פוליגוניים מותאמים אישית

ההתאמה האישית של קו פוליגוני מוגדרת באמצעות GMTCConsumerMapStyleCoordinator#setPolylineStyleOptions(_:polylineType:)

הדוגמה הבאה מראה איך להגדיר אפשרויות סגנון של קו פוליגוני:

Swift

/** ViewController.swift */

private func changePolylineStyleOptions(
  polylineStyleOptions: GMTCPolylineStyleOptions?,
  polylineType: GMTCPolylineType
) {
  let styleCoordinator = mapView.consumerMapStyleCoordinator
  styleCoordinator.setPolylineStyleOptions(polylineStyleOptions, polylineType: polylineType)
}

/* Setting custom polyline options will override the default values provided by the Consumer SDK.
The default values can be restored by calling setPolylineStyleOptions(_:polylineType:) with nil for the GMTCPolylineStyleOptions.
The active GMTCPolylineStyleOptions can be retrieved via */

private func retrievePolylineStyleOptions(for polylineType: GMTCPolylineType) {
  let styleCoordinator = mapView.consumerMapStyleCoordinator

  // The 'polylineStyleOptions' contains the stored style options for this polyline type.
  let polylineStyleOptions = styleCoordinator.polylineStyleOptions(for: polylineType)
}

Objective-C

/** ViewController.h */

- (void)changePolylineStyleOptions:(nullable GMTCPolylineStyleOptions *)polylineStyleOptions
                      polylineType:(GMTCPolylineType)polylineType {
  GMTCConsumerMapStyleCoordinator *styleCoordinator = _mapView.consumerMapStyleCoordinator;
  [styleCoordinator setPolylineStyleOptions:polylineStyleOptions polylineType:polylineType];
}

/* Setting custom polyline options will override the default values provided by the Consumer SDK.
The default values can be restored by calling setPolylineStyleOptions:polylineType: with nil for the GMTCPolylineStyleOptions.
The active GMTCPolylineStyleOptions can be retrieved via */

- (void)retrievePolylineStyleOptionsForType:(GMTCPolylineType)polylineType {
  GMTCConsumerMapStyleCoordinator *styleCoordinator = _mapView.consumerMapStyleCoordinator;

  // The 'polylineStyleOptions' contains the stored style options for this polyline type.
  GMTCPolylineStyleOptions *polylineStyleOptions = [styleCoordinator polylineStyleOptionsForType:polylineType];
}

סוגי קו פוליגוני

הסוגים הבאים של קווים פוליגוניים זמינים להתאמה אישית:

  • GMTCPolylineType.activeRoute
  • GMTCPolylineType.remainingRoute

GMTCPolylineType.activeRoute ו-GMTCPolylineType.remainingRoute מוצגים במהלך הנסיעה והתקדמות ההזמנה. GMTCPolylineType.activeRoute הוא המסלול שבו הרכב עובר עד לנקודה הבאה של הנוסע, בין אם האיסוף או המסירה. GMTCPolylineType.remainingRoute הוא הפלח של הנסיעה שנותרה אחרי השלמת GMTCPolylineType.activeRoute של הרכב.

מאפייני קו פוליגוני

המאפיינים הזמינים להתאמה אישית לכל קו פוליגוני הם קבוצת משנה של נכסים שסופקו במפות Google PolylineOptions ערכת ה-SDK לצרכנים GMTCPolylineStyleOptions נבנים באמצעות מאתחל. אם רוצים, אפשר להגדיר אותם כך שלא ניתן לשנות או לשנות אותם כדי לספק ערכים מותאמים אישית לכל נכס. ערכי ברירת מחדל ניתנים לכל נכס.

המאפיינים הבאים זמינים להתאמה אישית:

  • color
  • width
  • isVisible
  • isTrafficEnabled

הגדרת isVisible לערך false מקבילה להשבתת הקו הפוליגוני. כברירת מחדל, הערך של isTrafficEnabled הוא false.

דוגמה

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

קווים פוליגוניים שמתאימים לתנועה

כברירת מחדל, שכבת התנועה של הקו הפוליגוני מושבתת. כשהיא מופעלת עם polylineStyleOptions.isTrafficEnabled = true, פלחים שמייצגים קטעים של תנועה פסולה משורטטת כנתיב.

מצב התנועה מיוצג באחת מארבע מהירויות: GMTSSpeedType.noData, GMTSSpeedType.normal, GMTSSpeedType.slow וגם GMTSSpeedType.trafficJam. ניתן להתאים אישית את הצבע שמייצג כל אחד מסיווגי המהירות האלה. עם setTrafficColorFor(_:color:).