From 117c8ed1d100e2b64841f17714178bd1d9ffc40e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Mon, 12 Dec 2016 16:02:19 -0800 Subject: [core] Added URL accessor for tile sources --- src/mbgl/style/sources/geojson_source.cpp | 2 +- src/mbgl/style/sources/geojson_source_impl.cpp | 2 +- src/mbgl/style/sources/geojson_source_impl.hpp | 2 +- src/mbgl/style/sources/raster_source.cpp | 12 +++++++++++- src/mbgl/style/sources/vector_source.cpp | 12 +++++++++++- 5 files changed, 25 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/mbgl/style/sources/geojson_source.cpp b/src/mbgl/style/sources/geojson_source.cpp index 7480438132..62726cd127 100644 --- a/src/mbgl/style/sources/geojson_source.cpp +++ b/src/mbgl/style/sources/geojson_source.cpp @@ -18,7 +18,7 @@ void GeoJSONSource::setGeoJSON(const mapbox::geojson::geojson& geoJSON) { impl->setGeoJSON(geoJSON); } -optional GeoJSONSource::getURL() { +optional GeoJSONSource::getURL() const { return impl->getURL(); } diff --git a/src/mbgl/style/sources/geojson_source_impl.cpp b/src/mbgl/style/sources/geojson_source_impl.cpp index 4800b9c4be..2929d73d39 100644 --- a/src/mbgl/style/sources/geojson_source_impl.cpp +++ b/src/mbgl/style/sources/geojson_source_impl.cpp @@ -47,7 +47,7 @@ void GeoJSONSource::Impl::setURL(std::string url_) { } } -optional GeoJSONSource::Impl::getURL() { +optional GeoJSONSource::Impl::getURL() const { return url; } diff --git a/src/mbgl/style/sources/geojson_source_impl.hpp b/src/mbgl/style/sources/geojson_source_impl.hpp index 13994d9078..eec7cf0605 100644 --- a/src/mbgl/style/sources/geojson_source_impl.hpp +++ b/src/mbgl/style/sources/geojson_source_impl.hpp @@ -17,7 +17,7 @@ public: ~Impl() final; void setURL(std::string); - optional getURL(); + optional getURL() const; void setGeoJSON(const GeoJSON&); void setTileData(GeoJSONTile&, const OverscaledTileID& tileID); diff --git a/src/mbgl/style/sources/raster_source.cpp b/src/mbgl/style/sources/raster_source.cpp index 3c65476df0..94fdbcef12 100644 --- a/src/mbgl/style/sources/raster_source.cpp +++ b/src/mbgl/style/sources/raster_source.cpp @@ -5,7 +5,17 @@ namespace mbgl { namespace style { RasterSource::RasterSource(std::string id, variant urlOrTileset, uint16_t tileSize) - : Source(SourceType::Raster, std::make_unique(std::move(id), *this, std::move(urlOrTileset), tileSize)) { + : Source(SourceType::Raster, std::make_unique(std::move(id), *this, std::move(urlOrTileset), tileSize)), + impl(static_cast(baseImpl.get())) { +} + +optional RasterSource::getURL() const { + auto urlOrTileset = impl->getURLOrTileset(); + if (urlOrTileset.is()) { + return urlOrTileset.get(); + } else { + return {}; + } } } // namespace style diff --git a/src/mbgl/style/sources/vector_source.cpp b/src/mbgl/style/sources/vector_source.cpp index f2a6b166a9..4bcd3b8985 100644 --- a/src/mbgl/style/sources/vector_source.cpp +++ b/src/mbgl/style/sources/vector_source.cpp @@ -5,7 +5,17 @@ namespace mbgl { namespace style { VectorSource::VectorSource(std::string id, variant urlOrTileset) - : Source(SourceType::Vector, std::make_unique(std::move(id), *this, std::move(urlOrTileset))) { + : Source(SourceType::Vector, std::make_unique(std::move(id), *this, std::move(urlOrTileset))), + impl(static_cast(baseImpl.get())) { +} + +optional VectorSource::getURL() const { + auto urlOrTileset = impl->getURLOrTileset(); + if (urlOrTileset.is()) { + return urlOrTileset.get(); + } else { + return {}; + } } } // namespace style -- cgit v1.2.1 From 84f90697df57782263cec0e0d688820bf3c4b644 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Sun, 8 Jan 2017 14:51:35 -0800 Subject: [core] Avoid clustering unclusterable GeoJSON MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/mbgl/style/sources/geojson_source_impl.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src') 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(geoJSON, vtOptions); - - } else { + if (options.cluster + && geoJSON.is>() + && !geoJSON.get>().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>(); geoJSONOrSupercluster = std::make_unique(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(geoJSON, vtOptions); } for (auto const &item : tiles) { -- cgit v1.2.1