[core] Move setStyleJSON/URL to Style; add Map::setStyle
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <mbgl/util/default_thread_pool.hpp>
|
||||
#include <mbgl/annotation/annotation.hpp>
|
||||
#include <mbgl/style/style.hpp>
|
||||
#include <mbgl/style/image.hpp>
|
||||
#include <mbgl/map/map.hpp>
|
||||
#include <mbgl/map/backend_scope.hpp>
|
||||
@@ -45,7 +46,7 @@ public:
|
||||
TEST(Annotations, SymbolAnnotation) {
|
||||
AnnotationTest test;
|
||||
|
||||
test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.addAnnotationImage(namedMarker("default_marker"));
|
||||
test.map.addAnnotation(SymbolAnnotation { Point<double>(0, 0), "default_marker" });
|
||||
test.checkRendering("point_annotation");
|
||||
@@ -67,7 +68,7 @@ TEST(Annotations, LineAnnotation) {
|
||||
annotation.color = Color::red();
|
||||
annotation.width = { 5 };
|
||||
|
||||
test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.addAnnotation(annotation);
|
||||
test.checkRendering("line_annotation");
|
||||
|
||||
@@ -82,7 +83,7 @@ TEST(Annotations, FillAnnotation) {
|
||||
FillAnnotation annotation { polygon };
|
||||
annotation.color = Color::red();
|
||||
|
||||
test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.addAnnotation(annotation);
|
||||
test.checkRendering("fill_annotation");
|
||||
|
||||
@@ -95,7 +96,7 @@ TEST(Annotations, AntimeridianAnnotationSmall) {
|
||||
|
||||
double antimeridian = 180;
|
||||
test.map.setLatLngZoom(mbgl::LatLng(0, antimeridian), 0);
|
||||
test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
|
||||
LineString<double> line = {{ { antimeridian, 20 }, { antimeridian, -20 } }};
|
||||
LineAnnotation lineAnnotation { line };
|
||||
@@ -116,7 +117,7 @@ TEST(Annotations, AntimeridianAnnotationLarge) {
|
||||
|
||||
double antimeridian = 180;
|
||||
test.map.setLatLngZoom(mbgl::LatLng(0, antimeridian), 0);
|
||||
test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
|
||||
LineString<double> line = {{ { antimeridian, 20 }, { antimeridian, -20 } }};
|
||||
LineAnnotation lineAnnotation { line };
|
||||
@@ -141,7 +142,7 @@ TEST(Annotations, OverlappingFillAnnotation) {
|
||||
FillAnnotation overlaidAnnotation { polygon };
|
||||
overlaidAnnotation.color = Color::red();
|
||||
|
||||
test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.addAnnotation(underlaidAnnotation);
|
||||
test.map.addAnnotation(overlaidAnnotation);
|
||||
test.checkRendering("overlapping_fill_annotation");
|
||||
@@ -150,7 +151,7 @@ TEST(Annotations, OverlappingFillAnnotation) {
|
||||
TEST(Annotations, AddMultiple) {
|
||||
AnnotationTest test;
|
||||
|
||||
test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.addAnnotationImage(namedMarker("default_marker"));
|
||||
test.map.addAnnotation(SymbolAnnotation { Point<double> { -10, 0 }, "default_marker" });
|
||||
|
||||
@@ -163,7 +164,7 @@ TEST(Annotations, AddMultiple) {
|
||||
TEST(Annotations, NonImmediateAdd) {
|
||||
AnnotationTest test;
|
||||
|
||||
test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test::render(test.map, test.view);
|
||||
|
||||
Polygon<double> polygon = { {{ { 0, 0 }, { 0, 45 }, { 45, 45 }, { 45, 0 } }} };
|
||||
@@ -177,7 +178,7 @@ TEST(Annotations, NonImmediateAdd) {
|
||||
TEST(Annotations, UpdateSymbolAnnotationGeometry) {
|
||||
AnnotationTest test;
|
||||
|
||||
test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.addAnnotationImage(namedMarker("default_marker"));
|
||||
test.map.addAnnotationImage(namedMarker("flipped_marker"));
|
||||
AnnotationID point = test.map.addAnnotation(SymbolAnnotation { Point<double> { 0, 0 }, "default_marker" });
|
||||
@@ -191,7 +192,7 @@ TEST(Annotations, UpdateSymbolAnnotationGeometry) {
|
||||
TEST(Annotations, UpdateSymbolAnnotationIcon) {
|
||||
AnnotationTest test;
|
||||
|
||||
test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.addAnnotationImage(namedMarker("default_marker"));
|
||||
test.map.addAnnotationImage(namedMarker("flipped_marker"));
|
||||
AnnotationID point = test.map.addAnnotation(SymbolAnnotation { Point<double> { 0, 0 }, "default_marker" });
|
||||
@@ -209,7 +210,7 @@ TEST(Annotations, UpdateLineAnnotationGeometry) {
|
||||
annotation.color = Color::red();
|
||||
annotation.width = { 5 };
|
||||
|
||||
test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
AnnotationID line = test.map.addAnnotation(annotation);
|
||||
|
||||
test::render(test.map, test.view);
|
||||
@@ -226,7 +227,7 @@ TEST(Annotations, UpdateLineAnnotationStyle) {
|
||||
annotation.color = Color::red();
|
||||
annotation.width = { 5 };
|
||||
|
||||
test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
AnnotationID line = test.map.addAnnotation(annotation);
|
||||
|
||||
test::render(test.map, test.view);
|
||||
@@ -243,7 +244,7 @@ TEST(Annotations, UpdateFillAnnotationGeometry) {
|
||||
FillAnnotation annotation { Polygon<double> { {{ { 0, 0 }, { 0, 45 }, { 45, 45 }, { 45, 0 } }} } };
|
||||
annotation.color = Color::red();
|
||||
|
||||
test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
AnnotationID fill = test.map.addAnnotation(annotation);
|
||||
|
||||
test::render(test.map, test.view);
|
||||
@@ -260,7 +261,7 @@ TEST(Annotations, UpdateFillAnnotationStyle) {
|
||||
FillAnnotation annotation { polygon };
|
||||
annotation.color = Color::red();
|
||||
|
||||
test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
AnnotationID fill = test.map.addAnnotation(annotation);
|
||||
|
||||
test::render(test.map, test.view);
|
||||
@@ -273,7 +274,7 @@ TEST(Annotations, UpdateFillAnnotationStyle) {
|
||||
TEST(Annotations, RemovePoint) {
|
||||
AnnotationTest test;
|
||||
|
||||
test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.addAnnotationImage(namedMarker("default_marker"));
|
||||
AnnotationID point = test.map.addAnnotation(SymbolAnnotation { Point<double> { 0, 0 }, "default_marker" });
|
||||
|
||||
@@ -291,7 +292,7 @@ TEST(Annotations, RemoveShape) {
|
||||
annotation.color = Color::red();
|
||||
annotation.width = { 5 };
|
||||
|
||||
test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
AnnotationID shape = test.map.addAnnotation(annotation);
|
||||
|
||||
test::render(test.map, test.view);
|
||||
@@ -304,7 +305,7 @@ TEST(Annotations, ImmediateRemoveShape) {
|
||||
AnnotationTest test;
|
||||
|
||||
test.map.removeAnnotation(test.map.addAnnotation(LineAnnotation { LineString<double>() }));
|
||||
test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
|
||||
test::render(test.map, test.view);
|
||||
}
|
||||
@@ -312,20 +313,20 @@ TEST(Annotations, ImmediateRemoveShape) {
|
||||
TEST(Annotations, SwitchStyle) {
|
||||
AnnotationTest test;
|
||||
|
||||
test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.addAnnotationImage(namedMarker("default_marker"));
|
||||
test.map.addAnnotation(SymbolAnnotation { Point<double> { 0, 0 }, "default_marker" });
|
||||
|
||||
test::render(test.map, test.view);
|
||||
|
||||
test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.checkRendering("switch_style");
|
||||
}
|
||||
|
||||
TEST(Annotations, ReaddImage) {
|
||||
AnnotationTest test;
|
||||
|
||||
test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.addAnnotationImage(namedMarker("default_marker"));
|
||||
test.map.addAnnotation(SymbolAnnotation { Point<double> { 0, 0 }, "default_marker" });
|
||||
|
||||
@@ -338,7 +339,7 @@ TEST(Annotations, ReaddImage) {
|
||||
TEST(Annotations, QueryRenderedFeatures) {
|
||||
AnnotationTest test;
|
||||
|
||||
test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.addAnnotationImage(namedMarker("default_marker"));
|
||||
test.map.addAnnotation(SymbolAnnotation { Point<double> { 0, 0 }, "default_marker" });
|
||||
test.map.addAnnotation(SymbolAnnotation { Point<double> { 0, 50 }, "default_marker" });
|
||||
@@ -362,7 +363,7 @@ TEST(Annotations, QueryFractionalZoomLevels) {
|
||||
auto viewSize = test.view.getSize();
|
||||
auto box = ScreenBox { {}, { double(viewSize.width), double(viewSize.height) } };
|
||||
|
||||
test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.addAnnotationImage(namedMarker("default_marker"));
|
||||
|
||||
std::vector<mbgl::AnnotationID> ids;
|
||||
@@ -394,7 +395,7 @@ TEST(Annotations, VisibleFeatures) {
|
||||
auto viewSize = test.view.getSize();
|
||||
auto box = ScreenBox { {}, { double(viewSize.width), double(viewSize.height) } };
|
||||
|
||||
test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.addAnnotationImage(namedMarker("default_marker"));
|
||||
test.map.setLatLngZoom({ 5, 5 }, 3);
|
||||
|
||||
@@ -438,7 +439,7 @@ TEST(Annotations, DebugEmpty) {
|
||||
// should not render them.
|
||||
AnnotationTest test;
|
||||
|
||||
test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.setDebug(MapDebugOptions::TileBorders);
|
||||
test.map.setZoom(1);
|
||||
|
||||
@@ -451,7 +452,7 @@ TEST(Annotations, DebugSparse) {
|
||||
// tiles because they're all empty.
|
||||
AnnotationTest test;
|
||||
|
||||
test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
|
||||
test.map.setDebug(MapDebugOptions::TileBorders);
|
||||
test.map.setZoom(1);
|
||||
test.map.addAnnotationImage(namedMarker("default_marker"));
|
||||
|
||||
Reference in New Issue
Block a user