summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsheem Mamoowala <asheem.mamoowala@mapbox.com>2017-05-12 14:59:48 -0700
committerAsheem Mamoowala <asheem.mamoowala@mapbox.com>2017-05-18 16:29:06 -0700
commitd8836a923009c80da21245bea95fcf6217f7425e (patch)
tree9cb897f0a5472af4eb71d4401a9fd7566d1cc871
parent8bb1861ba11d5073224f5de45e32177445aebee5 (diff)
downloadqtlocation-mapboxgl-d8836a923009c80da21245bea95fcf6217f7425e.tar.gz
ImageSource ctor requires coordinates, but not image/url
-rw-r--r--include/mbgl/style/conversion/source.hpp3
-rw-r--r--include/mbgl/style/sources/image_source.hpp2
-rw-r--r--src/mbgl/renderer/sources/render_image_source.cpp15
-rw-r--r--src/mbgl/renderer/sources/render_image_source.hpp2
-rw-r--r--src/mbgl/style/sources/image_source.cpp7
-rw-r--r--src/mbgl/style/sources/image_source_impl.cpp17
-rw-r--r--src/mbgl/style/sources/image_source_impl.hpp2
-rw-r--r--test/style/source.test.cpp3
8 files changed, 30 insertions, 21 deletions
diff --git a/include/mbgl/style/conversion/source.hpp b/include/mbgl/style/conversion/source.hpp
index a67c3e6b17..e121e36955 100644
--- a/include/mbgl/style/conversion/source.hpp
+++ b/include/mbgl/style/conversion/source.hpp
@@ -179,7 +179,8 @@ private:
}
coordinates.push_back(*latLng);
}
- auto result = std::make_unique<ImageSource>(id, *urlString, coordinates);
+ auto result = std::make_unique<ImageSource>(id, coordinates);
+ result->setURL(*urlString);
return { std::move(result) };
}
diff --git a/include/mbgl/style/sources/image_source.hpp b/include/mbgl/style/sources/image_source.hpp
index edc19a7e51..a0ea29175f 100644
--- a/include/mbgl/style/sources/image_source.hpp
+++ b/include/mbgl/style/sources/image_source.hpp
@@ -10,7 +10,7 @@ namespace style {
class ImageSource : public Source {
public:
- ImageSource(std::string id, const std::string& url, const std::vector<LatLng>);
+ ImageSource(std::string id, const std::vector<LatLng>);
const std::string& getURL() const;
void setURL(const std::string& url) ;
diff --git a/src/mbgl/renderer/sources/render_image_source.cpp b/src/mbgl/renderer/sources/render_image_source.cpp
index 21232ac22b..0f3cc2459a 100644
--- a/src/mbgl/renderer/sources/render_image_source.cpp
+++ b/src/mbgl/renderer/sources/render_image_source.cpp
@@ -14,12 +14,11 @@ using namespace style;
RenderImageSource::RenderImageSource(const style::ImageSource::Impl& impl_)
: RenderSource(impl_),
- impl(impl_),
- loaded(false) {
+ impl(impl_) {
}
bool RenderImageSource::isLoaded() const {
- return loaded;
+ return !!bucket;
}
void RenderImageSource::startRender(algorithm::ClipIDGenerator& ,
@@ -27,7 +26,7 @@ void RenderImageSource::startRender(algorithm::ClipIDGenerator& ,
const mat4& ,
const TransformState& transformState) {
- if (!loaded) {
+ if (!isLoaded()) {
return;
}
matrix::identity(matrix);
@@ -36,7 +35,7 @@ void RenderImageSource::startRender(algorithm::ClipIDGenerator& ,
}
void RenderImageSource::finishRender(Painter& painter) {
- if (!loaded) {
+ if (!isLoaded()) {
return;
}
painter.renderTileDebug(matrix);
@@ -105,14 +104,14 @@ void RenderImageSource::updateTiles(const TileParameters& parameters) {
auto gc = TileCoordinate::toGeometryCoordinate(tileCover[0], tc.p);
geomCoords.push_back(gc);
}
-
setupBucket(geomCoords);
-
- loaded = true;
}
void RenderImageSource::setupBucket(GeometryCoordinates& geomCoords) {
UnassociatedImage img = impl.getData().clone();
+ if (!img.valid()) {
+ return;
+ }
bucket = std::make_unique<RasterBucket>(std::move(img));
//Set Bucket Vertices, Indices, and segments
diff --git a/src/mbgl/renderer/sources/render_image_source.hpp b/src/mbgl/renderer/sources/render_image_source.hpp
index ac69933c49..f2835d0925 100644
--- a/src/mbgl/renderer/sources/render_image_source.hpp
+++ b/src/mbgl/renderer/sources/render_image_source.hpp
@@ -56,7 +56,7 @@ private:
void setupBucket(GeometryCoordinates& coordiantes);
const style::ImageSource::Impl& impl;
std::map<UnwrappedTileID, RenderTile> tiles;
- bool loaded;
+
std::unique_ptr<UnwrappedTileID> tileId;
std::unique_ptr<RasterBucket> bucket;
mat4 matrix;
diff --git a/src/mbgl/style/sources/image_source.cpp b/src/mbgl/style/sources/image_source.cpp
index 3034037c89..d2f26bc8d1 100644
--- a/src/mbgl/style/sources/image_source.cpp
+++ b/src/mbgl/style/sources/image_source.cpp
@@ -5,10 +5,9 @@
namespace mbgl {
namespace style {
-ImageSource::ImageSource(std::string id, const std::string& url,
- const std::vector<LatLng> coords)
+ImageSource::ImageSource(std::string id, const std::vector<LatLng> coords)
: Source(SourceType::Image,
- std::make_unique<ImageSource::Impl>(std::move(id), *this, url, coords)),
+ std::make_unique<ImageSource::Impl>(std::move(id), *this, coords)),
impl(static_cast<Impl*>(baseImpl.get())) {
}
@@ -20,7 +19,7 @@ void ImageSource::setURL(const std::string& url) {
impl->setURL(url);
}
- void ImageSource::setImage(mbgl::UnassociatedImage image) {
+void ImageSource::setImage(mbgl::UnassociatedImage image) {
impl->setImage(std::move(image));
}
diff --git a/src/mbgl/style/sources/image_source_impl.cpp b/src/mbgl/style/sources/image_source_impl.cpp
index 7022e3b95f..6268f8d068 100644
--- a/src/mbgl/style/sources/image_source_impl.cpp
+++ b/src/mbgl/style/sources/image_source_impl.cpp
@@ -12,10 +12,8 @@
namespace mbgl {
namespace style {
-ImageSource::Impl::Impl(std::string id_, Source& base_, const std::string& url_,
- const std::vector<LatLng>& coords_)
+ImageSource::Impl::Impl(std::string id_, Source& base_, const std::vector<LatLng>& coords_)
: Source::Impl(SourceType::Image, std::move(id_), base_),
- url(url_),
coords(std::move(coords_)) {
}
@@ -23,7 +21,12 @@ ImageSource::Impl::~Impl() = default;
void ImageSource::Impl::setURL(std::string url_) {
url = std::move(url_);
- observer->onSourceChanged(base);
+ // Signal that the source description needs a reload
+ if (loaded || req) {
+ loaded = false;
+ req.reset();
+ observer->onSourceDescriptionChanged(base);
+ }
}
const std::string& ImageSource::Impl::getURL() const {
@@ -41,6 +44,9 @@ std::vector<LatLng> ImageSource::Impl::getCoordinates() const {
void ImageSource::Impl::setImage(mbgl::UnassociatedImage image_) {
image = std::move(image_);
+ if (req) {
+ req.reset();
+ }
observer->onSourceChanged(base);
}
@@ -50,6 +56,9 @@ std::unique_ptr<RenderSource> ImageSource::Impl::createRenderSource() const {
void ImageSource::Impl::loadDescription(FileSource& fileSource) {
+ if (url.empty()) {
+ loaded = true;
+ }
if (req || loaded) {
return;
diff --git a/src/mbgl/style/sources/image_source_impl.hpp b/src/mbgl/style/sources/image_source_impl.hpp
index bcb14f05f8..a7ae53d2f6 100644
--- a/src/mbgl/style/sources/image_source_impl.hpp
+++ b/src/mbgl/style/sources/image_source_impl.hpp
@@ -13,7 +13,7 @@ namespace style {
class ImageSource::Impl : public Source::Impl {
public:
- Impl(std::string id, Source&, const std::string& url, const std::vector<LatLng>& coords);
+ Impl(std::string id, Source&, const std::vector<LatLng>& coords);
~Impl() final;
diff --git a/test/style/source.test.cpp b/test/style/source.test.cpp
index be7ab0e890..5327ee245c 100644
--- a/test/style/source.test.cpp
+++ b/test/style/source.test.cpp
@@ -456,7 +456,8 @@ TEST(Source, ImageSourceImageUpdate) {
};
std::vector<LatLng> coords;
- ImageSource source("source", "http://url", coords);
+ ImageSource source("source", coords);
+ source.setURL("http://url");
source.baseImpl->setObserver(&test.styleObserver);
// Load initial, so the source state will be loaded=true