[core] Implement image expression (#15877)
* [core] Bump gl-js version * [core] Implement image expression * [core] Use new image expression * [core] Coerce image expression to / from string * [core] Serialize evaluated image * [core] Pass available images to layout * [core] Pass images to evaluation context * [core] Set available flag value based on image availability * [core] Allow image coercion to boolean to indicate image availability * [core] Coalesce image expression * [core] Add image expression to next build system * [core] Align serialization format and evaluated type with gl-js * [core] Add images to expression evaluation method * [core] Add support for Image expression to expression test runner * [core] Unskip image expression tests * [core] Update unit tests * [core] Use image expression in annotation manager * [core] Add string to ImageExpression conversion * [core] Add image expression to expression dsl * [core] Convert tokens for implicitly created Image literal * [core] Fix clang format * [core] Split generated style code lines that are over 120 characters * [core] Add unit test for image expression equality * [core] Add image property expression evaluation unit test * [core] Unskip image expression render test * [core] Skip 'in' expression tests * [core] Ignore fill-pattern/update-feature-state render test * [core] Rename Image::serialize to Image::toValue
This commit is contained in:
@@ -55,7 +55,7 @@ std::vector<Feature> getTopClusterFeature(QueryTest& test) {
|
||||
source->loadDescription(*test.fileSource);
|
||||
|
||||
auto clusterLayer = std::make_unique<SymbolLayer>("cluster_layer"s, "cluster_source"s);
|
||||
clusterLayer->setIconImage("test-icon"s);
|
||||
clusterLayer->setIconImage({"test-icon"s});
|
||||
clusterLayer->setIconSize(12.0f);
|
||||
|
||||
test.map.jumpTo(CameraOptions().withCenter(coordinate).withZoom(0.0));
|
||||
|
||||
4
test/fixtures/expression_equality/image.a.json
vendored
Normal file
4
test/fixtures/expression_equality/image.a.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[
|
||||
"image",
|
||||
"maki-11"
|
||||
]
|
||||
4
test/fixtures/expression_equality/image.b.json
vendored
Normal file
4
test/fixtures/expression_equality/image.b.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[
|
||||
"image",
|
||||
"bicycle-15"
|
||||
]
|
||||
@@ -35,7 +35,8 @@ TEST(Expression, IsExpression) {
|
||||
|
||||
// TODO: "interpolate-hcl": https://github.com/mapbox/mapbox-gl-native/issues/8720
|
||||
// TODO: "interpolate-lab": https://github.com/mapbox/mapbox-gl-native/issues/8720
|
||||
if (name == "interpolate-hcl" || name == "interpolate-lab") {
|
||||
// TODO: "in": https://github.com/mapbox/mapbox-gl-native/issues/15893
|
||||
if (name == "interpolate-hcl" || name == "interpolate-lab" || name == "in") {
|
||||
if (expression::isExpression(conversion::Convertible(expression))) {
|
||||
ASSERT_TRUE(false) << "Expression name" << name << "is implemented - please update Expression.IsExpression test.";
|
||||
}
|
||||
|
||||
@@ -14,21 +14,17 @@ using namespace mbgl::style::expression::dsl;
|
||||
|
||||
using namespace std::string_literals;
|
||||
|
||||
static StubGeometryTileFeature oneInteger {
|
||||
PropertyMap {{ "property", uint64_t(1) }}
|
||||
};
|
||||
static const StubGeometryTileFeature oneInteger{PropertyMap{{"property", uint64_t(1)}}};
|
||||
|
||||
static StubGeometryTileFeature oneDouble {
|
||||
PropertyMap {{ "property", 1.0 }}
|
||||
};
|
||||
static const StubGeometryTileFeature oneDouble{PropertyMap{{"property", 1.0}}};
|
||||
|
||||
static StubGeometryTileFeature oneString {
|
||||
PropertyMap {{ "property", "1"s }}
|
||||
};
|
||||
static const StubGeometryTileFeature oneString{PropertyMap{{"property", "1"s}}};
|
||||
|
||||
static StubGeometryTileFeature oneColor {
|
||||
PropertyMap {{ "color", "red"s }}
|
||||
};
|
||||
static const StubGeometryTileFeature oneColor{PropertyMap{{"color", "red"s}}};
|
||||
|
||||
static const StubGeometryTileFeature oneImage{PropertyMap{{"image_name", "maki-11"s}}};
|
||||
|
||||
static const StubGeometryTileFeature emptyTileFeature{PropertyMap{}};
|
||||
|
||||
float evaluate(PropertyValue<float> value, float zoom) {
|
||||
return value.evaluate(PropertyEvaluator<float>(PropertyEvaluationParameters(zoom), 0));
|
||||
@@ -171,3 +167,54 @@ TEST(PropertyExpression, FormatSectionOverride) {
|
||||
EXPECT_TRUE(*override1 != *override4);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(PropertyExpression, ImageExpression) {
|
||||
const std::set<std::string> emptySet;
|
||||
const std::set<std::string> availableImages = {"maki-11", "airport-11", "bicycle-15"};
|
||||
|
||||
// evaluation test without available images
|
||||
{
|
||||
PropertyExpression<expression::Image> propExpr(image(literal("airport-11")));
|
||||
auto evaluatedImage = propExpr.evaluate(emptyTileFeature, emptySet, expression::Image());
|
||||
EXPECT_FALSE(evaluatedImage.isAvailable());
|
||||
EXPECT_EQ(evaluatedImage.id(), "airport-11"s);
|
||||
|
||||
PropertyExpression<expression::Image> ddPropExpr(image(get(literal("image_name"s))));
|
||||
evaluatedImage = ddPropExpr.evaluate(oneImage, emptySet, expression::Image());
|
||||
EXPECT_FALSE(evaluatedImage.isAvailable());
|
||||
EXPECT_EQ(evaluatedImage.id(), "maki-11"s);
|
||||
|
||||
evaluatedImage = ddPropExpr.evaluate(emptyTileFeature, emptySet, expression::Image());
|
||||
EXPECT_FALSE(evaluatedImage.isAvailable());
|
||||
EXPECT_EQ(evaluatedImage.id(), ""s);
|
||||
}
|
||||
|
||||
// evaluation test with available images
|
||||
{
|
||||
PropertyExpression<expression::Image> propExpr(image(literal("airport-11")));
|
||||
auto evaluatedImage = propExpr.evaluate(emptyTileFeature, availableImages, expression::Image());
|
||||
EXPECT_TRUE(evaluatedImage.isAvailable());
|
||||
EXPECT_EQ(evaluatedImage.id(), "airport-11"s);
|
||||
|
||||
PropertyExpression<expression::Image> ddPropExpr(image(get(literal("image_name"s))));
|
||||
evaluatedImage = ddPropExpr.evaluate(oneImage, availableImages, expression::Image());
|
||||
EXPECT_TRUE(evaluatedImage.isAvailable());
|
||||
EXPECT_EQ(evaluatedImage.id(), "maki-11"s);
|
||||
|
||||
evaluatedImage = ddPropExpr.evaluate(emptyTileFeature, availableImages, expression::Image());
|
||||
EXPECT_FALSE(evaluatedImage.isAvailable());
|
||||
EXPECT_EQ(evaluatedImage.id(), ""s);
|
||||
}
|
||||
|
||||
// evaluation with zoom
|
||||
{
|
||||
auto expr = step(zoom(), image(literal("airport-11")), 18.0, image(literal("bicycle-15")));
|
||||
PropertyExpression<expression::Image> propExpr(std::move(expr));
|
||||
auto evaluatedImage = propExpr.evaluate(0.0, emptyTileFeature, availableImages, expression::Image());
|
||||
EXPECT_TRUE(evaluatedImage.isAvailable());
|
||||
EXPECT_EQ(evaluatedImage.id(), "airport-11"s);
|
||||
evaluatedImage = propExpr.evaluate(18.0, emptyTileFeature, availableImages, expression::Image());
|
||||
EXPECT_TRUE(evaluatedImage.isAvailable());
|
||||
EXPECT_EQ(evaluatedImage.id(), "bicycle-15"s);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <mbgl/style/expression/dsl.hpp>
|
||||
#include <mbgl/style/expression/match.hpp>
|
||||
#include <mbgl/style/expression/format_expression.hpp>
|
||||
#include <mbgl/style/style_impl.hpp>
|
||||
#include <mbgl/style/expression/image.hpp>
|
||||
#include <mbgl/style/expression/match.hpp>
|
||||
#include <mbgl/style/layers/background_layer.hpp>
|
||||
#include <mbgl/style/layers/background_layer_impl.hpp>
|
||||
#include <mbgl/style/layers/circle_layer.hpp>
|
||||
@@ -16,12 +16,13 @@
|
||||
#include <mbgl/style/layers/raster_layer_impl.hpp>
|
||||
#include <mbgl/style/layers/symbol_layer.hpp>
|
||||
#include <mbgl/style/layers/symbol_layer_impl.hpp>
|
||||
#include <mbgl/test/util.hpp>
|
||||
#include <mbgl/test/stub_layer_observer.hpp>
|
||||
#include <mbgl/style/style_impl.hpp>
|
||||
#include <mbgl/test/stub_file_source.hpp>
|
||||
#include <mbgl/test/stub_layer_observer.hpp>
|
||||
#include <mbgl/test/util.hpp>
|
||||
#include <mbgl/util/color.hpp>
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
#include <mbgl/util/io.hpp>
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
|
||||
#include <memory>
|
||||
|
||||
@@ -37,7 +38,7 @@ const auto color = Color { 1, 0, 0, 1 };
|
||||
const auto opacity = 1.0f;
|
||||
const auto radius = 1.0f;
|
||||
const auto blur = 1.0f;
|
||||
const auto pattern = std::string { "foo" };
|
||||
const auto pattern = PropertyValue<expression::Image>{"foo"};
|
||||
const auto antialias = false;
|
||||
const auto translate = std::array<float, 2> {{ 0, 0 }};
|
||||
const auto translateAnchor = TranslateAnchorType::Map;
|
||||
|
||||
@@ -19,11 +19,15 @@ LineString<int16_t> emptyLine;
|
||||
|
||||
class SymbolFeatureStub : public SymbolFeature {
|
||||
public:
|
||||
SymbolFeatureStub(FeatureIdentifier id_, FeatureType type_, GeometryCollection geometry_,
|
||||
PropertyMap properties_, optional<std::u16string> text_,
|
||||
optional<std::string> icon_, std::size_t index_) :
|
||||
SymbolFeature(std::make_unique<StubGeometryTileFeature>(std::move(id_), type_, std::move(geometry_), std::move(properties_)))
|
||||
{
|
||||
SymbolFeatureStub(FeatureIdentifier id_,
|
||||
FeatureType type_,
|
||||
GeometryCollection geometry_,
|
||||
PropertyMap properties_,
|
||||
optional<std::u16string> text_,
|
||||
optional<style::expression::Image> icon_,
|
||||
std::size_t index_)
|
||||
: SymbolFeature(std::make_unique<StubGeometryTileFeature>(
|
||||
std::move(id_), type_, std::move(geometry_), std::move(properties_))) {
|
||||
if (text_) {
|
||||
formattedText = TaggedString(*text_, SectionOptions(1.0, {}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user