diff --git a/platform/darwin/test/MGLSourceQueryTests.m b/platform/darwin/test/MGLSourceQueryTests.m index 28e968146b4..d1ef180a523 100644 --- a/platform/darwin/test/MGLSourceQueryTests.m +++ b/platform/darwin/test/MGLSourceQueryTests.m @@ -1,73 +1,25 @@ #import - -#import "NSBundle+MGLAdditions.h" - #import -#if TARGET_OS_IPHONE - #import -#else - #import -#endif @interface MGLSourceQueryTests : XCTestCase -@property (nonatomic) MGLMapView *mapView; -@property (nonatomic) MGLStyle *style; - @end -@implementation MGLSourceQueryTests { - XCTestExpectation *_styleLoadingExpectation; -} - -- (void)setUp { - [super setUp]; - - [MGLAccountManager setAccessToken:@"pk.feedcafedeadbeefbadebede"]; - NSURL *styleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"query-style" withExtension:@"json"]; - self.mapView = [[MGLMapView alloc] initWithFrame:CGRectMake(0, 0, 100, 100) styleURL:styleURL]; - self.mapView.delegate = self; - if (!self.mapView.style) { - _styleLoadingExpectation = [self expectationWithDescription:@"Map view should finish loading style."]; - [self waitForExpectationsWithTimeout:1 handler:nil]; - } -} - -- (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style { - XCTAssertNotNil(mapView.style); - XCTAssertEqual(mapView.style, style); - - [_styleLoadingExpectation fulfill]; -} - -- (void)tearDown { - _styleLoadingExpectation = nil; - self.mapView = nil; - - [super tearDown]; -} - -- (MGLStyle *)style { - return self.mapView.style; -} +@implementation MGLSourceQueryTests - (void) testQueryVectorSource { - MGLVectorSource *source = (MGLVectorSource *)[self.style sourceWithIdentifier:@"source5"]; - + MGLVectorSource *source = [[MGLVectorSource alloc] initWithIdentifier:@"vector" tileURLTemplates:@[@"fake"] options:nil]; NSSet *sourceLayers = [NSSet setWithObjects:@"buildings", @"water", nil]; NSArray* features = [source featuresInSourceLayersWithIdentifiers:sourceLayers predicate:nil]; - // Source won't be loaded yet, so features is 0 + // Source not added yet, so features is 0 XCTAssertEqual([features count], 0); } - (void) testQueryShapeSource { - MGLShapeSource *source = (MGLShapeSource *)[self.style sourceWithIdentifier:@"source4"]; - - NSPredicate *eqPredicate = [NSPredicate predicateWithFormat:@"key1 == 'value1'"]; - NSArray* features = [source featuresMatchingPredicate:eqPredicate]; - // Source won't be loaded yet, so features is 0 + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"shape" shape:[MGLShapeCollection shapeCollectionWithShapes:@[]] options:nil]; + NSArray* features = [source featuresMatchingPredicate:nil]; + // Source not added yet, so features is 0 XCTAssertEqual([features count], 0); - } @end diff --git a/platform/darwin/test/query-style.json b/platform/darwin/test/query-style.json deleted file mode 100644 index 97f1d044325..00000000000 --- a/platform/darwin/test/query-style.json +++ /dev/null @@ -1,98 +0,0 @@ -{ - "version": 8, - "sources": { - "source1": { - "type": "geojson", - "data": { - "type": "Point", - "coordinates": [ - 0, - 0 - ] - } - }, - "source2": { - "type": "geojson", - "data": { - "type": "Point", - "coordinates": [ - 0, - 0 - ] - } - }, - "source3": { - "type": "geojson", - "data": { - "type": "Point", - "coordinates": [ - 0, - 0 - ] - } - }, - "source4": { - "type": "geojson", - "data": { - "type": "Feature", - "id": "feature1", - "geometry": { - "type": "Point", - "coordinates": [ - 0.0, - 0.0 - ] - }, - "properties": { - "key1": "value1", - "key2": 1.5, - "key3": false, - "key4": 0.5 - } - } - }, - "source5": { - "type": "vector", - "url": "mapbox://mapbox.mapbox-streets-v6" - }, - "source6": { - "type": "raster", - "url": "mapbox://mapbox.satellite", - "tileSize": 256 - } - }, - "layers": [ - { - "id": "layer1", - "type": "symbol", - "source": "source1", - "layout": { - "icon-image": "test-icon" - } - }, - { - "id": "layer2", - "type": "symbol", - "source": "source2", - "layout": { - "icon-image": "test-icon" - } - }, - { - "id": "layer3", - "type": "symbol", - "source": "source3", - "layout": { - "icon-image": "test-icon" - } - }, - { - "id": "layer4", - "type": "symbol", - "source": "source4", - "layout": { - "icon-image": "test-icon" - } - } - ] -} diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index 432479ee5f3..9ebdd2f5bfc 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -193,7 +193,6 @@ 7E016D861D9E890300A29A21 /* MGLPolygon+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E016D831D9E890300A29A21 /* MGLPolygon+MGLAdditions.m */; }; 7E016D871D9E890300A29A21 /* MGLPolygon+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E016D831D9E890300A29A21 /* MGLPolygon+MGLAdditions.m */; }; 920A3E5D1E6F995200C16EFC /* MGLSourceQueryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 920A3E5C1E6F995200C16EFC /* MGLSourceQueryTests.m */; }; - 9221B2F11E6F9D1400A2385E /* query-style.json in Resources */ = {isa = PBXBuildFile; fileRef = 9221B2F01E6F9D1400A2385E /* query-style.json */; }; 9620BB381E69FE1700705A1D /* MGLSDKUpdateChecker.h in Headers */ = {isa = PBXBuildFile; fileRef = 9620BB361E69FE1700705A1D /* MGLSDKUpdateChecker.h */; }; 9620BB391E69FE1700705A1D /* MGLSDKUpdateChecker.h in Headers */ = {isa = PBXBuildFile; fileRef = 9620BB361E69FE1700705A1D /* MGLSDKUpdateChecker.h */; }; 9620BB3A1E69FE1700705A1D /* MGLSDKUpdateChecker.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9620BB371E69FE1700705A1D /* MGLSDKUpdateChecker.mm */; }; @@ -664,7 +663,6 @@ 7E016D821D9E890300A29A21 /* MGLPolygon+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MGLPolygon+MGLAdditions.h"; sourceTree = ""; }; 7E016D831D9E890300A29A21 /* MGLPolygon+MGLAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MGLPolygon+MGLAdditions.m"; sourceTree = ""; }; 920A3E5C1E6F995200C16EFC /* MGLSourceQueryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MGLSourceQueryTests.m; path = ../../darwin/test/MGLSourceQueryTests.m; sourceTree = ""; }; - 9221B2F01E6F9D1400A2385E /* query-style.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = "query-style.json"; path = "../../darwin/test/query-style.json"; sourceTree = ""; }; 9620BB361E69FE1700705A1D /* MGLSDKUpdateChecker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLSDKUpdateChecker.h; sourceTree = ""; }; 9620BB371E69FE1700705A1D /* MGLSDKUpdateChecker.mm */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 4; path = MGLSDKUpdateChecker.mm; sourceTree = ""; }; 9660916B1E5BBFD700A9A03B /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/Localizable.strings; sourceTree = ""; }; @@ -1259,7 +1257,6 @@ DA2E88551CC036F400F24E7B /* Info.plist */, DA2784FB1DF02FF4001D5B8D /* Media.xcassets */, DA35D0871E1A6309007DED41 /* one-liner.json */, - 9221B2F01E6F9D1400A2385E /* query-style.json */, ); name = "SDK Tests"; path = test; @@ -2050,7 +2047,6 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - 9221B2F11E6F9D1400A2385E /* query-style.json in Resources */, DA2784FC1DF02FF4001D5B8D /* Media.xcassets in Resources */, 353BAEF71D646370009A8DA9 /* amsterdam.geojson in Resources */, DA35D0881E1A6309007DED41 /* one-liner.json in Resources */, diff --git a/platform/macos/macos.xcodeproj/project.pbxproj b/platform/macos/macos.xcodeproj/project.pbxproj index 606cc803d84..2e459a50882 100644 --- a/platform/macos/macos.xcodeproj/project.pbxproj +++ b/platform/macos/macos.xcodeproj/project.pbxproj @@ -73,7 +73,6 @@ 558DE7A71E56161C00C7916D /* MGLFoundation.mm in Sources */ = {isa = PBXBuildFile; fileRef = 558DE7A51E56161C00C7916D /* MGLFoundation.mm */; }; 55E2AD111E5B0A6900E8C587 /* MGLOfflineStorageTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 55E2AD101E5B0A6900E8C587 /* MGLOfflineStorageTests.mm */; }; 920A3E591E6F859D00C16EFC /* MGLSourceQueryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 920A3E581E6F859D00C16EFC /* MGLSourceQueryTests.m */; }; - 920A3E5B1E6F8E0700C16EFC /* query-style.json in Resources */ = {isa = PBXBuildFile; fileRef = 920A3E5A1E6F8E0700C16EFC /* query-style.json */; }; 96E027311E57C9A7004B8E66 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 96E027331E57C9A7004B8E66 /* Localizable.strings */; }; DA00FC8A1D5EEAC3009AABC8 /* MGLAttributionInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = DA00FC881D5EEAC3009AABC8 /* MGLAttributionInfo.h */; settings = {ATTRIBUTES = (Public, ); }; }; DA00FC8B1D5EEAC3009AABC8 /* MGLAttributionInfo.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA00FC891D5EEAC3009AABC8 /* MGLAttributionInfo.mm */; }; @@ -337,7 +336,6 @@ 55E2AD101E5B0A6900E8C587 /* MGLOfflineStorageTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLOfflineStorageTests.mm; path = ../../darwin/test/MGLOfflineStorageTests.mm; sourceTree = ""; }; 55FE0E8D1D100A0900FD240B /* config.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = config.xcconfig; path = ../../build/macos/config.xcconfig; sourceTree = ""; }; 920A3E581E6F859D00C16EFC /* MGLSourceQueryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGLSourceQueryTests.m; sourceTree = ""; }; - 920A3E5A1E6F8E0700C16EFC /* query-style.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = "query-style.json"; path = "../../darwin/test/query-style.json"; sourceTree = ""; }; 966091701E5BBFF700A9A03B /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/Localizable.strings; sourceTree = ""; }; 966091711E5BBFF900A9A03B /* pl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pl; path = pl.lproj/Localizable.strings; sourceTree = ""; }; 966091721E5BBFFA00A9A03B /* uk */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = uk; path = uk.lproj/Localizable.strings; sourceTree = ""; }; @@ -998,7 +996,6 @@ DAE6C33A1CC30DB200DB3429 /* Info.plist */, DA2784FD1DF03060001D5B8D /* Media.xcassets */, DA35D0891E1A631B007DED41 /* one-liner.json */, - 920A3E5A1E6F8E0700C16EFC /* query-style.json */, ); name = "SDK Tests"; path = test; @@ -1341,7 +1338,6 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - 920A3E5B1E6F8E0700C16EFC /* query-style.json in Resources */, 35724FC41D630502002A4AB4 /* amsterdam.geojson in Resources */, DA2784FE1DF03060001D5B8D /* Media.xcassets in Resources */, DA35D08A1E1A631B007DED41 /* one-liner.json in Resources */, diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index 8dfe7eac067..0bc18415663 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -164,6 +164,8 @@ void Style::addSource(std::unique_ptr source) { } source->baseImpl->setObserver(this); + source->baseImpl->loadDescription(fileSource); + sources.emplace_back(std::move(source)); } @@ -387,9 +389,6 @@ void Style::recalculate(float z, const TimePoint& timePoint, MapMode mode) { // If this layer has a source, make sure that it gets loaded. if (Source* source = getSource(layer->baseImpl.source)) { source->baseImpl->enabled = true; - if (!source->baseImpl->loaded) { - source->baseImpl->loadDescription(fileSource); - } } } diff --git a/test/fixtures/api/annotation.json b/test/fixtures/api/annotation.json index ab83d434762..972b22fc4d4 100644 --- a/test/fixtures/api/annotation.json +++ b/test/fixtures/api/annotation.json @@ -3,7 +3,7 @@ "sources": { "fake": { "type": "vector", - "url": "fake" + "tiles": ["fake"] } }, "layers": [{ diff --git a/test/fixtures/api/query_style.json b/test/fixtures/api/query_style.json index 97f1d044325..2e499c383d6 100644 --- a/test/fixtures/api/query_style.json +++ b/test/fixtures/api/query_style.json @@ -53,11 +53,11 @@ }, "source5": { "type": "vector", - "url": "mapbox://mapbox.mapbox-streets-v6" + "tiles": ["fake"] }, "source6": { "type": "raster", - "url": "mapbox://mapbox.satellite", + "tiles": ["fake"], "tileSize": 256 } }, diff --git a/test/fixtures/api/water.json b/test/fixtures/api/water.json index 387471b8421..0a563a4955e 100644 --- a/test/fixtures/api/water.json +++ b/test/fixtures/api/water.json @@ -4,7 +4,7 @@ "sources": { "mapbox": { "type": "vector", - "url": "asset://streets.json" + "tiles": ["asset://streets/{z}-{x}-{y}.vector.pbf"] } }, "layers": [{ diff --git a/test/style/style.test.cpp b/test/style/style.test.cpp index f87e31cce25..b529abad4a9 100644 --- a/test/style/style.test.cpp +++ b/test/style/style.test.cpp @@ -14,78 +14,6 @@ using namespace mbgl; using namespace mbgl::style; -TEST(Style, UnusedSource) { - util::RunLoop loop; - - ThreadPool threadPool{ 1 }; - StubFileSource fileSource; - Style style { threadPool, fileSource, 1.0 }; - - auto now = Clock::now(); - - style.setJSON(util::read_file("test/fixtures/resources/style-unused-sources.json")); - - // If we haven't calculated whether the source is used, we have to assume it is used. - EXPECT_FALSE(style.isLoaded()); - - style.cascade(now, MapMode::Still); - style.recalculate(0, now, MapMode::Still); - - Source* usedSource = style.getSource("usedsource"); - EXPECT_TRUE(usedSource); - EXPECT_TRUE(usedSource->baseImpl->isLoaded()); - - Source* unusedSource = style.getSource("unusedsource"); - EXPECT_TRUE(unusedSource); - EXPECT_FALSE(unusedSource->baseImpl->isLoaded()); - - Layer* unusedLayer = style.getLayer("unusedlayervisibility"); - EXPECT_TRUE(unusedLayer); - - unusedLayer->setVisibility(mbgl::style::VisibilityType::Visible); - - style.relayout(); - EXPECT_FALSE(unusedSource->baseImpl->isLoaded()); - - // Style loads sources upon request when recalculating style. - style.recalculate(0, now, MapMode::Still); - EXPECT_TRUE(unusedSource->baseImpl->isLoaded()); -} - -TEST(Style, UnusedSourceActiveViaClassUpdate) { - util::RunLoop loop; - - ThreadPool threadPool{ 1 }; - StubFileSource fileSource; - Style style { threadPool, fileSource, 1.0 }; - - style.setJSON(util::read_file("test/fixtures/resources/style-unused-sources.json")); - EXPECT_TRUE(style.addClass("visible")); - EXPECT_TRUE(style.hasClass("visible")); - - auto now = Clock::now(); - - style.cascade(now, MapMode::Still); - style.recalculate(0, now, MapMode::Still); - - Source *unusedSource = style.getSource("unusedsource"); - EXPECT_TRUE(unusedSource); - EXPECT_TRUE(unusedSource->baseImpl->isLoaded()); - - // Style classes should be cleared upon new style load. - style.setJSON(util::read_file("test/fixtures/resources/style-unused-sources.json")); - EXPECT_FALSE(style.hasClass("visible")); - - now = Clock::now(); - - style.cascade(now, MapMode::Still); - style.recalculate(0, now, MapMode::Still); - - unusedSource = style.getSource("unusedsource"); - EXPECT_TRUE(unusedSource); - EXPECT_FALSE(unusedSource->baseImpl->isLoaded()); -} - TEST(Style, Properties) { util::RunLoop loop;