[core] Avoid clustering unclusterable GeoJSON
Ignore empty feature collections or non–feature collections for the purposes of clustering or tiling. A source’s clustering option can only be set when the source is constructed, but setGeoJSON() enables the developer to swap a clusterable feature for an unclusterable geometry and back.
This commit is contained in:
committed by
Minh Nguyễn
parent
226054bf71
commit
84f90697df
@@ -63,15 +63,9 @@ void GeoJSONSource::Impl::_setGeoJSON(const GeoJSON& geoJSON) {
|
||||
|
||||
cache.clear();
|
||||
|
||||
if (!options.cluster) {
|
||||
mapbox::geojsonvt::Options vtOptions;
|
||||
vtOptions.maxZoom = options.maxzoom;
|
||||
vtOptions.extent = util::EXTENT;
|
||||
vtOptions.buffer = std::round(scale * options.buffer);
|
||||
vtOptions.tolerance = scale * options.tolerance;
|
||||
geoJSONOrSupercluster = std::make_unique<mapbox::geojsonvt::GeoJSONVT>(geoJSON, vtOptions);
|
||||
|
||||
} else {
|
||||
if (options.cluster
|
||||
&& geoJSON.is<mapbox::geometry::feature_collection<double>>()
|
||||
&& !geoJSON.get<mapbox::geometry::feature_collection<double>>().empty()) {
|
||||
mapbox::supercluster::Options clusterOptions;
|
||||
clusterOptions.maxZoom = options.clusterMaxZoom;
|
||||
clusterOptions.extent = util::EXTENT;
|
||||
@@ -80,6 +74,13 @@ void GeoJSONSource::Impl::_setGeoJSON(const GeoJSON& geoJSON) {
|
||||
const auto& features = geoJSON.get<mapbox::geometry::feature_collection<double>>();
|
||||
geoJSONOrSupercluster =
|
||||
std::make_unique<mapbox::supercluster::Supercluster>(features, clusterOptions);
|
||||
} else {
|
||||
mapbox::geojsonvt::Options vtOptions;
|
||||
vtOptions.maxZoom = options.maxzoom;
|
||||
vtOptions.extent = util::EXTENT;
|
||||
vtOptions.buffer = std::round(scale * options.buffer);
|
||||
vtOptions.tolerance = scale * options.tolerance;
|
||||
geoJSONOrSupercluster = std::make_unique<mapbox::geojsonvt::GeoJSONVT>(geoJSON, vtOptions);
|
||||
}
|
||||
|
||||
for (auto const &item : tiles) {
|
||||
|
||||
Reference in New Issue
Block a user