summaryrefslogtreecommitdiff
path: root/platform/darwin
diff options
context:
space:
mode:
Diffstat (limited to 'platform/darwin')
-rw-r--r--platform/darwin/src/MGLRasterDEMSource.mm11
-rw-r--r--platform/darwin/src/MGLRasterTileSource.mm15
-rw-r--r--platform/darwin/src/MGLRasterTileSource_Private.h4
-rw-r--r--platform/darwin/test/MGLStyleTests.mm95
4 files changed, 67 insertions, 58 deletions
diff --git a/platform/darwin/src/MGLRasterDEMSource.mm b/platform/darwin/src/MGLRasterDEMSource.mm
index 27614b9ef4..753499ff94 100644
--- a/platform/darwin/src/MGLRasterDEMSource.mm
+++ b/platform/darwin/src/MGLRasterDEMSource.mm
@@ -7,11 +7,10 @@
@implementation MGLRasterDEMSource
-- (std::unique_ptr<mbgl::style::RasterSource>)pendingSourceWithIdentifier:(NSString *)identifier configurationURL:(NSURL *)configurationURL tileSize:(CGFloat)tileSize {
- NSString *configurationURLString = configurationURL.mgl_URLByStandardizingScheme.absoluteString;
- return std::make_unique<mbgl::style::RasterDEMSource>(identifier.UTF8String,
- configurationURLString.UTF8String,
- uint16_t(round(tileSize)));
+- (std::unique_ptr<mbgl::style::RasterSource>)pendingSourceWithIdentifier:(NSString *)identifier urlOrTileset:(mbgl::variant<std::string, mbgl::Tileset>)urlOrTileset tileSize:(uint16_t)tileSize {
+ auto source = std::make_unique<mbgl::style::RasterDEMSource>(identifier.UTF8String,
+ urlOrTileset,
+ tileSize);
+ return source;
}
-
@end
diff --git a/platform/darwin/src/MGLRasterTileSource.mm b/platform/darwin/src/MGLRasterTileSource.mm
index e89367711e..b31cee296f 100644
--- a/platform/darwin/src/MGLRasterTileSource.mm
+++ b/platform/darwin/src/MGLRasterTileSource.mm
@@ -33,15 +33,16 @@ static const CGFloat MGLRasterTileSourceRetinaTileSize = 512;
}
- (instancetype)initWithIdentifier:(NSString *)identifier configurationURL:(NSURL *)configurationURL tileSize:(CGFloat)tileSize {
- auto source = [self pendingSourceWithIdentifier:identifier configurationURL:configurationURL tileSize:tileSize];
+ NSString *configurationURLString = configurationURL.mgl_URLByStandardizingScheme.absoluteString;
+ auto source = [self pendingSourceWithIdentifier:identifier urlOrTileset:configurationURLString.UTF8String tileSize:uint16_t(round(tileSize))];
return self = [super initWithPendingSource:std::move(source)];
}
-- (std::unique_ptr<mbgl::style::RasterSource>)pendingSourceWithIdentifier:(NSString *)identifier configurationURL:(NSURL *)configurationURL tileSize:(CGFloat)tileSize {
- NSString *configurationURLString = configurationURL.mgl_URLByStandardizingScheme.absoluteString;
- return std::make_unique<mbgl::style::RasterSource>(identifier.UTF8String,
- configurationURLString.UTF8String,
- uint16_t(round(tileSize)));
+- (std::unique_ptr<mbgl::style::RasterSource>)pendingSourceWithIdentifier:(NSString *)identifier urlOrTileset:(mbgl::variant<std::string, mbgl::Tileset>)urlOrTileset tileSize:(uint16_t)tileSize {
+ auto source = std::make_unique<mbgl::style::RasterSource>(identifier.UTF8String,
+ urlOrTileset,
+ tileSize);
+ return source;
}
- (instancetype)initWithIdentifier:(NSString *)identifier tileURLTemplates:(NSArray<NSString *> *)tileURLTemplates options:(nullable NSDictionary<MGLTileSourceOption, id> *)options {
@@ -56,7 +57,7 @@ static const CGFloat MGLRasterTileSourceRetinaTileSize = 512;
tileSize = static_cast<uint16_t>(round(tileSizeNumber.doubleValue));
}
- auto source = std::make_unique<mbgl::style::RasterSource>(identifier.UTF8String, tileSet, tileSize);
+ auto source = [self pendingSourceWithIdentifier:identifier urlOrTileset:tileSet tileSize:tileSize];
return self = [super initWithPendingSource:std::move(source)];
}
diff --git a/platform/darwin/src/MGLRasterTileSource_Private.h b/platform/darwin/src/MGLRasterTileSource_Private.h
index 8502b811e2..55f342c7ff 100644
--- a/platform/darwin/src/MGLRasterTileSource_Private.h
+++ b/platform/darwin/src/MGLRasterTileSource_Private.h
@@ -1,8 +1,10 @@
#import "MGLRasterTileSource.h"
#include <memory>
+#include <mbgl/util/variant.hpp>
namespace mbgl {
+ class Tileset;
namespace style {
class RasterSource;
}
@@ -14,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, readonly, nullable) mbgl::style::RasterSource *rawSource;
-- (std::unique_ptr<mbgl::style::RasterSource>)pendingSourceWithIdentifier:(NSString *)identifier configurationURL:(NSURL *)configurationURL tileSize:(CGFloat)tileSize;
+- (std::unique_ptr<mbgl::style::RasterSource>)pendingSourceWithIdentifier:(NSString *)identifier urlOrTileset:(mbgl::variant<std::string, mbgl::Tileset>)urlOrTileset tileSize:(uint16_t)tileSize;
@end
diff --git a/platform/darwin/test/MGLStyleTests.mm b/platform/darwin/test/MGLStyleTests.mm
index 7aaf70a80a..ec2605646c 100644
--- a/platform/darwin/test/MGLStyleTests.mm
+++ b/platform/darwin/test/MGLStyleTests.mm
@@ -229,23 +229,23 @@
- (void)testRemovingSourceInUse {
// Add a raster tile source
- MGLRasterTileSource *rasterTileSource = [[MGLRasterTileSource alloc] initWithIdentifier:@"some-identifier" tileURLTemplates:@[] options:nil];
- [self.style addSource:rasterTileSource];
+ MGLVectorTileSource *vectorTileSource = [[MGLVectorTileSource alloc] initWithIdentifier:@"some-identifier" tileURLTemplates:@[] options:nil];
+ [self.style addSource:vectorTileSource];
// Add a layer using it
- MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"fillLayer" source:rasterTileSource];
+ MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"fillLayer" source:vectorTileSource];
[self.style addLayer:fillLayer];
// Attempt to remove the raster tile source
NSError *error;
- BOOL result = [self.style removeSource:rasterTileSource error:&error];
+ BOOL result = [self.style removeSource:vectorTileSource error:&error];
XCTAssertFalse(result);
XCTAssertEqualObjects(error.domain, MGLErrorDomain);
XCTAssertEqual(error.code, MGLErrorCodeSourceIsInUseCannotRemove);
// Ensure it is still there
- XCTAssertTrue([[self.style sourceWithIdentifier:rasterTileSource.identifier] isMemberOfClass:[MGLRasterTileSource class]]);
+ XCTAssertTrue([[self.style sourceWithIdentifier:vectorTileSource.identifier] isMemberOfClass:[MGLVectorTileSource class]]);
}
- (void)testLayers {
@@ -311,54 +311,61 @@
}
- (void)testRemovingLayerBeforeAddingSameLayer {
- MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"shape-source-removing-before-adding" shape:nil options:nil];
-
- // Attempting to find a layer with identifier will trigger an exception if the source associated with the layer is not added
- [self.style addSource:source];
-
- MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"fill-layer" source:source];
- [self.style removeLayer:fillLayer];
- [self.style addLayer:fillLayer];
- XCTAssertNotNil([self.style layerWithIdentifier:fillLayer.identifier]);
-
- MGLRasterStyleLayer *rasterLayer = [[MGLRasterStyleLayer alloc] initWithIdentifier:@"raster-layer" source:source];
- [self.style removeLayer:rasterLayer];
- [self.style addLayer:rasterLayer];
- XCTAssertNotNil([self.style layerWithIdentifier:rasterLayer.identifier]);
-
- MGLSymbolStyleLayer *symbolLayer = [[MGLSymbolStyleLayer alloc] initWithIdentifier:@"symbol-layer" source:source];
- [self.style removeLayer:symbolLayer];
- [self.style addLayer:symbolLayer];
- XCTAssertNotNil([self.style layerWithIdentifier:symbolLayer.identifier]);
-
- MGLLineStyleLayer *lineLayer = [[MGLLineStyleLayer alloc] initWithIdentifier:@"line-layer" source:source];
- [self.style removeLayer:lineLayer];
- [self.style addLayer:lineLayer];
- XCTAssertNotNil([self.style layerWithIdentifier:lineLayer.identifier]);
-
- MGLCircleStyleLayer *circleLayer = [[MGLCircleStyleLayer alloc] initWithIdentifier:@"circle-layer" source:source];
- [self.style removeLayer:circleLayer];
- [self.style addLayer:circleLayer];
- XCTAssertNotNil([self.style layerWithIdentifier:circleLayer.identifier]);
-
- MGLBackgroundStyleLayer *backgroundLayer = [[MGLBackgroundStyleLayer alloc] initWithIdentifier:@"background-layer"];
- [self.style removeLayer:backgroundLayer];
- [self.style addLayer:backgroundLayer];
- XCTAssertNotNil([self.style layerWithIdentifier:backgroundLayer.identifier]);
+ {
+ MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"shape-source-removing-before-adding" shape:nil options:nil];
+
+ // Attempting to find a layer with identifier will trigger an exception if the source associated with the layer is not added
+ [self.style addSource:source];
+
+ MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"fill-layer" source:source];
+ [self.style removeLayer:fillLayer];
+ [self.style addLayer:fillLayer];
+ XCTAssertNotNil([self.style layerWithIdentifier:fillLayer.identifier]);
+
+ MGLSymbolStyleLayer *symbolLayer = [[MGLSymbolStyleLayer alloc] initWithIdentifier:@"symbol-layer" source:source];
+ [self.style removeLayer:symbolLayer];
+ [self.style addLayer:symbolLayer];
+ XCTAssertNotNil([self.style layerWithIdentifier:symbolLayer.identifier]);
+
+ MGLLineStyleLayer *lineLayer = [[MGLLineStyleLayer alloc] initWithIdentifier:@"line-layer" source:source];
+ [self.style removeLayer:lineLayer];
+ [self.style addLayer:lineLayer];
+ XCTAssertNotNil([self.style layerWithIdentifier:lineLayer.identifier]);
+
+ MGLCircleStyleLayer *circleLayer = [[MGLCircleStyleLayer alloc] initWithIdentifier:@"circle-layer" source:source];
+ [self.style removeLayer:circleLayer];
+ [self.style addLayer:circleLayer];
+ XCTAssertNotNil([self.style layerWithIdentifier:circleLayer.identifier]);
+
+ MGLBackgroundStyleLayer *backgroundLayer = [[MGLBackgroundStyleLayer alloc] initWithIdentifier:@"background-layer"];
+ [self.style removeLayer:backgroundLayer];
+ [self.style addLayer:backgroundLayer];
+ XCTAssertNotNil([self.style layerWithIdentifier:backgroundLayer.identifier]);
+ }
+
+ {
+ MGLRasterTileSource *rasterSource = [[MGLRasterTileSource alloc] initWithIdentifier:@"raster-tile-source" tileURLTemplates:@[] options:nil];
+ [self.style addSource:rasterSource];
+
+ MGLRasterStyleLayer *rasterLayer = [[MGLRasterStyleLayer alloc] initWithIdentifier:@"raster-layer" source:rasterSource];
+ [self.style removeLayer:rasterLayer];
+ [self.style addLayer:rasterLayer];
+ XCTAssertNotNil([self.style layerWithIdentifier:rasterLayer.identifier]);
+ }
}
- (void)testAddingLayerOfTypeABeforeRemovingLayerOfTypeBWithSameIdentifier {
MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"shape-source-identifier" shape:nil options:nil];
[self.style addSource:source];
-
+
// Add a fill layer
MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"some-identifier" source:source];
[self.style addLayer:fillLayer];
-
+
// Attempt to remove a line layer with the same identifier as the fill layer
MGLLineStyleLayer *lineLayer = [[MGLLineStyleLayer alloc] initWithIdentifier:fillLayer.identifier source:source];
[self.style removeLayer:lineLayer];
-
+
XCTAssertTrue([[self.style layerWithIdentifier:fillLayer.identifier] isMemberOfClass:[MGLFillStyleLayer class]]);
}
@@ -382,10 +389,10 @@
MGLImage *image = [[NSBundle bundleForClass:[self class]] imageForResource:imageName];
#endif
XCTAssertNotNil(image);
-
+
[self.style setImage:image forName:imageName];
MGLImage *styleImage = [self.style imageForName:imageName];
-
+
XCTAssertNotNil(styleImage);
XCTAssertEqual(image.size.width, styleImage.size.width);
XCTAssertEqual(image.size.height, styleImage.size.height);