diff options
-rw-r--r-- | cmake/core-files.cmake | 7 | ||||
-rw-r--r-- | include/mbgl/style/conversion/coordinate.hpp | 37 | ||||
-rw-r--r-- | include/mbgl/style/conversion/source.hpp | 47 | ||||
-rw-r--r-- | include/mbgl/style/sources/image_source.hpp | 30 | ||||
-rw-r--r-- | include/mbgl/style/types.hpp | 3 | ||||
-rw-r--r-- | include/mbgl/util/geo.hpp | 2 | ||||
-rw-r--r-- | platform/default/mbgl/storage/offline_download.cpp | 4 | ||||
-rw-r--r-- | src/mbgl/style/parser.cpp | 11 | ||||
-rw-r--r-- | src/mbgl/style/sources/image_source.cpp | 22 | ||||
-rw-r--r-- | src/mbgl/style/sources/image_source_impl.cpp | 41 | ||||
-rw-r--r-- | src/mbgl/style/sources/image_source_impl.hpp | 36 | ||||
-rw-r--r-- | src/mbgl/style/types.cpp | 1 | ||||
-rw-r--r-- | test/fixtures/style_parser/center-not-latlong.info.json | 7 | ||||
-rw-r--r-- | test/fixtures/style_parser/center-not-latlong.style.json | 4 | ||||
-rw-r--r-- | test/fixtures/style_parser/image-coordinates.info.json | 7 | ||||
-rw-r--r-- | test/fixtures/style_parser/image-coordinates.style.json | 14 | ||||
-rw-r--r-- | test/fixtures/style_parser/image-url.info.json | 7 | ||||
-rw-r--r-- | test/fixtures/style_parser/image-url.style.json | 9 |
18 files changed, 282 insertions, 7 deletions
diff --git a/cmake/core-files.cmake b/cmake/core-files.cmake index dfe11b82b8..fbc300f5e8 100644 --- a/cmake/core-files.cmake +++ b/cmake/core-files.cmake @@ -72,6 +72,8 @@ set(MBGL_CORE_FILES src/mbgl/gl/object.hpp src/mbgl/gl/primitives.hpp src/mbgl/gl/program.hpp + src/mbgl/gl/program_binary.cpp + src/mbgl/gl/program_binary.hpp src/mbgl/gl/program_binary_extension.hpp src/mbgl/gl/renderbuffer.hpp src/mbgl/gl/segment.cpp @@ -357,6 +359,7 @@ set(MBGL_CORE_FILES # style/conversion include/mbgl/style/conversion/constant.hpp + include/mbgl/style/conversion/coordinate.hpp include/mbgl/style/conversion/data_driven_property_value.hpp include/mbgl/style/conversion/filter.hpp include/mbgl/style/conversion/function.hpp @@ -439,11 +442,15 @@ set(MBGL_CORE_FILES # style/sources include/mbgl/style/sources/geojson_source.hpp + include/mbgl/style/sources/image_source.hpp include/mbgl/style/sources/raster_source.hpp include/mbgl/style/sources/vector_source.hpp src/mbgl/style/sources/geojson_source.cpp src/mbgl/style/sources/geojson_source_impl.cpp src/mbgl/style/sources/geojson_source_impl.hpp + src/mbgl/style/sources/image_source.cpp + src/mbgl/style/sources/image_source_impl.cpp + src/mbgl/style/sources/image_source_impl.hpp src/mbgl/style/sources/raster_source.cpp src/mbgl/style/sources/raster_source_impl.cpp src/mbgl/style/sources/raster_source_impl.hpp diff --git a/include/mbgl/style/conversion/coordinate.hpp b/include/mbgl/style/conversion/coordinate.hpp new file mode 100644 index 0000000000..0adbb9a7ee --- /dev/null +++ b/include/mbgl/style/conversion/coordinate.hpp @@ -0,0 +1,37 @@ +#pragma once + +#include <mbgl/style/conversion.hpp> +#include <mbgl/util/geo.hpp> + +namespace mbgl { +namespace style { +namespace conversion { + +template<> +struct Converter<std::unique_ptr<LatLng>> { +public: + template <class V> + optional<std::unique_ptr<LatLng>> operator() (const V& value, Error& error) const { + if (!isArray(value) || arrayLength(value) < 2 ) { + error = { "coordinate array must contain numeric longtitude and latitude values" }; + return {}; + } + //Style spec uses GeoJSON convention for specifying coordinates + optional<float> latitude = toNumber(arrayMember(value, 1)); + optional<float> longitude = toNumber(arrayMember(value, 0)); + + if (!latitude || !longitude) { + error = { "coordinate array must contain numeric longtitude and latitude values" }; + return {}; + } + if (*latitude < -90 || *latitude > 90 ){ + error = { "coordinate latitude must be between -90 and 90" }; + return {}; + } + return { std::make_unique<LatLng>(*latitude, *longitude) }; + } +}; + +} // namespace conversion +} // namespace style +} // namespace mbgl diff --git a/include/mbgl/style/conversion/source.hpp b/include/mbgl/style/conversion/source.hpp index dc7cdc0d42..7c0f0eec70 100644 --- a/include/mbgl/style/conversion/source.hpp +++ b/include/mbgl/style/conversion/source.hpp @@ -1,6 +1,7 @@ #pragma once #include <mbgl/style/conversion.hpp> +#include <mbgl/style/conversion/coordinate.hpp> #include <mbgl/style/conversion/geojson.hpp> #include <mbgl/style/conversion/geojson_options.hpp> #include <mbgl/style/conversion/tileset.hpp> @@ -8,6 +9,8 @@ #include <mbgl/style/sources/geojson_source.hpp> #include <mbgl/style/sources/raster_source.hpp> #include <mbgl/style/sources/vector_source.hpp> +#include <mbgl/style/sources/image_source.hpp> +#include <mbgl/util/geo.hpp> namespace mbgl { namespace style { @@ -16,6 +19,7 @@ namespace conversion { template <> struct Converter<std::unique_ptr<Source>> { public: + template <class V> optional<std::unique_ptr<Source>> operator()(const V& value, Error& error, const std::string& id) const { if (!isObject(value)) { @@ -41,6 +45,8 @@ public: return convertVectorSource(id, value, error); } else if (*type == "geojson") { return convertGeoJSONSource(id, value, error); + } else if (*type == "image") { + return convertImageSource(id, value, error); } else { error = { "invalid source type" }; return {}; @@ -136,6 +142,47 @@ private: return { std::move(result) }; } + + template <class V> + optional<std::unique_ptr<Source>> convertImageSource(const std::string& id, + const V& value, + Error& error) const { + auto urlValue = objectMember(value, "url"); + if (!urlValue) { + error = { "Image source must have a url value" }; + return {}; + } + + auto urlString = toString(*urlValue); + if (!urlString) { + error = { "Image url must be a URL string" }; + return {}; + } + + auto result = std::make_unique<ImageSource>(id, *urlString); + + auto coordinatesValue = objectMember(value, "coordinates"); + if (!coordinatesValue) { + error = { "Image source must have a coordinates values" }; + return {}; + } + + if (!isArray(*coordinatesValue) || arrayLength(*coordinatesValue) != 4) { + error = { "Image coordinates must be an array of four longitude latitude pairs" }; + return {}; + } + + std::vector<std::unique_ptr<LatLng>> coordinates; + coordinates.reserve(4); + for( std::size_t i=0; i < arrayLength(*coordinatesValue); i++) { + auto latLng = conversion::convert<std::unique_ptr<LatLng>>(arrayMember(*coordinatesValue,i), error); + if (!latLng) { + return {}; + } + coordinates.push_back(std::move(*latLng)); + } + return { std::move(result) }; + } }; } // namespace conversion diff --git a/include/mbgl/style/sources/image_source.hpp b/include/mbgl/style/sources/image_source.hpp new file mode 100644 index 0000000000..63ca8842ac --- /dev/null +++ b/include/mbgl/style/sources/image_source.hpp @@ -0,0 +1,30 @@ +#pragma once + +#include <mbgl/style/source.hpp> + +namespace mbgl { +namespace style { + +class ImageSource : public Source { +public: + ImageSource(std::string id, const std::string& url); + + const std::string& getURL() const; + void setURL(const std::string& url) ; + +// void setCoordinates(const std::vector&); +// optional<std::vector> getCoordinates() const; + + // Private implementation + + class Impl; + Impl* const impl; +}; + +template <> +inline bool Source::is<ImageSource>() const { + return type == SourceType::Vector; +} + +} // namespace style +} // namespace mbgl diff --git a/include/mbgl/style/types.hpp b/include/mbgl/style/types.hpp index e0436efb67..44b16f16e7 100644 --- a/include/mbgl/style/types.hpp +++ b/include/mbgl/style/types.hpp @@ -10,7 +10,8 @@ enum class SourceType : uint8_t { Raster, GeoJSON, Video, - Annotations + Annotations, + Image }; namespace style { diff --git a/include/mbgl/util/geo.hpp b/include/mbgl/util/geo.hpp index 6d725b102b..e9e7c86d0b 100644 --- a/include/mbgl/util/geo.hpp +++ b/include/mbgl/util/geo.hpp @@ -47,7 +47,7 @@ public: wrap(); } } - + double latitude() const { return lat; } double longitude() const { return lon; } diff --git a/platform/default/mbgl/storage/offline_download.cpp b/platform/default/mbgl/storage/offline_download.cpp index 235baac12c..b0494882bb 100644 --- a/platform/default/mbgl/storage/offline_download.cpp +++ b/platform/default/mbgl/storage/offline_download.cpp @@ -120,6 +120,7 @@ OfflineRegionStatus OfflineDownload::getStatus() const { case SourceType::Video: case SourceType::Annotations: + case SourceType::Image: break; } } @@ -197,7 +198,8 @@ void OfflineDownload::activateDownload() { case SourceType::Video: case SourceType::Annotations: - break; + case SourceType::Image: + break; } } diff --git a/src/mbgl/style/parser.cpp b/src/mbgl/style/parser.cpp index ea96bda502..0a472b602d 100644 --- a/src/mbgl/style/parser.cpp +++ b/src/mbgl/style/parser.cpp @@ -2,6 +2,7 @@ #include <mbgl/style/layer_impl.hpp> #include <mbgl/style/rapidjson_conversion.hpp> #include <mbgl/style/conversion.hpp> +#include <mbgl/style/conversion/coordinate.hpp> #include <mbgl/style/conversion/source.hpp> #include <mbgl/style/conversion/layer.hpp> #include <mbgl/style/conversion/light.hpp> @@ -55,10 +56,12 @@ StyleParseResult Parser::parse(const std::string& json) { if (document.HasMember("center")) { const JSValue& value = document["center"]; - if (value.IsArray() && value.Size() >= 2) { - // Style spec uses lon/lat order - latLng = LatLng(value[1].IsNumber() ? value[1].GetDouble() : 0, - value[0].IsNumber() ? value[0].GetDouble() : 0); + conversion::Error error; + auto convertedLatLng = conversion::convert<std::unique_ptr<LatLng>>(value, error); + if (convertedLatLng) { + latLng = LatLng((*convertedLatLng)->latitude(), (*convertedLatLng)->longitude()); + } else { + Log::Warning(Event::ParseStyle, "center coordinate must be a longitude, latitude pair"); } } diff --git a/src/mbgl/style/sources/image_source.cpp b/src/mbgl/style/sources/image_source.cpp new file mode 100644 index 0000000000..16ec5d3098 --- /dev/null +++ b/src/mbgl/style/sources/image_source.cpp @@ -0,0 +1,22 @@ +#include <mbgl/style/sources/image_source.hpp> +#include <mbgl/style/sources/image_source_impl.hpp> + +namespace mbgl { + namespace style { + + ImageSource::ImageSource(std::string id, const std::string& url) + : Source(SourceType::Image, + std::make_unique<ImageSource::Impl>(std::move(id), *this, url)), + impl(static_cast<Impl*>(baseImpl.get())) { + } + + void ImageSource::setURL(const std::string& url) { + impl->setURL(url); + } + + const std::string& ImageSource::getURL() const { + return impl->getURL(); + } + + } // namespace style +} // namespace mbgl diff --git a/src/mbgl/style/sources/image_source_impl.cpp b/src/mbgl/style/sources/image_source_impl.cpp new file mode 100644 index 0000000000..c371f8c3e1 --- /dev/null +++ b/src/mbgl/style/sources/image_source_impl.cpp @@ -0,0 +1,41 @@ +#include <mbgl/util/logging.hpp> +#include <mbgl/storage/file_source.hpp> +#include <mbgl/style/source_observer.hpp> +#include <mbgl/style/sources/image_source_impl.hpp> + +#include <sstream> + +namespace mbgl { +namespace style { + +ImageSource::Impl::Impl(std::string id_, Source& base_, const std::string& url) + : Source::Impl(SourceType::Image, std::move(id_), base_), url(url) { +} + +ImageSource::Impl::~Impl() = default; + +void ImageSource::Impl::setURL(std::string url_) { + url = std::move(url_); +} + +const std::string& ImageSource::Impl::getURL() const { + return url; +} + +void ImageSource::Impl::loadDescription(FileSource&) { +} + +optional<Range<uint8_t>> ImageSource::Impl::getZoomRange() const { + //TODO: AHM + return {}; +} + +std::unique_ptr<Tile> ImageSource::Impl::createTile(const OverscaledTileID& , + const UpdateParameters& ) { + //TODO: AHM + assert(loaded); + return {}; +} + +} // namespace style +} // namespace mbgl diff --git a/src/mbgl/style/sources/image_source_impl.hpp b/src/mbgl/style/sources/image_source_impl.hpp new file mode 100644 index 0000000000..cceeb186fa --- /dev/null +++ b/src/mbgl/style/sources/image_source_impl.hpp @@ -0,0 +1,36 @@ +#pragma once + +#include <mbgl/style/source_impl.hpp> +#include <mbgl/style/sources/image_source.hpp> + +namespace mbgl { + +class AsyncRequest; + +namespace style { + +class ImageSource::Impl : public Source::Impl { +public: + Impl(std::string id, Source&, const std::string& url); + ~Impl() final; + + void setURL(std::string); + const std::string& getURL() const; + + void loadDescription(FileSource&) final; + + uint16_t getTileSize() const final { + return util::tileSize; + } + + optional<Range<uint8_t>> getZoomRange() const final; + +private: + std::string url; + std::unique_ptr<AsyncRequest> req; + std::unique_ptr<Tile> createTile(const OverscaledTileID& tileID, const UpdateParameters& parameters) final; + +}; + +} // namespace style +} // namespace mbgl diff --git a/src/mbgl/style/types.cpp b/src/mbgl/style/types.cpp index b37e73ffb1..4fbf767e11 100644 --- a/src/mbgl/style/types.cpp +++ b/src/mbgl/style/types.cpp @@ -11,6 +11,7 @@ MBGL_DEFINE_ENUM(SourceType, { { SourceType::GeoJSON, "geojson" }, { SourceType::Video, "video" }, { SourceType::Annotations, "annotations" }, + { SourceType::Image, "image" }, }); MBGL_DEFINE_ENUM(VisibilityType, { diff --git a/test/fixtures/style_parser/center-not-latlong.info.json b/test/fixtures/style_parser/center-not-latlong.info.json new file mode 100644 index 0000000000..c79de0a525 --- /dev/null +++ b/test/fixtures/style_parser/center-not-latlong.info.json @@ -0,0 +1,7 @@ +{ + "default": { + "log": [ + [1, "WARNING", "ParseStyle", "center coordinate must be a longitude, latitude pair"] + ] + } +}
\ No newline at end of file diff --git a/test/fixtures/style_parser/center-not-latlong.style.json b/test/fixtures/style_parser/center-not-latlong.style.json new file mode 100644 index 0000000000..eb847868f5 --- /dev/null +++ b/test/fixtures/style_parser/center-not-latlong.style.json @@ -0,0 +1,4 @@ +{ + "version": 8, + "center" : [ 75.123, 181.123] +}
\ No newline at end of file diff --git a/test/fixtures/style_parser/image-coordinates.info.json b/test/fixtures/style_parser/image-coordinates.info.json new file mode 100644 index 0000000000..5ef44badba --- /dev/null +++ b/test/fixtures/style_parser/image-coordinates.info.json @@ -0,0 +1,7 @@ +{ + "default": { + "log": [ + [1, "WARNING", "ParseStyle", "Image coordinates must be an array of four longitude latitude pairs"] + ] + } +}
\ No newline at end of file diff --git a/test/fixtures/style_parser/image-coordinates.style.json b/test/fixtures/style_parser/image-coordinates.style.json new file mode 100644 index 0000000000..51b0e93ee7 --- /dev/null +++ b/test/fixtures/style_parser/image-coordinates.style.json @@ -0,0 +1,14 @@ +{ + "version": 8, + "center" : [ 75.123, 81.123], + "sources": { + "image": { + "type": "image", + "url": "local://0.png", + "coordinates": [ + [ 12.2344, 87.23434], + [-12.234, 12.41242] + ] + } + } +}
\ No newline at end of file diff --git a/test/fixtures/style_parser/image-url.info.json b/test/fixtures/style_parser/image-url.info.json new file mode 100644 index 0000000000..988e89c011 --- /dev/null +++ b/test/fixtures/style_parser/image-url.info.json @@ -0,0 +1,7 @@ +{ + "default": { + "log": [ + [1, "WARNING", "ParseStyle", "Image source must have a url value"] + ] + } +}
\ No newline at end of file diff --git a/test/fixtures/style_parser/image-url.style.json b/test/fixtures/style_parser/image-url.style.json new file mode 100644 index 0000000000..94614cb7ab --- /dev/null +++ b/test/fixtures/style_parser/image-url.style.json @@ -0,0 +1,9 @@ +{ + "version": 8, + "center" : [ 75.123, 81.123], + "sources": { + "image": { + "type": "image" + } + } +}
\ No newline at end of file |