summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/annotation/annotation_source.cpp9
-rw-r--r--src/mbgl/annotation/annotation_source.hpp8
-rw-r--r--src/mbgl/renderer/layers/render_symbol_layer.cpp2
-rw-r--r--src/mbgl/renderer/render_source.cpp39
-rw-r--r--src/mbgl/renderer/sources/render_raster_dem_source.hpp2
-rw-r--r--src/mbgl/renderer/style_diff.cpp7
-rw-r--r--src/mbgl/renderer/tile_pyramid.cpp71
-rw-r--r--src/mbgl/style/layer.cpp6
-rw-r--r--src/mbgl/style/source.cpp73
-rw-r--r--src/mbgl/style/source_impl.cpp15
-rw-r--r--src/mbgl/style/source_impl.hpp19
-rw-r--r--src/mbgl/style/sources/custom_geometry_source.cpp2
-rw-r--r--src/mbgl/style/sources/custom_geometry_source_impl.cpp7
-rw-r--r--src/mbgl/style/sources/custom_geometry_source_impl.hpp2
-rw-r--r--src/mbgl/style/sources/geojson_source.cpp37
-rw-r--r--src/mbgl/style/sources/geojson_source_impl.cpp23
-rw-r--r--src/mbgl/style/sources/geojson_source_impl.hpp2
-rw-r--r--src/mbgl/style/sources/image_source.cpp43
-rw-r--r--src/mbgl/style/sources/image_source_impl.cpp12
-rw-r--r--src/mbgl/style/sources/image_source_impl.hpp3
-rw-r--r--src/mbgl/style/sources/raster_dem_source.cpp38
-rw-r--r--src/mbgl/style/sources/raster_dem_source_impl.cpp16
-rw-r--r--src/mbgl/style/sources/raster_dem_source_impl.hpp18
-rw-r--r--src/mbgl/style/sources/raster_source.cpp35
-rw-r--r--src/mbgl/style/sources/raster_source_impl.cpp15
-rw-r--r--src/mbgl/style/sources/raster_source_impl.hpp8
-rw-r--r--src/mbgl/style/sources/vector_source.cpp19
-rw-r--r--src/mbgl/style/sources/vector_source_impl.cpp14
-rw-r--r--src/mbgl/style/sources/vector_source_impl.hpp4
-rw-r--r--src/mbgl/style/types.cpp222
-rw-r--r--src/mbgl/tile/geometry_tile.cpp9
-rw-r--r--src/mbgl/tile/raster_dem_tile.cpp10
-rw-r--r--src/mbgl/tile/raster_tile.cpp10
-rw-r--r--src/mbgl/tile/tile.cpp20
-rw-r--r--src/mbgl/tile/tile.hpp32
-rw-r--r--src/mbgl/util/mapbox.cpp16
-rw-r--r--src/mbgl/util/mapbox.hpp10
-rw-r--r--src/mbgl/util/tile_cover.cpp9
-rw-r--r--src/mbgl/util/tile_cover.hpp2
39 files changed, 558 insertions, 331 deletions
diff --git a/src/mbgl/annotation/annotation_source.cpp b/src/mbgl/annotation/annotation_source.cpp
index 318241a914..712ad73651 100644
--- a/src/mbgl/annotation/annotation_source.cpp
+++ b/src/mbgl/annotation/annotation_source.cpp
@@ -10,9 +10,7 @@ AnnotationSource::AnnotationSource()
: Source(makeMutable<Impl>()) {
}
-AnnotationSource::Impl::Impl()
- : Source::Impl(SourceType::Annotations, AnnotationManager::SourceID) {
-}
+AnnotationSource::Impl::Impl() : Source::Impl(AnnotationManager::SourceID) {}
const AnnotationSource::Impl& AnnotationSource::impl() const {
return static_cast<const Impl&>(*baseImpl);
@@ -34,4 +32,9 @@ Mutable<Source::Impl> AnnotationSource::createMutable() const noexcept {
return staticMutableCast<Source::Impl>(makeMutable<Impl>(impl()));
}
+const SourceTypeInfo* AnnotationSource::Impl::staticTypeInfo() noexcept {
+ const static SourceTypeInfo typeInfo{"annotations", false, nullopt};
+ return &typeInfo;
+}
+
} // namespace mbgl
diff --git a/src/mbgl/annotation/annotation_source.hpp b/src/mbgl/annotation/annotation_source.hpp
index de432202a0..7503c4b066 100644
--- a/src/mbgl/annotation/annotation_source.hpp
+++ b/src/mbgl/annotation/annotation_source.hpp
@@ -18,10 +18,8 @@ protected:
private:
void loadDescription(FileSource&) final;
bool supportsLayerType(const mbgl::style::LayerTypeInfo*) const override;
- mapbox::base::WeakPtr<Source> makeWeakPtr() override {
- return weakFactory.makeWeakPtr();
- }
- mapbox::base::WeakPtrFactory<Source> weakFactory {this};
+ mapbox::base::WeakPtr<Source> makeWeakPtr() override { return weakFactory.makeWeakPtr(); }
+ mapbox::base::WeakPtrFactory<Source> weakFactory{this};
};
class AnnotationSource::Impl : public style::Source::Impl {
@@ -29,6 +27,8 @@ public:
Impl();
optional<std::string> getAttribution() const final;
+
+ DECLARE_SOURCE_TYPE_INFO;
};
} // namespace mbgl
diff --git a/src/mbgl/renderer/layers/render_symbol_layer.cpp b/src/mbgl/renderer/layers/render_symbol_layer.cpp
index 1d8c0a70a8..169e9d22ab 100644
--- a/src/mbgl/renderer/layers/render_symbol_layer.cpp
+++ b/src/mbgl/renderer/layers/render_symbol_layer.cpp
@@ -582,7 +582,7 @@ void RenderSymbolLayer::prepare(const LayerPrepareParameters& params) {
// Only place this layer if it's the "group leader" for the bucket
const Tile* tile = params.source->getRenderedTile(renderTile.id);
assert(tile);
- assert(tile->kind == Tile::Kind::Geometry);
+ assert(tile->kind == TileKind::Geometry);
auto featureIndex = static_cast<const GeometryTile*>(tile)->getFeatureIndex();
diff --git a/src/mbgl/renderer/render_source.cpp b/src/mbgl/renderer/render_source.cpp
index f39d3089d7..dd1959e2c7 100644
--- a/src/mbgl/renderer/render_source.cpp
+++ b/src/mbgl/renderer/render_source.cpp
@@ -1,16 +1,15 @@
+#include <mbgl/annotation/render_annotation_source.hpp>
+#include <mbgl/layermanager/layer_manager.hpp>
#include <mbgl/renderer/render_source.hpp>
#include <mbgl/renderer/render_source_observer.hpp>
+#include <mbgl/renderer/sources/render_custom_geometry_source.hpp>
#include <mbgl/renderer/sources/render_geojson_source.hpp>
-#include <mbgl/renderer/sources/render_raster_source.hpp>
+#include <mbgl/renderer/sources/render_image_source.hpp>
#include <mbgl/renderer/sources/render_raster_dem_source.hpp>
+#include <mbgl/renderer/sources/render_raster_source.hpp>
#include <mbgl/renderer/sources/render_vector_source.hpp>
#include <mbgl/renderer/tile_parameters.hpp>
-#include <mbgl/annotation/render_annotation_source.hpp>
-#include <mbgl/renderer/sources/render_image_source.hpp>
-#include <mbgl/renderer/sources/render_custom_geometry_source.hpp>
#include <mbgl/tile/tile.hpp>
-
-#include <mbgl/layermanager/layer_manager.hpp>
#include <mbgl/util/constants.hpp>
#include <utility>
@@ -19,42 +18,38 @@ namespace mbgl {
using namespace style;
std::unique_ptr<RenderSource> RenderSource::create(const Immutable<Source::Impl>& impl) {
- switch (impl->type) {
- case SourceType::Vector:
+ std::string sourceType{impl->getTypeInfo()->type};
+ if (sourceType == VectorSource::Impl::staticTypeInfo()->type) {
return std::make_unique<RenderVectorSource>(staticImmutableCast<VectorSource::Impl>(impl));
- case SourceType::Raster:
+ } else if (sourceType == RasterSource::Impl::staticTypeInfo()->type) {
return std::make_unique<RenderRasterSource>(staticImmutableCast<RasterSource::Impl>(impl));
- case SourceType::RasterDEM:
- return std::make_unique<RenderRasterDEMSource>(staticImmutableCast<RasterSource::Impl>(impl));
- case SourceType::GeoJSON:
+ } else if (sourceType == RasterDEMSource::Impl::staticTypeInfo()->type) {
+ return std::make_unique<RenderRasterDEMSource>(staticImmutableCast<RasterDEMSource::Impl>(impl));
+ } else if (sourceType == GeoJSONSource::Impl::staticTypeInfo()->type) {
return std::make_unique<RenderGeoJSONSource>(staticImmutableCast<GeoJSONSource::Impl>(impl));
- case SourceType::Video:
+ } else if (sourceType == "video") {
assert(false);
return nullptr;
- case SourceType::Annotations:
+ } else if (sourceType == AnnotationSource::Impl::staticTypeInfo()->type) {
if (LayerManager::annotationsEnabled) {
return std::make_unique<RenderAnnotationSource>(staticImmutableCast<AnnotationSource::Impl>(impl));
} else {
assert(false);
return nullptr;
}
- case SourceType::Image:
+ } else if (sourceType == ImageSource::Impl::staticTypeInfo()->type) {
return std::make_unique<RenderImageSource>(staticImmutableCast<ImageSource::Impl>(impl));
- case SourceType::CustomVector:
+ } else if (sourceType == CustomGeometrySource::Impl::staticTypeInfo()->type) {
return std::make_unique<RenderCustomGeometrySource>(staticImmutableCast<CustomGeometrySource::Impl>(impl));
}
- // Not reachable, but placate GCC.
assert(false);
return nullptr;
}
static RenderSourceObserver nullObserver;
-RenderSource::RenderSource(Immutable<style::Source::Impl> impl)
- : baseImpl(std::move(impl)),
- observer(&nullObserver) {
-}
+RenderSource::RenderSource(Immutable<style::Source::Impl> impl) : baseImpl(std::move(impl)), observer(&nullObserver) {}
RenderSource::~RenderSource() = default;
@@ -74,7 +69,7 @@ bool RenderSource::isEnabled() const {
return enabled;
}
-uint8_t RenderSource::getMaxZoom() const {
+uint8_t RenderSource::getMaxZoom() const {
assert(false);
return util::TERRAIN_RGB_MAXZOOM;
}
diff --git a/src/mbgl/renderer/sources/render_raster_dem_source.hpp b/src/mbgl/renderer/sources/render_raster_dem_source.hpp
index 72a3779e99..5768a058a6 100644
--- a/src/mbgl/renderer/sources/render_raster_dem_source.hpp
+++ b/src/mbgl/renderer/sources/render_raster_dem_source.hpp
@@ -1,7 +1,7 @@
#pragma once
#include <mbgl/renderer/sources/render_tile_source.hpp>
-#include <mbgl/style/sources/raster_source_impl.hpp>
+#include <mbgl/style/sources/raster_dem_source_impl.hpp>
namespace mbgl {
diff --git a/src/mbgl/renderer/style_diff.cpp b/src/mbgl/renderer/style_diff.cpp
index 270c4483cd..d925aaa9d7 100644
--- a/src/mbgl/renderer/style_diff.cpp
+++ b/src/mbgl/renderer/style_diff.cpp
@@ -53,15 +53,14 @@ ImageDifference diffImages(const Immutable<std::vector<ImmutableImage>>& a,
SourceDifference diffSources(const Immutable<std::vector<ImmutableSource>>& a,
const Immutable<std::vector<ImmutableSource>>& b) {
- return diff(a, b, [] (const ImmutableSource& lhs, const ImmutableSource& rhs) {
- return std::tie(lhs->id, lhs->type)
- == std::tie(rhs->id, rhs->type);
+ return diff(a, b, [](const ImmutableSource& lhs, const ImmutableSource& rhs) {
+ return (lhs->id == rhs->id) && (lhs->getTypeInfo() == rhs->getTypeInfo());
});
}
LayerDifference diffLayers(const Immutable<std::vector<ImmutableLayer>>& a,
const Immutable<std::vector<ImmutableLayer>>& b) {
- return diff(a, b, [] (const ImmutableLayer& lhs, const ImmutableLayer& rhs) {
+ return diff(a, b, [](const ImmutableLayer& lhs, const ImmutableLayer& rhs) {
return (lhs->id == rhs->id) && (lhs->getTypeInfo() == rhs->getTypeInfo());
});
}
diff --git a/src/mbgl/renderer/tile_pyramid.cpp b/src/mbgl/renderer/tile_pyramid.cpp
index 39a9c59283..60aabafd58 100644
--- a/src/mbgl/renderer/tile_pyramid.cpp
+++ b/src/mbgl/renderer/tile_pyramid.cpp
@@ -1,21 +1,18 @@
-#include <mbgl/renderer/tile_pyramid.hpp>
+#include <algorithm>
+#include <cmath>
+#include <mapbox/geometry/envelope.hpp>
+#include <mbgl/algorithm/update_renderables.hpp>
+#include <mbgl/map/transform.hpp>
+#include <mbgl/math/clamp.hpp>
#include <mbgl/renderer/paint_parameters.hpp>
+#include <mbgl/renderer/query.hpp>
#include <mbgl/renderer/render_source.hpp>
#include <mbgl/renderer/tile_parameters.hpp>
-#include <mbgl/renderer/query.hpp>
-#include <mbgl/map/transform.hpp>
-#include <mbgl/math/clamp.hpp>
-#include <mbgl/util/tile_cover.hpp>
-#include <mbgl/util/tile_range.hpp>
+#include <mbgl/renderer/tile_pyramid.hpp>
#include <mbgl/util/enum.hpp>
#include <mbgl/util/logging.hpp>
-
-#include <mbgl/algorithm/update_renderables.hpp>
-
-#include <mapbox/geometry/envelope.hpp>
-
-#include <cmath>
-#include <algorithm>
+#include <mbgl/util/tile_cover.hpp>
+#include <mbgl/util/tile_range.hpp>
namespace mbgl {
@@ -23,9 +20,7 @@ using namespace style;
static TileObserver nullObserver;
-TilePyramid::TilePyramid()
- : observer(&nullObserver) {
-}
+TilePyramid::TilePyramid() : observer(&nullObserver) {}
TilePyramid::~TilePyramid() = default;
@@ -84,9 +79,8 @@ void TilePyramid::update(const std::vector<Immutable<style::LayerProperties>>& l
handleWrapJump(parameters.transformState.getLatLng().longitude());
- const auto type = sourceImpl.type;
// Determine the overzooming/underzooming amounts and required tiles.
- int32_t overscaledZoom = util::coveringZoomLevel(parameters.transformState.getZoom(), type, tileSize);
+ int32_t overscaledZoom = sourceImpl.getCoveringZoomLevel(parameters.transformState.getZoom());
int32_t tileZoom = overscaledZoom;
int32_t panZoom = zoomRange.max;
@@ -101,14 +95,13 @@ void TilePyramid::update(const std::vector<Immutable<style::LayerProperties>>& l
if (overscaledZoom >= zoomRange.min) {
int32_t idealZoom = std::min<int32_t>(zoomRange.max, overscaledZoom);
-
// Make sure we're not reparsing overzoomed raster tiles.
- if (type == SourceType::Raster) {
+ if (sourceImpl.getTypeInfo()->tileKind == TileKind::Raster) {
tileZoom = idealZoom;
}
// Only attempt prefetching in continuous mode.
- if (parameters.mode == MapMode::Continuous && type != style::SourceType::GeoJSON && type != style::SourceType::Annotations) {
+ if (parameters.mode == MapMode::Continuous && sourceImpl.getTypeInfo()->supportsTilePrefetch) {
// Request lower zoom level tiles (if configured to do so) in an attempt
// to show something on the screen faster at the cost of a little of bandwidth.
const uint8_t prefetchZoomDelta =
@@ -123,8 +116,8 @@ void TilePyramid::update(const std::vector<Immutable<style::LayerProperties>>& l
}
idealTiles = util::tileCover(parameters.transformState, idealZoom, tileZoom);
- if (parameters.mode == MapMode::Tile && type != SourceType::Raster && type != SourceType::RasterDEM &&
- idealTiles.size() > 1) {
+ if (parameters.mode == MapMode::Tile && sourceImpl.getTypeInfo()->tileKind != TileKind::Raster &&
+ sourceImpl.getTypeInfo()->tileKind != TileKind::RasterDEM && idealTiles.size() > 1) {
mbgl::Log::Warning(mbgl::Event::General,
"Provided camera options returned %zu tiles, only %s is taken in Tile mode.",
idealTiles.size(),
@@ -212,7 +205,8 @@ void TilePyramid::update(const std::vector<Immutable<style::LayerProperties>>& l
}
}
- if (type != SourceType::Annotations) {
+ // TODO: can this be more generic than != "annotations"?
+ if (strcmp(sourceImpl.getTypeInfo()->type, "annotations") != 0) {
size_t conservativeCacheSize =
std::max(static_cast<float>(parameters.transformState.getSize().width) / tileSize, 1.0f) *
std::max(static_cast<float>(parameters.transformState.getSize().height) / tileSize, 1.0f) *
@@ -303,9 +297,12 @@ void TilePyramid::handleWrapJump(float lng) {
}
std::unordered_map<std::string, std::vector<Feature>> TilePyramid::queryRenderedFeatures(
- const ScreenLineString& geometry, const TransformState& transformState,
- const std::unordered_map<std::string, const RenderLayer*>& layers, const RenderedQueryOptions& options,
- const mat4& projMatrix, const SourceFeatureState& featureState) const {
+ const ScreenLineString& geometry,
+ const TransformState& transformState,
+ const std::unordered_map<std::string, const RenderLayer*>& layers,
+ const RenderedQueryOptions& options,
+ const mat4& projMatrix,
+ const SourceFeatureState& featureState) const {
std::unordered_map<std::string, std::vector<Feature>> result;
if (renderedTiles.empty() || geometry.empty()) {
return result;
@@ -315,18 +312,19 @@ std::unordered_map<std::string, std::vector<Feature>> TilePyramid::queryRendered
queryGeometry.reserve(geometry.size());
for (const auto& p : geometry) {
- queryGeometry.push_back(TileCoordinate::fromScreenCoordinate(
- transformState, 0, { p.x, transformState.getSize().height - p.y }).p);
+ queryGeometry.push_back(
+ TileCoordinate::fromScreenCoordinate(transformState, 0, {p.x, transformState.getSize().height - p.y}).p);
}
mapbox::geometry::box<double> box = mapbox::geometry::envelope(queryGeometry);
auto cmp = [](const UnwrappedTileID& a, const UnwrappedTileID& b) {
return std::tie(a.canonical.z, a.canonical.y, a.wrap, a.canonical.x) <
- std::tie(b.canonical.z, b.canonical.y, b.wrap, b.canonical.x);
+ std::tie(b.canonical.z, b.canonical.y, b.wrap, b.canonical.x);
};
- std::map<UnwrappedTileID, std::reference_wrapper<Tile>, decltype(cmp)> sortedTiles{renderedTiles.begin(), renderedTiles.end(), cmp};
+ std::map<UnwrappedTileID, std::reference_wrapper<Tile>, decltype(cmp)> sortedTiles{
+ renderedTiles.begin(), renderedTiles.end(), cmp};
auto maxPitchScaleFactor = transformState.maxPitchScaleFactor();
@@ -334,11 +332,14 @@ std::unordered_map<std::string, std::vector<Feature>> TilePyramid::queryRendered
const UnwrappedTileID& id = entry.first;
Tile& tile = entry.second;
- const float scale = transformState.getScale() / (1 << id.canonical.z); // equivalent to std::pow(2, transformState.getZoom() - id.canonical.z);
+ const float scale =
+ transformState.getScale() /
+ (1 << id.canonical.z); // equivalent to std::pow(2, transformState.getZoom() - id.canonical.z);
auto queryPadding = maxPitchScaleFactor * tile.getQueryPadding(layers) * util::EXTENT / util::tileSize / scale;
GeometryCoordinate tileSpaceBoundsMin = TileCoordinate::toGeometryCoordinate(id, box.min);
- if (tileSpaceBoundsMin.x - queryPadding >= util::EXTENT || tileSpaceBoundsMin.y - queryPadding >= util::EXTENT) {
+ if (tileSpaceBoundsMin.x - queryPadding >= util::EXTENT ||
+ tileSpaceBoundsMin.y - queryPadding >= util::EXTENT) {
continue;
}
@@ -353,8 +354,8 @@ std::unordered_map<std::string, std::vector<Feature>> TilePyramid::queryRendered
tileSpaceQueryGeometry.push_back(TileCoordinate::toGeometryCoordinate(id, c));
}
- tile.queryRenderedFeatures(result, tileSpaceQueryGeometry, transformState, layers, options, projMatrix,
- featureState);
+ tile.queryRenderedFeatures(
+ result, tileSpaceQueryGeometry, transformState, layers, options, projMatrix, featureState);
}
return result;
diff --git a/src/mbgl/style/layer.cpp b/src/mbgl/style/layer.cpp
index 428bcc9a5a..b1c14191be 100644
--- a/src/mbgl/style/layer.cpp
+++ b/src/mbgl/style/layer.cpp
@@ -12,11 +12,11 @@
namespace mbgl {
namespace style {
-static_assert(mbgl::underlying_type(Tile::Kind::Geometry) == mbgl::underlying_type(LayerTypeInfo::TileKind::Geometry),
+static_assert(mbgl::underlying_type(TileKind::Geometry) == mbgl::underlying_type(LayerTypeInfo::TileKind::Geometry),
"tile kind error");
-static_assert(mbgl::underlying_type(Tile::Kind::Raster) == mbgl::underlying_type(LayerTypeInfo::TileKind::Raster),
+static_assert(mbgl::underlying_type(TileKind::Raster) == mbgl::underlying_type(LayerTypeInfo::TileKind::Raster),
"tile kind error");
-static_assert(mbgl::underlying_type(Tile::Kind::RasterDEM) == mbgl::underlying_type(LayerTypeInfo::TileKind::RasterDEM),
+static_assert(mbgl::underlying_type(TileKind::RasterDEM) == mbgl::underlying_type(LayerTypeInfo::TileKind::RasterDEM),
"tile kind error");
static LayerObserver nullObserver;
diff --git a/src/mbgl/style/source.cpp b/src/mbgl/style/source.cpp
index b2a9473fe6..db195867c0 100644
--- a/src/mbgl/style/source.cpp
+++ b/src/mbgl/style/source.cpp
@@ -2,23 +2,17 @@
#include <mbgl/style/source_impl.hpp>
#include <mbgl/style/source_observer.hpp>
#include <mbgl/util/logging.hpp>
+#include <mbgl/util/tileset.hpp>
namespace mbgl {
namespace style {
static SourceObserver nullObserver;
-Source::Source(Immutable<Impl> impl)
- : baseImpl(std::move(impl)),
- observer(&nullObserver) {
-}
+Source::Source(Immutable<Impl> impl) : baseImpl(std::move(impl)), observer(&nullObserver) {}
Source::~Source() = default;
-SourceType Source::getType() const {
- return baseImpl->type;
-}
-
std::string Source::getID() const {
return baseImpl->id;
}
@@ -79,10 +73,73 @@ optional<uint8_t> Source::getMaxOverscaleFactorForParentTiles() const noexcept {
return baseImpl->getMaxOverscaleFactorForParentTiles();
}
+int32_t Source::getCoveringZoomLevel(double z) const noexcept {
+ return baseImpl->getCoveringZoomLevel(z);
+}
+
void Source::dumpDebugLogs() const {
Log::Info(Event::General, "Source::id: %s", getID().c_str());
Log::Info(Event::General, "Source::loaded: %d", loaded);
}
+const SourceTypeInfo* Source::getTypeInfo() const noexcept {
+ return baseImpl->getTypeInfo();
+}
+
+Value Source::serialize() const {
+ mapbox::base::ValueObject result;
+ result.insert(std::make_pair("id", getID()));
+ result.insert(std::make_pair("type", getTypeInfo()->type));
+ return result;
+}
+
+std::string tilesetSchemeToString(mbgl::Tileset::Scheme scheme) {
+ switch (scheme) {
+ case mbgl::Tileset::Scheme::XYZ:
+ return "xyz";
+ case mbgl::Tileset::Scheme::TMS:
+ return "tms";
+ }
+
+ return "xyz";
+}
+
+void Source::serializeTileSet(Value& value, const mbgl::Tileset& tileset) const {
+ assert(value.getObject());
+ const auto json = value.getObject();
+ std::vector<mapbox::base::Value> tiles;
+ tiles.reserve(tileset.tiles.size());
+ for (const auto& tile : tileset.tiles) tiles.emplace_back(tile);
+
+ json->insert({"tiles", tiles});
+ json->insert({"minzoom", tileset.zoomRange.min});
+ json->insert({"maxzoom", tileset.zoomRange.max});
+ json->insert({"scheme", tilesetSchemeToString(tileset.scheme)});
+
+ if (tileset.bounds.has_value()) {
+ json->insert({"bounds",
+ std::vector<mapbox::base::Value>{tileset.bounds->southwest().longitude(),
+ tileset.bounds->southwest().latitude(),
+ tileset.bounds->northeast().longitude(),
+ tileset.bounds->northeast().latitude()}});
+ }
+}
+
+void Source::serializeUrlOrTileSet(Value& value, const mbgl::variant<std::string, mbgl::Tileset>* urlOrTileSet) const {
+ assert(value.getObject());
+
+ if (!urlOrTileSet) return;
+
+ urlOrTileSet->match(
+ [&](const std::string& url) {
+ value.getObject()->insert({"url", url});
+ },
+ [&](const mbgl::Tileset& tileset) { serializeTileSet(value, tileset); });
+}
+
+uint16_t Source::getTileSize() const {
+ return baseImpl->getTileSize();
+}
+
} // namespace style
} // namespace mbgl
diff --git a/src/mbgl/style/source_impl.cpp b/src/mbgl/style/source_impl.cpp
index 98433a8c86..b4d3292884 100644
--- a/src/mbgl/style/source_impl.cpp
+++ b/src/mbgl/style/source_impl.cpp
@@ -1,3 +1,4 @@
+#include <mbgl/math/log2.hpp>
#include <mbgl/style/source_impl.hpp>
#include <mbgl/util/constants.hpp>
#include <mbgl/util/logging.hpp>
@@ -14,10 +15,7 @@ void WarnIfOverscaleFactorCapsPrefetchDelta(const optional<uint8_t>& overscale,
}
} // namespace
-Source::Impl::Impl(SourceType type_, std::string id_)
- : type(type_),
- id(std::move(id_)) {
-}
+Source::Impl::Impl(std::string id_) : id(std::move(id_)) {}
void Source::Impl::setPrefetchZoomDelta(optional<uint8_t> delta) noexcept {
prefetchZoomDelta = std::move(delta);
@@ -37,5 +35,14 @@ optional<uint8_t> Source::Impl::getMaxOverscaleFactorForParentTiles() const noex
return maxOverscaleFactor;
}
+int32_t Source::Impl::getCoveringZoomLevel(double zoom) const noexcept {
+ zoom += util::log2(util::tileSize / getTileSize());
+ if (getTypeInfo()->tileKind == TileKind::Raster) {
+ return ::round(zoom);
+ } else {
+ return std::floor(zoom);
+ }
+}
+
} // namespace style
} // namespace mbgl
diff --git a/src/mbgl/style/source_impl.hpp b/src/mbgl/style/source_impl.hpp
index 87a30dcf95..57e0ea5710 100644
--- a/src/mbgl/style/source_impl.hpp
+++ b/src/mbgl/style/source_impl.hpp
@@ -1,7 +1,6 @@
#pragma once
#include <mbgl/style/source.hpp>
-
#include <string>
namespace mbgl {
@@ -18,9 +17,13 @@ public:
Impl& operator=(const Impl&) = delete;
+ virtual uint16_t getTileSize() const { return util::tileSize; };
+
virtual optional<std::string> getAttribution() const = 0;
+
void setPrefetchZoomDelta(optional<uint8_t> delta) noexcept;
optional<uint8_t> getPrefetchZoomDelta() const noexcept;
+
void setMinimumTileUpdateInterval(Duration interval) { minimumTileUpdateInterval = interval; }
Duration getMinimumTileUpdateInterval() const { return minimumTileUpdateInterval; }
void setMaxOverscaleFactorForParentTiles(optional<uint8_t> overscaleFactor) noexcept;
@@ -28,7 +31,12 @@ public:
bool isVolatile() const { return volatileFlag; }
void setVolatile(bool set) { volatileFlag = set; }
- const SourceType type;
+
+ // Returns pointer to the statically allocated source type info structure.
+ virtual const SourceTypeInfo* getTypeInfo() const noexcept = 0;
+
+ int32_t getCoveringZoomLevel(double zoom) const noexcept;
+
const std::string id;
protected:
@@ -37,9 +45,14 @@ protected:
Duration minimumTileUpdateInterval{Duration::zero()};
bool volatileFlag = false;
- Impl(SourceType, std::string);
+ explicit Impl(std::string);
Impl(const Impl&) = default;
};
+// To be used in the inherited classes.
+#define DECLARE_SOURCE_TYPE_INFO \
+ const mbgl::style::SourceTypeInfo* getTypeInfo() const noexcept override { return staticTypeInfo(); } \
+ static const mbgl::style::SourceTypeInfo* staticTypeInfo() noexcept
+
} // namespace style
} // namespace mbgl
diff --git a/src/mbgl/style/sources/custom_geometry_source.cpp b/src/mbgl/style/sources/custom_geometry_source.cpp
index 9d3a58c151..278d4d5a72 100644
--- a/src/mbgl/style/sources/custom_geometry_source.cpp
+++ b/src/mbgl/style/sources/custom_geometry_source.cpp
@@ -32,7 +32,7 @@ void CustomGeometrySource::loadDescription(FileSource&) {
}
bool CustomGeometrySource::supportsLayerType(const mbgl::style::LayerTypeInfo* info) const {
- return mbgl::underlying_type(Tile::Kind::Geometry) == mbgl::underlying_type(info->tileKind);
+ return mbgl::underlying_type(TileKind::Geometry) == mbgl::underlying_type(info->tileKind);
}
void CustomGeometrySource::setTileData(const CanonicalTileID& tileID,
diff --git a/src/mbgl/style/sources/custom_geometry_source_impl.cpp b/src/mbgl/style/sources/custom_geometry_source_impl.cpp
index 184718fd76..59f25a3d2d 100644
--- a/src/mbgl/style/sources/custom_geometry_source_impl.cpp
+++ b/src/mbgl/style/sources/custom_geometry_source_impl.cpp
@@ -5,7 +5,7 @@ namespace mbgl {
namespace style {
CustomGeometrySource::Impl::Impl(std::string id_, const CustomGeometrySource::Options& options)
- : Source::Impl(SourceType::CustomVector, std::move(id_)),
+ : Source::Impl(std::move(id_)),
tileOptions(makeMutable<CustomGeometrySource::TileOptions>(options.tileOptions)),
zoomRange(options.zoomRange),
loaderRef({}) {}
@@ -33,5 +33,10 @@ optional<ActorRef<CustomTileLoader>> CustomGeometrySource::Impl::getTileLoader()
return loaderRef;
}
+const SourceTypeInfo* CustomGeometrySource::Impl::staticTypeInfo() noexcept {
+ const static SourceTypeInfo typeInfo{"customvector", true, nullopt};
+ return &typeInfo;
+}
+
} // namespace style
} // namespace mbgl
diff --git a/src/mbgl/style/sources/custom_geometry_source_impl.hpp b/src/mbgl/style/sources/custom_geometry_source_impl.hpp
index a441b38f69..efacdbedda 100644
--- a/src/mbgl/style/sources/custom_geometry_source_impl.hpp
+++ b/src/mbgl/style/sources/custom_geometry_source_impl.hpp
@@ -20,6 +20,8 @@ public:
optional<ActorRef<CustomTileLoader>> getTileLoader() const;
bool operator!=(const Impl&) const noexcept;
+ DECLARE_SOURCE_TYPE_INFO;
+
private:
Immutable<CustomGeometrySource::TileOptions> tileOptions;
Range<uint8_t> zoomRange;
diff --git a/src/mbgl/style/sources/geojson_source.cpp b/src/mbgl/style/sources/geojson_source.cpp
index d750d6b1d2..8bca19af35 100644
--- a/src/mbgl/style/sources/geojson_source.cpp
+++ b/src/mbgl/style/sources/geojson_source.cpp
@@ -61,6 +61,24 @@ void GeoJSONSource::setGeoJSONData(std::shared_ptr<GeoJSONData> geoJSONData) {
observer->onSourceChanged(*this);
}
+void GeoJSONSource::setSourceData(SourceData data) {
+ if (data.url) {
+ setURL(*data.url);
+ } else if (data.geoJSON) {
+ setGeoJSON(*data.geoJSON);
+ } else if (data.geoJSONData) {
+ setGeoJSONData(std::move(data.geoJSONData));
+ }
+}
+
+SourceDataResult GeoJSONSource::getSourceData() const {
+ SourceDataResult result{impl().getData()};
+ if (url) {
+ result.url = &*url;
+ }
+ return result;
+}
+
optional<std::string> GeoJSONSource::getURL() const {
return url;
}
@@ -81,13 +99,11 @@ void GeoJSONSource::loadDescription(FileSource& fileSource) {
req = fileSource.request(Resource::source(*url), [this](const Response& res) {
if (res.error) {
- observer->onSourceError(
- *this, std::make_exception_ptr(std::runtime_error(res.error->message)));
+ observer->onSourceError(*this, std::make_exception_ptr(std::runtime_error(res.error->message)));
} else if (res.notModified) {
return;
} else if (res.noContent) {
- observer->onSourceError(
- *this, std::make_exception_ptr(std::runtime_error("unexpectedly empty GeoJSON")));
+ observer->onSourceError(*this, std::make_exception_ptr(std::runtime_error("unexpectedly empty GeoJSON")));
} else {
auto makeImplInBackground = [currentImpl = baseImpl, data = res.data]() -> Immutable<Source::Impl> {
assert(data);
@@ -117,12 +133,23 @@ void GeoJSONSource::loadDescription(FileSource& fileSource) {
}
bool GeoJSONSource::supportsLayerType(const mbgl::style::LayerTypeInfo* info) const {
- return mbgl::underlying_type(Tile::Kind::Geometry) == mbgl::underlying_type(info->tileKind);
+ return mbgl::underlying_type(TileKind::Geometry) == mbgl::underlying_type(info->tileKind);
}
Mutable<Source::Impl> GeoJSONSource::createMutable() const noexcept {
return staticMutableCast<Source::Impl>(makeMutable<Impl>(impl()));
}
+Value GeoJSONSource::serialize() const {
+ auto value = Source::serialize();
+ assert(value.getObject());
+
+ if (url.has_value()) {
+ value.getObject()->insert({"data", url.value()});
+ }
+
+ return value;
+}
+
} // namespace style
} // namespace mbgl
diff --git a/src/mbgl/style/sources/geojson_source_impl.cpp b/src/mbgl/style/sources/geojson_source_impl.cpp
index fb33eee8f9..7193af0f1b 100644
--- a/src/mbgl/style/sources/geojson_source_impl.cpp
+++ b/src/mbgl/style/sources/geojson_source_impl.cpp
@@ -20,13 +20,11 @@ class GeoJSONVTData final : public GeoJSONData {
[id, impl = this->impl]() -> TileFeatures { return impl->getTile(id.z, id.x, id.y).features; }, fn);
}
- Features getChildren(const std::uint32_t) final { return {}; }
+ Features getChildren(const std::uint32_t) const final { return {}; }
- Features getLeaves(const std::uint32_t, const std::uint32_t, const std::uint32_t) final { return {}; }
+ Features getLeaves(const std::uint32_t, const std::uint32_t, const std::uint32_t) const final { return {}; }
- std::uint8_t getClusterExpansionZoom(std::uint32_t) final {
- return 0;
- }
+ std::uint8_t getClusterExpansionZoom(std::uint32_t) const final { return 0; }
std::shared_ptr<Scheduler> getScheduler() final { return scheduler; }
@@ -48,13 +46,15 @@ class SuperclusterData final : public GeoJSONData {
fn(impl.getTile(id.z, id.x, id.y));
}
- Features getChildren(const std::uint32_t cluster_id) final { return impl.getChildren(cluster_id); }
+ Features getChildren(const std::uint32_t cluster_id) const final { return impl.getChildren(cluster_id); }
- Features getLeaves(const std::uint32_t cluster_id, const std::uint32_t limit, const std::uint32_t offset) final {
+ Features getLeaves(const std::uint32_t cluster_id,
+ const std::uint32_t limit,
+ const std::uint32_t offset) const final {
return impl.getLeaves(cluster_id, limit, offset);
}
- std::uint8_t getClusterExpansionZoom(std::uint32_t cluster_id) final {
+ std::uint8_t getClusterExpansionZoom(std::uint32_t cluster_id) const final {
return impl.getClusterExpansionZoom(cluster_id);
}
@@ -122,7 +122,7 @@ std::shared_ptr<GeoJSONData> GeoJSONData::create(const GeoJSON& geoJSON,
}
GeoJSONSource::Impl::Impl(std::string id_, Immutable<GeoJSONOptions> options_)
- : Source::Impl(SourceType::GeoJSON, std::move(id_)), options(std::move(options_)) {}
+ : Source::Impl(std::move(id_)), options(std::move(options_)) {}
GeoJSONSource::Impl::Impl(const GeoJSONSource::Impl& other, std::shared_ptr<GeoJSONData> data_)
: Source::Impl(other), options(other.options), data(std::move(data_)) {}
@@ -141,5 +141,10 @@ optional<std::string> GeoJSONSource::Impl::getAttribution() const {
return {};
}
+const SourceTypeInfo* GeoJSONSource::Impl::staticTypeInfo() noexcept {
+ const static SourceTypeInfo typeInfo{"geojson", false, TileKind::Geometry};
+ return &typeInfo;
+}
+
} // namespace style
} // namespace mbgl
diff --git a/src/mbgl/style/sources/geojson_source_impl.hpp b/src/mbgl/style/sources/geojson_source_impl.hpp
index fd23ebdbe1..67b419bee9 100644
--- a/src/mbgl/style/sources/geojson_source_impl.hpp
+++ b/src/mbgl/style/sources/geojson_source_impl.hpp
@@ -23,6 +23,8 @@ public:
optional<std::string> getAttribution() const final;
+ DECLARE_SOURCE_TYPE_INFO;
+
private:
Immutable<GeoJSONOptions> options;
std::shared_ptr<GeoJSONData> data;
diff --git a/src/mbgl/style/sources/image_source.cpp b/src/mbgl/style/sources/image_source.cpp
index 144d007cc5..a1bc719c0c 100644
--- a/src/mbgl/style/sources/image_source.cpp
+++ b/src/mbgl/style/sources/image_source.cpp
@@ -50,6 +50,28 @@ void ImageSource::setImage(PremultipliedImage&& image_) {
observer->onSourceChanged(*this);
}
+void ImageSource::setSourceData(SourceData data) {
+ if (data.url) {
+ setURL(*data.url);
+ } else if (data.image) {
+ setImage(std::move(*data.image));
+ }
+}
+
+SourceDataResult ImageSource::getSourceData() const {
+ SourceDataResult result{};
+ if (url) {
+ result.url = &*url;
+ }
+
+ auto image = impl().getImage();
+ if (image) {
+ result.image = image;
+ }
+
+ return result;
+}
+
optional<std::string> ImageSource::getURL() const {
return url;
}
@@ -84,12 +106,31 @@ void ImageSource::loadDescription(FileSource& fileSource) {
}
bool ImageSource::supportsLayerType(const mbgl::style::LayerTypeInfo* info) const {
- return mbgl::underlying_type(Tile::Kind::Raster) == mbgl::underlying_type(info->tileKind);
+ return mbgl::underlying_type(TileKind::Raster) == mbgl::underlying_type(info->tileKind);
}
Mutable<Source::Impl> ImageSource::createMutable() const noexcept {
return staticMutableCast<Source::Impl>(makeMutable<Impl>(impl()));
}
+Value ImageSource::serialize() const {
+ auto value = Source::serialize();
+ assert(value.getObject());
+ auto object = value.getObject();
+
+ if (url) object->insert({"url", url.value()});
+
+ const auto source_coordinates = getCoordinates();
+ std::vector<mapbox::base::Value> coordinates;
+ coordinates.reserve(source_coordinates.size());
+
+ for (const auto& c : source_coordinates) {
+ coordinates.emplace_back(std::vector<mapbox::base::Value>{c.longitude(), c.latitude()});
+ }
+ object->insert({"coordinates", coordinates});
+
+ return value;
+}
+
} // namespace style
} // namespace mbgl
diff --git a/src/mbgl/style/sources/image_source_impl.cpp b/src/mbgl/style/sources/image_source_impl.cpp
index 7a4f5ac01f..41255b3bb0 100644
--- a/src/mbgl/style/sources/image_source_impl.cpp
+++ b/src/mbgl/style/sources/image_source_impl.cpp
@@ -5,16 +5,13 @@ namespace mbgl {
namespace style {
ImageSource::Impl::Impl(std::string id_, std::array<LatLng, 4> coords_)
- : Source::Impl(SourceType::Image, std::move(id_)), coords(coords_) {}
+ : Source::Impl(std::move(id_)), coords(coords_) {}
ImageSource::Impl::Impl(const Impl& other, std::array<LatLng, 4> coords_)
: Source::Impl(other), coords(coords_), image(other.image) {}
ImageSource::Impl::Impl(const Impl& rhs, PremultipliedImage&& image_)
- : Source::Impl(rhs),
- coords(rhs.coords),
- image(std::make_shared<PremultipliedImage>(std::move(image_))) {
-}
+ : Source::Impl(rhs), coords(rhs.coords), image(std::make_shared<PremultipliedImage>(std::move(image_))) {}
ImageSource::Impl::~Impl() = default;
std::shared_ptr<PremultipliedImage> ImageSource::Impl::getImage() const {
@@ -29,5 +26,10 @@ optional<std::string> ImageSource::Impl::getAttribution() const {
return {};
}
+const SourceTypeInfo* ImageSource::Impl::staticTypeInfo() noexcept {
+ const static SourceTypeInfo typeInfo{"image", true, nullopt};
+ return &typeInfo;
+}
+
} // namespace style
} // namespace mbgl
diff --git a/src/mbgl/style/sources/image_source_impl.hpp b/src/mbgl/style/sources/image_source_impl.hpp
index 16ddcfda71..d35891e27b 100644
--- a/src/mbgl/style/sources/image_source_impl.hpp
+++ b/src/mbgl/style/sources/image_source_impl.hpp
@@ -21,6 +21,9 @@ public:
std::array<LatLng, 4> getCoordinates() const;
optional<std::string> getAttribution() const final;
+
+ DECLARE_SOURCE_TYPE_INFO;
+
private:
std::array<LatLng, 4> coords;
std::shared_ptr<PremultipliedImage> image;
diff --git a/src/mbgl/style/sources/raster_dem_source.cpp b/src/mbgl/style/sources/raster_dem_source.cpp
index 98a83ee870..a7efc2ba69 100644
--- a/src/mbgl/style/sources/raster_dem_source.cpp
+++ b/src/mbgl/style/sources/raster_dem_source.cpp
@@ -3,19 +3,49 @@
#include <mbgl/style/layer.hpp>
#include <mbgl/style/source_observer.hpp>
#include <mbgl/style/sources/raster_dem_source.hpp>
-#include <mbgl/style/sources/raster_source_impl.hpp>
+#include <mbgl/style/sources/raster_dem_source_impl.hpp>
#include <mbgl/tile/tile.hpp>
-#include <mbgl/util/mapbox.hpp>
#include <utility>
namespace mbgl {
namespace style {
RasterDEMSource::RasterDEMSource(std::string id, variant<std::string, Tileset> urlOrTileset_, uint16_t tileSize)
- : RasterSource(std::move(id), std::move(urlOrTileset_), tileSize, SourceType::RasterDEM) {}
+ : RasterSource(makeMutable<Impl>(std::move(id), tileSize), std::move(urlOrTileset_)) {}
bool RasterDEMSource::supportsLayerType(const mbgl::style::LayerTypeInfo* info) const {
- return mbgl::underlying_type(Tile::Kind::RasterDEM) == mbgl::underlying_type(info->tileKind);
+ return mbgl::underlying_type(TileKind::RasterDEM) == mbgl::underlying_type(info->tileKind);
+}
+
+static std::string tilesetDEMEncodingToString(mbgl::Tileset::DEMEncoding encoding) {
+ switch (encoding) {
+ case mbgl::Tileset::DEMEncoding::Mapbox:
+ return "mapbox";
+ case mbgl::Tileset::DEMEncoding::Terrarium:
+ return "terrarium";
+ }
+ return "terrarium";
+}
+
+Value RasterDEMSource::serialize() const {
+ auto value = RasterSource::serialize();
+ getURLOrTileset()->match([](const std::string&) {},
+ [&](const mbgl::Tileset& tileset) {
+ value.getObject()->insert({"encoding", tilesetDEMEncodingToString(tileset.encoding)});
+ });
+ return value;
+}
+
+const RasterDEMSource::Impl& RasterDEMSource::impl() const {
+ return static_cast<const Impl&>(*baseImpl);
+}
+
+Mutable<Source::Impl> RasterDEMSource::createMutable() const noexcept {
+ return staticMutableCast<Source::Impl>(makeMutable<Impl>(impl()));
+}
+
+Mutable<Source::Impl> RasterDEMSource::createMutable(Tileset tileset) const noexcept {
+ return staticMutableCast<Source::Impl>(makeMutable<Impl>(impl(), std::move(tileset)));
}
} // namespace style
diff --git a/src/mbgl/style/sources/raster_dem_source_impl.cpp b/src/mbgl/style/sources/raster_dem_source_impl.cpp
new file mode 100644
index 0000000000..487c451d83
--- /dev/null
+++ b/src/mbgl/style/sources/raster_dem_source_impl.cpp
@@ -0,0 +1,16 @@
+#include <mbgl/style/sources/raster_dem_source_impl.hpp>
+
+namespace mbgl {
+namespace style {
+
+RasterDEMSource::Impl::Impl(std::string id_, uint16_t tileSize_) : RasterSource::Impl(std::move(id_), tileSize_) {}
+
+RasterDEMSource::Impl::Impl(const Impl& other, Tileset tileset_) : RasterSource::Impl(other, std::move(tileset_)) {}
+
+const SourceTypeInfo* RasterDEMSource::Impl::staticTypeInfo() noexcept {
+ const static SourceTypeInfo typeInfo{"raster-dem", true, TileKind::RasterDEM};
+ return &typeInfo;
+}
+
+} // namespace style
+} // namespace mbgl
diff --git a/src/mbgl/style/sources/raster_dem_source_impl.hpp b/src/mbgl/style/sources/raster_dem_source_impl.hpp
new file mode 100644
index 0000000000..dc8568766e
--- /dev/null
+++ b/src/mbgl/style/sources/raster_dem_source_impl.hpp
@@ -0,0 +1,18 @@
+#pragma once
+
+#include <mbgl/style/sources/raster_dem_source.hpp>
+#include <mbgl/style/sources/raster_source_impl.hpp>
+
+namespace mbgl {
+namespace style {
+
+class RasterDEMSource::Impl : public RasterSource::Impl {
+public:
+ Impl(std::string id, uint16_t tileSize);
+ Impl(const Impl&, Tileset);
+
+ DECLARE_SOURCE_TYPE_INFO;
+};
+
+} // namespace style
+} // namespace mbgl
diff --git a/src/mbgl/style/sources/raster_source.cpp b/src/mbgl/style/sources/raster_source.cpp
index aa56f9570b..6684b8a52e 100644
--- a/src/mbgl/style/sources/raster_source.cpp
+++ b/src/mbgl/style/sources/raster_source.cpp
@@ -13,10 +13,11 @@
namespace mbgl {
namespace style {
-RasterSource::RasterSource(std::string id, variant<std::string, Tileset> urlOrTileset_, uint16_t tileSize, SourceType sourceType)
- : Source(makeMutable<Impl>(sourceType, std::move(id), tileSize)),
- urlOrTileset(std::move(urlOrTileset_)) {
-}
+RasterSource::RasterSource(std::string id, variant<std::string, Tileset> urlOrTileset_, uint16_t tileSize)
+ : Source(makeMutable<Impl>(std::move(id), tileSize)), urlOrTileset(std::move(urlOrTileset_)) {}
+
+RasterSource::RasterSource(Immutable<Impl>&& impl, variant<std::string, Tileset> urlOrTileset_)
+ : Source(std::move(impl)), urlOrTileset(std::move(urlOrTileset_)) {}
RasterSource::~RasterSource() = default;
@@ -24,8 +25,8 @@ const RasterSource::Impl& RasterSource::impl() const {
return static_cast<const Impl&>(*baseImpl);
}
-const variant<std::string, Tileset>& RasterSource::getURLOrTileset() const {
- return urlOrTileset;
+const variant<std::string, Tileset>* RasterSource::getURLOrTileset() const {
+ return &urlOrTileset;
}
optional<std::string> RasterSource::getURL() const {
@@ -36,13 +37,9 @@ optional<std::string> RasterSource::getURL() const {
return urlOrTileset.get<std::string>();
}
-uint16_t RasterSource::getTileSize() const {
- return impl().getTileSize();
-}
-
void RasterSource::loadDescription(FileSource& fileSource) {
if (urlOrTileset.is<Tileset>()) {
- baseImpl = makeMutable<Impl>(impl(), urlOrTileset.get<Tileset>());
+ baseImpl = createMutable(urlOrTileset.get<Tileset>());
loaded = true;
observer->onSourceLoaded(*this);
return;
@@ -68,10 +65,10 @@ void RasterSource::loadDescription(FileSource& fileSource) {
return;
}
- util::mapbox::canonicalizeTileset(*tileset, url, getType(), getTileSize());
+ util::mapbox::canonicalizeTileset(*tileset, url, *this);
bool changed = impl().tileset != *tileset;
- baseImpl = makeMutable<Impl>(impl(), *tileset);
+ baseImpl = createMutable(*tileset);
loaded = true;
observer->onSourceLoaded(*this);
@@ -84,12 +81,22 @@ void RasterSource::loadDescription(FileSource& fileSource) {
}
bool RasterSource::supportsLayerType(const mbgl::style::LayerTypeInfo* info) const {
- return mbgl::underlying_type(Tile::Kind::Raster) == mbgl::underlying_type(info->tileKind);
+ return mbgl::underlying_type(TileKind::Raster) == mbgl::underlying_type(info->tileKind);
}
Mutable<Source::Impl> RasterSource::createMutable() const noexcept {
return staticMutableCast<Source::Impl>(makeMutable<Impl>(impl()));
}
+Mutable<Source::Impl> RasterSource::createMutable(Tileset tileset) const noexcept {
+ return staticMutableCast<Source::Impl>(makeMutable<Impl>(impl(), std::move(tileset)));
+}
+
+Value RasterSource::serialize() const {
+ auto value = Source::serialize();
+ serializeUrlOrTileSet(value, getURLOrTileset());
+ return value;
+}
+
} // namespace style
} // namespace mbgl
diff --git a/src/mbgl/style/sources/raster_source_impl.cpp b/src/mbgl/style/sources/raster_source_impl.cpp
index 4201fd0578..b18a34412b 100644
--- a/src/mbgl/style/sources/raster_source_impl.cpp
+++ b/src/mbgl/style/sources/raster_source_impl.cpp
@@ -3,16 +3,10 @@
namespace mbgl {
namespace style {
-RasterSource::Impl::Impl(SourceType sourceType, std::string id_, uint16_t tileSize_)
- : Source::Impl(sourceType, std::move(id_)),
- tileSize(tileSize_) {
-}
+RasterSource::Impl::Impl(std::string id_, uint16_t tileSize_) : Source::Impl(std::move(id_)), tileSize(tileSize_) {}
RasterSource::Impl::Impl(const Impl& other, Tileset tileset_)
- : Source::Impl(other),
- tileset(std::move(tileset_)),
- tileSize(other.tileSize) {
-}
+ : Source::Impl(other), tileset(std::move(tileset_)), tileSize(other.tileSize) {}
uint16_t RasterSource::Impl::getTileSize() const {
return tileSize;
@@ -25,5 +19,10 @@ optional<std::string> RasterSource::Impl::getAttribution() const {
return tileset->attribution;
}
+const SourceTypeInfo* RasterSource::Impl::staticTypeInfo() noexcept {
+ const static SourceTypeInfo typeInfo{"raster", true, TileKind::Raster};
+ return &typeInfo;
+}
+
} // namespace style
} // namespace mbgl
diff --git a/src/mbgl/style/sources/raster_source_impl.hpp b/src/mbgl/style/sources/raster_source_impl.hpp
index bb58455140..716d044f6f 100644
--- a/src/mbgl/style/sources/raster_source_impl.hpp
+++ b/src/mbgl/style/sources/raster_source_impl.hpp
@@ -1,22 +1,24 @@
#pragma once
-#include <mbgl/style/sources/raster_source.hpp>
#include <mbgl/style/source_impl.hpp>
+#include <mbgl/style/sources/raster_source.hpp>
namespace mbgl {
namespace style {
class RasterSource::Impl : public Source::Impl {
public:
- Impl(SourceType sourceType, std::string id, uint16_t tileSize);
+ Impl(std::string id, uint16_t tileSize);
Impl(const Impl&, Tileset);
- uint16_t getTileSize() const;
+ uint16_t getTileSize() const override;
optional<std::string> getAttribution() const final;
const optional<Tileset> tileset;
+ DECLARE_SOURCE_TYPE_INFO;
+
private:
uint16_t tileSize;
};
diff --git a/src/mbgl/style/sources/vector_source.cpp b/src/mbgl/style/sources/vector_source.cpp
index b482449fbf..c08be53e6f 100644
--- a/src/mbgl/style/sources/vector_source.cpp
+++ b/src/mbgl/style/sources/vector_source.cpp
@@ -10,11 +10,14 @@
#include <mbgl/util/constants.hpp>
#include <mbgl/util/exception.hpp>
#include <mbgl/util/mapbox.hpp>
+#include <mbgl/util/util.hpp>
namespace mbgl {
namespace style {
-VectorSource::VectorSource(std::string id, variant<std::string, Tileset> urlOrTileset_, optional<float> maxZoom_,
+VectorSource::VectorSource(std::string id,
+ variant<std::string, Tileset> urlOrTileset_,
+ optional<float> maxZoom_,
optional<float> minZoom_)
: Source(makeMutable<Impl>(std::move(id))),
urlOrTileset(std::move(urlOrTileset_)),
@@ -27,8 +30,8 @@ const VectorSource::Impl& VectorSource::impl() const {
return static_cast<const Impl&>(*baseImpl);
}
-const variant<std::string, Tileset>& VectorSource::getURLOrTileset() const {
- return urlOrTileset;
+const variant<std::string, Tileset>* VectorSource::getURLOrTileset() const {
+ return &urlOrTileset;
}
optional<std::string> VectorSource::getURL() const {
@@ -72,7 +75,7 @@ void VectorSource::loadDescription(FileSource& fileSource) {
if (minZoom) {
tileset->zoomRange.min = *minZoom;
}
- util::mapbox::canonicalizeTileset(*tileset, url, getType(), util::tileSize);
+ util::mapbox::canonicalizeTileset(*tileset, url, *this);
bool changed = impl().tileset != *tileset;
baseImpl = makeMutable<Impl>(impl(), *tileset);
@@ -88,12 +91,18 @@ void VectorSource::loadDescription(FileSource& fileSource) {
}
bool VectorSource::supportsLayerType(const mbgl::style::LayerTypeInfo* info) const {
- return mbgl::underlying_type(Tile::Kind::Geometry) == mbgl::underlying_type(info->tileKind);
+ return mbgl::underlying_type(TileKind::Geometry) == mbgl::underlying_type(info->tileKind);
}
Mutable<Source::Impl> VectorSource::createMutable() const noexcept {
return staticMutableCast<Source::Impl>(makeMutable<Impl>(impl()));
}
+Value VectorSource::serialize() const {
+ auto result = Source::serialize();
+ serializeUrlOrTileSet(result, getURLOrTileset());
+ return result;
+}
+
} // namespace style
} // namespace mbgl
diff --git a/src/mbgl/style/sources/vector_source_impl.cpp b/src/mbgl/style/sources/vector_source_impl.cpp
index 8f85a41ddb..172673be8a 100644
--- a/src/mbgl/style/sources/vector_source_impl.cpp
+++ b/src/mbgl/style/sources/vector_source_impl.cpp
@@ -3,14 +3,9 @@
namespace mbgl {
namespace style {
-VectorSource::Impl::Impl(std::string id_)
- : Source::Impl(SourceType::Vector, std::move(id_)) {
-}
+VectorSource::Impl::Impl(std::string id_) : Source::Impl(std::move(id_)) {}
-VectorSource::Impl::Impl(const Impl& other, Tileset tileset_)
- : Source::Impl(other),
- tileset(std::move(tileset_)) {
-}
+VectorSource::Impl::Impl(const Impl& other, Tileset tileset_) : Source::Impl(other), tileset(std::move(tileset_)) {}
optional<std::string> VectorSource::Impl::getAttribution() const {
if (!tileset) {
@@ -19,5 +14,10 @@ optional<std::string> VectorSource::Impl::getAttribution() const {
return tileset->attribution;
}
+const SourceTypeInfo* VectorSource::Impl::staticTypeInfo() noexcept {
+ const static SourceTypeInfo typeInfo{"vector", true, TileKind::Geometry};
+ return &typeInfo;
+}
+
} // namespace style
} // namespace mbgl
diff --git a/src/mbgl/style/sources/vector_source_impl.hpp b/src/mbgl/style/sources/vector_source_impl.hpp
index 4526fbe356..c616fb30a6 100644
--- a/src/mbgl/style/sources/vector_source_impl.hpp
+++ b/src/mbgl/style/sources/vector_source_impl.hpp
@@ -1,7 +1,7 @@
#pragma once
-#include <mbgl/style/sources/vector_source.hpp>
#include <mbgl/style/source_impl.hpp>
+#include <mbgl/style/sources/vector_source.hpp>
namespace mbgl {
namespace style {
@@ -14,6 +14,8 @@ public:
optional<std::string> getAttribution() const final;
const optional<Tileset> tileset;
+
+ DECLARE_SOURCE_TYPE_INFO;
};
} // namespace style
diff --git a/src/mbgl/style/types.cpp b/src/mbgl/style/types.cpp
index c4a7b76b66..dda72e11fe 100644
--- a/src/mbgl/style/types.cpp
+++ b/src/mbgl/style/types.cpp
@@ -5,118 +5,114 @@ namespace mbgl {
using namespace style;
-MBGL_DEFINE_ENUM(SourceType, {
- { SourceType::Vector, "vector" },
- { SourceType::Raster, "raster" },
- { SourceType::GeoJSON, "geojson" },
- { SourceType::Video, "video" },
- { SourceType::Annotations, "annotations" },
- { SourceType::Image, "image" },
- { SourceType::CustomVector, "customvector" }
-});
-
-MBGL_DEFINE_ENUM(VisibilityType, {
- { VisibilityType::Visible, "visible" },
- { VisibilityType::None, "none" },
-});
-
-MBGL_DEFINE_ENUM(TranslateAnchorType, {
- { TranslateAnchorType::Map, "map" },
- { TranslateAnchorType::Viewport, "viewport" },
-});
-
-MBGL_DEFINE_ENUM(RasterResamplingType, {
- { RasterResamplingType::Linear, "linear" },
- { RasterResamplingType::Nearest, "nearest" },
-});
-
-MBGL_DEFINE_ENUM(HillshadeIlluminationAnchorType, {
- { HillshadeIlluminationAnchorType::Map, "map" },
- { HillshadeIlluminationAnchorType::Viewport, "viewport" },
-});
-
-MBGL_DEFINE_ENUM(RotateAnchorType, {
- { RotateAnchorType::Map, "map" },
- { RotateAnchorType::Viewport, "viewport" },
-});
-
-MBGL_DEFINE_ENUM(CirclePitchScaleType, {
- { CirclePitchScaleType::Map, "map" },
- { CirclePitchScaleType::Viewport, "viewport" },
-});
-
-MBGL_DEFINE_ENUM(LineCapType, {
- { LineCapType::Round, "round" },
- { LineCapType::Butt, "butt" },
- { LineCapType::Square, "square" },
-});
-
-MBGL_DEFINE_ENUM(LineJoinType, {
- { LineJoinType::Miter, "miter" },
- { LineJoinType::Bevel, "bevel" },
- { LineJoinType::Round, "round" },
- { LineJoinType::FakeRound, "fakeround" },
- { LineJoinType::FlipBevel, "flipbevel" },
-});
-
-MBGL_DEFINE_ENUM(SymbolPlacementType, {
- { SymbolPlacementType::Point, "point" },
- { SymbolPlacementType::Line, "line" },
- { SymbolPlacementType::LineCenter, "line-center" },
-});
-
-MBGL_DEFINE_ENUM(SymbolAnchorType, {
- { SymbolAnchorType::Center, "center" },
- { SymbolAnchorType::Left, "left" },
- { SymbolAnchorType::Right, "right" },
- { SymbolAnchorType::Top, "top" },
- { SymbolAnchorType::Bottom, "bottom" },
- { SymbolAnchorType::TopLeft, "top-left" },
- { SymbolAnchorType::TopRight, "top-right" },
- { SymbolAnchorType::BottomLeft, "bottom-left" },
- { SymbolAnchorType::BottomRight, "bottom-right" }
-});
-
-MBGL_DEFINE_ENUM(SymbolZOrderType, {
- { SymbolZOrderType::Auto, "auto" },
- { SymbolZOrderType::ViewportY, "viewport-y" },
- { SymbolZOrderType::Source, "source" }
-});
-
-MBGL_DEFINE_ENUM(TextJustifyType, {
- { TextJustifyType::Auto, "auto" },
- { TextJustifyType::Center, "center" },
- { TextJustifyType::Left, "left" },
- { TextJustifyType::Right, "right" },
-});
-
-MBGL_DEFINE_ENUM(TextTransformType, {
- { TextTransformType::None, "none" },
- { TextTransformType::Uppercase, "uppercase" },
- { TextTransformType::Lowercase, "lowercase" },
-});
-
-MBGL_DEFINE_ENUM(TextWritingModeType, {
- { TextWritingModeType::Horizontal, "horizontal" },
- { TextWritingModeType::Vertical, "vertical" }
-});
-
-MBGL_DEFINE_ENUM(AlignmentType, {
- { AlignmentType::Map, "map" },
- { AlignmentType::Viewport, "viewport" },
- { AlignmentType::Auto, "auto" },
-});
-
-MBGL_DEFINE_ENUM(IconTextFitType, {
- { IconTextFitType::None, "none" },
- { IconTextFitType::Both, "both" },
- { IconTextFitType::Width, "width" },
- { IconTextFitType::Height, "height" },
-});
-
-MBGL_DEFINE_ENUM(LightAnchorType, {
- { LightAnchorType::Map, "map" },
- { LightAnchorType::Viewport, "viewport" }
-});
+MBGL_DEFINE_ENUM(VisibilityType,
+ {
+ {VisibilityType::Visible, "visible"},
+ {VisibilityType::None, "none"},
+ });
+
+MBGL_DEFINE_ENUM(TranslateAnchorType,
+ {
+ {TranslateAnchorType::Map, "map"},
+ {TranslateAnchorType::Viewport, "viewport"},
+ });
+
+MBGL_DEFINE_ENUM(RasterResamplingType,
+ {
+ {RasterResamplingType::Linear, "linear"},
+ {RasterResamplingType::Nearest, "nearest"},
+ });
+
+MBGL_DEFINE_ENUM(HillshadeIlluminationAnchorType,
+ {
+ {HillshadeIlluminationAnchorType::Map, "map"},
+ {HillshadeIlluminationAnchorType::Viewport, "viewport"},
+ });
+
+MBGL_DEFINE_ENUM(RotateAnchorType,
+ {
+ {RotateAnchorType::Map, "map"},
+ {RotateAnchorType::Viewport, "viewport"},
+ });
+
+MBGL_DEFINE_ENUM(CirclePitchScaleType,
+ {
+ {CirclePitchScaleType::Map, "map"},
+ {CirclePitchScaleType::Viewport, "viewport"},
+ });
+
+MBGL_DEFINE_ENUM(LineCapType,
+ {
+ {LineCapType::Round, "round"},
+ {LineCapType::Butt, "butt"},
+ {LineCapType::Square, "square"},
+ });
+
+MBGL_DEFINE_ENUM(LineJoinType,
+ {
+ {LineJoinType::Miter, "miter"},
+ {LineJoinType::Bevel, "bevel"},
+ {LineJoinType::Round, "round"},
+ {LineJoinType::FakeRound, "fakeround"},
+ {LineJoinType::FlipBevel, "flipbevel"},
+ });
+
+MBGL_DEFINE_ENUM(SymbolPlacementType,
+ {
+ {SymbolPlacementType::Point, "point"},
+ {SymbolPlacementType::Line, "line"},
+ {SymbolPlacementType::LineCenter, "line-center"},
+ });
+
+MBGL_DEFINE_ENUM(SymbolAnchorType,
+ {{SymbolAnchorType::Center, "center"},
+ {SymbolAnchorType::Left, "left"},
+ {SymbolAnchorType::Right, "right"},
+ {SymbolAnchorType::Top, "top"},
+ {SymbolAnchorType::Bottom, "bottom"},
+ {SymbolAnchorType::TopLeft, "top-left"},
+ {SymbolAnchorType::TopRight, "top-right"},
+ {SymbolAnchorType::BottomLeft, "bottom-left"},
+ {SymbolAnchorType::BottomRight, "bottom-right"}});
+
+MBGL_DEFINE_ENUM(SymbolZOrderType,
+ {{SymbolZOrderType::Auto, "auto"},
+ {SymbolZOrderType::ViewportY, "viewport-y"},
+ {SymbolZOrderType::Source, "source"}});
+
+MBGL_DEFINE_ENUM(TextJustifyType,
+ {
+ {TextJustifyType::Auto, "auto"},
+ {TextJustifyType::Center, "center"},
+ {TextJustifyType::Left, "left"},
+ {TextJustifyType::Right, "right"},
+ });
+
+MBGL_DEFINE_ENUM(TextTransformType,
+ {
+ {TextTransformType::None, "none"},
+ {TextTransformType::Uppercase, "uppercase"},
+ {TextTransformType::Lowercase, "lowercase"},
+ });
+
+MBGL_DEFINE_ENUM(TextWritingModeType,
+ {{TextWritingModeType::Horizontal, "horizontal"}, {TextWritingModeType::Vertical, "vertical"}});
+
+MBGL_DEFINE_ENUM(AlignmentType,
+ {
+ {AlignmentType::Map, "map"},
+ {AlignmentType::Viewport, "viewport"},
+ {AlignmentType::Auto, "auto"},
+ });
+
+MBGL_DEFINE_ENUM(IconTextFitType,
+ {
+ {IconTextFitType::None, "none"},
+ {IconTextFitType::Both, "both"},
+ {IconTextFitType::Width, "width"},
+ {IconTextFitType::Height, "height"},
+ });
+
+MBGL_DEFINE_ENUM(LightAnchorType, {{LightAnchorType::Map, "map"}, {LightAnchorType::Viewport, "viewport"}});
} // namespace mbgl
diff --git a/src/mbgl/tile/geometry_tile.cpp b/src/mbgl/tile/geometry_tile.cpp
index ee08121693..a33863352a 100644
--- a/src/mbgl/tile/geometry_tile.cpp
+++ b/src/mbgl/tile/geometry_tile.cpp
@@ -140,10 +140,8 @@ const LayerRenderData* GeometryTileRenderData::getLayerRenderData(const style::L
that could flag the tile as non-pending too early.
*/
-GeometryTile::GeometryTile(const OverscaledTileID& id_,
- std::string sourceID_,
- const TileParameters& parameters)
- : Tile(Kind::Geometry, id_),
+GeometryTile::GeometryTile(const OverscaledTileID& id_, std::string sourceID_, const TileParameters& parameters)
+ : Tile(TileKind::Geometry, id_),
ImageRequestor(parameters.imageManager),
sourceID(std::move(sourceID_)),
mailbox(std::make_shared<Mailbox>(*Scheduler::GetCurrent())),
@@ -159,8 +157,7 @@ GeometryTile::GeometryTile(const OverscaledTileID& id_,
glyphManager(parameters.glyphManager),
imageManager(parameters.imageManager),
mode(parameters.mode),
- showCollisionBoxes(parameters.debugOptions & MapDebugOptions::Collision) {
-}
+ showCollisionBoxes(parameters.debugOptions & MapDebugOptions::Collision) {}
GeometryTile::~GeometryTile() {
glyphManager.removeRequestor(*this);
diff --git a/src/mbgl/tile/raster_dem_tile.cpp b/src/mbgl/tile/raster_dem_tile.cpp
index bdd890bbbf..b3443dac34 100644
--- a/src/mbgl/tile/raster_dem_tile.cpp
+++ b/src/mbgl/tile/raster_dem_tile.cpp
@@ -14,15 +14,11 @@
namespace mbgl {
-RasterDEMTile::RasterDEMTile(const OverscaledTileID& id_,
- const TileParameters& parameters,
- const Tileset& tileset)
- : Tile(Kind::RasterDEM, id_),
+RasterDEMTile::RasterDEMTile(const OverscaledTileID& id_, const TileParameters& parameters, const Tileset& tileset)
+ : Tile(TileKind::RasterDEM, id_),
loader(*this, id_, parameters, tileset),
mailbox(std::make_shared<Mailbox>(*Scheduler::GetCurrent())),
- worker(Scheduler::GetBackground(),
- ActorRef<RasterDEMTile>(*this, mailbox)) {
-
+ worker(Scheduler::GetBackground(), ActorRef<RasterDEMTile>(*this, mailbox)) {
encoding = tileset.encoding;
if ( id.canonical.y == 0 ){
// this tile doesn't have upper neighboring tiles so marked those as backfilled
diff --git a/src/mbgl/tile/raster_tile.cpp b/src/mbgl/tile/raster_tile.cpp
index 2ba1dfcc07..6cc8046d4c 100644
--- a/src/mbgl/tile/raster_tile.cpp
+++ b/src/mbgl/tile/raster_tile.cpp
@@ -14,15 +14,11 @@
namespace mbgl {
-RasterTile::RasterTile(const OverscaledTileID& id_,
- const TileParameters& parameters,
- const Tileset& tileset)
- : Tile(Kind::Raster, id_),
+RasterTile::RasterTile(const OverscaledTileID& id_, const TileParameters& parameters, const Tileset& tileset)
+ : Tile(TileKind::Raster, id_),
loader(*this, id_, parameters, tileset),
mailbox(std::make_shared<Mailbox>(*Scheduler::GetCurrent())),
- worker(Scheduler::GetBackground(),
- ActorRef<RasterTile>(*this, mailbox)) {
-}
+ worker(Scheduler::GetBackground(), ActorRef<RasterTile>(*this, mailbox)) {}
RasterTile::~RasterTile() = default;
diff --git a/src/mbgl/tile/tile.cpp b/src/mbgl/tile/tile.cpp
index 441f0424aa..ea397318f6 100644
--- a/src/mbgl/tile/tile.cpp
+++ b/src/mbgl/tile/tile.cpp
@@ -8,7 +8,7 @@ namespace mbgl {
static TileObserver nullObserver;
-Tile::Tile(Kind kind_, OverscaledTileID id_) : kind(kind_), id(id_), observer(&nullObserver) {}
+Tile::Tile(TileKind kind_, OverscaledTileID id_) : kind(kind_), id(id_), observer(&nullObserver) {}
Tile::~Tile() = default;
@@ -27,12 +27,20 @@ void Tile::setTriedCache() {
void Tile::dumpDebugLogs() const {
std::string kindString;
switch (kind) {
- case Kind::Geometry: kindString = "Geometry"; break;
- case Kind::Raster: kindString = "Raster"; break;
- case Kind::RasterDEM: kindString = "RasterDEM"; break;
- default: kindString = "Unknown"; break;
+ case TileKind::Geometry:
+ kindString = "Geometry";
+ break;
+ case TileKind::Raster:
+ kindString = "Raster";
+ break;
+ case TileKind::RasterDEM:
+ kindString = "RasterDEM";
+ break;
+ default:
+ kindString = "Unknown";
+ break;
}
- Log::Info(Event::General, "Tile::Kind: %s", kindString.c_str());
+ Log::Info(Event::General, "TileKind: %s", kindString.c_str());
Log::Info(Event::General, "Tile::id: %s", util::toString(id).c_str());
Log::Info(Event::General, "Tile::renderable: %s", isRenderable() ? "yes" : "no");
Log::Info(Event::General, "Tile::complete: %s", isComplete() ? "yes" : "no");
diff --git a/src/mbgl/tile/tile.hpp b/src/mbgl/tile/tile.hpp
index 573b3a1c50..ded23263a1 100644
--- a/src/mbgl/tile/tile.hpp
+++ b/src/mbgl/tile/tile.hpp
@@ -1,17 +1,18 @@
#pragma once
-#include <mbgl/util/noncopyable.hpp>
-#include <mbgl/util/chrono.hpp>
-#include <mbgl/util/optional.hpp>
-#include <mbgl/util/feature.hpp>
-#include <mbgl/util/tile_coordinate.hpp>
-#include <mbgl/tile/tile_id.hpp>
-#include <mbgl/tile/tile_necessity.hpp>
-#include <mbgl/renderer/tile_mask.hpp>
#include <mbgl/renderer/bucket.hpp>
-#include <mbgl/tile/geometry_tile_data.hpp>
+#include <mbgl/renderer/tile_mask.hpp>
#include <mbgl/storage/resource.hpp>
#include <mbgl/style/layer_properties.hpp>
+#include <mbgl/tile/geometry_tile_data.hpp>
+#include <mbgl/tile/tile_id.hpp>
+#include <mbgl/tile/tile_kind.hpp>
+#include <mbgl/tile/tile_necessity.hpp>
+#include <mbgl/util/chrono.hpp>
+#include <mbgl/util/feature.hpp>
+#include <mbgl/util/noncopyable.hpp>
+#include <mbgl/util/optional.hpp>
+#include <mbgl/util/tile_coordinate.hpp>
#include <string>
#include <memory>
@@ -48,15 +49,10 @@ inline bool operator!=(const TileUpdateParameters& a, const TileUpdateParameters
}
class Tile {
public:
- enum class Kind : uint8_t {
- Geometry,
- Raster,
- RasterDEM
- };
Tile(const Tile&) = delete;
Tile& operator=(const Tile&) = delete;
- Tile(Kind, OverscaledTileID);
+ Tile(TileKind, OverscaledTileID);
virtual ~Tile();
virtual std::unique_ptr<TileRenderData> createRenderData() = 0;
@@ -74,7 +70,7 @@ public:
//
// Tile implementation should update the contained layer
// render data with the given properties.
- //
+ //
// Returns `true` if the corresponding render layer data is present in this tile (and i.e. it
// was succesfully updated); returns `false` otherwise.
virtual bool layerPropertiesUpdated(const Immutable<style::LayerProperties>& layerProperties) = 0;
@@ -124,7 +120,7 @@ public:
bool isComplete() const {
return loaded && !pending;
}
-
+
// "holdForFade" is used to keep tiles in the render tree after they're no longer
// ideal tiles in order to allow symbols to fade out
virtual bool holdForFade() const {
@@ -143,7 +139,7 @@ public:
void dumpDebugLogs() const;
- const Kind kind;
+ const TileKind kind;
OverscaledTileID id;
optional<Timestamp> modified;
optional<Timestamp> expires;
diff --git a/src/mbgl/util/mapbox.cpp b/src/mbgl/util/mapbox.cpp
index 6c36c152cd..ff24680296 100644
--- a/src/mbgl/util/mapbox.cpp
+++ b/src/mbgl/util/mapbox.cpp
@@ -1,8 +1,9 @@
-#include <mbgl/util/mapbox.hpp>
+#include <mbgl/style/source.hpp>
#include <mbgl/util/constants.hpp>
#include <mbgl/util/logging.hpp>
-#include <mbgl/util/url.hpp>
+#include <mbgl/util/mapbox.hpp>
#include <mbgl/util/tileset.hpp>
+#include <mbgl/util/url.hpp>
#include <stdexcept>
#include <vector>
@@ -112,8 +113,7 @@ std::string normalizeTileURL(const std::string& baseURL,
return transformURL(tpl, str, url);
}
-std::string
-canonicalizeTileURL(const std::string& str, const style::SourceType type, const uint16_t tileSize) {
+std::string canonicalizeTileURL(const std::string& str, const style::Source& source) {
const char* version = "/v4/";
const size_t versionLen = strlen(version);
@@ -132,8 +132,8 @@ canonicalizeTileURL(const std::string& str, const style::SourceType type, const
std::string result = "mapbox://tiles/";
result.append(str, path.directory.first + versionLen, path.directory.second - versionLen);
result.append(str, path.filename.first, path.filename.second);
- if (type == style::SourceType::Raster || type == style::SourceType::RasterDEM) {
- result += tileSize == util::tileSize ? "@2x" : "{ratio}";
+ if (source.getTypeInfo()->tileKind == TileKind::Raster) {
+ result += source.getTileSize() == util::tileSize ? "@2x" : "{ratio}";
}
result.append(str, path.extension.first, path.extension.second);
@@ -158,11 +158,11 @@ canonicalizeTileURL(const std::string& str, const style::SourceType type, const
return result;
}
-void canonicalizeTileset(Tileset& tileset, const std::string& sourceURL, style::SourceType type, uint16_t tileSize) {
+void canonicalizeTileset(Tileset& tileset, const std::string& sourceURL, const style::Source& source) {
// TODO: Remove this hack by delivering proper URLs in the TileJSON to begin with.
if (isMapboxURL(sourceURL)) {
for (auto& url : tileset.tiles) {
- url = canonicalizeTileURL(url, type, tileSize);
+ url = canonicalizeTileURL(url, source);
}
}
}
diff --git a/src/mbgl/util/mapbox.hpp b/src/mbgl/util/mapbox.hpp
index 815b338cab..1bedb17014 100644
--- a/src/mbgl/util/mapbox.hpp
+++ b/src/mbgl/util/mapbox.hpp
@@ -1,12 +1,16 @@
#pragma once
-#include <string>
#include <mbgl/style/types.hpp>
+#include <string>
namespace mbgl {
class Tileset;
+namespace style {
+class Source;
+}
+
namespace util {
namespace mapbox {
@@ -19,10 +23,10 @@ std::string normalizeGlyphsURL(const std::string& baseURL, const std::string& st
std::string normalizeTileURL(const std::string& baseURL, const std::string& str, const std::string& accessToken);
// Return a "mapbox://tiles/..." URL (suitable for normalizeTileURL) for the given Mapbox tile URL.
-std::string canonicalizeTileURL(const std::string& str, style::SourceType, uint16_t tileSize);
+std::string canonicalizeTileURL(const std::string& str, const style::Source&);
// Replace URL templates with "mapbox://tiles/..." URLs (suitable for normalizeTileURL).
-void canonicalizeTileset(Tileset&, const std::string& url, style::SourceType, uint16_t tileSize);
+void canonicalizeTileset(Tileset&, const std::string& url, const style::Source&);
extern const uint64_t DEFAULT_OFFLINE_TILE_COUNT_LIMIT;
diff --git a/src/mbgl/util/tile_cover.cpp b/src/mbgl/util/tile_cover.cpp
index fb4579b9ab..56a1ae7f69 100644
--- a/src/mbgl/util/tile_cover.cpp
+++ b/src/mbgl/util/tile_cover.cpp
@@ -138,15 +138,6 @@ std::vector<UnwrappedTileID> tileCover(const Point<double>& tl,
} // namespace
-int32_t coveringZoomLevel(double zoom, style::SourceType type, uint16_t size) {
- zoom += util::log2(util::tileSize / size);
- if (type == style::SourceType::Raster || type == style::SourceType::Video) {
- return ::round(zoom);
- } else {
- return std::floor(zoom);
- }
-}
-
std::vector<OverscaledTileID> tileCover(const TransformState& state, uint8_t z, const optional<uint8_t>& overscaledZ) {
struct Node {
AABB aabb;
diff --git a/src/mbgl/util/tile_cover.hpp b/src/mbgl/util/tile_cover.hpp
index 5e09d8a671..c5d0bd40c5 100644
--- a/src/mbgl/util/tile_cover.hpp
+++ b/src/mbgl/util/tile_cover.hpp
@@ -31,8 +31,6 @@ private:
std::unique_ptr<Impl> impl;
};
-int32_t coveringZoomLevel(double z, style::SourceType type, uint16_t tileSize);
-
std::vector<OverscaledTileID> tileCover(const TransformState&,
uint8_t z,
const optional<uint8_t>& overscaledZ = nullopt);