Rota çoklu çizgilerini (veya işaretçilerini) özelleştirmeden önce kullanıcı arayüzü özelleştirme seçeneklerini başlatmanız gerekir.
Kullanıcı arayüzü özelleştirme seçeneklerini başlatma
Kullanıcı arayüzü özelleştirme seçeneklerini ilk olarak ayarlamak için kullanılan önerilen geri çağırma işlevi GMTCMapViewDelegate
içinde tanımlanır. mapViewDidInitialize
Geri çağırma, GMTCMapView
nesnesi haritayı oluşturmaya hazır olduğunda tetiklenir.
Stil koordinatörü başlatılmış ancak kullanıcı arayüzü öğeleri 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 (teslim alma veya bırakma) giderken kullandığı rota.GMTCPolylineType.remainingRoute
: AraçGMTCPolylineType.activeRoute
tamamlandıktan sonra yolculuğun kalan kısmı.
Bu türlerin her ikisi de paylaşılan 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
.
Consumer SDK
GMTCPolylineStyleOptions
özellikleri aşağıdaki özelliklere sahiptir:
- Başlatıcı kullanılarak oluşturulmuş.
- Herhangi bir özellik için özel değerler sağlamak istiyorsanız değişmez veya değişebilir olabilir.
- Varsayılan değerlere sahip olmalıdır.
Aşağıdaki özellikleri özelleştirebilirsiniz:
color
width
isVisible
: Çoklu çizgiyi devre dışı bırakmak içinisVisible
değerinifalse
olarak ayarlayın.isTrafficEnabled
: Bu özellik varsayılan olarakfalse
olarak 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];
}
Trafiğe duyarlı çoklu çizgiler
Çoklu çizginin trafik katmanı varsayılan olarak devre dışıdır. polylineStyleOptions.isTrafficEnabled = true
kullanarak etkinleştirdiğinizde, normal olmayan trafik aralıklarını temsil eden segmentler rota olarak çizilir.
Trafik koşulları dört hızdan biriyle gösterilir:
GMTSSpeedType.noData
GMTSSpeedType.normal
GMTSSpeedType.slow
GMTSSpeedType.trafficJam
setTrafficColorFor(_:color:)
kullanarak bu hız sınıflandırmalarının her birini temsil eden rengi özelleştirebilirsiniz.