diff options
Diffstat (limited to 'src/mbgl')
-rw-r--r-- | src/mbgl/annotation/annotation_source.cpp | 7 | ||||
-rw-r--r-- | src/mbgl/annotation/annotation_source.hpp | 7 | ||||
-rw-r--r-- | src/mbgl/style/sources/custom_geometry_source.cpp | 18 | ||||
-rw-r--r-- | src/mbgl/style/sources/geojson_source.cpp | 15 | ||||
-rw-r--r-- | src/mbgl/style/sources/image_source.cpp | 9 | ||||
-rw-r--r-- | src/mbgl/style/sources/raster_dem_source.cpp | 11 | ||||
-rw-r--r-- | src/mbgl/style/sources/raster_source.cpp | 15 | ||||
-rw-r--r-- | src/mbgl/style/sources/vector_source.cpp | 17 | ||||
-rw-r--r-- | src/mbgl/style/style_impl.cpp | 38 |
9 files changed, 94 insertions, 43 deletions
diff --git a/src/mbgl/annotation/annotation_source.cpp b/src/mbgl/annotation/annotation_source.cpp index 68f36f2d3a..7a137f1881 100644 --- a/src/mbgl/annotation/annotation_source.cpp +++ b/src/mbgl/annotation/annotation_source.cpp @@ -1,5 +1,6 @@ -#include <mbgl/annotation/annotation_source.hpp> #include <mbgl/annotation/annotation_manager.hpp> +#include <mbgl/annotation/annotation_source.hpp> +#include <mbgl/style/layer.hpp> namespace mbgl { @@ -21,4 +22,8 @@ optional<std::string> AnnotationSource::Impl::getAttribution() const { return {}; } +bool AnnotationSource::supportsLayerType(const mbgl::style::LayerTypeInfo* info) const { + return !std::strcmp(info->type, "line") || !std::strcmp(info->type, "symbol") || !std::strcmp(info->type, "fill"); +} + } // namespace mbgl diff --git a/src/mbgl/annotation/annotation_source.hpp b/src/mbgl/annotation/annotation_source.hpp index 018e2136ea..0379426b3e 100644 --- a/src/mbgl/annotation/annotation_source.hpp +++ b/src/mbgl/annotation/annotation_source.hpp @@ -12,13 +12,12 @@ public: class Impl; const Impl& impl() const; +private: + void loadDescription(FileSource&) final; + bool supportsLayerType(const mbgl::style::LayerTypeInfo*) const override; mapbox::base::WeakPtr<Source> makeWeakPtr() override { return weakFactory.makeWeakPtr(); } - -private: - void loadDescription(FileSource&) final; - Mutable<Impl> mutableImpl() const; mapbox::base::WeakPtrFactory<Source> weakFactory {this}; }; diff --git a/src/mbgl/style/sources/custom_geometry_source.cpp b/src/mbgl/style/sources/custom_geometry_source.cpp index 73675c056f..5576277de8 100644 --- a/src/mbgl/style/sources/custom_geometry_source.cpp +++ b/src/mbgl/style/sources/custom_geometry_source.cpp @@ -1,12 +1,14 @@ -#include <mbgl/style/sources/custom_geometry_source.hpp> -#include <mbgl/style/custom_tile_loader.hpp> -#include <mbgl/style/sources/custom_geometry_source_impl.hpp> -#include <mbgl/style/source_observer.hpp> +#include <cstring> +#include <map> #include <mbgl/actor/actor.hpp> #include <mbgl/actor/scheduler.hpp> +#include <mbgl/style/custom_tile_loader.hpp> +#include <mbgl/style/layer.hpp> +#include <mbgl/style/source_observer.hpp> +#include <mbgl/style/sources/custom_geometry_source.hpp> +#include <mbgl/style/sources/custom_geometry_source_impl.hpp> #include <mbgl/tile/tile_id.hpp> #include <tuple> -#include <map> namespace mbgl { namespace style { @@ -29,6 +31,12 @@ void CustomGeometrySource::loadDescription(FileSource&) { observer->onSourceLoaded(*this); } +bool CustomGeometrySource::supportsLayerType(const mbgl::style::LayerTypeInfo* info) const { + return !std::strcmp(info->type, "line") || !std::strcmp(info->type, "symbol") || + !std::strcmp(info->type, "circle") || !std::strcmp(info->type, "fill") || + !std::strcmp(info->type, "fill-extrusion") || !std::strcmp(info->type, "heatmap"); +} + void CustomGeometrySource::setTileData(const CanonicalTileID& tileID, const GeoJSON& data) { loader->self().invoke(&CustomTileLoader::setTileData, tileID, data); diff --git a/src/mbgl/style/sources/geojson_source.cpp b/src/mbgl/style/sources/geojson_source.cpp index 72a51e212f..b1a5dd981a 100644 --- a/src/mbgl/style/sources/geojson_source.cpp +++ b/src/mbgl/style/sources/geojson_source.cpp @@ -1,9 +1,10 @@ +#include <mbgl/storage/file_source.hpp> +#include <mbgl/style/conversion/geojson.hpp> +#include <mbgl/style/conversion/json.hpp> +#include <mbgl/style/layer.hpp> +#include <mbgl/style/source_observer.hpp> #include <mbgl/style/sources/geojson_source.hpp> #include <mbgl/style/sources/geojson_source_impl.hpp> -#include <mbgl/style/source_observer.hpp> -#include <mbgl/style/conversion/json.hpp> -#include <mbgl/style/conversion/geojson.hpp> -#include <mbgl/storage/file_source.hpp> #include <mbgl/util/logging.hpp> namespace mbgl { @@ -78,5 +79,11 @@ void GeoJSONSource::loadDescription(FileSource& fileSource) { }); } +bool GeoJSONSource::supportsLayerType(const mbgl::style::LayerTypeInfo* info) const { + return !std::strcmp(info->type, "line") || !std::strcmp(info->type, "symbol") || + !std::strcmp(info->type, "circle") || !std::strcmp(info->type, "fill") || + !std::strcmp(info->type, "fill-extrusion") || !std::strcmp(info->type, "heatmap"); +} + } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/sources/image_source.cpp b/src/mbgl/style/sources/image_source.cpp index fa268da0ef..abd01af701 100644 --- a/src/mbgl/style/sources/image_source.cpp +++ b/src/mbgl/style/sources/image_source.cpp @@ -1,9 +1,10 @@ +#include <mbgl/storage/file_source.hpp> +#include <mbgl/style/layer.hpp> +#include <mbgl/style/source_observer.hpp> #include <mbgl/style/sources/image_source.hpp> #include <mbgl/style/sources/image_source_impl.hpp> #include <mbgl/util/geo.hpp> -#include <mbgl/style/source_observer.hpp> #include <mbgl/util/premultiply.hpp> -#include <mbgl/storage/file_source.hpp> namespace mbgl { namespace style { @@ -80,5 +81,9 @@ void ImageSource::loadDescription(FileSource& fileSource) { }); } +bool ImageSource::supportsLayerType(const mbgl::style::LayerTypeInfo* info) const { + return !std::strcmp(info->type, "raster"); +} + } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/sources/raster_dem_source.cpp b/src/mbgl/style/sources/raster_dem_source.cpp index bb745561b1..724a322917 100644 --- a/src/mbgl/style/sources/raster_dem_source.cpp +++ b/src/mbgl/style/sources/raster_dem_source.cpp @@ -1,8 +1,9 @@ -#include <mbgl/style/sources/raster_dem_source.hpp> -#include <mbgl/style/sources/raster_source_impl.hpp> -#include <mbgl/style/source_observer.hpp> #include <mbgl/style/conversion/json.hpp> #include <mbgl/style/conversion/tileset.hpp> +#include <mbgl/style/layer.hpp> +#include <mbgl/style/source_observer.hpp> +#include <mbgl/style/sources/raster_dem_source.hpp> +#include <mbgl/style/sources/raster_source_impl.hpp> #include <mbgl/util/mapbox.hpp> namespace mbgl { @@ -12,5 +13,9 @@ RasterDEMSource::RasterDEMSource(std::string id, variant<std::string, Tileset> u : RasterSource(std::move(id), urlOrTileset_, tileSize, SourceType::RasterDEM){ } +bool RasterDEMSource::supportsLayerType(const mbgl::style::LayerTypeInfo* info) const { + return !std::strcmp(info->type, "hillshade"); +} + } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/sources/raster_source.cpp b/src/mbgl/style/sources/raster_source.cpp index 115887d004..c758a7bc8b 100644 --- a/src/mbgl/style/sources/raster_source.cpp +++ b/src/mbgl/style/sources/raster_source.cpp @@ -1,11 +1,12 @@ -#include <mbgl/style/sources/raster_source.hpp> -#include <mbgl/style/sources/raster_source_impl.hpp> -#include <mbgl/style/source_observer.hpp> +#include <mbgl/storage/file_source.hpp> #include <mbgl/style/conversion/json.hpp> #include <mbgl/style/conversion/tileset.hpp> -#include <mbgl/storage/file_source.hpp> -#include <mbgl/util/mapbox.hpp> +#include <mbgl/style/layer.hpp> +#include <mbgl/style/source_observer.hpp> +#include <mbgl/style/sources/raster_source.hpp> +#include <mbgl/style/sources/raster_source_impl.hpp> #include <mbgl/util/exception.hpp> +#include <mbgl/util/mapbox.hpp> namespace mbgl { namespace style { @@ -80,5 +81,9 @@ void RasterSource::loadDescription(FileSource& fileSource) { }); } +bool RasterSource::supportsLayerType(const mbgl::style::LayerTypeInfo* info) const { + return !std::strcmp(info->type, "raster"); +} + } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/sources/vector_source.cpp b/src/mbgl/style/sources/vector_source.cpp index a69ff632d8..7cb89a9474 100644 --- a/src/mbgl/style/sources/vector_source.cpp +++ b/src/mbgl/style/sources/vector_source.cpp @@ -1,12 +1,13 @@ -#include <mbgl/style/sources/vector_source.hpp> -#include <mbgl/style/sources/vector_source_impl.hpp> -#include <mbgl/style/source_observer.hpp> +#include <mbgl/storage/file_source.hpp> #include <mbgl/style/conversion/json.hpp> #include <mbgl/style/conversion/tileset.hpp> -#include <mbgl/storage/file_source.hpp> -#include <mbgl/util/mapbox.hpp> +#include <mbgl/style/layer.hpp> +#include <mbgl/style/source_observer.hpp> +#include <mbgl/style/sources/vector_source.hpp> +#include <mbgl/style/sources/vector_source_impl.hpp> #include <mbgl/util/constants.hpp> #include <mbgl/util/exception.hpp> +#include <mbgl/util/mapbox.hpp> namespace mbgl { namespace style { @@ -84,5 +85,11 @@ void VectorSource::loadDescription(FileSource& fileSource) { }); } +bool VectorSource::supportsLayerType(const mbgl::style::LayerTypeInfo* info) const { + return !std::strcmp(info->type, "line") || !std::strcmp(info->type, "symbol") || + !std::strcmp(info->type, "circle") || !std::strcmp(info->type, "fill") || + !std::strcmp(info->type, "fill-extrusion") || !std::strcmp(info->type, "heatmap"); +} + } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/style_impl.cpp b/src/mbgl/style/style_impl.cpp index d3298c5cac..95a39819fc 100644 --- a/src/mbgl/style/style_impl.cpp +++ b/src/mbgl/style/style_impl.cpp @@ -1,26 +1,27 @@ -#include <mbgl/style/style_impl.hpp> -#include <mbgl/style/observer.hpp> -#include <mbgl/style/source_impl.hpp> -#include <mbgl/style/layers/symbol_layer.hpp> -#include <mbgl/style/layers/custom_layer.hpp> +#include <mbgl/sprite/sprite_loader.hpp> +#include <mbgl/storage/file_source.hpp> +#include <mbgl/storage/resource.hpp> +#include <mbgl/storage/response.hpp> +#include <mbgl/style/layer_impl.hpp> #include <mbgl/style/layers/background_layer.hpp> -#include <mbgl/style/layers/fill_layer.hpp> +#include <mbgl/style/layers/circle_layer.hpp> +#include <mbgl/style/layers/custom_layer.hpp> #include <mbgl/style/layers/fill_extrusion_layer.hpp> +#include <mbgl/style/layers/fill_layer.hpp> #include <mbgl/style/layers/heatmap_layer.hpp> +#include <mbgl/style/layers/hillshade_layer.hpp> #include <mbgl/style/layers/line_layer.hpp> -#include <mbgl/style/layers/circle_layer.hpp> #include <mbgl/style/layers/raster_layer.hpp> -#include <mbgl/style/layers/hillshade_layer.hpp> -#include <mbgl/style/layer_impl.hpp> +#include <mbgl/style/layers/symbol_layer.hpp> +#include <mbgl/style/observer.hpp> #include <mbgl/style/parser.hpp> +#include <mbgl/style/source_impl.hpp> +#include <mbgl/style/style_impl.hpp> #include <mbgl/style/transition_options.hpp> -#include <mbgl/sprite/sprite_loader.hpp> #include <mbgl/util/exception.hpp> -#include <mbgl/util/string.hpp> #include <mbgl/util/logging.hpp> -#include <mbgl/storage/file_source.hpp> -#include <mbgl/storage/resource.hpp> -#include <mbgl/storage/response.hpp> +#include <mbgl/util/string.hpp> +#include <sstream> namespace mbgl { namespace style { @@ -177,6 +178,15 @@ Layer* Style::Impl::getLayer(const std::string& id) const { Layer* Style::Impl::addLayer(std::unique_ptr<Layer> layer, optional<std::string> before) { // TODO: verify source + if (Source* source = sources.get(layer->getSourceID())) { + if (!source->supportsLayerType(layer->baseImpl->getTypeInfo())) { + std::ostringstream message; + message << "Layer '" << layer->getID() << "' is not compatible with source '" << layer->getSourceID() + << "'"; + + throw std::runtime_error(message.str()); + } + } if (layers.get(layer->getID())) { throw std::runtime_error(std::string{"Layer "} + layer->getID() + " already exists"); |