summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsheem Mamoowala <asheem.mamoowala@mapbox.com>2017-05-03 18:49:22 -0700
committerAsheem Mamoowala <asheem.mamoowala@mapbox.com>2017-05-18 16:29:06 -0700
commit2600303750ad48daf6117b051b4e6689c8d0dd51 (patch)
treec1af06a6d263d36b120da0715f0140778ff6b6f4
parentdb63b776e2c72ce1f5a7b02f1fe2dd2dca3b4468 (diff)
downloadqtlocation-mapboxgl-2600303750ad48daf6117b051b4e6689c8d0dd51.tar.gz
Add parsed coordinates to ImageSource::Impl
-rw-r--r--include/mbgl/style/conversion/source.hpp8
-rw-r--r--include/mbgl/style/sources/image_source.hpp12
-rw-r--r--src/mbgl/renderer/sources/render_image_source.cpp64
-rw-r--r--src/mbgl/renderer/sources/render_image_source.hpp44
-rw-r--r--src/mbgl/style/sources/image_source.cpp40
-rw-r--r--src/mbgl/style/sources/image_source_impl.cpp54
-rw-r--r--src/mbgl/style/sources/image_source_impl.hpp18
7 files changed, 194 insertions, 46 deletions
diff --git a/include/mbgl/style/conversion/source.hpp b/include/mbgl/style/conversion/source.hpp
index 7c0f0eec70..681d01c054 100644
--- a/include/mbgl/style/conversion/source.hpp
+++ b/include/mbgl/style/conversion/source.hpp
@@ -159,8 +159,6 @@ private:
return {};
}
- auto result = std::make_unique<ImageSource>(id, *urlString);
-
auto coordinatesValue = objectMember(value, "coordinates");
if (!coordinatesValue) {
error = { "Image source must have a coordinates values" };
@@ -172,15 +170,17 @@ private:
return {};
}
- std::vector<std::unique_ptr<LatLng>> coordinates;
+ std::vector<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));
+ coordinates.push_back(std::move(**latLng));
}
+ auto result = std::make_unique<ImageSource>(id, *urlString, coordinates);
+
return { std::move(result) };
}
};
diff --git a/include/mbgl/style/sources/image_source.hpp b/include/mbgl/style/sources/image_source.hpp
index 63ca8842ac..92ba8b3373 100644
--- a/include/mbgl/style/sources/image_source.hpp
+++ b/include/mbgl/style/sources/image_source.hpp
@@ -3,20 +3,20 @@
#include <mbgl/style/source.hpp>
namespace mbgl {
+class LatLng;
+
namespace style {
-
+
class ImageSource : public Source {
public:
- ImageSource(std::string id, const std::string& url);
+ ImageSource(std::string id, const std::string& url, const std::vector<LatLng>);
const std::string& getURL() const;
void setURL(const std::string& url) ;
-// void setCoordinates(const std::vector&);
-// optional<std::vector> getCoordinates() const;
-
- // Private implementation
+ void setCoordinates(const std::vector<LatLng>);
+ // Private implementation
class Impl;
Impl* const impl;
};
diff --git a/src/mbgl/renderer/sources/render_image_source.cpp b/src/mbgl/renderer/sources/render_image_source.cpp
new file mode 100644
index 0000000000..555c64f24e
--- /dev/null
+++ b/src/mbgl/renderer/sources/render_image_source.cpp
@@ -0,0 +1,64 @@
+#include <mbgl/renderer/sources/render_image_source.hpp>
+#include <mbgl/renderer/render_tile.hpp>
+#include <mbgl/algorithm/generate_clip_ids.hpp>
+#include <mbgl/algorithm/generate_clip_ids_impl.hpp>
+
+namespace mbgl {
+
+using namespace style;
+
+RenderImageSource::RenderImageSource(const style::ImageSource::Impl& impl_)
+: RenderSource(impl_),
+impl(impl_) {
+}
+
+bool RenderImageSource::isLoaded() const {
+ return false;
+}
+
+void RenderImageSource::startRender(algorithm::ClipIDGenerator& ,
+ const mat4& , const mat4& , const TransformState& ) {
+ impl.getData();
+}
+
+void RenderImageSource::finishRender(Painter& ) {
+}
+
+std::unordered_map<std::string, std::vector<Feature>>
+RenderImageSource::queryRenderedFeatures(const ScreenLineString& ,
+ const TransformState& ,
+ const RenderedQueryOptions& ) const {
+ return {};
+}
+
+std::vector<Feature> RenderImageSource::querySourceFeatures(const SourceQueryOptions& ) const {
+ return {};
+}
+
+void RenderImageSource::removeTiles() {
+
+}
+
+void RenderImageSource::updateTiles(const TileParameters&) {
+}
+
+void RenderImageSource::reloadTiles() {
+}
+
+void RenderImageSource::invalidateTiles() {
+}
+
+std::map<UnwrappedTileID, RenderTile>& RenderImageSource::getRenderTiles() {
+ return tiles;
+}
+
+void RenderImageSource::setCacheSize(size_t ) {
+}
+
+void RenderImageSource::onLowMemory() {
+}
+
+void RenderImageSource::dumpDebugLogs() const {
+}
+
+} // namespace mbgl
diff --git a/src/mbgl/renderer/sources/render_image_source.hpp b/src/mbgl/renderer/sources/render_image_source.hpp
new file mode 100644
index 0000000000..bc4003a22e
--- /dev/null
+++ b/src/mbgl/renderer/sources/render_image_source.hpp
@@ -0,0 +1,44 @@
+#pragma once
+
+#include <mbgl/renderer/render_source.hpp>
+#include <mbgl/style/sources/image_source_impl.hpp>
+
+namespace mbgl {
+
+class RenderImageSource : public RenderSource {
+public:
+ RenderImageSource(const style::ImageSource::Impl&);
+
+ bool isLoaded() const final;
+
+ void startRender(algorithm::ClipIDGenerator&,
+ const mat4& projMatrix,
+ const mat4& clipMatrix,
+ const TransformState&) final;
+ void finishRender(Painter&) final;
+
+ void updateTiles(const TileParameters&);
+ void removeTiles();
+ void invalidateTiles();
+ void reloadTiles();
+
+ std::map<UnwrappedTileID, RenderTile>& getRenderTiles();
+
+ std::unordered_map<std::string, std::vector<Feature>>
+ queryRenderedFeatures(const ScreenLineString& geometry,
+ const TransformState& transformState,
+ const RenderedQueryOptions& options) const final;
+
+ std::vector<Feature>
+ querySourceFeatures(const SourceQueryOptions&) const final;
+
+ void setCacheSize(size_t) final;
+ void onLowMemory() final;
+ void dumpDebugLogs() const final;
+
+private:
+ const style::ImageSource::Impl& impl;
+ std::map<UnwrappedTileID, RenderTile> tiles;
+};
+
+} // namespace mbgl
diff --git a/src/mbgl/style/sources/image_source.cpp b/src/mbgl/style/sources/image_source.cpp
index 16ec5d3098..51e4f57e82 100644
--- a/src/mbgl/style/sources/image_source.cpp
+++ b/src/mbgl/style/sources/image_source.cpp
@@ -1,22 +1,28 @@
#include <mbgl/style/sources/image_source.hpp>
#include <mbgl/style/sources/image_source_impl.hpp>
+#include <mbgl/util/geo.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 style {
+
+ImageSource::ImageSource(std::string id, const std::string& url,
+ const std::vector<LatLng> coords)
+ : Source(SourceType::Image,
+ std::make_unique<ImageSource::Impl>(std::move(id), *this, url, coords)),
+ impl(static_cast<Impl*>(baseImpl.get())) {
+}
+
+void ImageSource::setCoordinates(const std::vector<LatLng> coords) {
+ impl->setCoordinates(coords);
+}
+
+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
index c371f8c3e1..b889895b8e 100644
--- a/src/mbgl/style/sources/image_source_impl.cpp
+++ b/src/mbgl/style/sources/image_source_impl.cpp
@@ -2,14 +2,21 @@
#include <mbgl/storage/file_source.hpp>
#include <mbgl/style/source_observer.hpp>
#include <mbgl/style/sources/image_source_impl.hpp>
+#include <mbgl/renderer/raster_bucket.hpp>
+#include <mbgl/util/premultiply.hpp>
+#include <mbgl/renderer/sources/render_image_source.hpp>
+#include <mbgl/renderer/render_tile.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(std::string id_, Source& base_, const std::string& url_,
+ const std::vector<LatLng>& coords_)
+ : Source::Impl(SourceType::Image, std::move(id_), base_),
+ url(url_),
+ coords(std::move(coords_)) {
}
ImageSource::Impl::~Impl() = default;
@@ -22,19 +29,44 @@ const std::string& ImageSource::Impl::getURL() const {
return url;
}
-void ImageSource::Impl::loadDescription(FileSource&) {
+void ImageSource::Impl::setCoordinates(const std::vector<LatLng> coords_) {
+ coords = std::move(coords_);
}
-optional<Range<uint8_t>> ImageSource::Impl::getZoomRange() const {
- //TODO: AHM
- return {};
+std::unique_ptr<RenderSource> ImageSource::Impl::createRenderSource() const {
+ return std::make_unique<RenderImageSource>(*this);
}
-std::unique_ptr<Tile> ImageSource::Impl::createTile(const OverscaledTileID& ,
- const UpdateParameters& ) {
- //TODO: AHM
- assert(loaded);
- return {};
+
+void ImageSource::Impl::loadDescription(FileSource& fileSource) {
+
+ if (req) {
+ return;
+ }
+
+ req = fileSource.request(Resource::source(url), [this](Response res) {
+ if (res.error) {
+ observer->onSourceError(base, std::make_exception_ptr(std::runtime_error(res.error->message)));
+ } else if (res.notModified) {
+ return;
+ } else if (res.noContent) {
+ observer->onSourceError(base, std::make_exception_ptr(std::runtime_error("unexpectedly empty image url")));
+ } else {
+ try {
+ image = std::make_unique<mbgl::UnassociatedImage>(util::unpremultiply(decodeImage(*res.data)));
+ } catch (...) {
+ observer->onSourceError(base, std::current_exception());
+ }
+
+ loaded = true;
+
+ observer->onSourceLoaded(base);
+ }
+ });
+}
+
+mbgl::UnassociatedImage* ImageSource::Impl::getData() const {
+ return image.get();
}
} // namespace style
diff --git a/src/mbgl/style/sources/image_source_impl.hpp b/src/mbgl/style/sources/image_source_impl.hpp
index cceeb186fa..0f1be625b9 100644
--- a/src/mbgl/style/sources/image_source_impl.hpp
+++ b/src/mbgl/style/sources/image_source_impl.hpp
@@ -2,34 +2,36 @@
#include <mbgl/style/source_impl.hpp>
#include <mbgl/style/sources/image_source.hpp>
+#include <mbgl/util/image.hpp>
namespace mbgl {
class AsyncRequest;
+class RenderSource;
namespace style {
class ImageSource::Impl : public Source::Impl {
public:
- Impl(std::string id, Source&, const std::string& url);
+ Impl(std::string id, Source&, const std::string& url, const std::vector<LatLng>& coords);
+
~Impl() final;
void setURL(std::string);
const std::string& getURL() const;
+ void setCoordinates(const std::vector<LatLng> coords);
- void loadDescription(FileSource&) final;
+ mbgl::UnassociatedImage* getData() const;
- uint16_t getTileSize() const final {
- return util::tileSize;
- }
+ void loadDescription(FileSource&) final;
- optional<Range<uint8_t>> getZoomRange() const final;
+ std::unique_ptr<RenderSource> createRenderSource() const final;
private:
std::string url;
+ std::vector<LatLng> coords;
std::unique_ptr<AsyncRequest> req;
- std::unique_ptr<Tile> createTile(const OverscaledTileID& tileID, const UpdateParameters& parameters) final;
-
+ std::unique_ptr<mbgl::UnassociatedImage> image;
};
} // namespace style