[core][node] Support ImageSource#8968
Conversation
d6d17e4 to
32615d4
Compare
There was a problem hiding this comment.
👍 on subdirectories for buckets and layer. Can you submit that as an independent PR so that it's easily reviewable independently? Will also help minimize potential merge conflicts as these files are getting touched a lot right now.
There was a problem hiding this comment.
No need for unique_ptr here; LatLng is a value class.
There was a problem hiding this comment.
Nit: whitespace change.
There was a problem hiding this comment.
We'll need to add offline support for image sources -- it should download and store the image in the offline database.
There was a problem hiding this comment.
Whitespace: We're using for (std::size_t i = 0; i < arrayLength(*coordinatesValue); i++) {
There was a problem hiding this comment.
We could move the string into the constructor
There was a problem hiding this comment.
Nit: We're not indenting namespaces
There was a problem hiding this comment.
Whitespace: RenderSource* source;
There was a problem hiding this comment.
This should be either a non-const value (to enable move), or a const & to avoid two copies.
8da5ce5 to
ffff1c6
Compare
|
|
||
| class ImageSource : public Source { | ||
| public: | ||
| ImageSource(std::string id, const std::vector<LatLng>); |
There was a problem hiding this comment.
How come this isn't a LatLngBounds? Similarly, it's very hard to discern the coordinate order this way.
There was a problem hiding this comment.
Apparently an image source can be associated with any quadrilateral, not necessarily a rectangle.
mbgl tends to use std::array to represent fixed-length collections in style values (cf. padding and offsets). As @incanus points out, a struct with named fields would be another option that would avoid corner-swapping problems, although maybe we could make it so that the input order doesn’t matter.
There was a problem hiding this comment.
@incanus - thats an excellent point. Ive tried to wrap around that in the SDKs in the draft API PR. If the Quad struct makes sense, I think it might make more sense to move it into native.
There was a problem hiding this comment.
Note that there would have to be separate types for mbgl and for the iOS/macOS SDK, because the iOS/macOS SDKs can’t expose any C++ to the public.
There was a problem hiding this comment.
mbgl tends to use
std::arrayto represent fixed-length collections
Correct -- the type should be std::array<LatLng, 4>.
|
Quick & dirty iOS bindings for a near-term use case I have, per chat with @asheemmamoowala: |
ffff1c6 to
ffad32a
Compare
ffad32a to
6d940a9
Compare
jfirebaugh
left a comment
There was a problem hiding this comment.
Getting close! In addition to the changes requested below, please enable the relevant integration tests in mapbox-gl-js, open a PR there, and update the submodule pin here.
| template <class V> | ||
| optional<LatLng> operator() (const V& value, Error& error) const { | ||
| if (!isArray(value) || arrayLength(value) < 2 ) { | ||
| error = { "coordinate array must contain numeric longtitude and latitude values" }; |
|
|
||
| std::vector<LatLng> coordinates; | ||
| coordinates.reserve(4); | ||
| for( std::size_t i=0; i < arrayLength(*coordinatesValue); i++) { |
There was a problem hiding this comment.
Nit: whitespace. Also can use fixed upper bound. for (std::size_t i = 0; i < 4; i++)
|
|
||
| class ImageSource : public Source { | ||
| public: | ||
| ImageSource(std::string id, const std::vector<LatLng>); |
There was a problem hiding this comment.
mbgl tends to use
std::arrayto represent fixed-length collections
Correct -- the type should be std::array<LatLng, 4>.
|
|
||
| inline optional<double> toDouble(const mbgl::android::Value& value) { | ||
| if (value.isNumber()) { | ||
| auto num = value.toDouble(); |
There was a problem hiding this comment.
return value.toDouble();
| ImageSource(std::string id, const std::vector<LatLng>); | ||
| ~ImageSource() override; | ||
|
|
||
| const std::string& getURL() const; |
There was a problem hiding this comment.
Return type should be optional<std::string>, matching {Vector,Raster}Source::getURL and reflecting the possibility of absence.
| setupBucket(geomCoords); | ||
| } | ||
|
|
||
| void RenderImageSource::setupBucket(GeometryCoordinates& geomCoords) { |
There was a problem hiding this comment.
This is only called from updateTiles -- inline it there.
| @@ -0,0 +1,71 @@ | |||
| #pragma once | |||
|
|
|||
| #include <mbgl/renderer/buckets/raster_bucket.hpp> | |||
There was a problem hiding this comment.
Forward declare RasterBucket (and define ~RenderImageSource in the .cpp file) instead.
| #include <mbgl/renderer/render_source.hpp> | ||
| #include <mbgl/renderer/render_tile.hpp> | ||
| #include <mbgl/style/sources/image_source_impl.hpp> | ||
| #include <mbgl/tile/geometry_tile_data.hpp> |
| #include <mbgl/renderer/render_tile.hpp> | ||
| #include <mbgl/style/sources/image_source_impl.hpp> | ||
| #include <mbgl/tile/geometry_tile_data.hpp> | ||
| #include <mbgl/util/image.hpp> |
| #include <mbgl/style/sources/image_source_impl.hpp> | ||
| #include <mbgl/tile/geometry_tile_data.hpp> | ||
| #include <mbgl/util/image.hpp> | ||
| #include <mbgl/util/optional.hpp> |
jfirebaugh
left a comment
There was a problem hiding this comment.
Good to merge once CI is passing. The current failure is:
==12458== Invalid write of size 4
==12458== at 0x5D79AF: std::vector<unsigned int, std::allocator<unsigned int> >::push_back(unsigned int const&) (in /home/travis/build/mapbox/mapbox-gl-native/build/qt-linux-x86_64/Release/mbgl-test)
==12458== by 0x5D7872: mbgl::gl::detail::TextureDeleter::operator()(unsigned int) const (in /home/travis/build/mapbox/mapbox-gl-native/build/qt-linux-x86_64/Release/mbgl-test)
==12458== by 0x49B1BC: mbgl::RasterBucket::~RasterBucket() (in /home/travis/build/mapbox/mapbox-gl-native/build/qt-linux-x86_64/Release/mbgl-test)
==12458== by 0x498189: Buckets_RasterBucket_Test::TestBody() (in /home/travis/build/mapbox/mapbox-gl-native/build/qt-linux-x86_64/Release/mbgl-test)
Which indicates that in the RasterBucket test, the declaration order for the bucket and the context should be switched, so that the context is still alive when the bucket is destroyed.
989918b to
91f2a9b
Compare
Add support for ImageSource to mbgl-core. The current source passes existing render tests and can be verified with the macos app/mbgl-glfw.
Remaining Tasks
iOS/Android/Qt Bindings ? ⛷(Working on a separate PR)//cc @jfirebaugh @ivovandongen @kkaefer