Rota çoklu çizgilerini (veya işaretçileri) özelleştirmeden önce kullanıcı arayüzü özelleştirme seçeneklerini ilk kullanıma hazırlamanız gerekir.
Kullanıcı arayüzü özelleştirme seçeneklerini başlatma
Kullanıcı arayüzü özelleştirme seçeneklerini ilk kez ayarlamak için kullanılan önerilen geri çağırma, GMTCMapViewDelegate içinde tanımlanır. mapViewDidInitialize geri çağırma işlevi, GMTCMapView nesnesi haritayı oluşturmaya hazır olduğunda tetiklenir.
Stil koordinatörü başlatıldı ancak kullanıcı arayüzü öğesi yok.
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.
}
Çoklu çizgileri özelleştirme
Çoklu çizgi özelleştirmesi GMTCConsumerMapStyleCoordinator#setPolylineStyleOptions(_:polylineType:) kullanılarak ayarlanır.
Aşağıdaki örnekte, çoklu çizgi stili seçeneklerinin nasıl ayarlanacağı gösterilmektedir:
Çoklu çizgi türleri
Aşağıdaki çoklu çizgi türlerini özelleştirebilirsiniz:
GMTCPolylineType.activeRoute: Aracın yolcunun bir sonraki noktasına (alınacağı veya bırakılacağı yer) gitmek için kullandığı rota.GMTCPolylineType.remainingRoute: AraçGMTCPolylineType.activeRoutetamamladıktan sonra seyahatin kalan bölümü.
Bu türlerin her ikisi de paylaşılan bir yolculuk boyunca gösterilir.
Çoklu çizgi özellikleri
Her çoklu çizgi için özelleştirebileceğiniz özellikler, Google Haritalar'da sağlanan özelliklerin bir alt kümesidir PolylineOptions.
Tüketici SDK'sı
GMTCPolylineStyleOptions
özellikleri aşağıdaki niteliklere sahiptir:
- Başlatıcı kullanılarak oluşturulur.
- Herhangi bir özellik için özel değerler sağlamak istiyorsanız sabit veya değişken olabilir.
- Varsayılan değerleri vardır.
Aşağıdaki özellikleri özelleştirebilirsiniz:
colorwidthisVisible: Çoklu çizgiyi devre dışı bırakmak içinisVisibledeğerinifalseolarak ayarlayın.isTrafficEnabled: Bu özellik varsayılan olarakfalseşeklinde ayarlanır.
Örnek
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];
}
Trafik bilgisine dayalı çoklu çizgiler
Çoklu çizginin trafik katmanı varsayılan olarak devre dışıdır. polylineStyleOptions.isTrafficEnabled = true kullanarak bu özelliği etkinleştirdiğinizde, normal olmayan trafik bölümlerini temsil eden segmentler rota olarak çizilir.
Trafik koşulları dört hızdan biriyle gösterilir:
GMTSSpeedType.noDataGMTSSpeedType.normalGMTSSpeedType.slowGMTSSpeedType.trafficJam
setTrafficColorFor(_:color:) kullanarak bu hız sınıflandırmalarının her birini temsil eden rengi özelleştirebilirsiniz.