summaryrefslogtreecommitdiff
path: root/src/mbgl/sourcemanager
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/sourcemanager')
-rw-r--r--src/mbgl/sourcemanager/annotation_source_factory.cpp23
-rw-r--r--src/mbgl/sourcemanager/custom_geometry_source_factory.cpp24
-rw-r--r--src/mbgl/sourcemanager/geojson_source_factory.cpp52
-rw-r--r--src/mbgl/sourcemanager/image_source_factory.cpp59
-rw-r--r--src/mbgl/sourcemanager/raster_dem_source_factory.cpp42
-rw-r--r--src/mbgl/sourcemanager/raster_source_factory.cpp43
-rw-r--r--src/mbgl/sourcemanager/source_manager.cpp30
-rw-r--r--src/mbgl/sourcemanager/vector_source_factory.cpp49
8 files changed, 322 insertions, 0 deletions
diff --git a/src/mbgl/sourcemanager/annotation_source_factory.cpp b/src/mbgl/sourcemanager/annotation_source_factory.cpp
new file mode 100644
index 0000000000..a5d1986efd
--- /dev/null
+++ b/src/mbgl/sourcemanager/annotation_source_factory.cpp
@@ -0,0 +1,23 @@
+#include <mbgl/annotation/annotation_source.hpp>
+#include <mbgl/annotation/render_annotation_source.hpp>
+#include <mbgl/sourcemanager/annotation_source_factory.hpp>
+
+namespace mbgl {
+
+const style::SourceTypeInfo* AnnotationSourceFactory::getTypeInfo() const noexcept {
+ return AnnotationSource::Impl::staticTypeInfo();
+}
+
+std::unique_ptr<style::Source> AnnotationSourceFactory::createSource(const std::string&,
+ const style::conversion::Convertible&,
+ style::conversion::Error&) noexcept {
+ return std::unique_ptr<style::Source>(new AnnotationSource());
+}
+
+std::unique_ptr<RenderSource> AnnotationSourceFactory::createRenderSource(
+ Immutable<style::Source::Impl> impl) noexcept {
+ assert(impl->getTypeInfo() == getTypeInfo());
+ return std::make_unique<RenderAnnotationSource>(staticImmutableCast<AnnotationSource::Impl>(impl));
+}
+
+} // namespace mbgl
diff --git a/src/mbgl/sourcemanager/custom_geometry_source_factory.cpp b/src/mbgl/sourcemanager/custom_geometry_source_factory.cpp
new file mode 100644
index 0000000000..054aa15bd5
--- /dev/null
+++ b/src/mbgl/sourcemanager/custom_geometry_source_factory.cpp
@@ -0,0 +1,24 @@
+#include <mbgl/renderer/sources/render_custom_geometry_source.hpp>
+#include <mbgl/sourcemanager/custom_geometry_source_factory.hpp>
+#include <mbgl/style/sources/custom_geometry_source.hpp>
+#include <mbgl/style/sources/custom_geometry_source_impl.hpp>
+
+namespace mbgl {
+
+const style::SourceTypeInfo* CustomGeometrySourceFactory::getTypeInfo() const noexcept {
+ return style::CustomGeometrySource::Impl::staticTypeInfo();
+}
+
+std::unique_ptr<style::Source> CustomGeometrySourceFactory::createSource(const std::string& id,
+ const style::conversion::Convertible&,
+ style::conversion::Error&) noexcept {
+ return std::unique_ptr<style::Source>(new style::CustomGeometrySource(id, style::CustomGeometrySource::Options{}));
+}
+
+std::unique_ptr<RenderSource> CustomGeometrySourceFactory::createRenderSource(
+ Immutable<style::Source::Impl> impl) noexcept {
+ assert(impl->getTypeInfo() == getTypeInfo());
+ return std::make_unique<RenderCustomGeometrySource>(staticImmutableCast<style::CustomGeometrySource::Impl>(impl));
+}
+
+} // namespace mbgl
diff --git a/src/mbgl/sourcemanager/geojson_source_factory.cpp b/src/mbgl/sourcemanager/geojson_source_factory.cpp
new file mode 100644
index 0000000000..3152fe04ae
--- /dev/null
+++ b/src/mbgl/sourcemanager/geojson_source_factory.cpp
@@ -0,0 +1,52 @@
+#include <mbgl/renderer/sources/render_geojson_source.hpp>
+#include <mbgl/sourcemanager/geojson_source_factory.hpp>
+#include <mbgl/style/conversion/geojson.hpp>
+#include <mbgl/style/conversion/geojson_options.hpp>
+#include <mbgl/style/conversion_impl.hpp>
+#include <mbgl/style/sources/geojson_source.hpp>
+#include <mbgl/style/sources/geojson_source_impl.hpp>
+
+namespace mbgl {
+
+const style::SourceTypeInfo* GeoJSONSourceFactory::getTypeInfo() const noexcept {
+ return style::GeoJSONSource::Impl::staticTypeInfo();
+}
+
+std::unique_ptr<style::Source> GeoJSONSourceFactory::createSource(const std::string& id,
+ const style::conversion::Convertible& value,
+ style::conversion::Error& error) noexcept {
+ auto dataValue = objectMember(value, "data");
+ if (!dataValue) {
+ error.message = "GeoJSON source must have a data value";
+ return nullptr;
+ }
+
+ Immutable<style::GeoJSONOptions> options = style::GeoJSONOptions::defaultOptions();
+ if (optional<style::GeoJSONOptions> converted = style::conversion::convert<style::GeoJSONOptions>(value, error)) {
+ options = makeMutable<style::GeoJSONOptions>(std::move(*converted));
+ }
+
+ auto result = std::make_unique<style::GeoJSONSource>(id, std::move(options));
+
+ if (isObject(*dataValue)) {
+ optional<GeoJSON> geoJSON = style::conversion::convert<GeoJSON>(*dataValue, error);
+ if (!geoJSON) {
+ return nullptr;
+ }
+ result->setGeoJSON(*geoJSON);
+ } else if (toString(*dataValue)) {
+ result->setURL(*toString(*dataValue));
+ } else {
+ error.message = "GeoJSON data must be a URL or an object";
+ return nullptr;
+ }
+
+ return {std::move(result)};
+}
+
+std::unique_ptr<RenderSource> GeoJSONSourceFactory::createRenderSource(Immutable<style::Source::Impl> impl) noexcept {
+ assert(impl->getTypeInfo() == getTypeInfo());
+ return std::make_unique<RenderGeoJSONSource>(staticImmutableCast<style::GeoJSONSource::Impl>(impl));
+}
+
+} // namespace mbgl
diff --git a/src/mbgl/sourcemanager/image_source_factory.cpp b/src/mbgl/sourcemanager/image_source_factory.cpp
new file mode 100644
index 0000000000..3cd3c41914
--- /dev/null
+++ b/src/mbgl/sourcemanager/image_source_factory.cpp
@@ -0,0 +1,59 @@
+#include <mbgl/renderer/sources/render_image_source.hpp>
+#include <mbgl/sourcemanager/image_source_factory.hpp>
+#include <mbgl/style/conversion/coordinate.hpp>
+#include <mbgl/style/conversion_impl.hpp>
+#include <mbgl/style/sources/image_source.hpp>
+#include <mbgl/style/sources/image_source_impl.hpp>
+
+namespace mbgl {
+
+const style::SourceTypeInfo* ImageSourceFactory::getTypeInfo() const noexcept {
+ return style::ImageSource::Impl::staticTypeInfo();
+}
+
+std::unique_ptr<style::Source> ImageSourceFactory::createSource(const std::string& id,
+ const style::conversion::Convertible& value,
+ style::conversion::Error& error) noexcept {
+ auto urlValue = objectMember(value, "url");
+ if (!urlValue) {
+ error.message = "Image source must have a url value";
+ return nullptr;
+ }
+
+ auto urlString = toString(*urlValue);
+ if (!urlString) {
+ error.message = "Image url must be a URL string";
+ return nullptr;
+ }
+
+ auto coordinatesValue = objectMember(value, "coordinates");
+ if (!coordinatesValue) {
+ error.message = "Image source must have a coordinates values";
+ return nullptr;
+ }
+
+ if (!isArray(*coordinatesValue) || arrayLength(*coordinatesValue) != 4) {
+ error.message = "Image coordinates must be an array of four longitude latitude pairs";
+ return nullptr;
+ }
+
+ std::array<LatLng, 4> coordinates;
+ for (std::size_t i = 0; i < 4; i++) {
+ auto latLng = style::conversion::convert<LatLng>(arrayMember(*coordinatesValue, i), error);
+ if (!latLng) {
+ return nullptr;
+ }
+ coordinates[i] = *latLng;
+ }
+ auto result = std::make_unique<style::ImageSource>(id, coordinates);
+ result->setURL(*urlString);
+
+ return {std::move(result)};
+}
+
+std::unique_ptr<RenderSource> ImageSourceFactory::createRenderSource(Immutable<style::Source::Impl> impl) noexcept {
+ assert(impl->getTypeInfo() == getTypeInfo());
+ return std::make_unique<RenderImageSource>(staticImmutableCast<style::ImageSource::Impl>(impl));
+}
+
+} // namespace mbgl
diff --git a/src/mbgl/sourcemanager/raster_dem_source_factory.cpp b/src/mbgl/sourcemanager/raster_dem_source_factory.cpp
new file mode 100644
index 0000000000..119a7eae27
--- /dev/null
+++ b/src/mbgl/sourcemanager/raster_dem_source_factory.cpp
@@ -0,0 +1,42 @@
+#include <mbgl/renderer/sources/render_raster_dem_source.hpp>
+#include <mbgl/sourcemanager/raster_dem_source_factory.hpp>
+#include <mbgl/style/conversion/url_or_tileset.hpp>
+#include <mbgl/style/conversion_impl.hpp>
+#include <mbgl/style/sources/raster_dem_source.hpp>
+#include <mbgl/style/sources/raster_dem_source_impl.hpp>
+
+namespace mbgl {
+
+const style::SourceTypeInfo* RasterDEMSourceFactory::getTypeInfo() const noexcept {
+ return style::RasterDEMSource::Impl::staticTypeInfo();
+}
+
+std::unique_ptr<style::Source> RasterDEMSourceFactory::createSource(const std::string& id,
+ const style::conversion::Convertible& value,
+ style::conversion::Error& error) noexcept {
+ optional<variant<std::string, Tileset>> urlOrTileset =
+ style::conversion::convert<variant<std::string, Tileset>>(value, error);
+ if (!urlOrTileset) {
+ return nullptr;
+ }
+
+ uint16_t tileSize = util::tileSize;
+ auto tileSizeValue = objectMember(value, "tileSize");
+ if (tileSizeValue) {
+ optional<float> size = toNumber(*tileSizeValue);
+ if (!size || *size < 0 || *size > std::numeric_limits<uint16_t>::max()) {
+ error.message = "invalid tileSize";
+ return nullptr;
+ }
+ tileSize = *size;
+ }
+
+ return {std::make_unique<style::RasterDEMSource>(id, std::move(*urlOrTileset), tileSize)};
+}
+
+std::unique_ptr<RenderSource> RasterDEMSourceFactory::createRenderSource(Immutable<style::Source::Impl> impl) noexcept {
+ assert(impl->getTypeInfo() == getTypeInfo());
+ return std::make_unique<RenderRasterDEMSource>(staticImmutableCast<style::RasterDEMSource::Impl>(impl));
+}
+
+} // namespace mbgl
diff --git a/src/mbgl/sourcemanager/raster_source_factory.cpp b/src/mbgl/sourcemanager/raster_source_factory.cpp
new file mode 100644
index 0000000000..a06595059d
--- /dev/null
+++ b/src/mbgl/sourcemanager/raster_source_factory.cpp
@@ -0,0 +1,43 @@
+#include <mbgl/renderer/sources/render_raster_source.hpp>
+#include <mbgl/sourcemanager/raster_source_factory.hpp>
+#include <mbgl/style/conversion/url_or_tileset.hpp>
+#include <mbgl/style/conversion_impl.hpp>
+#include <mbgl/style/sources/raster_source.hpp>
+#include <mbgl/style/sources/raster_source_impl.hpp>
+
+namespace mbgl {
+
+const style::SourceTypeInfo* RasterSourceFactory::getTypeInfo() const noexcept {
+ return style::RasterSource::Impl::staticTypeInfo();
+}
+
+std::unique_ptr<style::Source> RasterSourceFactory::createSource(const std::string& id,
+ const style::conversion::Convertible& value,
+ style::conversion::Error& error) noexcept {
+ optional<variant<std::string, Tileset>> urlOrTileset =
+ style::conversion::convert<variant<std::string, Tileset>>(value, error);
+
+ if (!urlOrTileset) {
+ return nullptr;
+ }
+
+ uint16_t tileSize = util::tileSize;
+ auto tileSizeValue = objectMember(value, "tileSize");
+ if (tileSizeValue) {
+ optional<float> size = toNumber(*tileSizeValue);
+ if (!size || *size < 0 || *size > std::numeric_limits<uint16_t>::max()) {
+ error.message = "invalid tileSize";
+ return nullptr;
+ }
+ tileSize = *size;
+ }
+
+ return {std::make_unique<style::RasterSource>(id, std::move(*urlOrTileset), tileSize)};
+}
+
+std::unique_ptr<RenderSource> RasterSourceFactory::createRenderSource(Immutable<style::Source::Impl> impl) noexcept {
+ assert(impl->getTypeInfo() == getTypeInfo());
+ return std::make_unique<RenderRasterSource>(staticImmutableCast<style::RasterSource::Impl>(impl));
+}
+
+} // namespace mbgl
diff --git a/src/mbgl/sourcemanager/source_manager.cpp b/src/mbgl/sourcemanager/source_manager.cpp
new file mode 100644
index 0000000000..742cedef2d
--- /dev/null
+++ b/src/mbgl/sourcemanager/source_manager.cpp
@@ -0,0 +1,30 @@
+#include <mbgl/renderer/render_source.hpp>
+#include <mbgl/sourcemanager/source_factory.hpp>
+#include <mbgl/sourcemanager/source_manager.hpp>
+#include <mbgl/style/conversion_impl.hpp>
+#include <mbgl/style/source.hpp>
+#include <mbgl/style/source_impl.hpp>
+
+namespace mbgl {
+
+std::unique_ptr<style::Source> SourceManager::createSource(const std::string& type,
+ const std::string& id,
+ const style::conversion::Convertible& value,
+ style::conversion::Error& error) noexcept {
+ SourceFactory* factory = getFactory(type);
+ if (factory) {
+ return factory->createSource(id, value, error);
+ } else {
+ error.message = "Null factory for type: " + type;
+ }
+ error.message = "Unsupported source type! " + error.message;
+ return nullptr;
+}
+
+std::unique_ptr<RenderSource> SourceManager::createRenderSource(Immutable<style::Source::Impl> impl) noexcept {
+ SourceFactory* factory = getFactory(impl->getTypeInfo());
+ assert(factory);
+ return factory->createRenderSource(std::move(impl));
+}
+
+} // namespace mbgl
diff --git a/src/mbgl/sourcemanager/vector_source_factory.cpp b/src/mbgl/sourcemanager/vector_source_factory.cpp
new file mode 100644
index 0000000000..efc6f3144f
--- /dev/null
+++ b/src/mbgl/sourcemanager/vector_source_factory.cpp
@@ -0,0 +1,49 @@
+#include <mbgl/renderer/sources/render_vector_source.hpp>
+#include <mbgl/sourcemanager/vector_source_factory.hpp>
+#include <mbgl/style/conversion/url_or_tileset.hpp>
+#include <mbgl/style/conversion_impl.hpp>
+#include <mbgl/style/sources/vector_source.hpp>
+#include <mbgl/style/sources/vector_source_impl.hpp>
+
+namespace mbgl {
+
+const style::SourceTypeInfo* VectorSourceFactory::getTypeInfo() const noexcept {
+ return style::VectorSource::Impl::staticTypeInfo();
+}
+
+std::unique_ptr<style::Source> VectorSourceFactory::createSource(const std::string& id,
+ const style::conversion::Convertible& value,
+ style::conversion::Error& error) noexcept {
+ optional<variant<std::string, Tileset>> urlOrTileset =
+ style::conversion::convert<variant<std::string, Tileset>>(value, error);
+ if (!urlOrTileset) {
+ return nullptr;
+ }
+ auto maxzoomValue = objectMember(value, "maxzoom");
+ optional<float> maxzoom;
+ if (maxzoomValue) {
+ maxzoom = toNumber(*maxzoomValue);
+ if (!maxzoom || *maxzoom < 0 || *maxzoom > std::numeric_limits<uint8_t>::max()) {
+ error.message = "invalid maxzoom";
+ return nullptr;
+ }
+ }
+ auto minzoomValue = objectMember(value, "minzoom");
+ optional<float> minzoom;
+ if (minzoomValue) {
+ minzoom = toNumber(*minzoomValue);
+ if (!minzoom || *minzoom < 0 || *minzoom > std::numeric_limits<uint8_t>::max()) {
+ error.message = "invalid minzoom";
+ return nullptr;
+ }
+ }
+ return {
+ std::make_unique<style::VectorSource>(id, std::move(*urlOrTileset), std::move(maxzoom), std::move(minzoom))};
+}
+
+std::unique_ptr<RenderSource> VectorSourceFactory::createRenderSource(Immutable<style::Source::Impl> impl) noexcept {
+ assert(impl->getTypeInfo() == getTypeInfo());
+ return std::make_unique<RenderVectorSource>(staticImmutableCast<style::VectorSource::Impl>(impl));
+}
+
+} // namespace mbgl