summaryrefslogtreecommitdiff
path: root/src/mbgl/tile/geojson_tile.cpp
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2016-05-19 15:34:08 +0200
committerKonstantin Käfer <mail@kkaefer.com>2016-06-10 12:42:14 +0200
commite8d8f52d2ea8b788a0dbe859549ec86fc0732df3 (patch)
tree80e8d41f1bbd8de633e851086be523860b8979db /src/mbgl/tile/geojson_tile.cpp
parent6998479d05497baf57eb264e92807d327920f7d6 (diff)
downloadqtlocation-mapboxgl-e8d8f52d2ea8b788a0dbe859549ec86fc0732df3.tar.gz
[core] *TileMonitor => *TileSource
Diffstat (limited to 'src/mbgl/tile/geojson_tile.cpp')
-rw-r--r--src/mbgl/tile/geojson_tile.cpp95
1 files changed, 0 insertions, 95 deletions
diff --git a/src/mbgl/tile/geojson_tile.cpp b/src/mbgl/tile/geojson_tile.cpp
index 90147ffd87..ec399d6e5a 100644
--- a/src/mbgl/tile/geojson_tile.cpp
+++ b/src/mbgl/tile/geojson_tile.cpp
@@ -1,6 +1,4 @@
#include <mbgl/tile/geojson_tile.hpp>
-#include <mbgl/storage/file_source.hpp>
-#include <mapbox/geojsonvt.hpp>
namespace mbgl {
@@ -45,97 +43,4 @@ util::ptr<GeometryTileLayer> GeoJSONTile::getLayer(const std::string&) const {
return layer;
}
-// Converts the geojsonvt::Tile to a a GeoJSONTile. They have a differing internal structure.
-std::unique_ptr<GeoJSONTile> convertTile(const mapbox::geojsonvt::Tile& tile) {
- std::shared_ptr<GeoJSONTileLayer> layer;
-
- if (tile) {
- std::vector<std::shared_ptr<const GeoJSONTileFeature>> features;
- GeometryCoordinates line;
-
- for (auto& feature : tile.features) {
- const FeatureType featureType =
- (feature.type == mapbox::geojsonvt::TileFeatureType::Point
- ? FeatureType::Point
- : (feature.type == mapbox::geojsonvt::TileFeatureType::LineString
- ? FeatureType::LineString
- : (feature.type == mapbox::geojsonvt::TileFeatureType::Polygon
- ? FeatureType::Polygon
- : FeatureType::Unknown)));
- if (featureType == FeatureType::Unknown) {
- continue;
- }
-
- GeometryCollection geometry;
-
- // Flatten the geometry; GeoJSONVT distinguishes between a Points array and Rings array
- // (Points = GeoJSON types Point, MultiPoint, LineString)
- // (Rings = GeoJSON types MultiLineString, Polygon, MultiPolygon)
- // However, in Mapbox GL, we use one structure for both types, and just have one outer
- // element for Points.
- if (feature.tileGeometry.is<mapbox::geojsonvt::TilePoints>()) {
- line.clear();
- for (auto& point : feature.tileGeometry.get<mapbox::geojsonvt::TilePoints>()) {
- line.emplace_back(point.x, point.y);
- }
- geometry.emplace_back(std::move(line));
- } else if (feature.tileGeometry.is<mapbox::geojsonvt::TileRings>()) {
- for (auto& ring : feature.tileGeometry.get<mapbox::geojsonvt::TileRings>()) {
- line.clear();
- for (auto& point : ring) {
- line.emplace_back(point.x, point.y);
- }
- geometry.emplace_back(std::move(line));
- }
- }
-
- // https://github.com/mapbox/geojson-vt-cpp/issues/44
- if (featureType == FeatureType::Polygon) {
- geometry = fixupPolygons(geometry);
- }
-
- Feature::property_map properties { feature.tags.begin(), feature.tags.end() };
-
- features.emplace_back(std::make_shared<GeoJSONTileFeature>(
- featureType, std::move(geometry), std::move(properties)));
- }
-
- layer = std::make_unique<GeoJSONTileLayer>(std::move(features));
- }
-
- return std::make_unique<GeoJSONTile>(layer);
-}
-
-GeoJSONTileMonitor::GeoJSONTileMonitor(mapbox::geojsonvt::GeoJSONVT* geojsonvt_,
- const OverscaledTileID& id)
- : tileID(id), geojsonvt(geojsonvt_) {
-}
-
-GeoJSONTileMonitor::~GeoJSONTileMonitor() = default;
-
-// A monitor can have its GeoJSONVT object swapped out (e.g. when loading a new GeoJSON file).
-// In that case, we're sending new notifications to all observers.
-void GeoJSONTileMonitor::setGeoJSONVT(mapbox::geojsonvt::GeoJSONVT* vt) {
- // Don't duplicate notifications in case of nil changes.
- if (geojsonvt != vt) {
- geojsonvt = vt;
- update();
- }
-}
-
-void GeoJSONTileMonitor::update() {
- if (geojsonvt) {
- auto tile = convertTile(
- geojsonvt->getTile(tileID.canonical.z, tileID.canonical.x, tileID.canonical.y));
- callback(nullptr, std::move(tile), {}, {});
- }
-}
-
-std::unique_ptr<AsyncRequest>
-GeoJSONTileMonitor::monitorTile(const GeometryTileMonitor::Callback& cb) {
- callback = cb;
- update();
- return nullptr;
-}
-
} // namespace mbgl