summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2017-01-08 14:51:35 -0800
committerMinh Nguyễn <mxn@1ec5.org>2017-01-08 17:45:18 -0800
commit84f90697df57782263cec0e0d688820bf3c4b644 (patch)
treefd34213dbb274f7fb16c3d7335be46b1ceaf055f /src
parent226054bf7186bed5269e7de5ca23f2e4bb2df002 (diff)
downloadqtlocation-mapboxgl-84f90697df57782263cec0e0d688820bf3c4b644.tar.gz
[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.
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/style/sources/geojson_source_impl.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/mbgl/style/sources/geojson_source_impl.cpp b/src/mbgl/style/sources/geojson_source_impl.cpp
index 2929d73d39..5aa335a389 100644
--- a/src/mbgl/style/sources/geojson_source_impl.cpp
+++ b/src/mbgl/style/sources/geojson_source_impl.cpp
@@ -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) {