diff options
author | Justin R. Miller <incanus@codesorcery.net> | 2017-05-25 16:25:57 -0700 |
---|---|---|
committer | Justin R. Miller <incanus@codesorcery.net> | 2017-05-25 16:25:57 -0700 |
commit | 4443eba18fd9a64f366356fa7bdc74e95f5e55ab (patch) | |
tree | 18f1381002e23e59b28af67036402fd25ddac43b | |
parent | ffff1c60b52128585fdc6cd8bfc9b034f8b058cf (diff) | |
download | qtlocation-mapboxgl-4443eba18fd9a64f366356fa7bdc74e95f5e55ab.tar.gz |
refs #1350, refs #8968: quick cut of iOS image source bindings
-rw-r--r-- | platform/darwin/src/MGLImageSource.h | 10 | ||||
-rw-r--r-- | platform/darwin/src/MGLImageSource.mm | 44 | ||||
-rw-r--r-- | platform/darwin/src/MGLImageSource_Private.h | 8 | ||||
-rw-r--r-- | platform/darwin/src/MGLStyle.mm | 4 | ||||
-rw-r--r-- | platform/ios/ios.xcodeproj/project.pbxproj | 18 | ||||
-rw-r--r-- | platform/ios/src/Mapbox.h | 1 |
6 files changed, 85 insertions, 0 deletions
diff --git a/platform/darwin/src/MGLImageSource.h b/platform/darwin/src/MGLImageSource.h new file mode 100644 index 0000000000..8e435a7072 --- /dev/null +++ b/platform/darwin/src/MGLImageSource.h @@ -0,0 +1,10 @@ +#import "MGLFoundation.h" +#import "MGLGeometry.h" +#import "MGLTileSource.h" + +MGL_EXPORT +@interface MGLImageSource : MGLTileSource + +- (instancetype)initWithIdentifier:(NSString *)identifier imageURL:(NSURL *)imageURL coordinateBounds:(MGLCoordinateBounds)coordinateBounds; + +@end diff --git a/platform/darwin/src/MGLImageSource.mm b/platform/darwin/src/MGLImageSource.mm new file mode 100644 index 0000000000..b118bb103c --- /dev/null +++ b/platform/darwin/src/MGLImageSource.mm @@ -0,0 +1,44 @@ +#import "MGLImageSource_Private.h" + +#import "MGLGeometry_Private.h" +#import "MGLSource_Private.h" +#import "MGLTileSource_Private.h" +#import "NSURL+MGLAdditions.h" + +#include <mbgl/style/sources/image_source.hpp> + +@interface MGLImageSource () + +@property (nonatomic, readonly) mbgl::style::ImageSource *rawSource; + +@end + +@implementation MGLImageSource + +- (instancetype)initWithIdentifier:(NSString *)identifier imageURL:(NSURL *)imageURL coordinateBounds:(MGLCoordinateBounds)coordinateBounds { + + const auto coordinates = MGLLatLngBoundsFromCoordinateBounds(coordinateBounds); + std::vector<mbgl::LatLng> coordinatesVector; + coordinatesVector.reserve(4); + coordinatesVector.push_back(coordinates.northwest()); + coordinatesVector.push_back(coordinates.northeast()); + coordinatesVector.push_back(coordinates.southeast()); + coordinatesVector.push_back(coordinates.southwest()); + + auto source = std::make_unique<mbgl::style::ImageSource>(identifier.UTF8String, coordinatesVector); + + source->setURL(imageURL.mgl_URLByStandardizingScheme.absoluteString.UTF8String); + + return self = [super initWithPendingSource:std::move(source)]; +} + +- (mbgl::style::ImageSource *)rawSource { + return (mbgl::style::ImageSource *)super.rawSource; +} + +- (NSString *)attributionHTMLString { + auto attribution = self.rawSource->getAttribution(); + return attribution ? @(attribution->c_str()) : nil; +} + +@end diff --git a/platform/darwin/src/MGLImageSource_Private.h b/platform/darwin/src/MGLImageSource_Private.h new file mode 100644 index 0000000000..a648cc9094 --- /dev/null +++ b/platform/darwin/src/MGLImageSource_Private.h @@ -0,0 +1,8 @@ +#import "MGLImageSource.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface MGLImageSource (Private) +@end + +NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm index 5f26b4fed2..a2a7100025 100644 --- a/platform/darwin/src/MGLStyle.mm +++ b/platform/darwin/src/MGLStyle.mm @@ -22,6 +22,7 @@ #import "MGLVectorSource.h" #import "MGLRasterSource.h" #import "MGLShapeSource.h" +#import "MGLImageSource.h" #import "MGLAttributionInfo_Private.h" @@ -39,6 +40,7 @@ #include <mbgl/style/sources/geojson_source.hpp> #include <mbgl/style/sources/vector_source.hpp> #include <mbgl/style/sources/raster_source.hpp> +#include <mbgl/style/sources/image_source.hpp> #if TARGET_OS_IPHONE #import "UIImage+MGLAdditions.h" @@ -176,6 +178,8 @@ static NSURL *MGLStyleURL_emerald; return [[MGLShapeSource alloc] initWithRawSource:geoJSONSource]; } else if (auto rasterSource = rawSource->as<mbgl::style::RasterSource>()) { return [[MGLRasterSource alloc] initWithRawSource:rasterSource]; + } else if (auto imageSource = rawSource->as<mbgl::style::ImageSource>()) { + return [[MGLImageSource alloc] initWithRawSource:rasterSource]; } else { return [[MGLSource alloc] initWithRawSource:rawSource]; } diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index 215d31810d..cc6bb94ed5 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -453,6 +453,12 @@ DD4823761D94AE6C00EB71B7 /* line_filter_style.json in Resources */ = {isa = PBXBuildFile; fileRef = DD4823731D94AE6C00EB71B7 /* line_filter_style.json */; }; DD4823771D94AE6C00EB71B7 /* numeric_filter_style.json in Resources */ = {isa = PBXBuildFile; fileRef = DD4823741D94AE6C00EB71B7 /* numeric_filter_style.json */; }; DD58A4C61D822BD000E1F038 /* MGLExpressionTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = DD58A4C51D822BD000E1F038 /* MGLExpressionTests.mm */; }; + DD945C111ED78D8A00AB8DB0 /* MGLImageSource.h in Headers */ = {isa = PBXBuildFile; fileRef = DD945C0F1ED78D8A00AB8DB0 /* MGLImageSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; + DD945C121ED78D8A00AB8DB0 /* MGLImageSource.h in Headers */ = {isa = PBXBuildFile; fileRef = DD945C0F1ED78D8A00AB8DB0 /* MGLImageSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; + DD945C131ED78D8A00AB8DB0 /* MGLImageSource.mm in Sources */ = {isa = PBXBuildFile; fileRef = DD945C101ED78D8A00AB8DB0 /* MGLImageSource.mm */; }; + DD945C141ED78D8A00AB8DB0 /* MGLImageSource.mm in Sources */ = {isa = PBXBuildFile; fileRef = DD945C101ED78D8A00AB8DB0 /* MGLImageSource.mm */; }; + DD945C161ED792D500AB8DB0 /* MGLImageSource_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = DD945C151ED792D500AB8DB0 /* MGLImageSource_Private.h */; }; + DD945C171ED792D500AB8DB0 /* MGLImageSource_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = DD945C151ED792D500AB8DB0 /* MGLImageSource_Private.h */; }; DD9BE4F71EB263C50079A3AF /* UIViewController+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = DD9BE4F51EB263C50079A3AF /* UIViewController+MGLAdditions.h */; }; DD9BE4F81EB263C50079A3AF /* UIViewController+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = DD9BE4F61EB263C50079A3AF /* UIViewController+MGLAdditions.m */; }; DD9BE4F91EB263D20079A3AF /* UIViewController+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = DD9BE4F51EB263C50079A3AF /* UIViewController+MGLAdditions.h */; }; @@ -928,6 +934,9 @@ DD4823731D94AE6C00EB71B7 /* line_filter_style.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = line_filter_style.json; sourceTree = "<group>"; }; DD4823741D94AE6C00EB71B7 /* numeric_filter_style.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = numeric_filter_style.json; sourceTree = "<group>"; }; DD58A4C51D822BD000E1F038 /* MGLExpressionTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLExpressionTests.mm; path = ../../darwin/test/MGLExpressionTests.mm; sourceTree = "<group>"; }; + DD945C0F1ED78D8A00AB8DB0 /* MGLImageSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLImageSource.h; sourceTree = "<group>"; }; + DD945C101ED78D8A00AB8DB0 /* MGLImageSource.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLImageSource.mm; sourceTree = "<group>"; }; + DD945C151ED792D500AB8DB0 /* MGLImageSource_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLImageSource_Private.h; sourceTree = "<group>"; }; DD9BE4F51EB263C50079A3AF /* UIViewController+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIViewController+MGLAdditions.h"; sourceTree = "<group>"; }; DD9BE4F61EB263C50079A3AF /* UIViewController+MGLAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+MGLAdditions.m"; sourceTree = "<group>"; }; FA68F1481E9D656600F9F6C2 /* MGLFillExtrusionStyleLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLFillExtrusionStyleLayer.h; sourceTree = "<group>"; }; @@ -983,6 +992,9 @@ 35136D491D4277EA00C20EFD /* Sources */ = { isa = PBXGroup; children = ( + DD945C0F1ED78D8A00AB8DB0 /* MGLImageSource.h */, + DD945C151ED792D500AB8DB0 /* MGLImageSource_Private.h */, + DD945C101ED78D8A00AB8DB0 /* MGLImageSource.mm */, 3566C76A1D4A8DFA008152BC /* MGLRasterSource.h */, DAF0D80F1DFE0EA000B28378 /* MGLRasterSource_Private.h */, 3566C76B1D4A8DFA008152BC /* MGLRasterSource.mm */, @@ -1634,11 +1646,13 @@ 35E1A4D81D74336F007AA97F /* MGLValueEvaluator.h in Headers */, DA88482C1CBAFA6200AB86E3 /* NSBundle+MGLAdditions.h in Headers */, 357FE2DD1E02D2B20068B753 /* NSCoder+MGLAdditions.h in Headers */, + DD945C111ED78D8A00AB8DB0 /* MGLImageSource.h in Headers */, 7E016D7E1D9E86BE00A29A21 /* MGLPolyline+MGLAdditions.h in Headers */, 35D13AB71D3D15E300AFB4E0 /* MGLStyleLayer.h in Headers */, DA88488E1CBB047F00AB86E3 /* reachability.h in Headers */, 40F887701D7A1E58008ECB67 /* MGLShapeSource_Private.h in Headers */, 350098DC1D484E60004B2AF0 /* NSValue+MGLStyleAttributeAdditions.h in Headers */, + DD945C161ED792D500AB8DB0 /* MGLImageSource_Private.h in Headers */, DA8848231CBAFA6200AB86E3 /* MGLOfflineStorage_Private.h in Headers */, 404326891D5B9B27007111BD /* MGLAnnotationContainerView_Private.h in Headers */, DA88483B1CBAFB8500AB86E3 /* MGLCalloutView.h in Headers */, @@ -1757,6 +1771,7 @@ DA35A29F1CC9E94C00E826B2 /* MGLCoordinateFormatter.h in Headers */, 404C26E31D89B877000AA13D /* MGLTileSource.h in Headers */, DABFB8611CBE99E500D62B32 /* MGLMultiPoint.h in Headers */, + DD945C171ED792D500AB8DB0 /* MGLImageSource_Private.h in Headers */, 3510FFF11D6D9D8C00F413B2 /* NSExpression+MGLAdditions.h in Headers */, 35D3A1E71E9BE7EC002B38EE /* MGLScaleBar.h in Headers */, 35E0CFE71D3E501500188327 /* MGLStyle_Private.h in Headers */, @@ -1812,6 +1827,7 @@ DABFB85D1CBE99E500D62B32 /* MGLAccountManager.h in Headers */, 353933F91D3FB79F003F57D7 /* MGLLineStyleLayer.h in Headers */, 35D13AB81D3D15E300AFB4E0 /* MGLStyleLayer.h in Headers */, + DD945C121ED78D8A00AB8DB0 /* MGLImageSource.h in Headers */, 35136D4D1D4277FC00C20EFD /* MGLSource.h in Headers */, DA35A2BC1CCA9A6900E826B2 /* MGLClockDirectionFormatter.h in Headers */, 35D13AC41D3D19DD00AFB4E0 /* MGLFillStyleLayer.h in Headers */, @@ -2233,6 +2249,7 @@ DA35A2B31CCA141D00E826B2 /* MGLCompassDirectionFormatter.m in Sources */, DD0902A91DB1929D00C5BDCE /* MGLNetworkConfiguration.m in Sources */, 35D13AB91D3D15E300AFB4E0 /* MGLStyleLayer.mm in Sources */, + DD945C131ED78D8A00AB8DB0 /* MGLImageSource.mm in Sources */, DA35A2CB1CCAAAD200E826B2 /* NSValue+MGLAdditions.m in Sources */, DA8848321CBAFA6200AB86E3 /* NSString+MGLAdditions.m in Sources */, 408AA8581DAEDA1E00022900 /* NSDictionary+MGLAdditions.mm in Sources */, @@ -2314,6 +2331,7 @@ DAA4E41F1CBB730400178DFB /* MGLMultiPoint.mm in Sources */, DD0902AA1DB1929D00C5BDCE /* MGLNetworkConfiguration.m in Sources */, DA35A2B41CCA141D00E826B2 /* MGLCompassDirectionFormatter.m in Sources */, + DD945C141ED78D8A00AB8DB0 /* MGLImageSource.mm in Sources */, 35D13ABA1D3D15E300AFB4E0 /* MGLStyleLayer.mm in Sources */, DA35A2CC1CCAAAD200E826B2 /* NSValue+MGLAdditions.m in Sources */, 408AA8591DAEDA1E00022900 /* NSDictionary+MGLAdditions.mm in Sources */, diff --git a/platform/ios/src/Mapbox.h b/platform/ios/src/Mapbox.h index 9a9dc702ca..41b48d83f4 100644 --- a/platform/ios/src/Mapbox.h +++ b/platform/ios/src/Mapbox.h @@ -51,6 +51,7 @@ FOUNDATION_EXPORT MGL_EXPORT const unsigned char MapboxVersionString[]; #import "MGLVectorSource.h" #import "MGLShapeSource.h" #import "MGLRasterSource.h" +#import "MGLImageSource.h" #import "MGLTilePyramidOfflineRegion.h" #import "MGLTypes.h" #import "MGLUserLocation.h" |