From f467165fb37d8d0319b81f27b4c57c47ac5dc827 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20M=C3=A4rki?= Date: Fri, 12 Jan 2024 19:45:53 +0100 Subject: [PATCH 1/3] min/max for geojson tiling --- shared/public/GeoJsonTypes.h | 1 + .../Tiled2dMapVectorLayerParserHelper.cpp | 12 ++++++++++-- .../tiled/vector/geojson/GeoJsonVTFactory.h | 10 ++++++---- .../vector/geojson/geojsonvt/geojsonvt.hpp | 18 +++++++++++++++--- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/shared/public/GeoJsonTypes.h b/shared/public/GeoJsonTypes.h index 9270b8a47..2fa8050dc 100644 --- a/shared/public/GeoJsonTypes.h +++ b/shared/public/GeoJsonTypes.h @@ -80,6 +80,7 @@ class GeoJSONVTInterface { virtual const GeoJSONTileInterface& getTile(const uint8_t z, const uint32_t x_, const uint32_t y) = 0; virtual bool isLoaded() = 0; virtual void waitIfNotLoaded(std::shared_ptr<::djinni::Promise>> promise) = 0; + virtual uint8_t getMinZoom() = 0; virtual uint8_t getMaxZoom() = 0; virtual void reload(const std::vector> &loaders) = 0; virtual void reload(const std::shared_ptr &geoJson) = 0; diff --git a/shared/src/map/layers/tiled/vector/Tiled2dMapVectorLayerParserHelper.cpp b/shared/src/map/layers/tiled/vector/Tiled2dMapVectorLayerParserHelper.cpp index 0f49fa087..dd2ece844 100644 --- a/shared/src/map/layers/tiled/vector/Tiled2dMapVectorLayerParserHelper.cpp +++ b/shared/src/map/layers/tiled/vector/Tiled2dMapVectorLayerParserHelper.cpp @@ -180,11 +180,19 @@ Tiled2dMapVectorLayerParserResult Tiled2dMapVectorLayerParserHelper::parseStyleJ tileJsons[key] = val; } else if (type == "geojson") { nlohmann::json geojson; + Options options; + + if (val["minzoom"].is_number_integer()) { + options.minZoom = val["minzoom"].get(); + } + if (val["maxzoom"].is_number_integer()) { + options.maxZoom = val["maxzoom"].get(); + } if (val["data"].is_string()) { - geojsonSources[key] = GeoJsonVTFactory::getGeoJsonVt(key, replaceUrlParams(val["data"].get(), sourceUrlParams), loaders, localDataProvider); + geojsonSources[key] = GeoJsonVTFactory::getGeoJsonVt(key, replaceUrlParams(val["data"].get(), sourceUrlParams), loaders, localDataProvider, options); } else { assert(val["data"].is_object()); - geojsonSources[key] = GeoJsonVTFactory::getGeoJsonVt(GeoJsonParser::getGeoJson(val["data"])); + geojsonSources[key] = GeoJsonVTFactory::getGeoJsonVt(GeoJsonParser::getGeoJson(val["data"]), options); } } } diff --git a/shared/src/map/layers/tiled/vector/geojson/GeoJsonVTFactory.h b/shared/src/map/layers/tiled/vector/geojson/GeoJsonVTFactory.h index 1c1528280..00ea58786 100644 --- a/shared/src/map/layers/tiled/vector/geojson/GeoJsonVTFactory.h +++ b/shared/src/map/layers/tiled/vector/geojson/GeoJsonVTFactory.h @@ -17,12 +17,14 @@ class GeoJsonVTFactory { public: - static std::shared_ptr getGeoJsonVt(const std::shared_ptr &geoJson) { - return std::static_pointer_cast(std::make_shared(geoJson)); + static std::shared_ptr getGeoJsonVt(const std::shared_ptr &geoJson, + const Options& options = Options()) { + return std::static_pointer_cast(std::make_shared(geoJson, options)); } - static std::shared_ptr getGeoJsonVt(const std::string &sourceName, const std::string &geoJsonUrl, const std::vector> &loaders, const std::shared_ptr &localDataProvider) { - std::shared_ptr vt = std::make_shared(sourceName, geoJsonUrl, loaders, localDataProvider); + static std::shared_ptr getGeoJsonVt(const std::string &sourceName, const std::string &geoJsonUrl, const std::vector> &loaders, const std::shared_ptr &localDataProvider, + const Options& options = Options()) { + std::shared_ptr vt = std::make_shared(sourceName, geoJsonUrl, loaders, localDataProvider, options); vt->load(); return vt; } diff --git a/shared/src/map/layers/tiled/vector/geojson/geojsonvt/geojsonvt.hpp b/shared/src/map/layers/tiled/vector/geojson/geojsonvt/geojsonvt.hpp index ce7290bc9..c8946bd2e 100644 --- a/shared/src/map/layers/tiled/vector/geojson/geojsonvt/geojsonvt.hpp +++ b/shared/src/map/layers/tiled/vector/geojson/geojsonvt/geojsonvt.hpp @@ -26,6 +26,9 @@ struct TileOptions { }; struct Options : TileOptions { + // min zoom to will be visible + uint8_t minZoom = 0; + // max zoom to preserve detail on uint8_t maxZoom = 18; @@ -53,7 +56,7 @@ class GeoJSONVT: public GeoJSONVTInterface, public std::enable_shared_from_this< // If the GeoJSON contains only points, there is no need to split it into smaller tiles, // as there are no opportunities for simplification, merging, or meaningful point reduction. if (geoJson->hasOnlyPoints) { - options.maxZoom = 0; + options.maxZoom = options.minZoom; } @@ -114,7 +117,7 @@ class GeoJSONVT: public GeoJSONVTInterface, public std::enable_shared_from_this< // If the GeoJSON contains only points, there is no need to split it into smaller tiles, // as there are no opportunities for simplification, merging, or meaningful point reduction. if (geoJson->hasOnlyPoints) { - self->options.maxZoom = 0; + self->options.maxZoom = self->options.minZoom; } else { self->options.maxZoom = 18; } @@ -150,6 +153,10 @@ class GeoJSONVT: public GeoJSONVTInterface, public std::enable_shared_from_this< } } + uint8_t getMinZoom() override { + return options.minZoom; + } + uint8_t getMaxZoom() override { return options.maxZoom; } @@ -167,7 +174,7 @@ class GeoJSONVT: public GeoJSONVTInterface, public std::enable_shared_from_this< // If the GeoJSON contains only points, there is no need to split it into smaller tiles, // as there are no opportunities for simplification, merging, or meaningful point reduction. if (geoJson->hasOnlyPoints) { - options.maxZoom = 0; + options.maxZoom = options.minZoom; } else { options.maxZoom = 18; } @@ -317,6 +324,11 @@ class GeoJSONVT: public GeoJSONVTInterface, public std::enable_shared_from_this< // if we sliced further down, no need to keep source geometry tile.source_features.clear(); + + if (z < options.minZoom) { + // if z smaller than min zoom, no need to keep tile + tiles.erase(it); + } } void resolveAllWaitingPromises() { From 955d9dc8359dff36d29bfa8b64804e82e160222d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20M=C3=A4rki?= Date: Mon, 15 Jan 2024 11:02:33 +0100 Subject: [PATCH 2/3] remove empty tiles --- .../map/layers/tiled/vector/geojson/geojsonvt/geojsonvt.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/shared/src/map/layers/tiled/vector/geojson/geojsonvt/geojsonvt.hpp b/shared/src/map/layers/tiled/vector/geojson/geojsonvt/geojsonvt.hpp index c8946bd2e..87db2bf65 100644 --- a/shared/src/map/layers/tiled/vector/geojson/geojsonvt/geojsonvt.hpp +++ b/shared/src/map/layers/tiled/vector/geojson/geojsonvt/geojsonvt.hpp @@ -278,9 +278,11 @@ class GeoJSONVT: public GeoJSONVTInterface, public std::enable_shared_from_this< auto& tile = it->second; - if (geometries.empty()) + if (geometries.empty()) { + tiles.erase(it); return; - + } + //if it's the first-pass tiling if (cz == 0u) { // stop tiling if we reached max zoom, or if the tile is too simple From 6146851da3989c239bc4d1ebe08273f862194a7a Mon Sep 17 00:00:00 2001 From: Christoph Maurhofer Date: Mon, 22 Jan 2024 07:32:33 +0100 Subject: [PATCH 3/3] Unify min/max-zoom type --- .../layers/tiled/vector/Tiled2dMapVectorLayerParserHelper.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared/src/map/layers/tiled/vector/Tiled2dMapVectorLayerParserHelper.cpp b/shared/src/map/layers/tiled/vector/Tiled2dMapVectorLayerParserHelper.cpp index dd2ece844..8eaf2afd5 100644 --- a/shared/src/map/layers/tiled/vector/Tiled2dMapVectorLayerParserHelper.cpp +++ b/shared/src/map/layers/tiled/vector/Tiled2dMapVectorLayerParserHelper.cpp @@ -183,10 +183,10 @@ Tiled2dMapVectorLayerParserResult Tiled2dMapVectorLayerParserHelper::parseStyleJ Options options; if (val["minzoom"].is_number_integer()) { - options.minZoom = val["minzoom"].get(); + options.minZoom = val["minzoom"].get(); } if (val["maxzoom"].is_number_integer()) { - options.maxZoom = val["maxzoom"].get(); + options.maxZoom = val["maxzoom"].get(); } if (val["data"].is_string()) { geojsonSources[key] = GeoJsonVTFactory::getGeoJsonVt(key, replaceUrlParams(val["data"].get(), sourceUrlParams), loaders, localDataProvider, options);