Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

min/max for geojson tiling #568

Merged
merged 3 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions shared/public/GeoJsonTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::shared_ptr<DataLoaderResult>>> promise) = 0;
virtual uint8_t getMinZoom() = 0;
virtual uint8_t getMaxZoom() = 0;
virtual void reload(const std::vector<std::shared_ptr<::LoaderInterface>> &loaders) = 0;
virtual void reload(const std::shared_ptr<GeoJson> &geoJson) = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<u_int8_t>();
}
if (val["maxzoom"].is_number_integer()) {
options.maxZoom = val["maxzoom"].get<int>();
}
if (val["data"].is_string()) {
geojsonSources[key] = GeoJsonVTFactory::getGeoJsonVt(key, replaceUrlParams(val["data"].get<std::string>(), sourceUrlParams), loaders, localDataProvider);
geojsonSources[key] = GeoJsonVTFactory::getGeoJsonVt(key, replaceUrlParams(val["data"].get<std::string>(), 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);
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions shared/src/map/layers/tiled/vector/geojson/GeoJsonVTFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@

class GeoJsonVTFactory {
public:
static std::shared_ptr<GeoJSONVTInterface> getGeoJsonVt(const std::shared_ptr<GeoJson> &geoJson) {
return std::static_pointer_cast<GeoJSONVTInterface>(std::make_shared<GeoJSONVT>(geoJson));
static std::shared_ptr<GeoJSONVTInterface> getGeoJsonVt(const std::shared_ptr<GeoJson> &geoJson,
const Options& options = Options()) {
return std::static_pointer_cast<GeoJSONVTInterface>(std::make_shared<GeoJSONVT>(geoJson, options));
}

static std::shared_ptr<GeoJSONVTInterface> getGeoJsonVt(const std::string &sourceName, const std::string &geoJsonUrl, const std::vector<std::shared_ptr<::LoaderInterface>> &loaders, const std::shared_ptr<Tiled2dMapVectorLayerLocalDataProviderInterface> &localDataProvider) {
std::shared_ptr<GeoJSONVT> vt = std::make_shared<GeoJSONVT>(sourceName, geoJsonUrl, loaders, localDataProvider);
static std::shared_ptr<GeoJSONVTInterface> getGeoJsonVt(const std::string &sourceName, const std::string &geoJsonUrl, const std::vector<std::shared_ptr<::LoaderInterface>> &loaders, const std::shared_ptr<Tiled2dMapVectorLayerLocalDataProviderInterface> &localDataProvider,
const Options& options = Options()) {
std::shared_ptr<GeoJSONVT> vt = std::make_shared<GeoJSONVT>(sourceName, geoJsonUrl, loaders, localDataProvider, options);
vt->load();
return vt;
}
Expand Down
18 changes: 15 additions & 3 deletions shared/src/map/layers/tiled/vector/geojson/geojsonvt/geojsonvt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}


Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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() {
Expand Down
Loading