diff options
Diffstat (limited to 'src/mbgl/map')
-rw-r--r-- | src/mbgl/map/annotation.cpp | 8 | ||||
-rw-r--r-- | src/mbgl/map/live_tile_data.cpp | 6 | ||||
-rw-r--r-- | src/mbgl/map/live_tile_data.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/map/source.cpp | 28 | ||||
-rw-r--r-- | src/mbgl/map/tile_id.cpp | 46 | ||||
-rw-r--r-- | src/mbgl/map/tile_id.hpp | 12 | ||||
-rw-r--r-- | src/mbgl/map/tile_parser.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/map/transform_state.cpp | 4 | ||||
-rw-r--r-- | src/mbgl/map/transform_state.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/map/vector_tile_data.cpp | 6 | ||||
-rw-r--r-- | src/mbgl/map/vector_tile_data.hpp | 5 |
11 files changed, 73 insertions, 48 deletions
diff --git a/src/mbgl/map/annotation.cpp b/src/mbgl/map/annotation.cpp index 7a7a0ed683..9d21b4e48b 100644 --- a/src/mbgl/map/annotation.cpp +++ b/src/mbgl/map/annotation.cpp @@ -125,7 +125,7 @@ AnnotationManager::addPointAnnotations(const std::vector<LatLng>& points, uint32_t y = p.y * z2; for (int8_t z = maxZoom; z >= 0; z--) { - affectedTiles.emplace_back(z, x, y); + affectedTiles.emplace_back(z, x, y, z); TileID tileID = affectedTiles.back(); // calculate tile coordinate @@ -214,7 +214,7 @@ std::vector<TileID> AnnotationManager::removeAnnotations(const AnnotationIDs& id p = projectPoint(latLng); x = z2s[z] * p.x; y = z2s[z] * p.y; - TileID tid(z, x, y); + TileID tid(z, x, y, z); // erase annotation from tile's list auto& tileAnnotations = tiles[tid].first; tileAnnotations.erase(annotationID); @@ -245,8 +245,8 @@ std::vector<uint32_t> AnnotationManager::getAnnotationsInBounds(const LatLngBoun const vec2<double> nePoint = projectPoint(queryBounds.ne); // tiles number y from top down - const TileID nwTile(z, swPoint.x * z2, nePoint.y * z2); - const TileID seTile(z, nePoint.x * z2, swPoint.y * z2); + const TileID nwTile(z, swPoint.x * z2, nePoint.y * z2, z); + const TileID seTile(z, nePoint.x * z2, swPoint.y * z2, z); std::vector<uint32_t> matchingAnnotations; diff --git a/src/mbgl/map/live_tile_data.cpp b/src/mbgl/map/live_tile_data.cpp index d63ea43470..f2b5e0427d 100644 --- a/src/mbgl/map/live_tile_data.cpp +++ b/src/mbgl/map/live_tile_data.cpp @@ -10,17 +10,17 @@ using namespace mbgl; LiveTileData::LiveTileData(const TileID& id_, AnnotationManager& annotationManager_, - float mapMaxZoom, Style& style_, GlyphAtlas& glyphAtlas_, GlyphStore& glyphStore_, SpriteAtlas& spriteAtlas_, util::ptr<Sprite> sprite_, const SourceInfo& source_, + float overscaling_, float angle_, bool collisionDebug_) - : VectorTileData::VectorTileData(id_, mapMaxZoom, style_, glyphAtlas_, glyphStore_, - spriteAtlas_, sprite_, source_, angle_, collisionDebug_), + : VectorTileData::VectorTileData(id_, style_, glyphAtlas_, glyphStore_, + spriteAtlas_, sprite_, source_, overscaling_, angle_, collisionDebug_), annotationManager(annotationManager_) { // live features are always ready setState(State::loaded); diff --git a/src/mbgl/map/live_tile_data.hpp b/src/mbgl/map/live_tile_data.hpp index 0247c47fa7..7066fe13c9 100644 --- a/src/mbgl/map/live_tile_data.hpp +++ b/src/mbgl/map/live_tile_data.hpp @@ -11,7 +11,6 @@ class LiveTileData : public VectorTileData { public: LiveTileData(const TileID&, AnnotationManager&, - float mapMaxZoom, Style&, GlyphAtlas&, GlyphStore&, @@ -19,6 +18,7 @@ public: util::ptr<Sprite>, const SourceInfo&, float, + float, bool); ~LiveTileData(); diff --git a/src/mbgl/map/source.cpp b/src/mbgl/map/source.cpp index 3d7ab6fd32..331e48436f 100644 --- a/src/mbgl/map/source.cpp +++ b/src/mbgl/map/source.cpp @@ -99,7 +99,7 @@ std::string SourceInfo::tileURL(const TileID& id, float pixelRatio) const { std::string result = tiles.at((id.x + id.y) % tiles.size()); result = util::mapbox::normalizeTileURL(result, url, type); result = util::replaceTokens(result, [&](const std::string &token) -> std::string { - if (token == "z") return util::toString(id.z); + if (token == "z") return util::toString(std::min(id.z, static_cast<int8_t>(max_zoom))); if (token == "x") return util::toString(id.x); if (token == "y") return util::toString(id.y); if (token == "prefix") { @@ -172,7 +172,7 @@ void Source::load(const std::string& accessToken) { void Source::updateMatrices(const mat4 &projMatrix, const TransformState &transform) { for (const auto& pair : tiles) { Tile &tile = *pair.second; - transform.matrixFor(tile.matrix, tile.id); + transform.matrixFor(tile.matrix, tile.id, std::min(static_cast<int8_t>(info.max_zoom), tile.id.z)); matrix::multiply(tile.matrix, projMatrix, tile.matrix); } } @@ -260,7 +260,8 @@ TileData::State Source::addTile(MapData& data, return state; } - auto pos = tiles.emplace(id, util::make_unique<Tile>(id)); + const float overscaling = id.z > info.max_zoom ? std::pow(2.0f, id.z - info.max_zoom) : 1.0f; + auto pos = tiles.emplace(id, util::make_unique<Tile>(id));//, util::tileSize * overscaling)); Tile& new_tile = *pos.first->second; // We couldn't find the tile in the list. Create a new one. @@ -287,16 +288,18 @@ TileData::State Source::addTile(MapData& data, // If we don't find working tile data, we're just going to load it. if (info.type == SourceType::Vector) { new_tile.data = - std::make_shared<VectorTileData>(normalized_id, data.transform.getMaxZoom(), style, glyphAtlas, - glyphStore, spriteAtlas, sprite, info, transformState.getAngle(), data.getCollisionDebug()); + std::make_shared<VectorTileData>(normalized_id, style, glyphAtlas, + glyphStore, spriteAtlas, sprite, info, + overscaling, transformState.getAngle(), data.getCollisionDebug()); new_tile.data->request(style.workers, transformState.getPixelRatio(), callback); } else if (info.type == SourceType::Raster) { new_tile.data = std::make_shared<RasterTileData>(normalized_id, texturePool, info); new_tile.data->request(style.workers, transformState.getPixelRatio(), callback); } else if (info.type == SourceType::Annotations) { new_tile.data = std::make_shared<LiveTileData>(normalized_id, data.annotationManager, - data.transform.getMaxZoom(), style, glyphAtlas, - glyphStore, spriteAtlas, sprite, info, transformState.getAngle(), data.getCollisionDebug()); + style, glyphAtlas, + glyphStore, spriteAtlas, sprite, info, + overscaling, transformState.getAngle(), data.getCollisionDebug()); new_tile.data->reparse(style.workers, callback); } else { throw std::runtime_error("source type not implemented"); @@ -319,6 +322,11 @@ int32_t Source::coveringZoomLevel(const TransformState& state) const { std::forward_list<TileID> Source::coveringTiles(const TransformState& state) const { int32_t z = coveringZoomLevel(state); + auto actualZ = z; + const bool reparseOverscaled = + info.type == SourceType::Vector || + info.type == SourceType::Annotations; + if (z < info.min_zoom) return {{}}; if (z > info.max_zoom) z = info.max_zoom; @@ -326,7 +334,7 @@ std::forward_list<TileID> Source::coveringTiles(const TransformState& state) con box points = state.cornersToBox(z); const vec2<double>& center = points.center; - std::forward_list<TileID> covering_tiles = tileCover(z, points); + std::forward_list<TileID> covering_tiles = tileCover(z, points, reparseOverscaled ? actualZ : z); covering_tiles.sort([¢er](const TileID& a, const TileID& b) { // Sorts by distance from the box center @@ -349,7 +357,7 @@ std::forward_list<TileID> Source::coveringTiles(const TransformState& state) con bool Source::findLoadedChildren(const TileID& id, int32_t maxCoveringZoom, std::forward_list<TileID>& retain) { bool complete = true; int32_t z = id.z; - auto ids = id.children(z + 1); + auto ids = id.children(info.max_zoom); for (const auto& child_id : ids) { const TileData::State state = hasTile(child_id); if (TileData::isReadyState(state)) { @@ -376,7 +384,7 @@ bool Source::findLoadedChildren(const TileID& id, int32_t maxCoveringZoom, std:: */ bool Source::findLoadedParent(const TileID& id, int32_t minCoveringZoom, std::forward_list<TileID>& retain) { for (int32_t z = id.z - 1; z >= minCoveringZoom; --z) { - const TileID parent_id = id.parent(z); + const TileID parent_id = id.parent(z, info.max_zoom); const TileData::State state = hasTile(parent_id); if (TileData::isReadyState(state)) { retain.emplace_front(parent_id); diff --git a/src/mbgl/map/tile_id.cpp b/src/mbgl/map/tile_id.cpp index 518ee14c42..ad7ec2e0f6 100644 --- a/src/mbgl/map/tile_id.cpp +++ b/src/mbgl/map/tile_id.cpp @@ -5,35 +5,49 @@ namespace mbgl { -TileID TileID::parent(int8_t parent_z) const { +TileID TileID::parent(int8_t parent_z, int8_t sourceMaxZoom) const { assert(parent_z < z); - int32_t dim = std::pow(2, z - parent_z); - return TileID{ - parent_z, - (x >= 0 ? x : x - dim + 1) / dim, - y / dim - }; + auto newX = x; + auto newY = y; + for (auto newZ = z; newZ > parent_z; newZ--) { + if (newZ > sourceMaxZoom) { + // the id represents an overscaled tile, return the same coordinates with a lower z + // do nothing + } else { + newX = newX / 2; + newY = newY / 2; + } + } + + return TileID{parent_z, newX, newY, parent_z > sourceMaxZoom ? sourceMaxZoom : parent_z}; } -std::forward_list<TileID> TileID::children(int32_t child_z) const { - assert(child_z > z); - int32_t factor = std::pow(2, child_z - z); +std::forward_list<TileID> TileID::children(int8_t sourceMaxZoom) const { + auto childZ = z + 1; std::forward_list<TileID> child_ids; - for (int32_t ty = y * factor, y_max = (y + 1) * factor; ty < y_max; ++ty) { - for (int32_t tx = x * factor, x_max = (x + 1) * factor; tx < x_max; ++tx) { - child_ids.emplace_front(child_z, tx, ty); - } + if (z >= sourceMaxZoom) { + // return a single tile id representing a an overscaled tile + child_ids.emplace_front(childZ, x, y, sourceMaxZoom); + + } else { + auto childX = x * 2; + auto childY = y * 2; + child_ids.emplace_front(childZ, childX, childY, childZ); + child_ids.emplace_front(childZ, childX + 1, childY, childZ); + child_ids.emplace_front(childZ, childX, childY + 1, childZ); + child_ids.emplace_front(childZ, childX + 1, childY + 1, childZ); } + return child_ids; } TileID TileID::normalized() const { - int32_t dim = std::pow(2, z); + int32_t dim = std::pow(2, sourceZ); int32_t nx = x, ny = y; while (nx < 0) nx += dim; while (nx >= dim) nx -= dim; - return TileID { z, nx, ny }; + return TileID { z, nx, ny, sourceZ}; } bool TileID::isChildOf(const TileID &parent_id) const { diff --git a/src/mbgl/map/tile_id.hpp b/src/mbgl/map/tile_id.hpp index 056fcdbfa5..f2e2171f1a 100644 --- a/src/mbgl/map/tile_id.hpp +++ b/src/mbgl/map/tile_id.hpp @@ -14,9 +14,12 @@ public: const int16_t w = 0; const int8_t z = 0; const int32_t x = 0, y = 0; + const int8_t sourceZ; + const float overscaling; - inline explicit TileID(int8_t z_, int32_t x_, int32_t y_) - : w((x_ < 0 ? x_ - (1 << z_) + 1 : x_) / (1 << z_)), z(z_), x(x_), y(y_) {} + inline explicit TileID(int8_t z_, int32_t x_, int32_t y_, int8_t sourceZ_) + : w((x_ < 0 ? x_ - (1 << z_) + 1 : x_) / (1 << z_)), z(z_), x(x_), y(y_), + sourceZ(sourceZ_), overscaling(std::pow(2, z_ - sourceZ_)) {} inline uint64_t to_uint64() const { return ((std::pow(2, z) * y + x) * 32) + z; @@ -43,11 +46,12 @@ public: return y < rhs.y; } - TileID parent(int8_t z) const; + TileID parent(int8_t z, int8_t sourceMaxZoom) const; TileID normalized() const; - std::forward_list<TileID> children(int32_t z) const; + std::forward_list<TileID> children(int8_t sourceMaxZoom) const; bool isChildOf(const TileID&) const; operator std::string() const; + }; } diff --git a/src/mbgl/map/tile_parser.cpp b/src/mbgl/map/tile_parser.cpp index a932453136..eb9a7c2e9f 100644 --- a/src/mbgl/map/tile_parser.cpp +++ b/src/mbgl/map/tile_parser.cpp @@ -180,7 +180,7 @@ std::unique_ptr<Bucket> TileParser::createLineBucket(const GeometryTileLayer& la std::unique_ptr<Bucket> TileParser::createSymbolBucket(const GeometryTileLayer& layer, const StyleBucket& bucket_desc) { - auto bucket = util::make_unique<SymbolBucket>(*tile.getCollision()); + auto bucket = util::make_unique<SymbolBucket>(*tile.getCollision(), tile.id.overscaling); const float z = tile.id.z; auto& layout = bucket->layout; diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp index 2a1cc4b9ea..8002a07f2b 100644 --- a/src/mbgl/map/transform_state.cpp +++ b/src/mbgl/map/transform_state.cpp @@ -8,8 +8,8 @@ using namespace mbgl; #pragma mark - Matrix -void TransformState::matrixFor(mat4& matrix, const TileID& id) const { - const double tile_scale = std::pow(2, id.z); +void TransformState::matrixFor(mat4& matrix, const TileID& id, const int8_t z) const { + const double tile_scale = std::pow(2, z); const double tile_size = scale * util::tileSize / tile_scale; matrix::identity(matrix); diff --git a/src/mbgl/map/transform_state.hpp b/src/mbgl/map/transform_state.hpp index e09be8ca63..3e76c7f817 100644 --- a/src/mbgl/map/transform_state.hpp +++ b/src/mbgl/map/transform_state.hpp @@ -20,7 +20,7 @@ class TransformState { public: // Matrix - void matrixFor(mat4& matrix, const TileID& id) const; + void matrixFor(mat4& matrix, const TileID& id, const int8_t z) const; box cornersToBox(uint32_t z) const; // Dimensions diff --git a/src/mbgl/map/vector_tile_data.cpp b/src/mbgl/map/vector_tile_data.cpp index c453d893a8..fb64c224cf 100644 --- a/src/mbgl/map/vector_tile_data.cpp +++ b/src/mbgl/map/vector_tile_data.cpp @@ -15,23 +15,23 @@ using namespace mbgl; VectorTileData::VectorTileData(const TileID& id_, - float mapMaxZoom, Style& style_, GlyphAtlas& glyphAtlas_, GlyphStore& glyphStore_, SpriteAtlas& spriteAtlas_, util::ptr<Sprite> sprite_, const SourceInfo& source_, + float overscaling_, float angle, bool collisionDebug) : TileData(id_, source_), - depth(id_.z >= source_.max_zoom ? mapMaxZoom - id_.z : 1), glyphAtlas(glyphAtlas_), glyphStore(glyphStore_), spriteAtlas(spriteAtlas_), sprite(sprite_), style(style_), - collision(util::make_unique<CollisionTile>(id_.z, 4096, source_.tile_size, angle, collisionDebug)), + overscaling(overscaling_), + collision(util::make_unique<CollisionTile>(id_.z, 4096, source_.tile_size * id.overscaling, angle, collisionDebug)), lastAngle(angle), currentAngle(angle) { } diff --git a/src/mbgl/map/vector_tile_data.hpp b/src/mbgl/map/vector_tile_data.hpp index 95a389c199..bb60668c8b 100644 --- a/src/mbgl/map/vector_tile_data.hpp +++ b/src/mbgl/map/vector_tile_data.hpp @@ -33,7 +33,6 @@ class VectorTileData : public TileData { public: VectorTileData(const TileID&, - float mapMaxZoom, Style&, GlyphAtlas&, GlyphStore&, @@ -41,6 +40,7 @@ public: util::ptr<Sprite>, const SourceInfo&, float, + float, bool); ~VectorTileData(); @@ -57,8 +57,6 @@ public: return collision.get(); } - const float depth; - protected: void redoPlacement(); @@ -85,6 +83,7 @@ private: std::unordered_map<std::string, std::unique_ptr<Bucket>> buckets; mutable std::mutex bucketsMutex; + const float overscaling; std::unique_ptr<CollisionTile> collision; float lastAngle = 0; |