diff --git a/src/mbgl/annotation/point_annotation_impl.hpp b/src/mbgl/annotation/point_annotation_impl.hpp index 2977caf5773..4522f0514a3 100644 --- a/src/mbgl/annotation/point_annotation_impl.hpp +++ b/src/mbgl/annotation/point_annotation_impl.hpp @@ -31,6 +31,7 @@ // Make Boost Geometry aware of our LatLng type BOOST_GEOMETRY_REGISTER_POINT_2D(mbgl::LatLng, double, boost::geometry::cs::cartesian, longitude, latitude) BOOST_GEOMETRY_REGISTER_BOX(mbgl::LatLngBounds, mbgl::LatLng, sw, ne) +// FIXME like Collision/Feature namespace mbgl { diff --git a/src/mbgl/map/tile_worker.cpp b/src/mbgl/map/tile_worker.cpp index 9dc0698db7c..e243d5945f6 100644 --- a/src/mbgl/map/tile_worker.cpp +++ b/src/mbgl/map/tile_worker.cpp @@ -140,6 +140,53 @@ void TileWorker::parseLayer(const StyleLayer& layer, const GeometryTile& geometr // We cannot parse this bucket yet. Instead, we're saving it for later. pending.emplace_back(layer, std::move(bucket)); } else { + + // catalog features for interactivity + // + // if (layer.interactive) { ... + // + // also, we don't get here for raster buckets, since they don't have layers + + if (!partialParse && layer.id.substr(0, 3) == "poi" && bucket->hasData()) { + result.featureTree.clear(); + for (std::size_t i = 0; i < geometryLayer->featureCount(); i++) { + const auto feature = geometryLayer->getFeature(i); + const auto geometries = feature->getGeometries(); + for (std::size_t j = 0; j < geometries.size(); j++) { + FeatureBox featureBox {{ 4096 + 64, 4096 + 64 }, { -64, -64 }}; + const auto geometry = geometries.at(j); + for (std::size_t k = 0; k < geometry.size(); k++) { + const auto point = geometry.at(k); + const auto min = featureBox.min_corner(); + const auto max = featureBox.max_corner(); + if (point.x < min.get<0>()) { + featureBox.min_corner().set<0>(point.x); + } + if (point.y < min.get<1>()) { + featureBox.min_corner().set<1>(point.y); + } + if (point.x > max.get<0>()) { + featureBox.max_corner().set<0>(point.x); + } + if (point.y > max.get<1>()) { + featureBox.max_corner().set<1>(point.y); + } + std::string name = "(unknown)"; + const auto maybe_name = feature->getValue("name_en"); + if (maybe_name.get().is()) { + name = maybe_name.get().get(); + } + name = layer.id + " - " + name; + result.featureTree.insert(std::make_pair(featureBox, layer.id + name)); +// printf("added %s\n", name.c_str()); + } + } + } + if (result.featureTree.size()) { +// printf("feature tree for %i,%i,%i [%s] has %lu members\n", id.z, id.x, id.y, layer.id.c_str(), result.featureTree.size()); + } + } + insertBucket(layer.bucketName(), std::move(bucket)); } } diff --git a/src/mbgl/map/tile_worker.hpp b/src/mbgl/map/tile_worker.hpp index ee94f756ed0..82b7fe96074 100644 --- a/src/mbgl/map/tile_worker.hpp +++ b/src/mbgl/map/tile_worker.hpp @@ -4,6 +4,8 @@ #include #include +#include +#include #include #include #include @@ -14,6 +16,25 @@ #include #include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-function" +#pragma GCC diagnostic ignored "-Wunused-parameter" +#pragma GCC diagnostic ignored "-Wunused-variable" +#pragma GCC diagnostic ignored "-Wshadow" +#ifdef __clang__ +#pragma GCC diagnostic ignored "-Wunknown-pragmas" +#endif +#pragma GCC diagnostic ignored "-Wpragmas" +#pragma GCC diagnostic ignored "-Wdeprecated-register" +#pragma GCC diagnostic ignored "-Wshorten-64-to-32" +#pragma GCC diagnostic ignored "-Wunused-local-typedefs" +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +#include +#include +#include +#include +#pragma GCC diagnostic pop + namespace mbgl { class CollisionTile; @@ -22,12 +43,21 @@ class Style; class Bucket; class StyleLayer; +namespace FeatureBG = boost::geometry; +namespace FeatureBGM = FeatureBG::model; +namespace FeatureBGI = FeatureBG::index; +typedef FeatureBGM::point FeaturePoint; +typedef FeatureBGM::box FeatureBox; +typedef std::pair Feature; +typedef FeatureBGI::rtree> FeatureTree; + // We're using this class to shuttle the resulting buckets from the worker thread to the MapContext // thread. This class is movable-only because the vector contains movable-only value elements. class TileParseResultBuckets { public: TileData::State state = TileData::State::invalid; std::unordered_map> buckets; + FeatureTree featureTree; }; using TileParseResult = mapbox::util::variant blockingBoxes; - tree.query(bgi::intersects(getTreeBox(anchor, box)), std::back_inserter(blockingBoxes)); + tree.query(CollisionBGI::intersects(getTreeBox(anchor, box)), std::back_inserter(blockingBoxes)); for (auto& blockingTreeBox : blockingBoxes) { const auto& blocking = std::get<1>(blockingTreeBox); diff --git a/src/mbgl/text/collision_tile.hpp b/src/mbgl/text/collision_tile.hpp index edd5eb61a0e..64577a06b97 100644 --- a/src/mbgl/text/collision_tile.hpp +++ b/src/mbgl/text/collision_tile.hpp @@ -25,13 +25,13 @@ namespace mbgl { -namespace bg = boost::geometry; -namespace bgm = bg::model; -namespace bgi = bg::index; -typedef bgm::point CollisionPoint; -typedef bgm::box Box; +namespace CollisionBG = boost::geometry; +namespace CollisionBGM = CollisionBG::model; +namespace CollisionBGI = CollisionBG::index; +typedef CollisionBGM::point CollisionPoint; +typedef CollisionBGM::box Box; typedef std::pair CollisionTreeBox; -typedef bgi::rtree> Tree; +typedef CollisionBGI::rtree> CollisionTree; class CollisionTile { public: @@ -49,7 +49,7 @@ class CollisionTile { private: Box getTreeBox(const vec2& anchor, const CollisionBox& box); - Tree tree; + CollisionTree tree; std::array rotationMatrix; };