মার্কার (বা পলিলাইন) কাস্টমাইজ করার আগে, আপনাকে প্রথমে UI কাস্টমাইজেশন অপশনগুলো ইনিশিয়ালাইজ করতে হবে।
UI কাস্টমাইজেশন বিকল্পগুলি শুরু করুন
UI কাস্টমাইজেশন অপশনগুলো প্রাথমিকভাবে সেট করার জন্য ব্যবহৃত প্রস্তাবিত কলব্যাকটি GMTCMapViewDelegate এ ডিক্লেয়ার করা থাকে। যখন GMTCMapView অবজেক্টটি ম্যাপ রেন্ডার করার জন্য প্রস্তুত হয়, তখন mapViewDidInitialize কলব্যাকটি ট্রিগার হয়। স্টাইল কোঅর্ডিনেটরটি ইনিশিয়ালাইজ করা হয়, কিন্তু কোনো UI এলিমেন্ট উপস্থিত থাকে না।
সুইফট
/** ViewController.swift */
class ViewController: UIViewController, GMTCMapViewDelegate {
// MARK: - GMTCMapViewDelegate
func mapViewDidInitialize(_ mapview: GMTCMapView) {
// Set the UI customization options here.
}
}
উদ্দেশ্য-সি
/** ViewController.m */
@interface ViewController () <GMTCMapViewDelegate>
#pragma mark GMTCMapViewDelegate
- (void)mapViewDidInitialize:(GMTCMapView *)mapview {
// Set the UI customization options here.
}
মার্কার কাস্টমাইজ করুন
নিম্নলিখিত উদাহরণটি মার্কার স্টাইল কাস্টমাইজ করার জন্য GMTCMapView ব্যবহার করে। মার্কারের ধরন এবং এর প্রোপার্টিগুলো সেট করতে, setMarkerStyleOptions(_:markerType:) ব্যবহার করুন। আপনার কাস্টম মার্কার অপশনগুলো কনজিউমার SDK দ্বারা প্রদত্ত ডিফল্ট মানগুলোকে ওভাররাইড করে।
সুইফট
/** MapViewController.swift */
func updateMarkerUIOptions() {
let customizableMarkerType = GMTCCustomizableMarkerType.tripVehicle
let markerStyleOptions = GMTCMutableMarkerStyleOptions()
markerStyleOptions.groundAnchor = groundAnchor
markerStyleOptions.isVisible = true
markerStyleOptions.icon = icon
markerStyleOptions.zIndex = 100
markerStyleOptions.isFlat = false
let coordinator = self.mapView.consumerMapStyleCoordinator
coordinator.setMarkerStyleOptions(markerStyleOptions, markerType: customizableMarkerType)
}
/** 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)
}
উদ্দেশ্য-সি
/** MapViewController.m */
- (void)updateMarkerUIOptions {
// The marker type that you would like to set custom UI options for.
GMTCCustomizableMarkerType customizableMarkerType = GMTCCustomizableMarkerTypeTripVehicle;
GMTCMutableMarkerStyleOptions *markerStyleOptions =
[[GMTCMutableMarkerStyleOptions alloc] init];
markerStyleOptions.groundAnchor = groundAnchor;
markerStyleOptions.isVisible = YES;
markerStyleOptions.icon = icon;
markerStyleOptions.zIndex = 100;
markerStyleOptions.isFlat = NO;
[[_mapView consumerMapStyleCoordinator] setMarkerStyleOptions:markerStyleOptions markerType:customizableMarkerType];
}
/** 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 Maps MarkerOptions দ্বারা প্রদত্ত প্রোপার্টিগুলোর একটি উপসেট। কনজিউমার SDK-এর GMTCMarkerStyleOptions নিম্নলিখিত বৈশিষ্ট্যগুলো রয়েছে:
- ইনিশিয়ালাইজার ব্যবহার করে নির্মিত
- একবার নির্মিত হলে অপরিবর্তনীয়।
- এগুলোর ডিফল্ট মান রয়েছে, তাই আপনাকে শুধু যেকোনো কাস্টম মান নির্দিষ্ট করতে হবে।
আপনি নিম্নলিখিত বৈশিষ্ট্যগুলি কাস্টমাইজ করতে পারেন:
-
groundAnchor -
isVisible: কোনো মার্কার বন্ধ করতে,isVisibleকে false সেট করুন। এর জায়গায় আপনার নিজস্ব UI এলিমেন্ট ব্যবহার করার জন্য পর্যাপ্ত ডেটা সরবরাহ করা উচিত। -
iconView -
icon -
zIndex -
isFlat
উদাহরণ
সুইফট
/** 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)
}
উদ্দেশ্য-সি
/** 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];
}
পিকআপ মার্কারগুলির জন্য ডায়নামিক ETA আপডেট
এমন একটি পিকআপ মার্কার তৈরি করতে যা পর্যায়ক্রমে আপডেট হওয়া ETA গতিশীলভাবে দেখায়, GMTCCustomizableMarkerType.tripPickupPoint এর জন্য মার্কার স্টাইল অপশনগুলো আপডেট করুন।
উদাহরণ
সুইফট
/** 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)
}
উদ্দেশ্য-সি
/** 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];
}