[core] Merge geojson_tile_data.{hpp,cpp} into geojson_tile.{hpp,cpp}
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
|
||||
#include <mbgl/tile/raster_tile_data.hpp>
|
||||
#include <mbgl/tile/annotation_tile_data.hpp>
|
||||
#include <mbgl/tile/geojson_tile_data.hpp>
|
||||
#include <mbgl/tile/geojson_tile.hpp>
|
||||
#include <mbgl/tile/vector_tile_data.hpp>
|
||||
#include <mbgl/style/parser.hpp>
|
||||
#include <mbgl/gl/debugging.hpp>
|
||||
|
||||
@@ -1,7 +1,87 @@
|
||||
#include <mbgl/tile/geojson_tile.hpp>
|
||||
#include <mbgl/style/update_parameters.hpp>
|
||||
|
||||
#include <mapbox/geojsonvt.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
GeoJSONTileData::GeoJSONTileData(const OverscaledTileID& overscaledTileID,
|
||||
std::string sourceID,
|
||||
const style::UpdateParameters& parameters,
|
||||
mapbox::geojsonvt::GeoJSONVT* geojsonvt)
|
||||
: GeometryTileData(overscaledTileID, sourceID, parameters.style, parameters.mode) {
|
||||
if (geojsonvt) {
|
||||
auto tile = convertTile(
|
||||
geojsonvt->getTile(id.canonical.z, id.canonical.x, id.canonical.y));
|
||||
setData(std::move(tile), {}, {});
|
||||
}
|
||||
}
|
||||
|
||||
GeoJSONTileData::~GeoJSONTileData() = default;
|
||||
|
||||
void GeoJSONTileData::setNecessity(Necessity) {}
|
||||
|
||||
GeoJSONTileFeature::GeoJSONTileFeature(FeatureType type_,
|
||||
GeometryCollection&& geometries_,
|
||||
Feature::property_map&& properties_)
|
||||
|
||||
@@ -1,9 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/tile/geometry_tile.hpp>
|
||||
#include <mbgl/tile/geometry_tile_data.hpp>
|
||||
|
||||
namespace mapbox {
|
||||
namespace geojsonvt {
|
||||
class GeoJSONVT;
|
||||
} // namespace geojsonvt
|
||||
} // namespace mapbox
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
namespace style {
|
||||
class UpdateParameters;
|
||||
}
|
||||
|
||||
class GeoJSONTileData : public GeometryTileData {
|
||||
public:
|
||||
GeoJSONTileData(const OverscaledTileID&,
|
||||
std::string sourceID,
|
||||
const style::UpdateParameters&,
|
||||
mapbox::geojsonvt::GeoJSONVT*);
|
||||
~GeoJSONTileData();
|
||||
|
||||
void setNecessity(Necessity) final;
|
||||
};
|
||||
|
||||
// Implements a simple in-memory Tile type that holds GeoJSON values. A GeoJSON tile can only have
|
||||
// one layer, and it is always returned regardless of which layer is requested.
|
||||
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
#include <mbgl/tile/geojson_tile_data.hpp>
|
||||
#include <mbgl/tile/geojson_tile.hpp>
|
||||
#include <mbgl/style/update_parameters.hpp>
|
||||
|
||||
#include <mapbox/geojsonvt.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
GeoJSONTileData::GeoJSONTileData(const OverscaledTileID& overscaledTileID,
|
||||
std::string sourceID,
|
||||
const style::UpdateParameters& parameters,
|
||||
mapbox::geojsonvt::GeoJSONVT* geojsonvt)
|
||||
: GeometryTileData(overscaledTileID, sourceID, parameters.style, parameters.mode) {
|
||||
if (geojsonvt) {
|
||||
auto tile = convertTile(
|
||||
geojsonvt->getTile(id.canonical.z, id.canonical.x, id.canonical.y));
|
||||
setData(std::move(tile), {}, {});
|
||||
}
|
||||
}
|
||||
|
||||
GeoJSONTileData::~GeoJSONTileData() = default;
|
||||
|
||||
void GeoJSONTileData::setNecessity(Necessity) {}
|
||||
|
||||
} // namespace mbgl
|
||||
@@ -1,28 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/tile/geometry_tile_data.hpp>
|
||||
|
||||
namespace mapbox {
|
||||
namespace geojsonvt {
|
||||
class GeoJSONVT;
|
||||
} // namespace geojsonvt
|
||||
} // namespace mapbox
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
namespace style {
|
||||
class UpdateParameters;
|
||||
}
|
||||
|
||||
class GeoJSONTileData : public GeometryTileData {
|
||||
public:
|
||||
GeoJSONTileData(const OverscaledTileID&,
|
||||
std::string sourceID,
|
||||
const style::UpdateParameters&,
|
||||
mapbox::geojsonvt::GeoJSONVT*);
|
||||
~GeoJSONTileData();
|
||||
|
||||
void setNecessity(Necessity) final;
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
Reference in New Issue
Block a user