summaryrefslogtreecommitdiff
path: root/platform/darwin/test
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-12-13 17:36:15 -0800
committerGitHub <noreply@github.com>2016-12-13 17:36:15 -0800
commitef71597932820fa09426d43a4e86e025d0628738 (patch)
treef8e0af2fc235859eb75bc00d97ea180ee68c9d73 /platform/darwin/test
parentb221b6c5fb8ed3360c74a38266b4321e94c10659 (diff)
downloadqtlocation-mapboxgl-ef71597932820fa09426d43a4e86e025d0628738.tar.gz
[ios, macos] Simplify MGLSource and subclasses (#7377)
* [ios, macos] Audited source headers for nullability * [macos] Made MGLTileSet public * [ios, macos] Replaced MGLTileSet with MGLTileSource MGLRasterSource and MGLVectorSource now share a common abstract superclass, MGLTileSource. MGLTileSet has been removed. MGLTileSource is modeled after mbgl::style::RasterSource and mbgl::style::VectorSource. It has initializers that incorporate the parameters of MGLTileSet’s initializers, but it lacks getters for everything but the attribution string. MGLTileSet’s properties have been converted into options that can be passed into MGLTileSource’s initializers in a dictionary. Properly implement rawSource as a covariant property so that it doesn’t end up getting autosynthesized as a shadow ivar. This prevents concrete subclasses of MGLSource from setting _rawSource directly but getting a different value out of self.rawSource. Marked -[MGLSource init] as unavailable and ensured that concrete subclasses of MGLSource have the right set of initializers marked as designated initializers. Documentation comments for each concrete source class identify the corresponding source type in the style specification. Clarified the purpose of MGLTileSetScheme, now known as MGLTileCoordinateSystem. * [ios, macos] Clarified tile size interpretation Sticking to a default value of 256 for mapbox: URLs, but other URLs get the standard 512 value. * [ios, macos] rawSource is always set * [ios, macos] Cleaned up MGLShapeSource initialization rawSource is never nil, so there’s no need for a -commonInit method. Extracted -geoJSONOptions from MGLShapeSource into a standalone function for easier testing. * [ios, macos] Synchronized headers in project Realphabetized headers in groups. Added headers missing from one project or the other. * [ios, macos] Added MGLShape methods to (de)serialize GeoJSON data Added a class initializer and instance method to MGLShape that deserialize and serialize the shape as GeoJSON data, respectively. The new initializer handles parsing errors gracefully. Removed methods specific to GeoJSON data from MGLShapeSource, in an effort to reduce parallel state. Developers are now expected to go through the new MGLShape initializer to get an MGLShape representation. Alternatively, a local file URL can be passed into the other MGLShapeSource initializer. * [ios, macos] Typo in assertion message * [ios, macos] Simplified GeoJSON serialization Every MGLShape now knows its most specific mbgl::GeoJSON representation. * [ios, macos] Reremoved MGLFeaturePrivate mbgl::GeoJSON, which is a variant, allows a single GeoJSON representation method to traffic in whatever type is needed for a particular shape class. This change removes some hidden private protocols, which are a bug waiting to happen. * [ios, macos] Fixed covariant rawLayer property Properly implement rawLayer as a covariant property so that it doesn’t end up getting autosynthesized as a shadow ivar. This prevents concrete subclasses of MGLStyleLayer from setting _rawLayer directly but getting a different value out of self.rawLayer. * [ios, macos] Use MGLAttributionInfo for source attribution Made MGLAttributionInfo public. Replaced MGLTileSource’s attribution property with an attributionInfos property set to an array of MGLAttributionInfo objects. Added an MGLTileSourceOption for specifying an array of MGLAttributionInfo objects instead of an HTML string (either is acceptable when creating an MGLTileSource). * [ios, macos] Corrected method references in documentation
Diffstat (limited to 'platform/darwin/test')
-rw-r--r--platform/darwin/test/MGLAttributionInfoTests.m2
-rw-r--r--platform/darwin/test/MGLFeatureTests.mm2
-rw-r--r--platform/darwin/test/MGLFilterTests.mm6
-rw-r--r--platform/darwin/test/MGLGeometryTests.mm45
-rw-r--r--platform/darwin/test/MGLShapeSourceTests.mm37
-rw-r--r--platform/darwin/test/MGLStyleTests.mm10
-rw-r--r--platform/darwin/test/MGLTileSetTests.mm103
7 files changed, 140 insertions, 65 deletions
diff --git a/platform/darwin/test/MGLAttributionInfoTests.m b/platform/darwin/test/MGLAttributionInfoTests.m
index 003637bf1b..3cdb7adffb 100644
--- a/platform/darwin/test/MGLAttributionInfoTests.m
+++ b/platform/darwin/test/MGLAttributionInfoTests.m
@@ -1,7 +1,7 @@
#import <Mapbox/Mapbox.h>
#import <XCTest/XCTest.h>
-#import "MGLAttributionInfo.h"
+#import "MGLAttributionInfo_Private.h"
@interface MGLAttributionInfoTests : XCTestCase
diff --git a/platform/darwin/test/MGLFeatureTests.mm b/platform/darwin/test/MGLFeatureTests.mm
index 7f464aaab1..33c146e723 100644
--- a/platform/darwin/test/MGLFeatureTests.mm
+++ b/platform/darwin/test/MGLFeatureTests.mm
@@ -159,7 +159,7 @@
}
- (void)testPointFeatureGeoJSONDictionary {
- MGLPointFeature<MGLFeaturePrivate> *pointFeature = (MGLPointFeature<MGLFeaturePrivate> *)[[MGLPointFeature alloc] init];
+ MGLPointFeature *pointFeature = [[MGLPointFeature alloc] init];
CLLocationCoordinate2D coordinate = { 10, 10 };
pointFeature.coordinate = coordinate;
diff --git a/platform/darwin/test/MGLFilterTests.mm b/platform/darwin/test/MGLFilterTests.mm
index 4b393fd1dc..e688d50583 100644
--- a/platform/darwin/test/MGLFilterTests.mm
+++ b/platform/darwin/test/MGLFilterTests.mm
@@ -18,7 +18,11 @@
NSString *filePath = [[NSBundle bundleForClass:self.class] pathForResource:@"amsterdam" ofType:@"geojson"];
NSURL *url = [NSURL fileURLWithPath:filePath];
NSData *geoJSONData = [NSData dataWithContentsOfURL:url];
- source = [[MGLShapeSource alloc] initWithIdentifier:@"test-source" geoJSONData:geoJSONData options:nil];
+ NSError *error;
+ MGLShape *shape = [MGLShape shapeWithData:geoJSONData encoding:NSUTF8StringEncoding error:&error];
+ XCTAssertNil(error);
+ XCTAssertNotNil(shape);
+ source = [[MGLShapeSource alloc] initWithIdentifier:@"test-source" shape:shape options:nil];
[self.mapView.style addSource:source];
layer = [[MGLLineStyleLayer alloc] initWithIdentifier:@"test-layer" source:source];
}
diff --git a/platform/darwin/test/MGLGeometryTests.mm b/platform/darwin/test/MGLGeometryTests.mm
index b15916e6fa..0ffc27b29e 100644
--- a/platform/darwin/test/MGLGeometryTests.mm
+++ b/platform/darwin/test/MGLGeometryTests.mm
@@ -99,4 +99,49 @@
XCTAssertFalse(MGLCoordinateInCoordinateBounds(kCLLocationCoordinate2DInvalid, wyoming));
}
+- (void)testGeoJSONDeserialization {
+ NSData *data = [@"{\"type\": \"Feature\", \"geometry\": {\"type\": \"Point\", \"coordinates\": [0, 0]}, \"properties\": {}}" dataUsingEncoding:NSUTF8StringEncoding];
+ NSError *error;
+ MGLPointFeature *feature = (MGLPointFeature *)[MGLShape shapeWithData:data encoding:NSUTF8StringEncoding error:&error];
+ XCTAssertNil(error, @"Valid GeoJSON data should produce no error on deserialization.");
+ XCTAssertNotNil(feature, @"Valid GeoJSON data should produce an object on deserialization.");
+ XCTAssertTrue([feature isKindOfClass:[MGLPointFeature class]], @"Valid GeoJSON point feature data should produce an MGLPointFeature.");
+ XCTAssertEqual(feature.attributes.count, 0);
+ XCTAssertEqual(feature.coordinate.latitude, 0);
+ XCTAssertEqual(feature.coordinate.longitude, 0);
+
+ data = [@"{\"type\": \"Feature\", \"feature\": {\"type\": \"Point\", \"coordinates\": [0, 0]}}" dataUsingEncoding:NSUTF8StringEncoding];
+ error = nil;
+ MGLShape *shape = [MGLShape shapeWithData:data encoding:NSUTF8StringEncoding error:&error];
+ XCTAssertNotNil(error, @"Invalid GeoJSON data should produce an error on deserialization.");
+ XCTAssertNil(shape, @"Invalid GeoJSON data should produce no object on deserialization.");
+}
+
+- (void)testGeoJSONSerialization {
+ MGLPointFeature *feature = [[MGLPointFeature alloc] init];
+ feature.identifier = @504;
+ feature.coordinate = CLLocationCoordinate2DMake(29.95, -90.066667);
+
+ NSData *data = [feature geoJSONDataUsingEncoding:NSUTF8StringEncoding];
+ XCTAssertNotNil(data, @"MGLPointFeature should serialize as an UTF-8 string data object.");
+ NSError *error;
+ NSDictionary *serializedGeoJSON = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
+ XCTAssertNil(error, @"Serialized GeoJSON data should be deserializable JSON.");
+ XCTAssertNotNil(serializedGeoJSON, @"Serialized GeoJSON data should be valid JSON.");
+ XCTAssertTrue([serializedGeoJSON isKindOfClass:[NSDictionary class]], @"Serialized GeoJSON data should be a JSON object.");
+ NSDictionary *geoJSON = @{
+ @"type": @"Feature",
+ @"id": @504,
+ @"geometry": @{
+ @"type": @"Point",
+ @"coordinates": @[
+ @(-90.066667),
+ @29.95,
+ ],
+ },
+ @"properties": @{},
+ };
+ XCTAssertEqualObjects(serializedGeoJSON, geoJSON, @"MGLPointFeature should serialize as a GeoJSON point feature.");
+}
+
@end
diff --git a/platform/darwin/test/MGLShapeSourceTests.mm b/platform/darwin/test/MGLShapeSourceTests.mm
index df90ea74d7..efff4b393e 100644
--- a/platform/darwin/test/MGLShapeSourceTests.mm
+++ b/platform/darwin/test/MGLShapeSourceTests.mm
@@ -12,18 +12,15 @@
@implementation MGLShapeSourceTests
-- (void)testMGLShapeSourceWithOptions {
- NSURL *url = [NSURL URLWithString:@"http://www.mapbox.com/source"];
-
+- (void)testGeoJSONOptionsFromDictionary {
NSDictionary *options = @{MGLShapeSourceOptionClustered: @YES,
MGLShapeSourceOptionClusterRadius: @42,
MGLShapeSourceOptionMaximumZoomLevelForClustering: @98,
MGLShapeSourceOptionMaximumZoomLevel: @99,
MGLShapeSourceOptionBuffer: @1976,
MGLShapeSourceOptionSimplificationTolerance: @0.42};
- MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"source-id" URL:url options:options];
- auto mbglOptions = [source geoJSONOptions];
+ auto mbglOptions = MGLGeoJSONOptionsFromDictionary(options);
XCTAssertTrue(mbglOptions.cluster);
XCTAssertEqual(mbglOptions.clusterRadius, 42);
XCTAssertEqual(mbglOptions.clusterMaxZoom, 98);
@@ -32,7 +29,7 @@
XCTAssertEqual(mbglOptions.tolerance, 0.42);
options = @{MGLShapeSourceOptionClustered: @"number 1"};
- XCTAssertThrows([[MGLShapeSource alloc] initWithIdentifier:@"source-id" URL:url options:options]);
+ XCTAssertThrows(MGLGeoJSONOptionsFromDictionary(options));
}
- (void)testNilShape {
@@ -45,7 +42,11 @@
NSString *geoJSON = @"{\"type\": \"FeatureCollection\",\"features\": [{\"type\": \"Feature\",\"properties\": {},\"geometry\": {\"type\": \"LineString\",\"coordinates\": [[-107.75390625,40.329795743702064],[-104.34814453125,37.64903402157866]]}}]}";
NSData *data = [geoJSON dataUsingEncoding:NSUTF8StringEncoding];
- MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"source-id" geoJSONData:data options:nil];
+ NSError *error;
+ MGLShape *shape = [MGLShape shapeWithData:data encoding:NSUTF8StringEncoding error:&error];
+ XCTAssertNil(error);
+ XCTAssertNotNil(shape);
+ MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"source-id" shape:shape options:nil];
MGLShapeCollection *collection = (MGLShapeCollection *)source.shape;
XCTAssertNotNil(collection);
@@ -54,18 +55,24 @@
}
- (void)testMGLShapeSourceWithSingleGeometry {
- MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"geojson"
- geoJSONData:[@"{\"type\": \"Point\", \"coordinates\": [0, 0]}" dataUsingEncoding:NSUTF8StringEncoding]
- options:nil];
+ NSData *data = [@"{\"type\": \"Point\", \"coordinates\": [0, 0]}" dataUsingEncoding:NSUTF8StringEncoding];
+ NSError *error;
+ MGLShape *shape = [MGLShape shapeWithData:data encoding:NSUTF8StringEncoding error:&error];
+ XCTAssertNil(error);
+ XCTAssertNotNil(shape);
+ MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"geojson" shape:shape options:nil];
XCTAssertNotNil(source.shape);
- XCTAssert([source.shape isKindOfClass:[MGLPointFeature class]]);
+ XCTAssert([source.shape isKindOfClass:[MGLPointAnnotation class]]);
}
- (void)testMGLGeoJSONSourceWithSingleFeature {
NSString *geoJSON = @"{\"type\": \"Feature\", \"properties\": {\"color\": \"green\"}, \"geometry\": { \"type\": \"Point\", \"coordinates\": [ -114.06847000122069, 51.050459433092655 ] }}";
- MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"geojson"
- geoJSONData:[geoJSON dataUsingEncoding:NSUTF8StringEncoding]
- options:nil];
+ NSData *data = [geoJSON dataUsingEncoding:NSUTF8StringEncoding];
+ NSError *error;
+ MGLShape *shape = [MGLShape shapeWithData:data encoding:NSUTF8StringEncoding error:&error];
+ XCTAssertNil(error);
+ XCTAssertNotNil(shape);
+ MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"geojson" shape:shape options:nil];
XCTAssertNotNil(source.shape);
XCTAssert([source.shape isKindOfClass:[MGLPointFeature class]]);
MGLPointFeature *feature = (MGLPointFeature *)source.shape;
@@ -90,7 +97,7 @@
CLLocationCoordinate2DMake(100.0, 1.0),
CLLocationCoordinate2DMake(100.0, 0.0)};
- MGLPolygonFeature<MGLFeaturePrivate> *polygonFeature = (MGLPolygonFeature<MGLFeaturePrivate> *)[MGLPolygonFeature polygonWithCoordinates:coordinates count:5];
+ MGLPolygonFeature *polygonFeature = [MGLPolygonFeature polygonWithCoordinates:coordinates count:5];
polygonFeature.identifier = @"feature-id";
NSString *stringAttribute = @"string";
NSNumber *boolAttribute = [NSNumber numberWithBool:YES];
diff --git a/platform/darwin/test/MGLStyleTests.mm b/platform/darwin/test/MGLStyleTests.mm
index 7abc88eebc..c67497640b 100644
--- a/platform/darwin/test/MGLStyleTests.mm
+++ b/platform/darwin/test/MGLStyleTests.mm
@@ -126,18 +126,18 @@
[self.style addSource:shapeSource];
XCTAssertThrowsSpecificNamed([self.style addSource:shapeSource], NSException, @"MGLRedundantSourceException");
- MGLRasterSource *rasterSource = [[MGLRasterSource alloc] initWithIdentifier:@"rasterSource" URL:[NSURL new] tileSize:42];
+ MGLRasterSource *rasterSource = [[MGLRasterSource alloc] initWithIdentifier:@"rasterSource" configurationURL:[NSURL URLWithString:@".json"] tileSize:42];
[self.style addSource:rasterSource];
XCTAssertThrowsSpecificNamed([self.style addSource:rasterSource], NSException, @"MGLRedundantSourceException");
- MGLVectorSource *vectorSource = [[MGLVectorSource alloc] initWithIdentifier:@"vectorSource" URL:[NSURL new]];
+ MGLVectorSource *vectorSource = [[MGLVectorSource alloc] initWithIdentifier:@"vectorSource" configurationURL:[NSURL URLWithString:@".json"]];
[self.style addSource:vectorSource];
XCTAssertThrowsSpecificNamed([self.style addSource:vectorSource], NSException, @"MGLRedundantSourceException");
}
- (void)testAddingSourcesWithDuplicateIdentifiers {
- MGLVectorSource *source1 = [[MGLVectorSource alloc] initWithIdentifier:@"my-source" URL:[NSURL URLWithString:@"mapbox://mapbox.mapbox-terrain-v2"]];
- MGLVectorSource *source2 = [[MGLVectorSource alloc] initWithIdentifier:@"my-source" URL:[NSURL URLWithString:@"mapbox://mapbox.mapbox-terrain-v2"]];
+ MGLVectorSource *source1 = [[MGLVectorSource alloc] initWithIdentifier:@"my-source" configurationURL:[NSURL URLWithString:@"mapbox://mapbox.mapbox-terrain-v2"]];
+ MGLVectorSource *source2 = [[MGLVectorSource alloc] initWithIdentifier:@"my-source" configurationURL:[NSURL URLWithString:@"mapbox://mapbox.mapbox-terrain-v2"]];
[self.style addSource: source1];
XCTAssertThrowsSpecificNamed([self.style addSource: source2], NSException, @"MGLRedundantSourceIdentifierException");
@@ -173,7 +173,7 @@
- (void)testAddingLayersWithDuplicateIdentifiers {
//Just some source
- MGLVectorSource *source = [[MGLVectorSource alloc] initWithIdentifier:@"my-source" URL:[NSURL URLWithString:@"mapbox://mapbox.mapbox-terrain-v2"]];
+ MGLVectorSource *source = [[MGLVectorSource alloc] initWithIdentifier:@"my-source" configurationURL:[NSURL URLWithString:@"mapbox://mapbox.mapbox-terrain-v2"]];
[self.mapView.style addSource: source];
//Add initial layer
diff --git a/platform/darwin/test/MGLTileSetTests.mm b/platform/darwin/test/MGLTileSetTests.mm
index d77046928c..06901a0e96 100644
--- a/platform/darwin/test/MGLTileSetTests.mm
+++ b/platform/darwin/test/MGLTileSetTests.mm
@@ -1,7 +1,7 @@
#import <XCTest/XCTest.h>
#import <Mapbox/Mapbox.h>
-#import "MGLTileSet_Private.h"
+#import "MGLTileSource_Private.h"
#include <mbgl/util/tileset.hpp>
@@ -11,72 +11,91 @@
@implementation MGLTileSetTests
-- (void)testTileSet {
+- (void)testTileSetFromTileURLTemplates {
// a tile set that provides an mbgl tile set
- MGLTileSet *tileSet = [[MGLTileSet alloc] initWithTileURLTemplates:@[@"tile.1",
- @"tile.2",
- @"tile.3"]];
- mbgl::Tileset mbglTileset = [tileSet mbglTileset];
+ NSArray *tileURLTemplates = @[@"tile.1", @"tile.2", @"tile.3"];
+ mbgl::Tileset tileSet = MGLTileSetFromTileURLTemplates(tileURLTemplates, nil);
// has the correct URL templates
- XCTAssertEqual(mbglTileset.tiles.size(), 3);
- XCTAssertEqual(mbglTileset.tiles[0], "tile.1");
- XCTAssertEqual(mbglTileset.tiles[1], "tile.2");
- XCTAssertEqual(mbglTileset.tiles[2], "tile.3");
+ XCTAssertEqual(tileSet.tiles.size(), 3);
+ XCTAssertEqual(tileSet.tiles[0], "tile.1");
+ XCTAssertEqual(tileSet.tiles[1], "tile.2");
+ XCTAssertEqual(tileSet.tiles[2], "tile.3");
// has the default scheme
- XCTAssertEqual(mbglTileset.scheme, mbgl::Tileset::Scheme::XYZ);
+ XCTAssertEqual(tileSet.scheme, mbgl::Tileset::Scheme::XYZ);
// when the tile set has no min or max zoom level set
- tileSet.minimumZoomLevel = nil;
- tileSet.maximumZoomLevel = nil;
-
// the mbgl object has default values for min and max zoom level
- XCTAssertEqual([tileSet mbglTileset].zoomRange.min, 0);
- XCTAssertEqual([tileSet mbglTileset].zoomRange.max, 22);
+ XCTAssertEqual(tileSet.zoomRange.min, 0);
+ XCTAssertEqual(tileSet.zoomRange.max, 22);
// when the tile set has min and/or max zoom level set
- tileSet.minimumZoomLevel = @(1);
- tileSet.maximumZoomLevel = @(2);
+ tileSet = MGLTileSetFromTileURLTemplates(@[@"tile.1"], @{
+ MGLTileSourceOptionMinimumZoomLevel: @1,
+ MGLTileSourceOptionMaximumZoomLevel: @2,
+ });
// the mbgl object reflects the set values for min and max zoom level
- XCTAssertEqual([tileSet mbglTileset].zoomRange.min, 1);
- XCTAssertEqual([tileSet mbglTileset].zoomRange.max, 2);
+ XCTAssertEqual(tileSet.zoomRange.min, 1);
+ XCTAssertEqual(tileSet.zoomRange.max, 2);
// when the tile set has an attribution
- tileSet.attribution = @"my tileset © ©️🎈";
+ NSString *attribution = @"my tileset © ©️🎈";
+ tileSet = MGLTileSetFromTileURLTemplates(tileURLTemplates, @{
+ MGLTileSourceOptionAttributionHTMLString: attribution,
+ });
// the attribution is reflected by the mbgl tileset
- XCTAssertEqual([tileSet mbglTileset].attribution, tileSet.attribution.UTF8String);
+ XCTAssertEqual(tileSet.attribution, attribution.UTF8String);
+
+ // when the tile set has attribution infos
+ MGLAttributionInfo *mapboxInfo = [[MGLAttributionInfo alloc] initWithTitle:[[NSAttributedString alloc] initWithString:@"Mapbox"]
+ URL:[NSURL URLWithString:@"https://www.mapbox.com/"]];
+ NSAttributedString *gl = [[NSAttributedString alloc] initWithString:@"GL" attributes:@{
+ NSBackgroundColorAttributeName: [MGLColor redColor],
+ }];
+ MGLAttributionInfo *glInfo = [[MGLAttributionInfo alloc] initWithTitle:gl URL:nil];
+ tileSet = MGLTileSetFromTileURLTemplates(tileURLTemplates, @{
+ MGLTileSourceOptionAttributionInfos: @[mapboxInfo, glInfo],
+ });
- // when the scheme is changed
- tileSet.scheme = MGLTileSetSchemeTMS;
+ // the attribution is reflected by the mbgl tileset
+#if TARGET_OS_IPHONE
+ NSString *html = (@"<font style=\"font-family: 'Helvetica'; font-weight: normal; font-style: normal; font-size: 12.00pt\">"
+ @"<a href=\"https://www.mapbox.com/\">Mapbox</a> </font>"
+ @"<font style=\"font-family: 'Helvetica'; font-weight: normal; font-style: normal; font-size: 12.00pt; background-color: #ff0000\">GL</font>\n");
+#else
+ NSString *html = (@"<font face=\"Helvetica\" size=\"3\" style=\"font: 12.0px Helvetica\">"
+ @"<a href=\"https://www.mapbox.com/\">Mapbox</a> </font>"
+ @"<font face=\"Helvetica\" size=\"3\" style=\"font: 12.0px Helvetica; background-color: #ff2600\">GL</font>\n");
+#endif
+ XCTAssertEqualObjects(@(tileSet.attribution.c_str()), html);
+
+ // when the tile coordinate system is changed using an NSNumber
+ tileSet = MGLTileSetFromTileURLTemplates(tileURLTemplates, @{
+ MGLTileSourceOptionTileCoordinateSystem: @(MGLTileCoordinateSystemTMS),
+ });
// the scheme is reflected by the mbgl tileset
- XCTAssertEqual([tileSet mbglTileset].scheme , mbgl::Tileset::Scheme::TMS);
+ XCTAssertEqual(tileSet.scheme, mbgl::Tileset::Scheme::TMS);
- // a tile set that provides an mbgl tile set and minimum and maximum zoom levels
- tileSet = [[MGLTileSet alloc] initWithTileURLTemplates:@[@"tile.1"] minimumZoomLevel:15 maximumZoomLevel:20];
+ // when the tile coordinate system is changed using an NSValue
+ MGLTileCoordinateSystem tms = MGLTileCoordinateSystemTMS;
+ tileSet = MGLTileSetFromTileURLTemplates(tileURLTemplates, @{
+ MGLTileSourceOptionTileCoordinateSystem: [NSValue value:&tms withObjCType:@encode(MGLTileCoordinateSystem)],
+ });
- // the zoom levels are reflected by the mbgl tileset
- XCTAssertEqual([tileSet mbglTileset].zoomRange.min, 15);
- XCTAssertEqual([tileSet mbglTileset].zoomRange.max, 20);
+ // the scheme is reflected by the mbgl tileset
+ XCTAssertEqual(tileSet.scheme, mbgl::Tileset::Scheme::TMS);
}
- (void)testInvalidTileSet {
// a tile set that provides an mbgl tile set and invalid (crossed) minimum and maximum zoom levels throws an exception
- XCTAssertThrowsSpecificNamed([[MGLTileSet alloc] initWithTileURLTemplates:@[@"tile.1"] minimumZoomLevel:10 maximumZoomLevel:9], NSException, @"Invalid minimumZoomLevel");
-
- // a tile set that provides an mbgl tile set
- MGLTileSet *tileSet = [[MGLTileSet alloc] initWithTileURLTemplates:@[@"tile.1"]];
- tileSet.maximumZoomLevel = @(10);
-
- // when the minimum zoom level is set higher than the maximum zoom level
- XCTAssertThrowsSpecificNamed(tileSet.minimumZoomLevel = @(11), NSException, @"Invalid minimumZoomLevel");
-
- // when the maximum zoom level is set lower than the minimum zoom level
- tileSet.minimumZoomLevel = @(5);
- XCTAssertThrowsSpecificNamed(tileSet.maximumZoomLevel = @(4), NSException, @"Invalid minimumZoomLevel");
+ XCTAssertThrowsSpecificNamed(MGLTileSetFromTileURLTemplates(@[@"tile.1"], @{
+ MGLTileSourceOptionMinimumZoomLevel: @10,
+ MGLTileSourceOptionMaximumZoomLevel: @9,
+ }), NSException, NSInvalidArgumentException);
}
@end