ট্যাপ ইভেন্টগুলি পরিচালনা করুন

প্ল্যাটফর্ম নির্বাচন করুন: অ্যান্ড্রয়েড আইওএস জাভাস্ক্রিপ্ট

ডেটা ফিচারগুলোকে ট্যাপ ইভেন্টে সাড়া দেওয়ার উপযোগী করুন এবং ট্যাপ করা ফিচারটির কোনো অ্যাট্রিবিউটের মান প্রদর্শন করতে ইভেন্টটি ব্যবহার করুন।

ট্যাপ ইভেন্টের প্রতিক্রিয়ায় স্টাইলিং প্রয়োগ করুন।

ডেটাসেট লেয়ার ইভেন্টগুলি পরিচালনা করুন

এই উদাহরণটি YOUR_DATASET_ID আইডিযুক্ত একটি ডেটাসেটের ডেটা ফিচারগুলো দেখায় এবং ট্যাপ করা ফিচারের একটি অ্যাট্রিবিউটের মান প্রদর্শন করার জন্য ডেলিগেট ফাংশনটি প্রয়োগ করে।

এই উদাহরণে, ডেটাসেটটি নিউ ইয়র্ক সিটির পার্কগুলো দেখাচ্ছে। প্রতিটি পার্কের সাথে সম্পর্কিত ডেটাসেট ফিচারের জন্য, ডেটাসেটটিতে acres নামের একটি অ্যাট্রিবিউট থাকে, যেখানে পার্কটির পৃষ্ঠতলের ক্ষেত্রফল উল্লেখ করা থাকে। ট্যাপ করা কোনো পার্কের ক্ষেত্রে, acres অ্যাট্রিবিউটের মানটি প্রদর্শন করুন।

সুইফট

class SampleViewController: UIViewController {

  private lazy var mapView: GMSMapView = {
    let options = GMSMapViewOptions()
    options.mapID = GMSMapID(identifier: "YOUR_MAP_ID")
    options.camera = GMSCameraPosition(latitude: 40.7, longitude: -74, zoom: 12)
    return GMSMapView(options: options)
  }()

  // Set default styles.
  view = mapView
  let style = FeatureStyle(fill: .green.withAlphaComponent(0.5), stroke: .green, strokeWidth: 2)
  mapView.datasetFeatureLayer(of: "YOUR_DATASET_ID").style = { _ in style }
  mapView.delegate = self
}

extension SampleViewController: GMSMapViewDelegate {
  func mapView(_ mapView: GMSMapView, didTap features: [Feature], in featureLayer: FeatureLayer<Feature>, atLocation: CLLocationCoordinate2D) {
    let toast = UIAlertController(title: "Area of park", message: (features.compactMap { ($0 as? DatasetFeature)?.datasetAttributes["acres"] }).joined(separator: ", "), preferredStyle: .alert)
    present(toast, animated: true, completion: nil)
  }
}

উদ্দেশ্য-সি

@interface SampleViewController: UIViewController <GMSMapViewDelegate>
@end

@implementation SampleViewController
- (void)loadView {
    GMSMapViewOptions *options = [[GMSMapViewOptions alloc] init];
    options.camera = [GMSCameraPosition cameraWithLatitude:40.7 longitude:-74 zoom:12];
    options.mapID = [GMSMapID mapIDWithIdentifier:@"YOUR_MAP_ID"];
    GMSMapView *mapView = [[GMSMapView alloc] initWithOptions:options];
    mapView.delegate = self;

    // Set default styles.
    GMSFeatureStyle *style = [GMSFeatureStyle styleWithFillColor:[[UIColor greenColor] colorWithAlphaComponent:0.5] strokeColor:[UIColor greenColor] strokeWidth:2.0];
    [mapView datasetFeatureLayerOfDatasetID:@"YOUR_DATASET_ID"].style = ^(GMSDatasetFeature *feature) { return style; };

    self.view = mapView;
}

- (void)mapView:(GMSMapView *)mapView didTapFeatures:(NSArray<id<GMSFeature>> *)features inFeatureLayer:(GMSFeatureLayer *)featureLayer atLocation:(CLLocationCoordinate2D)location {
  NSMutableArray<NSString *> *parkAreas = [NSMutableArray array];

  for (id<GMSFeature> feature in features) {
    if (![feature isKindOfClass:[GMSDatasetFeature class]]) { continue; }
    NSString *nameDefinedInDataset = ((GMSDatasetFeature *)feature).datasetAttributes[@"acres"];
    [parkAreas addObject:nameDefinedInDataset];
  }

  UIAlertController *toast = [UIAlertController alertControllerWithTitle:@"Area of park" message:[parkAreas componentsJoinedByString:@", "] preferredStyle:UIAlertControllerStyleAlert];
  [self presentViewController:toast animated:YES completion:nil];
}
@end