[core] Use TilePoint in Source::Impl::queryRenderedFeatures
This commit is contained in:
@@ -181,18 +181,6 @@ void Source::Impl::reloadTiles() {
|
||||
}
|
||||
}
|
||||
|
||||
static Point<int16_t> coordinateToTilePoint(const UnwrappedTileID& tileID, const Point<double>& p) {
|
||||
auto zoomedCoord = TileCoordinate { p, 0 }.zoomTo(tileID.canonical.z);
|
||||
return {
|
||||
int16_t(util::clamp<int64_t>((zoomedCoord.p.x - tileID.canonical.x - tileID.wrap * std::pow(2, tileID.canonical.z)) * util::EXTENT,
|
||||
std::numeric_limits<int16_t>::min(),
|
||||
std::numeric_limits<int16_t>::max())),
|
||||
int16_t(util::clamp<int64_t>((zoomedCoord.p.y - tileID.canonical.y) * util::EXTENT,
|
||||
std::numeric_limits<int16_t>::min(),
|
||||
std::numeric_limits<int16_t>::max()))
|
||||
};
|
||||
}
|
||||
|
||||
std::unordered_map<std::string, std::vector<Feature>> Source::Impl::queryRenderedFeatures(const QueryParameters& parameters) const {
|
||||
std::unordered_map<std::string, std::vector<Feature>> result;
|
||||
if (renderTiles.empty()) {
|
||||
@@ -215,16 +203,20 @@ std::unordered_map<std::string, std::vector<Feature>> Source::Impl::queryRendere
|
||||
for (const auto& tilePtr : renderTiles) {
|
||||
const RenderTile& tile = tilePtr.second;
|
||||
|
||||
Point<int16_t> tileSpaceBoundsMin = coordinateToTilePoint(tile.id, box.min);
|
||||
Point<int16_t> tileSpaceBoundsMax = coordinateToTilePoint(tile.id, box.max);
|
||||
GeometryCoordinate tileSpaceBoundsMin = TileCoordinate::toGeometryCoordinate(tile.id, box.min);
|
||||
if (tileSpaceBoundsMin.x >= util::EXTENT || tileSpaceBoundsMin.y >= util::EXTENT) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tileSpaceBoundsMin.x >= util::EXTENT || tileSpaceBoundsMin.y >= util::EXTENT ||
|
||||
tileSpaceBoundsMax.x < 0 || tileSpaceBoundsMax.y < 0) continue;
|
||||
GeometryCoordinate tileSpaceBoundsMax = TileCoordinate::toGeometryCoordinate(tile.id, box.max);
|
||||
if (tileSpaceBoundsMax.x < 0 || tileSpaceBoundsMax.y < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
GeometryCoordinates tileSpaceQueryGeometry;
|
||||
|
||||
tileSpaceQueryGeometry.reserve(queryGeometry.size());
|
||||
for (const auto& c : queryGeometry) {
|
||||
tileSpaceQueryGeometry.push_back(coordinateToTilePoint(tile.id, c));
|
||||
tileSpaceQueryGeometry.push_back(TileCoordinate::toGeometryCoordinate(tile.id, c));
|
||||
}
|
||||
|
||||
tile.tile.queryRenderedFeatures(result,
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#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/renderer/bucket.hpp>
|
||||
#include <mbgl/tile/geometry_tile_data.hpp>
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/util/geometry.hpp>
|
||||
#include <mbgl/map/transform_state.hpp>
|
||||
#include <mbgl/math/clamp.hpp>
|
||||
#include <mbgl/tile/geometry_tile_data.hpp>
|
||||
#include <mbgl/tile/tile_id.hpp>
|
||||
#include <mbgl/util/geometry.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
using TileCoordinatePoint = Point<double>;
|
||||
|
||||
// Has floating point x/y coordinates.
|
||||
// Used for computing the tiles that need to be visible in the viewport.
|
||||
class TileCoordinate {
|
||||
public:
|
||||
Point<double> p;
|
||||
TileCoordinatePoint p;
|
||||
double z;
|
||||
|
||||
static TileCoordinate fromLatLng(const TransformState& state, double zoom, const LatLng& latLng) {
|
||||
@@ -17,13 +22,25 @@ public:
|
||||
return { state.project(latLng) * scale / double(util::tileSize), zoom };
|
||||
}
|
||||
|
||||
static TileCoordinate fromScreenCoordinate(const TransformState& state, double zoom, const ScreenCoordinate& point) {
|
||||
return fromLatLng(state, zoom, state.screenCoordinateToLatLng(point));
|
||||
static TileCoordinate fromScreenCoordinate(const TransformState& state, double zoom, const ScreenCoordinate& screenCoordinate) {
|
||||
return fromLatLng(state, zoom, state.screenCoordinateToLatLng(screenCoordinate));
|
||||
}
|
||||
|
||||
TileCoordinate zoomTo(double zoom) const {
|
||||
return { p * std::pow(2, zoom - z), zoom };
|
||||
}
|
||||
|
||||
static GeometryCoordinate toGeometryCoordinate(const UnwrappedTileID& tileID, const TileCoordinatePoint& point) {
|
||||
auto zoomed = TileCoordinate { point, 0 }.zoomTo(tileID.canonical.z);
|
||||
return {
|
||||
int16_t(util::clamp<int64_t>((zoomed.p.x - tileID.canonical.x - tileID.wrap * std::pow(2.0, tileID.canonical.z)) * util::EXTENT,
|
||||
std::numeric_limits<int16_t>::min(),
|
||||
std::numeric_limits<int16_t>::max())),
|
||||
int16_t(util::clamp<int64_t>((zoomed.p.y - tileID.canonical.y) * util::EXTENT,
|
||||
std::numeric_limits<int16_t>::min(),
|
||||
std::numeric_limits<int16_t>::max()))
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
Reference in New Issue
Block a user