[core] Add ImageSource support to style parsers
This commit is contained in:
7
test/fixtures/style_parser/center-not-latlong.info.json
vendored
Normal file
7
test/fixtures/style_parser/center-not-latlong.info.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"default": {
|
||||
"log": [
|
||||
[1, "WARNING", "ParseStyle", "center coordinate must be a longitude, latitude pair"]
|
||||
]
|
||||
}
|
||||
}
|
||||
4
test/fixtures/style_parser/center-not-latlong.style.json
vendored
Normal file
4
test/fixtures/style_parser/center-not-latlong.style.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"version": 8,
|
||||
"center" : [ 75.123, 181.123]
|
||||
}
|
||||
7
test/fixtures/style_parser/image-coordinates.info.json
vendored
Normal file
7
test/fixtures/style_parser/image-coordinates.info.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"default": {
|
||||
"log": [
|
||||
[1, "WARNING", "ParseStyle", "Image coordinates must be an array of four longitude latitude pairs"]
|
||||
]
|
||||
}
|
||||
}
|
||||
14
test/fixtures/style_parser/image-coordinates.style.json
vendored
Normal file
14
test/fixtures/style_parser/image-coordinates.style.json
vendored
Normal file
@@ -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]
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
7
test/fixtures/style_parser/image-url.info.json
vendored
Normal file
7
test/fixtures/style_parser/image-url.info.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"default": {
|
||||
"log": [
|
||||
[1, "WARNING", "ParseStyle", "Image source must have a url value"]
|
||||
]
|
||||
}
|
||||
}
|
||||
9
test/fixtures/style_parser/image-url.style.json
vendored
Normal file
9
test/fixtures/style_parser/image-url.style.json
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"version": 8,
|
||||
"center" : [ 75.123, 81.123],
|
||||
"sources": {
|
||||
"image": {
|
||||
"type": "image"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <mbgl/style/sources/raster_source.hpp>
|
||||
#include <mbgl/style/sources/vector_source.hpp>
|
||||
#include <mbgl/style/sources/geojson_source.hpp>
|
||||
#include <mbgl/style/sources/image_source.hpp>
|
||||
|
||||
#include <mbgl/renderer/sources/render_raster_source.hpp>
|
||||
#include <mbgl/renderer/sources/render_vector_source.hpp>
|
||||
@@ -16,6 +17,9 @@
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
#include <mbgl/util/string.hpp>
|
||||
#include <mbgl/util/io.hpp>
|
||||
#include <mbgl/util/premultiply.hpp>
|
||||
#include <mbgl/util/image.hpp>
|
||||
|
||||
#include <mbgl/util/tileset.hpp>
|
||||
#include <mbgl/util/default_thread_pool.hpp>
|
||||
#include <mbgl/util/logging.hpp>
|
||||
@@ -436,3 +440,39 @@ TEST(Source, GeoJSonSourceUrlUpdate) {
|
||||
|
||||
test.run();
|
||||
}
|
||||
|
||||
TEST(Source, ImageSourceImageUpdate) {
|
||||
SourceTest test;
|
||||
|
||||
test.fileSource.response = [&] (const Resource& resource) {
|
||||
EXPECT_EQ("http://url", resource.url);
|
||||
Response response;
|
||||
response.data = std::make_unique<std::string>(util::read_file("test/fixtures/image/no_profile.png"));
|
||||
return response;
|
||||
};
|
||||
test.styleObserver.sourceChanged = [&] (Source&) {
|
||||
// Should be called (test will hang if it doesn't)
|
||||
test.end();
|
||||
};
|
||||
std::vector<LatLng> coords;
|
||||
|
||||
ImageSource source("source", coords);
|
||||
source.setURL("http://url");
|
||||
source.setObserver(&test.styleObserver);
|
||||
|
||||
// Load initial, so the source state will be loaded=true
|
||||
source.loadDescription(test.fileSource);
|
||||
UnassociatedImage rgba({ 1, 1 });
|
||||
rgba.data[0] = 255;
|
||||
rgba.data[1] = 254;
|
||||
rgba.data[2] = 253;
|
||||
rgba.data[3] = 128;
|
||||
|
||||
// Schedule an update
|
||||
test.loop.invoke([&] () {
|
||||
// Update the url
|
||||
source.setImage(std::move(rgba));
|
||||
});
|
||||
|
||||
test.run();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user