Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] Load source TileJSON immediately
Browse files Browse the repository at this point in the history
This reverses #3095. Rationale:

* We're now exposing source attributes as a public API. Making those attributes unavailable at certain times complicates that API.
* We're preparing to split RenderSource out of Source. Removing this removes a point of coupling between the two.
  • Loading branch information
jfirebaugh committed May 2, 2017
1 parent c2b0037 commit 197751b
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 239 deletions.
60 changes: 6 additions & 54 deletions platform/darwin/test/MGLSourceQueryTests.m
Original file line number Diff line number Diff line change
@@ -1,73 +1,25 @@
#import <Mapbox/Mapbox.h>

#import "NSBundle+MGLAdditions.h"

#import <XCTest/XCTest.h>
#if TARGET_OS_IPHONE
#import <UIKit/UIKit.h>
#else
#import <Cocoa/Cocoa.h>
#endif

@interface MGLSourceQueryTests : XCTestCase <MGLMapViewDelegate>

@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
98 changes: 0 additions & 98 deletions platform/darwin/test/query-style.json

This file was deleted.

4 changes: 0 additions & 4 deletions platform/ios/ios.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -664,7 +663,6 @@
7E016D821D9E890300A29A21 /* MGLPolygon+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MGLPolygon+MGLAdditions.h"; sourceTree = "<group>"; };
7E016D831D9E890300A29A21 /* MGLPolygon+MGLAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MGLPolygon+MGLAdditions.m"; sourceTree = "<group>"; };
920A3E5C1E6F995200C16EFC /* MGLSourceQueryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MGLSourceQueryTests.m; path = ../../darwin/test/MGLSourceQueryTests.m; sourceTree = "<group>"; };
9221B2F01E6F9D1400A2385E /* query-style.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = "query-style.json"; path = "../../darwin/test/query-style.json"; sourceTree = "<group>"; };
9620BB361E69FE1700705A1D /* MGLSDKUpdateChecker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLSDKUpdateChecker.h; sourceTree = "<group>"; };
9620BB371E69FE1700705A1D /* MGLSDKUpdateChecker.mm */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 4; path = MGLSDKUpdateChecker.mm; sourceTree = "<group>"; };
9660916B1E5BBFD700A9A03B /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/Localizable.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1259,7 +1257,6 @@
DA2E88551CC036F400F24E7B /* Info.plist */,
DA2784FB1DF02FF4001D5B8D /* Media.xcassets */,
DA35D0871E1A6309007DED41 /* one-liner.json */,
9221B2F01E6F9D1400A2385E /* query-style.json */,
);
name = "SDK Tests";
path = test;
Expand Down Expand Up @@ -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 */,
Expand Down
4 changes: 0 additions & 4 deletions platform/macos/macos.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -337,7 +336,6 @@
55E2AD101E5B0A6900E8C587 /* MGLOfflineStorageTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLOfflineStorageTests.mm; path = ../../darwin/test/MGLOfflineStorageTests.mm; sourceTree = "<group>"; };
55FE0E8D1D100A0900FD240B /* config.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = config.xcconfig; path = ../../build/macos/config.xcconfig; sourceTree = "<group>"; };
920A3E581E6F859D00C16EFC /* MGLSourceQueryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGLSourceQueryTests.m; sourceTree = "<group>"; };
920A3E5A1E6F8E0700C16EFC /* query-style.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = "query-style.json"; path = "../../darwin/test/query-style.json"; sourceTree = "<group>"; };
966091701E5BBFF700A9A03B /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/Localizable.strings; sourceTree = "<group>"; };
966091711E5BBFF900A9A03B /* pl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pl; path = pl.lproj/Localizable.strings; sourceTree = "<group>"; };
966091721E5BBFFA00A9A03B /* uk */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = uk; path = uk.lproj/Localizable.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -998,7 +996,6 @@
DAE6C33A1CC30DB200DB3429 /* Info.plist */,
DA2784FD1DF03060001D5B8D /* Media.xcassets */,
DA35D0891E1A631B007DED41 /* one-liner.json */,
920A3E5A1E6F8E0700C16EFC /* query-style.json */,
);
name = "SDK Tests";
path = test;
Expand Down Expand Up @@ -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 */,
Expand Down
5 changes: 2 additions & 3 deletions src/mbgl/style/style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ void Style::addSource(std::unique_ptr<Source> source) {
}

source->baseImpl->setObserver(this);
source->baseImpl->loadDescription(fileSource);

sources.emplace_back(std::move(source));
}

Expand Down Expand Up @@ -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);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/api/annotation.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"sources": {
"fake": {
"type": "vector",
"url": "fake"
"tiles": ["fake"]
}
},
"layers": [{
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/api/query_style.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
},
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/api/water.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"sources": {
"mapbox": {
"type": "vector",
"url": "asset://streets.json"
"tiles": ["asset://streets/{z}-{x}-{y}.vector.pbf"]
}
},
"layers": [{
Expand Down
72 changes: 0 additions & 72 deletions test/style/style.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 197751b

Please sign in to comment.