تخصيص واجهة مستخدم iOS

باستخدام حزمة SDK للمستهلكين، يمكنك تطبيق علامات مخصصة توجيه الخطوط المتعددة إلى تصميم تطبيقك. تمكن عناصر التصميم هذه المستهلك التطبيق لعرض معاينة ديناميكية لمسار المركبة.

يستعرض هذا الدليل الخيارات التي توفرها حزمة SDK في الموقع الإلكتروني consumerMapStyleCoordinator. هذا الموقع متاح من خلال لفئة GMTCMapView. فهو يتناول عناصر واجهة المستخدم فقط، ويفترض أن لديك تطبيق المستهلك الوظيفي. للحصول على معلومات حول إعداد الواجهة الخلفية التي تحتاجها SDK للمستهلك، فراجع بدء استخدام Fleet Engine

جارٍ تهيئة خيارات تخصيص واجهة المستخدم

رد الاتصال المقترَح المستخدَم في ضبط خيارات تخصيص واجهة المستخدم في البداية تم الإعلان عنه في GMTCMapViewDelegate. mapViewDidInitialize يتم تشغيل طلب الاستدعاء عندما يكون الكائن 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:) تلغي خيارات العلامة المخصصة والقيم التلقائية التي تقدّمها حزمة تطوير البرامج (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 على "خطأ" يساوي "إيقاف". محدد الموقع. يجب توفير بيانات كافية للسماح لك باستخدام عنصر واجهة المستخدم الخاص بك بدلاً منه.

مثال

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:).