From dc2dc31c0bdd4f0b27412125032bfa694ade26b9 Mon Sep 17 00:00:00 2001 From: Fredrik Karlsson Date: Tue, 22 Nov 2016 15:54:38 +0100 Subject: [ios, macos] MGLGeoJSONSource can now be initialized with any shape --- platform/ios/app/MBXViewController.m | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'platform/ios/app') diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index 8a2ccee413..de1a337e42 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -877,7 +877,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { - (void)styleQuery { CGRect queryRect = CGRectInset(self.mapView.bounds, 100, 200); - NSArray *features = [self.mapView visibleFeaturesInRect:queryRect]; + NSArray *visibleFeatures = [self.mapView visibleFeaturesInRect:queryRect]; NSString *querySourceID = @"query-source-id"; NSString *queryLayerID = @"query-layer-id"; @@ -895,9 +895,9 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { [self.mapView.style removeSource:source]; } - dispatch_async(dispatch_get_main_queue(), ^{ - MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:querySourceID features:features options:nil]; + MGLShapeCollectionFeature *features = [MGLShapeCollectionFeature shapeCollectionWithShapes:visibleFeatures]; + MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:querySourceID shape:features options:nil]; [self.mapView.style addSource:source]; MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:queryLayerID source:source]; @@ -950,7 +950,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { feature.identifier = @"leaf-feature"; feature.attributes = @{@"color": @"red"}; - MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"leaf-source" features:@[feature] options:nil]; + MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"leaf-source" shape:feature options:nil]; [self.mapView.style addSource:source]; MGLFillStyleLayer *layer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"leaf-fill-layer" source:source]; @@ -1026,7 +1026,10 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { MGLPolygonFeature *smallBoxFeature = [MGLPolygonFeature polygonWithCoordinates:smallBox count:sizeof(smallBox)/sizeof(smallBox[0])]; MGLPolygonFeature *largeBoxFeature = [MGLPolygonFeature polygonWithCoordinates:largeBox count:sizeof(largeBox)/sizeof(largeBox[0])]; - MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"mutable-data-source-features-id" features:@[smallBoxFeature] options:nil]; + MGLShapeCollectionFeature *collection = [MGLShapeCollectionFeature shapeCollectionWithShapes:@[smallBoxFeature]]; + MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"mutable-data-source-features-id" + shape:collection + options:nil]; [self.mapView.style addSource:source]; MGLFillStyleLayer *layer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"mutable-data-layer-features-id" source:source]; @@ -1035,7 +1038,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { [self.mapView.style addLayer:layer]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - source.features = @[largeBoxFeature]; + source.shape = largeBoxFeature; }); } @@ -1049,7 +1052,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { {36.99508088541243, -109.04007911682129}, }; MGLPointCollectionFeature *feature = [MGLPointCollectionFeature pointCollectionWithCoordinates:coordinates count:4]; - MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"wiggle-source" features:@[feature] options:nil]; + MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithIdentifier:@"wiggle-source" shape:feature options:nil]; [self.mapView.style addSource:source]; MGLCircleStyleLayer *layer = [[MGLCircleStyleLayer alloc] initWithIdentifier:@"wiggle-layer" source:source]; @@ -1116,7 +1119,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { MGLPolylineFeature *routeLine = [MGLPolylineFeature polylineWithCoordinates:coords count:count]; - MGLGeoJSONSource *routeSource = [[MGLGeoJSONSource alloc] initWithIdentifier:@"style-route-source" features:@[routeLine] options:nil]; + MGLGeoJSONSource *routeSource = [[MGLGeoJSONSource alloc] initWithIdentifier:@"style-route-source" shape:routeLine options:nil]; [self.mapView.style addSource:routeSource]; MGLLineStyleLayer *baseRouteLayer = [[MGLLineStyleLayer alloc] initWithIdentifier:@"style-base-route-layer" source:routeSource]; -- cgit v1.2.1