diff options
author | Jesse Bounds <jesse@rebounds.net> | 2016-12-12 10:38:49 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-12 10:38:49 -0800 |
commit | e38b4b590df2f74b47e25df9c44f4152ef1c582c (patch) | |
tree | a1c1579773b8cb70b0a6743c1bcdfb906e8662a3 /platform/ios | |
parent | 3fed3c10edb2cd015bd733a22c56ace7af900ef8 (diff) | |
download | qtlocation-mapboxgl-e38b4b590df2f74b47e25df9c44f4152ef1c582c.tar.gz |
[ios, macos] Load features into shape source if possible (#7339)
This checks the kind of MGLShape passed into the source and, if it
is a feature, it mbgl feature objects to pass to core. This keeps the
feature id and attributes data intact. If the shape is a
`MGLShapeCollectionFeature` it creates an `mbgl::FeatureCollection`
object (also to keep feature properties). If the shape is not any
sort of feature, it passes along just the geometry.
This also uses the MGLFeatureFromMBGLFeature converter for the case where
GeoJSON data passed in to a source contains a single feature. The
converter has logic to keep the id and attributes properties intact.
Before, these properties were lost because only geometry conversion
was done.
Finally, logic to handle (and associated tests) of nested shape
collection features is removed since that is not supported by
the GeoJSON spec or the core implementation.
[ios] Add test of drawing plain shape to iosapp
Diffstat (limited to 'platform/ios')
-rw-r--r-- | platform/ios/app/MBXViewController.m | 29 | ||||
-rw-r--r-- | platform/ios/ios.xcodeproj/project.pbxproj | 2 |
2 files changed, 30 insertions, 1 deletions
diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index 2858753e83..9b3d003e23 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -954,10 +954,37 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { [self.mapView.style addSource:source]; MGLFillStyleLayer *layer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"leaf-fill-layer" source:source]; - layer.predicate = [NSPredicate predicateWithFormat:@"color = %@", @"red"]; + layer.predicate = [NSPredicate predicateWithFormat:@"color = 'red'"]; MGLStyleValue *fillColor = [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor redColor]]; layer.fillColor = fillColor; [self.mapView.style addLayer:layer]; + + NSString *geoJSON = @"{\"type\": \"Feature\", \"properties\": {\"color\": \"green\"}, \"geometry\": { \"type\": \"Point\", \"coordinates\": [ -114.06847000122069, 51.050459433092655 ] }}"; + + NSData *data = [geoJSON dataUsingEncoding:NSUTF8StringEncoding]; + MGLShapeSource *pointSource = [[MGLShapeSource alloc] initWithIdentifier:@"leaf-point-source" geoJSONData:data options:nil]; + [self.mapView.style addSource:pointSource]; + + MGLCircleStyleLayer *circleLayer = [[MGLCircleStyleLayer alloc] initWithIdentifier:@"leaf-circle-layer" source:pointSource]; + circleLayer.circleColor = [MGLStyleValue valueWithRawValue:[UIColor greenColor]]; + circleLayer.predicate = [NSPredicate predicateWithFormat:@"color = 'green'"]; + [self.mapView.style addLayer:circleLayer]; + + + CLLocationCoordinate2D squareCoords[] = { + {51.056070541830934, -114.0274429321289}, + {51.07937094724242, -114.0274429321289}, + {51.07937094724242, -113.98761749267578}, + {51.05607054183093, -113.98761749267578}, + {51.056070541830934, -114.0274429321289}, + }; + MGLPolygon *polygon = [MGLPolygon polygonWithCoordinates:squareCoords count:sizeof(squareCoords)/sizeof(squareCoords[0])]; + MGLShapeSource *plainShapeSource = [[MGLShapeSource alloc] initWithIdentifier:@"leaf-plain-shape-source" shape:polygon options:nil]; + [self.mapView.style addSource:plainShapeSource]; + + MGLFillStyleLayer *plainFillLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"leaf-plain-fill-layer" source:plainShapeSource]; + plainFillLayer.fillColor = [MGLStyleValue valueWithRawValue:[UIColor yellowColor]]; + [self.mapView.style addLayer:plainFillLayer]; } - (void)updateShapeSourceData diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index 8c69d7105e..6d778c571a 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -592,6 +592,7 @@ 4085AF081D933DEA00F11B22 /* MGLTileSetTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLTileSetTests.mm; path = ../../darwin/test/MGLTileSetTests.mm; sourceTree = "<group>"; }; 408AA8551DAEDA0800022900 /* NSDictionary+MGLAdditions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSDictionary+MGLAdditions.h"; sourceTree = "<group>"; }; 408AA8561DAEDA0800022900 /* NSDictionary+MGLAdditions.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = "NSDictionary+MGLAdditions.mm"; sourceTree = "<group>"; }; + 40986FE51DFA2B5C004A7E6E /* MGLShapeCollectionFeature_Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLShapeCollectionFeature_Private.h; sourceTree = "<group>"; }; 40CF6DBA1DAC3C1800A4D18B /* MGLShape_Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLShape_Private.h; sourceTree = "<group>"; }; 40CFA6501D787579008103BD /* MGLShapeSourceTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLShapeSourceTests.mm; path = ../../darwin/test/MGLShapeSourceTests.mm; sourceTree = "<group>"; }; 40EDA1BD1CFE0D4A00D9EA68 /* MGLAnnotationContainerView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAnnotationContainerView.h; sourceTree = "<group>"; }; @@ -1299,6 +1300,7 @@ DA8847E01CBAFA5100AB86E3 /* MGLAnnotation.h */, DAD165691CF41981001FF4B9 /* MGLFeature.h */, DAD1656A1CF41981001FF4B9 /* MGLFeature_Private.h */, + 40986FE51DFA2B5C004A7E6E /* MGLShapeCollectionFeature_Private.h */, DAD1656B1CF41981001FF4B9 /* MGLFeature.mm */, DA8847E11CBAFA5100AB86E3 /* MGLGeometry.h */, DA8848011CBAFA6200AB86E3 /* MGLGeometry_Private.h */, |