From fe2a26225f3746381b36ad8b6c6a3ce7727bf655 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 29 Aug 2016 12:00:08 -0700 Subject: [PATCH] [core, ios, android, qt] Observe style layer mutations rather than requiring SDKs to use Map::update This paves the way for updates to filter and layout properties to trigger a source reload, without each SDK having to participate in the implementation. --- cmake/core-files.cmake | 1 + include/mbgl/style/function.hpp | 12 ++ include/mbgl/style/property_value.hpp | 15 ++ .../mapbox/mapboxsdk/style/layers/Layer.java | 6 - platform/android/src/style/layers/layer.cpp | 14 -- .../darwin/scripts/generate-style-code.js | 1 - .../darwin/src/MGLBackgroundStyleLayer.mm | 5 +- platform/darwin/src/MGLBaseStyleLayer.mm | 9 -- .../darwin/src/MGLBaseStyleLayer_Private.h | 9 -- platform/darwin/src/MGLCircleStyleLayer.mm | 9 +- platform/darwin/src/MGLFillStyleLayer.mm | 9 +- platform/darwin/src/MGLLineStyleLayer.mm | 16 +- platform/darwin/src/MGLRasterStyleLayer.mm | 9 +- platform/darwin/src/MGLStyleLayer.mm.ejs | 2 +- platform/darwin/src/MGLSymbolStyleLayer.mm | 50 +----- platform/ios/ios.xcodeproj/project.pbxproj | 6 - .../macos/macos.xcodeproj/project.pbxproj | 4 - platform/node/src/node_map.cpp | 2 - platform/qt/src/qmapboxgl.cpp | 4 - src/mbgl/style/layer_impl.cpp | 4 + src/mbgl/style/layer_impl.hpp | 6 + src/mbgl/style/layer_observer.hpp | 18 +++ src/mbgl/style/layers/background_layer.cpp | 9 ++ src/mbgl/style/layers/circle_layer.cpp | 22 +++ src/mbgl/style/layers/fill_layer.cpp | 22 +++ src/mbgl/style/layers/layer.cpp.ejs | 7 + src/mbgl/style/layers/line_layer.cpp | 43 ++++++ src/mbgl/style/layers/raster_layer.cpp | 21 +++ src/mbgl/style/layers/symbol_layer.cpp | 145 ++++++++++++++++++ src/mbgl/style/style.cpp | 15 ++ src/mbgl/style/style.hpp | 7 + test/src/mbgl/test/stub_layer_observer.hpp | 28 ++++ test/style/style_layer.cpp | 44 ++++++ 33 files changed, 426 insertions(+), 148 deletions(-) delete mode 100644 platform/darwin/src/MGLBaseStyleLayer_Private.h create mode 100644 src/mbgl/style/layer_observer.hpp create mode 100644 test/src/mbgl/test/stub_layer_observer.hpp diff --git a/cmake/core-files.cmake b/cmake/core-files.cmake index 5c13e925b..c76bb3592 100644 --- a/cmake/core-files.cmake +++ b/cmake/core-files.cmake @@ -229,6 +229,7 @@ set(MBGL_CORE_FILES src/mbgl/style/layer.cpp src/mbgl/style/layer_impl.cpp src/mbgl/style/layer_impl.hpp + src/mbgl/style/layer_observer.hpp src/mbgl/style/layout_property.hpp src/mbgl/style/observer.hpp src/mbgl/style/paint_property.hpp diff --git a/include/mbgl/style/function.hpp b/include/mbgl/style/function.hpp index 44ffa3107..97e880b28 100644 --- a/include/mbgl/style/function.hpp +++ b/include/mbgl/style/function.hpp @@ -21,7 +21,19 @@ public: private: float base = 1; std::vector> stops; + + template friend bool operator==(const Function&, const Function&); }; +template +bool operator==(const Function& lhs, const Function& rhs) { + return lhs.base == rhs.base && lhs.stops == rhs.stops; +} + +template +bool operator!=(const Function& lhs, const Function& rhs) { + return !(lhs == rhs); +} + } // namespace style } // namespace mbgl diff --git a/include/mbgl/style/property_value.hpp b/include/mbgl/style/property_value.hpp index d8f83a0fb..d7e160fdc 100644 --- a/include/mbgl/style/property_value.hpp +++ b/include/mbgl/style/property_value.hpp @@ -8,12 +8,17 @@ namespace style { class Undefined {}; +inline bool operator==(const Undefined&, const Undefined&) { return true; } +inline bool operator!=(const Undefined&, const Undefined&) { return false; } + template class PropertyValue { private: using Value = variant>; Value value; + template friend bool operator==(const PropertyValue&, const PropertyValue&); + public: PropertyValue() : value() {} PropertyValue( T constant) : value(constant) {} @@ -34,5 +39,15 @@ public: } }; +template +bool operator==(const PropertyValue& lhs, const PropertyValue& rhs) { + return lhs.value == rhs.value; +} + +template +bool operator!=(const PropertyValue& lhs, const PropertyValue& rhs) { + return !(lhs == rhs); +} + } // namespace style } // namespace mbgl diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Layer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Layer.java index 8c33fc976..54d18962c 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Layer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Layer.java @@ -24,18 +24,14 @@ public abstract class Layer { return; } - boolean updateClasses = false; for (Property property : properties) { Object converted = convertValue(property.value); if (property instanceof PaintProperty) { - updateClasses = true; nativeSetPaintProperty(property.name, converted); } else { nativeSetLayoutProperty(property.name, converted); } } - - nativeUpdateStyle(updateClasses); } public String getId() { @@ -83,8 +79,6 @@ public abstract class Layer { protected native void nativeSetSourceLayer(String sourceLayer); - protected native void nativeUpdateStyle(boolean updateClasses); - protected native float nativeGetMinZoom(); protected native float nativeGetMaxZoom(); diff --git a/platform/android/src/style/layers/layer.cpp b/platform/android/src/style/layers/layer.cpp index 4d5f90f67..3c1fc0af6 100644 --- a/platform/android/src/style/layers/layer.cpp +++ b/platform/android/src/style/layers/layer.cpp @@ -63,19 +63,6 @@ namespace android { } } - void Layer::updateStyle(jni::JNIEnv&, jni::jboolean updateClasses) { - //Update the style only if attached - if (ownedLayer == nullptr) { - Update flags = mbgl::Update::RecalculateStyle; - if(updateClasses) { - flags = flags | mbgl::Update::Classes; - } - map->update(flags); - } else { - mbgl::Log::Debug(mbgl::Event::JNI, "Not updating as layer is not attached to map (yet)"); - } - } - void Layer::setFilter(jni::JNIEnv& env, jni::Array> jfilter) { using namespace mbgl::style; using namespace mbgl::style::conversion; @@ -155,7 +142,6 @@ namespace android { METHOD(&Layer::getId, "nativeGetId"), METHOD(&Layer::setLayoutProperty, "nativeSetLayoutProperty"), METHOD(&Layer::setPaintProperty, "nativeSetPaintProperty"), - METHOD(&Layer::updateStyle, "nativeUpdateStyle"), METHOD(&Layer::setFilter, "nativeSetFilter"), METHOD(&Layer::setSourceLayer, "nativeSetSourceLayer"), METHOD(&Layer::getMinZoom, "nativeGetMinZoom"), diff --git a/platform/darwin/scripts/generate-style-code.js b/platform/darwin/scripts/generate-style-code.js index 29040d3c5..4a875f784 100644 --- a/platform/darwin/scripts/generate-style-code.js +++ b/platform/darwin/scripts/generate-style-code.js @@ -219,7 +219,6 @@ global.setterImplementation = function(property, layerType) { break; default: throw new Error(`unknown type for ${property.name}`) } - implementation += "\n [self update];" return implementation; } diff --git a/platform/darwin/src/MGLBackgroundStyleLayer.mm b/platform/darwin/src/MGLBackgroundStyleLayer.mm index 32e2e7847..adfa31e4e 100644 --- a/platform/darwin/src/MGLBackgroundStyleLayer.mm +++ b/platform/darwin/src/MGLBackgroundStyleLayer.mm @@ -1,7 +1,7 @@ // This file is generated. // Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. -#import "MGLBaseStyleLayer_Private.h" +#import "NSPredicate+MGLAdditions.h" #import "MGLStyleLayer_Private.h" #import "MGLStyleAttributeValue.h" #import "MGLBackgroundStyleLayer.h" @@ -33,7 +33,6 @@ - (void)setBackgroundColor:(id )backgroundColor { self.layer->setBackgroundColor(backgroundColor.mbgl_colorPropertyValue); - [self update]; } - (id )backgroundColor { @@ -42,7 +41,6 @@ - (void)setBackgroundPattern:(id )backgroundPattern { self.layer->setBackgroundPattern(backgroundPattern.mbgl_stringPropertyValue); - [self update]; } - (id )backgroundPattern { @@ -51,7 +49,6 @@ - (void)setBackgroundOpacity:(id )backgroundOpacity { self.layer->setBackgroundOpacity(backgroundOpacity.mbgl_floatPropertyValue); - [self update]; } - (id )backgroundOpacity { diff --git a/platform/darwin/src/MGLBaseStyleLayer.mm b/platform/darwin/src/MGLBaseStyleLayer.mm index d9d57d661..a74746773 100644 --- a/platform/darwin/src/MGLBaseStyleLayer.mm +++ b/platform/darwin/src/MGLBaseStyleLayer.mm @@ -1,6 +1,5 @@ #import "MGLBaseStyleLayer.h" -#import "MGLBaseStyleLayer_Private.h" #import "MGLStyleLayer_Private.h" #import "MGLMapView_Private.h" @@ -15,14 +14,6 @@ @synthesize mapView; @synthesize layer; -- (void)update -{ - // A style layer's map view can be nil when first created at runtime - // before being added to a map style. In these cases, just no-op since - // the addition of the layer will trigger a visual refresh. - if (self.mapView) self.mapView.mbglMap->update(mbgl::Update::RecalculateStyle | mbgl::Update::Classes); -} - - (void)setVisible:(BOOL)visible { mbgl::style::VisibilityType v = visible diff --git a/platform/darwin/src/MGLBaseStyleLayer_Private.h b/platform/darwin/src/MGLBaseStyleLayer_Private.h deleted file mode 100644 index 0cbb076b3..000000000 --- a/platform/darwin/src/MGLBaseStyleLayer_Private.h +++ /dev/null @@ -1,9 +0,0 @@ -#import "MGLBaseStyleLayer.h" - -#import "NSPredicate+MGLAdditions.h" - -@interface MGLBaseStyleLayer (MGLBaseStyleLayer_Private) - -- (void)update; - -@end diff --git a/platform/darwin/src/MGLCircleStyleLayer.mm b/platform/darwin/src/MGLCircleStyleLayer.mm index 6c038318c..a90640748 100644 --- a/platform/darwin/src/MGLCircleStyleLayer.mm +++ b/platform/darwin/src/MGLCircleStyleLayer.mm @@ -1,7 +1,7 @@ // This file is generated. // Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. -#import "MGLBaseStyleLayer_Private.h" +#import "NSPredicate+MGLAdditions.h" #import "MGLStyleLayer_Private.h" #import "MGLStyleAttributeValue.h" #import "MGLCircleStyleLayer.h" @@ -43,7 +43,6 @@ - (void)setCircleRadius:(id )circleRadius { self.layer->setCircleRadius(circleRadius.mbgl_floatPropertyValue); - [self update]; } - (id )circleRadius { @@ -52,7 +51,6 @@ - (void)setCircleColor:(id )circleColor { self.layer->setCircleColor(circleColor.mbgl_colorPropertyValue); - [self update]; } - (id )circleColor { @@ -61,7 +59,6 @@ - (void)setCircleBlur:(id )circleBlur { self.layer->setCircleBlur(circleBlur.mbgl_floatPropertyValue); - [self update]; } - (id )circleBlur { @@ -70,7 +67,6 @@ - (void)setCircleOpacity:(id )circleOpacity { self.layer->setCircleOpacity(circleOpacity.mbgl_floatPropertyValue); - [self update]; } - (id )circleOpacity { @@ -79,7 +75,6 @@ - (void)setCircleTranslate:(id )circleTranslate { self.layer->setCircleTranslate(circleTranslate.mbgl_offsetPropertyValue); - [self update]; } - (id )circleTranslate { @@ -88,7 +83,6 @@ - (void)setCircleTranslateAnchor:(id )circleTranslateAnchor { MGLSetEnumProperty(circleTranslateAnchor, CircleTranslateAnchor, TranslateAnchorType, MGLCircleStyleLayerCircleTranslateAnchor); - [self update]; } - (id )circleTranslateAnchor { @@ -97,7 +91,6 @@ - (void)setCirclePitchScale:(id )circlePitchScale { MGLSetEnumProperty(circlePitchScale, CirclePitchScale, CirclePitchScaleType, MGLCircleStyleLayerCirclePitchScale); - [self update]; } - (id )circlePitchScale { diff --git a/platform/darwin/src/MGLFillStyleLayer.mm b/platform/darwin/src/MGLFillStyleLayer.mm index c54ddba42..6867c50f1 100644 --- a/platform/darwin/src/MGLFillStyleLayer.mm +++ b/platform/darwin/src/MGLFillStyleLayer.mm @@ -1,7 +1,7 @@ // This file is generated. // Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. -#import "MGLBaseStyleLayer_Private.h" +#import "NSPredicate+MGLAdditions.h" #import "MGLStyleLayer_Private.h" #import "MGLStyleAttributeValue.h" #import "MGLFillStyleLayer.h" @@ -43,7 +43,6 @@ - (void)setFillAntialias:(id )fillAntialias { self.layer->setFillAntialias(fillAntialias.mbgl_boolPropertyValue); - [self update]; } - (id )fillAntialias { @@ -52,7 +51,6 @@ - (void)setFillOpacity:(id )fillOpacity { self.layer->setFillOpacity(fillOpacity.mbgl_floatPropertyValue); - [self update]; } - (id )fillOpacity { @@ -61,7 +59,6 @@ - (void)setFillColor:(id )fillColor { self.layer->setFillColor(fillColor.mbgl_colorPropertyValue); - [self update]; } - (id )fillColor { @@ -70,7 +67,6 @@ - (void)setFillOutlineColor:(id )fillOutlineColor { self.layer->setFillOutlineColor(fillOutlineColor.mbgl_colorPropertyValue); - [self update]; } - (id )fillOutlineColor { @@ -79,7 +75,6 @@ - (void)setFillTranslate:(id )fillTranslate { self.layer->setFillTranslate(fillTranslate.mbgl_offsetPropertyValue); - [self update]; } - (id )fillTranslate { @@ -88,7 +83,6 @@ - (void)setFillTranslateAnchor:(id )fillTranslateAnchor { MGLSetEnumProperty(fillTranslateAnchor, FillTranslateAnchor, TranslateAnchorType, MGLFillStyleLayerFillTranslateAnchor); - [self update]; } - (id )fillTranslateAnchor { @@ -97,7 +91,6 @@ - (void)setFillPattern:(id )fillPattern { self.layer->setFillPattern(fillPattern.mbgl_stringPropertyValue); - [self update]; } - (id )fillPattern { diff --git a/platform/darwin/src/MGLLineStyleLayer.mm b/platform/darwin/src/MGLLineStyleLayer.mm index ce9ad75f8..8c5af877f 100644 --- a/platform/darwin/src/MGLLineStyleLayer.mm +++ b/platform/darwin/src/MGLLineStyleLayer.mm @@ -1,7 +1,7 @@ // This file is generated. // Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. -#import "MGLBaseStyleLayer_Private.h" +#import "NSPredicate+MGLAdditions.h" #import "MGLStyleLayer_Private.h" #import "MGLStyleAttributeValue.h" #import "MGLLineStyleLayer.h" @@ -43,7 +43,6 @@ - (void)setLineCap:(id )lineCap { MGLSetEnumProperty(lineCap, LineCap, LineCapType, MGLLineStyleLayerLineCap); - [self update]; } - (id )lineCap { @@ -52,7 +51,6 @@ - (void)setLineJoin:(id )lineJoin { MGLSetEnumProperty(lineJoin, LineJoin, LineJoinType, MGLLineStyleLayerLineJoin); - [self update]; } - (id )lineJoin { @@ -61,7 +59,6 @@ - (void)setLineMiterLimit:(id )lineMiterLimit { self.layer->setLineMiterLimit(lineMiterLimit.mbgl_floatPropertyValue); - [self update]; } - (id )lineMiterLimit { @@ -70,7 +67,6 @@ - (void)setLineRoundLimit:(id )lineRoundLimit { self.layer->setLineRoundLimit(lineRoundLimit.mbgl_floatPropertyValue); - [self update]; } - (id )lineRoundLimit { @@ -81,7 +77,6 @@ - (void)setLineOpacity:(id )lineOpacity { self.layer->setLineOpacity(lineOpacity.mbgl_floatPropertyValue); - [self update]; } - (id )lineOpacity { @@ -90,7 +85,6 @@ - (void)setLineColor:(id )lineColor { self.layer->setLineColor(lineColor.mbgl_colorPropertyValue); - [self update]; } - (id )lineColor { @@ -99,7 +93,6 @@ - (void)setLineTranslate:(id )lineTranslate { self.layer->setLineTranslate(lineTranslate.mbgl_offsetPropertyValue); - [self update]; } - (id )lineTranslate { @@ -108,7 +101,6 @@ - (void)setLineTranslateAnchor:(id )lineTranslateAnchor { MGLSetEnumProperty(lineTranslateAnchor, LineTranslateAnchor, TranslateAnchorType, MGLLineStyleLayerLineTranslateAnchor); - [self update]; } - (id )lineTranslateAnchor { @@ -117,7 +109,6 @@ - (void)setLineWidth:(id )lineWidth { self.layer->setLineWidth(lineWidth.mbgl_floatPropertyValue); - [self update]; } - (id )lineWidth { @@ -126,7 +117,6 @@ - (void)setLineGapWidth:(id )lineGapWidth { self.layer->setLineGapWidth(lineGapWidth.mbgl_floatPropertyValue); - [self update]; } - (id )lineGapWidth { @@ -135,7 +125,6 @@ - (void)setLineOffset:(id )lineOffset { self.layer->setLineOffset(lineOffset.mbgl_floatPropertyValue); - [self update]; } - (id )lineOffset { @@ -144,7 +133,6 @@ - (void)setLineBlur:(id )lineBlur { self.layer->setLineBlur(lineBlur.mbgl_floatPropertyValue); - [self update]; } - (id )lineBlur { @@ -153,7 +141,6 @@ - (void)setLineDasharray:(id )lineDasharray { self.layer->setLineDasharray(lineDasharray.mbgl_numberArrayPropertyValue); - [self update]; } - (id )lineDasharray { @@ -162,7 +149,6 @@ - (void)setLinePattern:(id )linePattern { self.layer->setLinePattern(linePattern.mbgl_stringPropertyValue); - [self update]; } - (id )linePattern { diff --git a/platform/darwin/src/MGLRasterStyleLayer.mm b/platform/darwin/src/MGLRasterStyleLayer.mm index 37368c657..dc70dfbde 100644 --- a/platform/darwin/src/MGLRasterStyleLayer.mm +++ b/platform/darwin/src/MGLRasterStyleLayer.mm @@ -1,7 +1,7 @@ // This file is generated. // Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. -#import "MGLBaseStyleLayer_Private.h" +#import "NSPredicate+MGLAdditions.h" #import "MGLStyleLayer_Private.h" #import "MGLStyleAttributeValue.h" #import "MGLRasterStyleLayer.h" @@ -33,7 +33,6 @@ - (void)setRasterOpacity:(id )rasterOpacity { self.layer->setRasterOpacity(rasterOpacity.mbgl_floatPropertyValue); - [self update]; } - (id )rasterOpacity { @@ -42,7 +41,6 @@ - (void)setRasterHueRotate:(id )rasterHueRotate { self.layer->setRasterHueRotate(rasterHueRotate.mbgl_floatPropertyValue); - [self update]; } - (id )rasterHueRotate { @@ -51,7 +49,6 @@ - (void)setRasterBrightnessMin:(id )rasterBrightnessMin { self.layer->setRasterBrightnessMin(rasterBrightnessMin.mbgl_floatPropertyValue); - [self update]; } - (id )rasterBrightnessMin { @@ -60,7 +57,6 @@ - (void)setRasterBrightnessMax:(id )rasterBrightnessMax { self.layer->setRasterBrightnessMax(rasterBrightnessMax.mbgl_floatPropertyValue); - [self update]; } - (id )rasterBrightnessMax { @@ -69,7 +65,6 @@ - (void)setRasterSaturation:(id )rasterSaturation { self.layer->setRasterSaturation(rasterSaturation.mbgl_floatPropertyValue); - [self update]; } - (id )rasterSaturation { @@ -78,7 +73,6 @@ - (void)setRasterContrast:(id )rasterContrast { self.layer->setRasterContrast(rasterContrast.mbgl_floatPropertyValue); - [self update]; } - (id )rasterContrast { @@ -87,7 +81,6 @@ - (void)setRasterFadeDuration:(id )rasterFadeDuration { self.layer->setRasterFadeDuration(rasterFadeDuration.mbgl_floatPropertyValue); - [self update]; } - (id )rasterFadeDuration { diff --git a/platform/darwin/src/MGLStyleLayer.mm.ejs b/platform/darwin/src/MGLStyleLayer.mm.ejs index 4e59c3c6c..4615aeeb9 100644 --- a/platform/darwin/src/MGLStyleLayer.mm.ejs +++ b/platform/darwin/src/MGLStyleLayer.mm.ejs @@ -6,7 +6,7 @@ // This file is generated. // Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. -#import "MGLBaseStyleLayer_Private.h" +#import "NSPredicate+MGLAdditions.h" #import "MGLStyleLayer_Private.h" #import "MGLStyleAttributeValue.h" #import "MGL<%- camelize(type) %>StyleLayer.h" diff --git a/platform/darwin/src/MGLSymbolStyleLayer.mm b/platform/darwin/src/MGLSymbolStyleLayer.mm index b0553ea42..1fb3a0a58 100644 --- a/platform/darwin/src/MGLSymbolStyleLayer.mm +++ b/platform/darwin/src/MGLSymbolStyleLayer.mm @@ -1,7 +1,7 @@ // This file is generated. // Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. -#import "MGLBaseStyleLayer_Private.h" +#import "NSPredicate+MGLAdditions.h" #import "MGLStyleLayer_Private.h" #import "MGLStyleAttributeValue.h" #import "MGLSymbolStyleLayer.h" @@ -43,7 +43,6 @@ - (void)setSymbolPlacement:(id )symbolPlacement { MGLSetEnumProperty(symbolPlacement, SymbolPlacement, SymbolPlacementType, MGLSymbolStyleLayerSymbolPlacement); - [self update]; } - (id )symbolPlacement { @@ -52,7 +51,6 @@ - (void)setSymbolSpacing:(id )symbolSpacing { self.layer->setSymbolSpacing(symbolSpacing.mbgl_floatPropertyValue); - [self update]; } - (id )symbolSpacing { @@ -61,7 +59,6 @@ - (void)setSymbolAvoidEdges:(id )symbolAvoidEdges { self.layer->setSymbolAvoidEdges(symbolAvoidEdges.mbgl_boolPropertyValue); - [self update]; } - (id )symbolAvoidEdges { @@ -70,7 +67,6 @@ - (void)setIconAllowOverlap:(id )iconAllowOverlap { self.layer->setIconAllowOverlap(iconAllowOverlap.mbgl_boolPropertyValue); - [self update]; } - (id )iconAllowOverlap { @@ -79,7 +75,6 @@ - (void)setIconIgnorePlacement:(id )iconIgnorePlacement { self.layer->setIconIgnorePlacement(iconIgnorePlacement.mbgl_boolPropertyValue); - [self update]; } - (id )iconIgnorePlacement { @@ -88,7 +83,6 @@ - (void)setIconOptional:(id )iconOptional { self.layer->setIconOptional(iconOptional.mbgl_boolPropertyValue); - [self update]; } - (id )iconOptional { @@ -97,7 +91,6 @@ - (void)setIconRotationAlignment:(id )iconRotationAlignment { MGLSetEnumProperty(iconRotationAlignment, IconRotationAlignment, AlignmentType, MGLSymbolStyleLayerIconRotationAlignment); - [self update]; } - (id )iconRotationAlignment { @@ -106,7 +99,6 @@ - (void)setIconSize:(id )iconSize { self.layer->setIconSize(iconSize.mbgl_floatPropertyValue); - [self update]; } - (id )iconSize { @@ -115,7 +107,6 @@ - (void)setIconTextFit:(id )iconTextFit { MGLSetEnumProperty(iconTextFit, IconTextFit, IconTextFitType, MGLSymbolStyleLayerIconTextFit); - [self update]; } - (id )iconTextFit { @@ -124,7 +115,6 @@ - (void)setIconTextFitPadding:(id )iconTextFitPadding { self.layer->setIconTextFitPadding(iconTextFitPadding.mbgl_paddingPropertyValue); - [self update]; } - (id )iconTextFitPadding { @@ -133,7 +123,6 @@ - (void)setIconImage:(id )iconImage { self.layer->setIconImage(iconImage.mbgl_stringPropertyValue); - [self update]; } - (id )iconImage { @@ -142,7 +131,6 @@ - (void)setIconRotate:(id )iconRotate { self.layer->setIconRotate(iconRotate.mbgl_floatPropertyValue); - [self update]; } - (id )iconRotate { @@ -151,7 +139,6 @@ - (void)setIconPadding:(id )iconPadding { self.layer->setIconPadding(iconPadding.mbgl_floatPropertyValue); - [self update]; } - (id )iconPadding { @@ -160,7 +147,6 @@ - (void)setIconKeepUpright:(id )iconKeepUpright { self.layer->setIconKeepUpright(iconKeepUpright.mbgl_boolPropertyValue); - [self update]; } - (id )iconKeepUpright { @@ -169,7 +155,6 @@ - (void)setIconOffset:(id )iconOffset { self.layer->setIconOffset(iconOffset.mbgl_offsetPropertyValue); - [self update]; } - (id )iconOffset { @@ -178,7 +163,6 @@ - (void)setTextPitchAlignment:(id )textPitchAlignment { MGLSetEnumProperty(textPitchAlignment, TextPitchAlignment, AlignmentType, MGLSymbolStyleLayerTextPitchAlignment); - [self update]; } - (id )textPitchAlignment { @@ -187,7 +171,6 @@ - (void)setTextRotationAlignment:(id )textRotationAlignment { MGLSetEnumProperty(textRotationAlignment, TextRotationAlignment, AlignmentType, MGLSymbolStyleLayerTextRotationAlignment); - [self update]; } - (id )textRotationAlignment { @@ -196,7 +179,6 @@ - (void)setTextField:(id )textField { self.layer->setTextField(textField.mbgl_stringPropertyValue); - [self update]; } - (id )textField { @@ -205,7 +187,6 @@ - (void)setTextFont:(id )textFont { self.layer->setTextFont(textFont.mbgl_stringArrayPropertyValue); - [self update]; } - (id )textFont { @@ -214,7 +195,6 @@ - (void)setTextSize:(id )textSize { self.layer->setTextSize(textSize.mbgl_floatPropertyValue); - [self update]; } - (id )textSize { @@ -223,7 +203,6 @@ - (void)setTextMaxWidth:(id )textMaxWidth { self.layer->setTextMaxWidth(textMaxWidth.mbgl_floatPropertyValue); - [self update]; } - (id )textMaxWidth { @@ -232,7 +211,6 @@ - (void)setTextLineHeight:(id )textLineHeight { self.layer->setTextLineHeight(textLineHeight.mbgl_floatPropertyValue); - [self update]; } - (id )textLineHeight { @@ -241,7 +219,6 @@ - (void)setTextLetterSpacing:(id )textLetterSpacing { self.layer->setTextLetterSpacing(textLetterSpacing.mbgl_floatPropertyValue); - [self update]; } - (id )textLetterSpacing { @@ -250,7 +227,6 @@ - (void)setTextJustify:(id )textJustify { MGLSetEnumProperty(textJustify, TextJustify, TextJustifyType, MGLSymbolStyleLayerTextJustify); - [self update]; } - (id )textJustify { @@ -259,7 +235,6 @@ - (void)setTextAnchor:(id )textAnchor { MGLSetEnumProperty(textAnchor, TextAnchor, TextAnchorType, MGLSymbolStyleLayerTextAnchor); - [self update]; } - (id )textAnchor { @@ -268,7 +243,6 @@ - (void)setTextMaxAngle:(id )textMaxAngle { self.layer->setTextMaxAngle(textMaxAngle.mbgl_floatPropertyValue); - [self update]; } - (id )textMaxAngle { @@ -277,7 +251,6 @@ - (void)setTextRotate:(id )textRotate { self.layer->setTextRotate(textRotate.mbgl_floatPropertyValue); - [self update]; } - (id )textRotate { @@ -286,7 +259,6 @@ - (void)setTextPadding:(id )textPadding { self.layer->setTextPadding(textPadding.mbgl_floatPropertyValue); - [self update]; } - (id )textPadding { @@ -295,7 +267,6 @@ - (void)setTextKeepUpright:(id )textKeepUpright { self.layer->setTextKeepUpright(textKeepUpright.mbgl_boolPropertyValue); - [self update]; } - (id )textKeepUpright { @@ -304,7 +275,6 @@ - (void)setTextTransform:(id )textTransform { MGLSetEnumProperty(textTransform, TextTransform, TextTransformType, MGLSymbolStyleLayerTextTransform); - [self update]; } - (id )textTransform { @@ -313,7 +283,6 @@ - (void)setTextOffset:(id )textOffset { self.layer->setTextOffset(textOffset.mbgl_offsetPropertyValue); - [self update]; } - (id )textOffset { @@ -322,7 +291,6 @@ - (void)setTextAllowOverlap:(id )textAllowOverlap { self.layer->setTextAllowOverlap(textAllowOverlap.mbgl_boolPropertyValue); - [self update]; } - (id )textAllowOverlap { @@ -331,7 +299,6 @@ - (void)setTextIgnorePlacement:(id )textIgnorePlacement { self.layer->setTextIgnorePlacement(textIgnorePlacement.mbgl_boolPropertyValue); - [self update]; } - (id )textIgnorePlacement { @@ -340,7 +307,6 @@ - (void)setTextOptional:(id )textOptional { self.layer->setTextOptional(textOptional.mbgl_boolPropertyValue); - [self update]; } - (id )textOptional { @@ -351,7 +317,6 @@ - (void)setIconOpacity:(id )iconOpacity { self.layer->setIconOpacity(iconOpacity.mbgl_floatPropertyValue); - [self update]; } - (id )iconOpacity { @@ -360,7 +325,6 @@ - (void)setIconColor:(id )iconColor { self.layer->setIconColor(iconColor.mbgl_colorPropertyValue); - [self update]; } - (id )iconColor { @@ -369,7 +333,6 @@ - (void)setIconHaloColor:(id )iconHaloColor { self.layer->setIconHaloColor(iconHaloColor.mbgl_colorPropertyValue); - [self update]; } - (id )iconHaloColor { @@ -378,7 +341,6 @@ - (void)setIconHaloWidth:(id )iconHaloWidth { self.layer->setIconHaloWidth(iconHaloWidth.mbgl_floatPropertyValue); - [self update]; } - (id )iconHaloWidth { @@ -387,7 +349,6 @@ - (void)setIconHaloBlur:(id )iconHaloBlur { self.layer->setIconHaloBlur(iconHaloBlur.mbgl_floatPropertyValue); - [self update]; } - (id )iconHaloBlur { @@ -396,7 +357,6 @@ - (void)setIconTranslate:(id )iconTranslate { self.layer->setIconTranslate(iconTranslate.mbgl_offsetPropertyValue); - [self update]; } - (id )iconTranslate { @@ -405,7 +365,6 @@ - (void)setIconTranslateAnchor:(id )iconTranslateAnchor { MGLSetEnumProperty(iconTranslateAnchor, IconTranslateAnchor, TranslateAnchorType, MGLSymbolStyleLayerIconTranslateAnchor); - [self update]; } - (id )iconTranslateAnchor { @@ -414,7 +373,6 @@ - (void)setTextOpacity:(id )textOpacity { self.layer->setTextOpacity(textOpacity.mbgl_floatPropertyValue); - [self update]; } - (id )textOpacity { @@ -423,7 +381,6 @@ - (void)setTextColor:(id )textColor { self.layer->setTextColor(textColor.mbgl_colorPropertyValue); - [self update]; } - (id )textColor { @@ -432,7 +389,6 @@ - (void)setTextHaloColor:(id )textHaloColor { self.layer->setTextHaloColor(textHaloColor.mbgl_colorPropertyValue); - [self update]; } - (id )textHaloColor { @@ -441,7 +397,6 @@ - (void)setTextHaloWidth:(id )textHaloWidth { self.layer->setTextHaloWidth(textHaloWidth.mbgl_floatPropertyValue); - [self update]; } - (id )textHaloWidth { @@ -450,7 +405,6 @@ - (void)setTextHaloBlur:(id )textHaloBlur { self.layer->setTextHaloBlur(textHaloBlur.mbgl_floatPropertyValue); - [self update]; } - (id )textHaloBlur { @@ -459,7 +413,6 @@ - (void)setTextTranslate:(id )textTranslate { self.layer->setTextTranslate(textTranslate.mbgl_offsetPropertyValue); - [self update]; } - (id )textTranslate { @@ -468,7 +421,6 @@ - (void)setTextTranslateAnchor:(id )textTranslateAnchor { MGLSetEnumProperty(textTranslateAnchor, TextTranslateAnchor, TranslateAnchorType, MGLSymbolStyleLayerTextTranslateAnchor); - [self update]; } - (id )textTranslateAnchor { diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index 6c71b1b3d..90e0f1cfb 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -353,8 +353,6 @@ DAA4E4341CBB730400178DFB /* MGLFaux3DUserLocationAnnotationView.m in Sources */ = {isa = PBXBuildFile; fileRef = DA88484E1CBAFB9800AB86E3 /* MGLFaux3DUserLocationAnnotationView.m */; }; DAA4E4351CBB730400178DFB /* SMCalloutView.m in Sources */ = {isa = PBXBuildFile; fileRef = DA88488A1CBB037E00AB86E3 /* SMCalloutView.m */; }; DAABF73D1CBC59BB005B1825 /* libmbgl-core.a in Frameworks */ = {isa = PBXBuildFile; fileRef = DAABF73B1CBC59BB005B1825 /* libmbgl-core.a */; }; - DAB4F8301D63DD7600E27738 /* MGLBaseStyleLayer_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = DAB4F82F1D63DD7600E27738 /* MGLBaseStyleLayer_Private.h */; }; - DAB4F8311D63DD7600E27738 /* MGLBaseStyleLayer_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = DAB4F82F1D63DD7600E27738 /* MGLBaseStyleLayer_Private.h */; }; DABCABAC1CB80692000A7C39 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = DABCABAB1CB80692000A7C39 /* main.m */; }; DABCABAF1CB80692000A7C39 /* MBXBenchAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = DABCABAE1CB80692000A7C39 /* MBXBenchAppDelegate.m */; }; DABCABB21CB80692000A7C39 /* MBXBenchViewController.mm in Sources */ = {isa = PBXBuildFile; fileRef = DABCABB11CB80692000A7C39 /* MBXBenchViewController.mm */; }; @@ -729,7 +727,6 @@ DAA4E4061CBB5CBF00178DFB /* MobileCoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MobileCoreServices.framework; path = System/Library/Frameworks/MobileCoreServices.framework; sourceTree = SDKROOT; }; DAA4E4131CBB71D400178DFB /* libMapbox.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libMapbox.a; sourceTree = BUILT_PRODUCTS_DIR; }; DAABF73B1CBC59BB005B1825 /* libmbgl-core.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = "libmbgl-core.a"; sourceTree = BUILT_PRODUCTS_DIR; }; - DAB4F82F1D63DD7600E27738 /* MGLBaseStyleLayer_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLBaseStyleLayer_Private.h; sourceTree = ""; }; DABCABA81CB80692000A7C39 /* Bench GL.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Bench GL.app"; sourceTree = BUILT_PRODUCTS_DIR; }; DABCABAB1CB80692000A7C39 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; DABCABAD1CB80692000A7C39 /* MBXBenchAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MBXBenchAppDelegate.h; sourceTree = ""; }; @@ -836,7 +833,6 @@ 353933FD1D3FB7DD003F57D7 /* MGLSymbolStyleLayer.h */, 35136D441D42275100C20EFD /* MGLSymbolStyleLayer.mm */, 3538AA1B1D542239008EC33D /* MGLBaseStyleLayer.h */, - DAB4F82F1D63DD7600E27738 /* MGLBaseStyleLayer_Private.h */, 3538AA1C1D542239008EC33D /* MGLBaseStyleLayer.mm */, ); name = Layers; @@ -1391,7 +1387,6 @@ 35E0CFE61D3E501500188327 /* MGLStyle_Private.h in Headers */, 3510FFF01D6D9D8C00F413B2 /* NSExpression+MGLAdditions.h in Headers */, 353AFA141D65AB17005A69F4 /* NSDate+MGLAdditions.h in Headers */, - DAB4F8301D63DD7600E27738 /* MGLBaseStyleLayer_Private.h in Headers */, 3593E5261D529EDC006D9365 /* UIColor+MGLStyleAttributeAdditions_Private.h in Headers */, 35599DF01D46F3A60048254D /* MGLStyleAttributeValue.h in Headers */, DA8848531CBAFB9800AB86E3 /* MGLCompactCalloutView.h in Headers */, @@ -1494,7 +1489,6 @@ DABFB8611CBE99E500D62B32 /* MGLMultiPoint.h in Headers */, 3510FFF11D6D9D8C00F413B2 /* NSExpression+MGLAdditions.h in Headers */, 35E0CFE71D3E501500188327 /* MGLStyle_Private.h in Headers */, - DAB4F8311D63DD7600E27738 /* MGLBaseStyleLayer_Private.h in Headers */, DABFB86D1CBE9A0F00D62B32 /* MGLAnnotationImage.h in Headers */, DABFB8721CBE9A0F00D62B32 /* MGLUserLocation.h in Headers */, 3566C7721D4A9198008152BC /* MGLSource_Private.h in Headers */, diff --git a/platform/macos/macos.xcodeproj/project.pbxproj b/platform/macos/macos.xcodeproj/project.pbxproj index 2fb0630ea..92a130594 100644 --- a/platform/macos/macos.xcodeproj/project.pbxproj +++ b/platform/macos/macos.xcodeproj/project.pbxproj @@ -98,7 +98,6 @@ DA8F25B21D51CB270010E6B5 /* NSValue+MGLStyleAttributeAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = DA8F25A61D51CB270010E6B5 /* NSValue+MGLStyleAttributeAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; }; DA8F25B31D51CB270010E6B5 /* NSValue+MGLStyleAttributeAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA8F25A71D51CB270010E6B5 /* NSValue+MGLStyleAttributeAdditions.mm */; }; DA8F25B41D51CB270010E6B5 /* NSValue+MGLStyleAttributeAdditions_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = DA8F25A81D51CB270010E6B5 /* NSValue+MGLStyleAttributeAdditions_Private.h */; }; - DAB4F8331D63DD8900E27738 /* MGLBaseStyleLayer_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = DAB4F8321D63DD8900E27738 /* MGLBaseStyleLayer_Private.h */; }; DAC2ABC51CC6D343006D18C4 /* MGLAnnotationImage_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = DAC2ABC41CC6D343006D18C4 /* MGLAnnotationImage_Private.h */; }; DACC22141CF3D3E200D220D9 /* MGLFeature.h in Headers */ = {isa = PBXBuildFile; fileRef = DACC22121CF3D3E200D220D9 /* MGLFeature.h */; settings = {ATTRIBUTES = (Public, ); }; }; DACC22151CF3D3E200D220D9 /* MGLFeature.mm in Sources */ = {isa = PBXBuildFile; fileRef = DACC22131CF3D3E200D220D9 /* MGLFeature.mm */; }; @@ -325,7 +324,6 @@ DA8F25B51D51D2240010E6B5 /* MGLRuntimeStylingTests.m.ejs */ = {isa = PBXFileReference; lastKnownFileType = text; path = MGLRuntimeStylingTests.m.ejs; sourceTree = ""; }; DA8F25B61D51D2240010E6B5 /* MGLStyleLayer.h.ejs */ = {isa = PBXFileReference; lastKnownFileType = text; path = MGLStyleLayer.h.ejs; sourceTree = ""; }; DA8F25B71D51D2240010E6B5 /* MGLStyleLayer.mm.ejs */ = {isa = PBXFileReference; lastKnownFileType = text; path = MGLStyleLayer.mm.ejs; sourceTree = ""; }; - DAB4F8321D63DD8900E27738 /* MGLBaseStyleLayer_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLBaseStyleLayer_Private.h; sourceTree = ""; }; DAC2ABC41CC6D343006D18C4 /* MGLAnnotationImage_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAnnotationImage_Private.h; sourceTree = ""; }; DACC22121CF3D3E200D220D9 /* MGLFeature.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLFeature.h; sourceTree = ""; }; DACC22131CF3D3E200D220D9 /* MGLFeature.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLFeature.mm; sourceTree = ""; }; @@ -453,7 +451,6 @@ isa = PBXGroup; children = ( 3538AA211D542685008EC33D /* MGLBaseStyleLayer.h */, - DAB4F8321D63DD8900E27738 /* MGLBaseStyleLayer_Private.h */, 3538AA221D542685008EC33D /* MGLBaseStyleLayer.mm */, DA8F25851D51C9E10010E6B5 /* MGLBackgroundStyleLayer.h */, DA8F25861D51C9E10010E6B5 /* MGLBackgroundStyleLayer.mm */, @@ -922,7 +919,6 @@ DAE6C3A51CC31E9400DB3429 /* MGLMapView+IBAdditions.h in Headers */, DA35A2AD1CCA091800E826B2 /* MGLCompassDirectionFormatter.h in Headers */, 352742851D4C244700A1ECE6 /* MGLRasterSource.h in Headers */, - DAB4F8331D63DD8900E27738 /* MGLBaseStyleLayer_Private.h in Headers */, DACC22181CF3D4F700D220D9 /* MGLFeature_Private.h in Headers */, 352742891D4C245800A1ECE6 /* MGLGeoJSONSource.h in Headers */, DAE6C3671CC31E0400DB3429 /* MGLStyle.h in Headers */, diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp index f737ddfd8..31259f897 100644 --- a/platform/node/src/node_map.cpp +++ b/platform/node/src/node_map.cpp @@ -579,7 +579,6 @@ void NodeMap::SetLayoutProperty(const Nan::FunctionCallbackInfo& info return Nan::ThrowTypeError(error->message.c_str()); } - nodeMap->map->update(mbgl::Update::RecalculateStyle); info.GetReturnValue().SetUndefined(); } @@ -617,7 +616,6 @@ void NodeMap::SetPaintProperty(const Nan::FunctionCallbackInfo& info) return Nan::ThrowTypeError(error->message.c_str()); } - nodeMap->map->update(mbgl::Update::RecalculateStyle | mbgl::Update::Classes); info.GetReturnValue().SetUndefined(); } diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp index 111e92d1f..f7f1a7fb5 100644 --- a/platform/qt/src/qmapboxgl.cpp +++ b/platform/qt/src/qmapboxgl.cpp @@ -541,8 +541,6 @@ void QMapboxGL::setLayoutProperty(const QString& layer_, const QString& property qWarning() << "Error setting layout property:" << layer_ << "-" << property; return; } - - d_ptr->mapObj->update(mbgl::Update::RecalculateStyle); } void QMapboxGL::setPaintProperty(const QString& layer_, const QString& property, const QVariant& value, const QString& klass_) @@ -564,8 +562,6 @@ void QMapboxGL::setPaintProperty(const QString& layer_, const QString& property, qWarning() << "Error setting paint property:" << layer_ << "-" << property; return; } - - d_ptr->mapObj->update(mbgl::Update::RecalculateStyle | mbgl::Update::Classes); } bool QMapboxGL::isRotating() const diff --git a/src/mbgl/style/layer_impl.cpp b/src/mbgl/style/layer_impl.cpp index f50bf8733..7a0195c55 100644 --- a/src/mbgl/style/layer_impl.cpp +++ b/src/mbgl/style/layer_impl.cpp @@ -28,5 +28,9 @@ bool Layer::Impl::needsRendering(float zoom) const { && maxZoom >= zoom; } +void Layer::Impl::setObserver(LayerObserver* observer_) { + observer = observer_; +} + } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/layer_impl.hpp b/src/mbgl/style/layer_impl.hpp index c1f04fe51..55b1ff058 100644 --- a/src/mbgl/style/layer_impl.hpp +++ b/src/mbgl/style/layer_impl.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -73,6 +74,8 @@ public: const float, const float) const { return false; }; + void setObserver(LayerObserver*); + public: std::string id; std::string ref; @@ -83,6 +86,9 @@ public: float maxZoom = std::numeric_limits::infinity(); VisibilityType visibility = VisibilityType::Visible; + LayerObserver nullObserver; + LayerObserver* observer = &nullObserver; + protected: Impl() = default; Impl(const Impl&) = default; diff --git a/src/mbgl/style/layer_observer.hpp b/src/mbgl/style/layer_observer.hpp new file mode 100644 index 000000000..1d3d1aef4 --- /dev/null +++ b/src/mbgl/style/layer_observer.hpp @@ -0,0 +1,18 @@ +#pragma once + +namespace mbgl { +namespace style { + +class Layer; + +class LayerObserver { +public: + virtual ~LayerObserver() = default; + + virtual void onLayerFilterChanged(Layer&) {} + virtual void onLayerPaintPropertyChanged(Layer&) {} + virtual void onLayerLayoutPropertyChanged(Layer&) {} +}; + +} // namespace style +} // namespace mbgl diff --git a/src/mbgl/style/layers/background_layer.cpp b/src/mbgl/style/layers/background_layer.cpp index 25de2a943..5e5faf37e 100644 --- a/src/mbgl/style/layers/background_layer.cpp +++ b/src/mbgl/style/layers/background_layer.cpp @@ -46,7 +46,10 @@ PropertyValue BackgroundLayer::getBackgroundColor(const optional value, const optional& klass) { + if (value == getBackgroundColor(klass)) + return; impl->paint.backgroundColor.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue BackgroundLayer::getDefaultBackgroundPattern() { @@ -58,7 +61,10 @@ PropertyValue BackgroundLayer::getBackgroundPattern(const optional< } void BackgroundLayer::setBackgroundPattern(PropertyValue value, const optional& klass) { + if (value == getBackgroundPattern(klass)) + return; impl->paint.backgroundPattern.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue BackgroundLayer::getDefaultBackgroundOpacity() { @@ -70,7 +76,10 @@ PropertyValue BackgroundLayer::getBackgroundOpacity(const optional value, const optional& klass) { + if (value == getBackgroundOpacity(klass)) + return; impl->paint.backgroundOpacity.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } } // namespace style diff --git a/src/mbgl/style/layers/circle_layer.cpp b/src/mbgl/style/layers/circle_layer.cpp index 5fa29d9d3..a2b8d316d 100644 --- a/src/mbgl/style/layers/circle_layer.cpp +++ b/src/mbgl/style/layers/circle_layer.cpp @@ -50,6 +50,7 @@ const std::string& CircleLayer::getSourceLayer() const { void CircleLayer::setFilter(const Filter& filter) { impl->filter = filter; + impl->observer->onLayerFilterChanged(*this); } const Filter& CircleLayer::getFilter() const { @@ -70,7 +71,10 @@ PropertyValue CircleLayer::getCircleRadius(const optional& k } void CircleLayer::setCircleRadius(PropertyValue value, const optional& klass) { + if (value == getCircleRadius(klass)) + return; impl->paint.circleRadius.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue CircleLayer::getDefaultCircleColor() { @@ -82,7 +86,10 @@ PropertyValue CircleLayer::getCircleColor(const optional& kl } void CircleLayer::setCircleColor(PropertyValue value, const optional& klass) { + if (value == getCircleColor(klass)) + return; impl->paint.circleColor.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue CircleLayer::getDefaultCircleBlur() { @@ -94,7 +101,10 @@ PropertyValue CircleLayer::getCircleBlur(const optional& kla } void CircleLayer::setCircleBlur(PropertyValue value, const optional& klass) { + if (value == getCircleBlur(klass)) + return; impl->paint.circleBlur.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue CircleLayer::getDefaultCircleOpacity() { @@ -106,7 +116,10 @@ PropertyValue CircleLayer::getCircleOpacity(const optional& } void CircleLayer::setCircleOpacity(PropertyValue value, const optional& klass) { + if (value == getCircleOpacity(klass)) + return; impl->paint.circleOpacity.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue> CircleLayer::getDefaultCircleTranslate() { @@ -118,7 +131,10 @@ PropertyValue> CircleLayer::getCircleTranslate(const option } void CircleLayer::setCircleTranslate(PropertyValue> value, const optional& klass) { + if (value == getCircleTranslate(klass)) + return; impl->paint.circleTranslate.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue CircleLayer::getDefaultCircleTranslateAnchor() { @@ -130,7 +146,10 @@ PropertyValue CircleLayer::getCircleTranslateAnchor(const o } void CircleLayer::setCircleTranslateAnchor(PropertyValue value, const optional& klass) { + if (value == getCircleTranslateAnchor(klass)) + return; impl->paint.circleTranslateAnchor.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue CircleLayer::getDefaultCirclePitchScale() { @@ -142,7 +161,10 @@ PropertyValue CircleLayer::getCirclePitchScale(const optio } void CircleLayer::setCirclePitchScale(PropertyValue value, const optional& klass) { + if (value == getCirclePitchScale(klass)) + return; impl->paint.circlePitchScale.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } } // namespace style diff --git a/src/mbgl/style/layers/fill_layer.cpp b/src/mbgl/style/layers/fill_layer.cpp index 6bc4b892e..c61de81d1 100644 --- a/src/mbgl/style/layers/fill_layer.cpp +++ b/src/mbgl/style/layers/fill_layer.cpp @@ -50,6 +50,7 @@ const std::string& FillLayer::getSourceLayer() const { void FillLayer::setFilter(const Filter& filter) { impl->filter = filter; + impl->observer->onLayerFilterChanged(*this); } const Filter& FillLayer::getFilter() const { @@ -70,7 +71,10 @@ PropertyValue FillLayer::getFillAntialias(const optional& kla } void FillLayer::setFillAntialias(PropertyValue value, const optional& klass) { + if (value == getFillAntialias(klass)) + return; impl->paint.fillAntialias.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue FillLayer::getDefaultFillOpacity() { @@ -82,7 +86,10 @@ PropertyValue FillLayer::getFillOpacity(const optional& klas } void FillLayer::setFillOpacity(PropertyValue value, const optional& klass) { + if (value == getFillOpacity(klass)) + return; impl->paint.fillOpacity.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue FillLayer::getDefaultFillColor() { @@ -94,7 +101,10 @@ PropertyValue FillLayer::getFillColor(const optional& klass) } void FillLayer::setFillColor(PropertyValue value, const optional& klass) { + if (value == getFillColor(klass)) + return; impl->paint.fillColor.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue FillLayer::getDefaultFillOutlineColor() { @@ -106,7 +116,10 @@ PropertyValue FillLayer::getFillOutlineColor(const optional& } void FillLayer::setFillOutlineColor(PropertyValue value, const optional& klass) { + if (value == getFillOutlineColor(klass)) + return; impl->paint.fillOutlineColor.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue> FillLayer::getDefaultFillTranslate() { @@ -118,7 +131,10 @@ PropertyValue> FillLayer::getFillTranslate(const optional> value, const optional& klass) { + if (value == getFillTranslate(klass)) + return; impl->paint.fillTranslate.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue FillLayer::getDefaultFillTranslateAnchor() { @@ -130,7 +146,10 @@ PropertyValue FillLayer::getFillTranslateAnchor(const optio } void FillLayer::setFillTranslateAnchor(PropertyValue value, const optional& klass) { + if (value == getFillTranslateAnchor(klass)) + return; impl->paint.fillTranslateAnchor.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue FillLayer::getDefaultFillPattern() { @@ -142,7 +161,10 @@ PropertyValue FillLayer::getFillPattern(const optional } void FillLayer::setFillPattern(PropertyValue value, const optional& klass) { + if (value == getFillPattern(klass)) + return; impl->paint.fillPattern.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } } // namespace style diff --git a/src/mbgl/style/layers/layer.cpp.ejs b/src/mbgl/style/layers/layer.cpp.ejs index 75a8de8e7..237a68aad 100644 --- a/src/mbgl/style/layers/layer.cpp.ejs +++ b/src/mbgl/style/layers/layer.cpp.ejs @@ -65,6 +65,7 @@ const std::string& <%- camelize(type) %>Layer::getSourceLayer() const { void <%- camelize(type) %>Layer::setFilter(const Filter& filter) { impl->filter = filter; + impl->observer->onLayerFilterChanged(*this); } const Filter& <%- camelize(type) %>Layer::getFilter() const { @@ -85,7 +86,10 @@ PropertyValue<<%- propertyType(property) %>> <%- camelize(type) %>Layer::get<%- } void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>(PropertyValue<<%- propertyType(property) %>> value) { + if (value == get<%- camelize(property.name) %>()) + return; impl->layout.<%- camelizeWithLeadingLowercase(property.name) %>.set(value); + impl->observer->onLayerLayoutPropertyChanged(*this); } <% } -%> @@ -100,7 +104,10 @@ PropertyValue<<%- propertyType(property) %>> <%- camelize(type) %>Layer::get<%- } void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>(PropertyValue<<%- propertyType(property) %>> value, const optional& klass) { + if (value == get<%- camelize(property.name) %>(klass)) + return; impl->paint.<%- camelizeWithLeadingLowercase(property.name) %>.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } <% } -%> diff --git a/src/mbgl/style/layers/line_layer.cpp b/src/mbgl/style/layers/line_layer.cpp index dbf4b682b..100ee7247 100644 --- a/src/mbgl/style/layers/line_layer.cpp +++ b/src/mbgl/style/layers/line_layer.cpp @@ -50,6 +50,7 @@ const std::string& LineLayer::getSourceLayer() const { void LineLayer::setFilter(const Filter& filter) { impl->filter = filter; + impl->observer->onLayerFilterChanged(*this); } const Filter& LineLayer::getFilter() const { @@ -67,7 +68,10 @@ PropertyValue LineLayer::getLineCap() const { } void LineLayer::setLineCap(PropertyValue value) { + if (value == getLineCap()) + return; impl->layout.lineCap.set(value); + impl->observer->onLayerLayoutPropertyChanged(*this); } PropertyValue LineLayer::getDefaultLineJoin() { return { LineJoinType::Miter }; @@ -78,7 +82,10 @@ PropertyValue LineLayer::getLineJoin() const { } void LineLayer::setLineJoin(PropertyValue value) { + if (value == getLineJoin()) + return; impl->layout.lineJoin.set(value); + impl->observer->onLayerLayoutPropertyChanged(*this); } PropertyValue LineLayer::getDefaultLineMiterLimit() { return { 2 }; @@ -89,7 +96,10 @@ PropertyValue LineLayer::getLineMiterLimit() const { } void LineLayer::setLineMiterLimit(PropertyValue value) { + if (value == getLineMiterLimit()) + return; impl->layout.lineMiterLimit.set(value); + impl->observer->onLayerLayoutPropertyChanged(*this); } PropertyValue LineLayer::getDefaultLineRoundLimit() { return { 1 }; @@ -100,7 +110,10 @@ PropertyValue LineLayer::getLineRoundLimit() const { } void LineLayer::setLineRoundLimit(PropertyValue value) { + if (value == getLineRoundLimit()) + return; impl->layout.lineRoundLimit.set(value); + impl->observer->onLayerLayoutPropertyChanged(*this); } // Paint properties @@ -114,7 +127,10 @@ PropertyValue LineLayer::getLineOpacity(const optional& klas } void LineLayer::setLineOpacity(PropertyValue value, const optional& klass) { + if (value == getLineOpacity(klass)) + return; impl->paint.lineOpacity.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue LineLayer::getDefaultLineColor() { @@ -126,7 +142,10 @@ PropertyValue LineLayer::getLineColor(const optional& klass) } void LineLayer::setLineColor(PropertyValue value, const optional& klass) { + if (value == getLineColor(klass)) + return; impl->paint.lineColor.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue> LineLayer::getDefaultLineTranslate() { @@ -138,7 +157,10 @@ PropertyValue> LineLayer::getLineTranslate(const optional> value, const optional& klass) { + if (value == getLineTranslate(klass)) + return; impl->paint.lineTranslate.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue LineLayer::getDefaultLineTranslateAnchor() { @@ -150,7 +172,10 @@ PropertyValue LineLayer::getLineTranslateAnchor(const optio } void LineLayer::setLineTranslateAnchor(PropertyValue value, const optional& klass) { + if (value == getLineTranslateAnchor(klass)) + return; impl->paint.lineTranslateAnchor.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue LineLayer::getDefaultLineWidth() { @@ -162,7 +187,10 @@ PropertyValue LineLayer::getLineWidth(const optional& klass) } void LineLayer::setLineWidth(PropertyValue value, const optional& klass) { + if (value == getLineWidth(klass)) + return; impl->paint.lineWidth.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue LineLayer::getDefaultLineGapWidth() { @@ -174,7 +202,10 @@ PropertyValue LineLayer::getLineGapWidth(const optional& kla } void LineLayer::setLineGapWidth(PropertyValue value, const optional& klass) { + if (value == getLineGapWidth(klass)) + return; impl->paint.lineGapWidth.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue LineLayer::getDefaultLineOffset() { @@ -186,7 +217,10 @@ PropertyValue LineLayer::getLineOffset(const optional& klass } void LineLayer::setLineOffset(PropertyValue value, const optional& klass) { + if (value == getLineOffset(klass)) + return; impl->paint.lineOffset.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue LineLayer::getDefaultLineBlur() { @@ -198,7 +232,10 @@ PropertyValue LineLayer::getLineBlur(const optional& klass) } void LineLayer::setLineBlur(PropertyValue value, const optional& klass) { + if (value == getLineBlur(klass)) + return; impl->paint.lineBlur.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue> LineLayer::getDefaultLineDasharray() { @@ -210,7 +247,10 @@ PropertyValue> LineLayer::getLineDasharray(const optional> value, const optional& klass) { + if (value == getLineDasharray(klass)) + return; impl->paint.lineDasharray.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue LineLayer::getDefaultLinePattern() { @@ -222,7 +262,10 @@ PropertyValue LineLayer::getLinePattern(const optional } void LineLayer::setLinePattern(PropertyValue value, const optional& klass) { + if (value == getLinePattern(klass)) + return; impl->paint.linePattern.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } } // namespace style diff --git a/src/mbgl/style/layers/raster_layer.cpp b/src/mbgl/style/layers/raster_layer.cpp index 084b29ee3..238bfef6e 100644 --- a/src/mbgl/style/layers/raster_layer.cpp +++ b/src/mbgl/style/layers/raster_layer.cpp @@ -53,7 +53,10 @@ PropertyValue RasterLayer::getRasterOpacity(const optional& } void RasterLayer::setRasterOpacity(PropertyValue value, const optional& klass) { + if (value == getRasterOpacity(klass)) + return; impl->paint.rasterOpacity.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue RasterLayer::getDefaultRasterHueRotate() { @@ -65,7 +68,10 @@ PropertyValue RasterLayer::getRasterHueRotate(const optional } void RasterLayer::setRasterHueRotate(PropertyValue value, const optional& klass) { + if (value == getRasterHueRotate(klass)) + return; impl->paint.rasterHueRotate.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue RasterLayer::getDefaultRasterBrightnessMin() { @@ -77,7 +83,10 @@ PropertyValue RasterLayer::getRasterBrightnessMin(const optional value, const optional& klass) { + if (value == getRasterBrightnessMin(klass)) + return; impl->paint.rasterBrightnessMin.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue RasterLayer::getDefaultRasterBrightnessMax() { @@ -89,7 +98,10 @@ PropertyValue RasterLayer::getRasterBrightnessMax(const optional value, const optional& klass) { + if (value == getRasterBrightnessMax(klass)) + return; impl->paint.rasterBrightnessMax.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue RasterLayer::getDefaultRasterSaturation() { @@ -101,7 +113,10 @@ PropertyValue RasterLayer::getRasterSaturation(const optional value, const optional& klass) { + if (value == getRasterSaturation(klass)) + return; impl->paint.rasterSaturation.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue RasterLayer::getDefaultRasterContrast() { @@ -113,7 +128,10 @@ PropertyValue RasterLayer::getRasterContrast(const optional& } void RasterLayer::setRasterContrast(PropertyValue value, const optional& klass) { + if (value == getRasterContrast(klass)) + return; impl->paint.rasterContrast.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue RasterLayer::getDefaultRasterFadeDuration() { @@ -125,7 +143,10 @@ PropertyValue RasterLayer::getRasterFadeDuration(const optional value, const optional& klass) { + if (value == getRasterFadeDuration(klass)) + return; impl->paint.rasterFadeDuration.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } } // namespace style diff --git a/src/mbgl/style/layers/symbol_layer.cpp b/src/mbgl/style/layers/symbol_layer.cpp index 78fbfda6d..c9fd2c098 100644 --- a/src/mbgl/style/layers/symbol_layer.cpp +++ b/src/mbgl/style/layers/symbol_layer.cpp @@ -50,6 +50,7 @@ const std::string& SymbolLayer::getSourceLayer() const { void SymbolLayer::setFilter(const Filter& filter) { impl->filter = filter; + impl->observer->onLayerFilterChanged(*this); } const Filter& SymbolLayer::getFilter() const { @@ -67,7 +68,10 @@ PropertyValue SymbolLayer::getSymbolPlacement() const { } void SymbolLayer::setSymbolPlacement(PropertyValue value) { + if (value == getSymbolPlacement()) + return; impl->layout.symbolPlacement.set(value); + impl->observer->onLayerLayoutPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultSymbolSpacing() { return { 250 }; @@ -78,7 +82,10 @@ PropertyValue SymbolLayer::getSymbolSpacing() const { } void SymbolLayer::setSymbolSpacing(PropertyValue value) { + if (value == getSymbolSpacing()) + return; impl->layout.symbolSpacing.set(value); + impl->observer->onLayerLayoutPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultSymbolAvoidEdges() { return { false }; @@ -89,7 +96,10 @@ PropertyValue SymbolLayer::getSymbolAvoidEdges() const { } void SymbolLayer::setSymbolAvoidEdges(PropertyValue value) { + if (value == getSymbolAvoidEdges()) + return; impl->layout.symbolAvoidEdges.set(value); + impl->observer->onLayerLayoutPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultIconAllowOverlap() { return { false }; @@ -100,7 +110,10 @@ PropertyValue SymbolLayer::getIconAllowOverlap() const { } void SymbolLayer::setIconAllowOverlap(PropertyValue value) { + if (value == getIconAllowOverlap()) + return; impl->layout.iconAllowOverlap.set(value); + impl->observer->onLayerLayoutPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultIconIgnorePlacement() { return { false }; @@ -111,7 +124,10 @@ PropertyValue SymbolLayer::getIconIgnorePlacement() const { } void SymbolLayer::setIconIgnorePlacement(PropertyValue value) { + if (value == getIconIgnorePlacement()) + return; impl->layout.iconIgnorePlacement.set(value); + impl->observer->onLayerLayoutPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultIconOptional() { return { false }; @@ -122,7 +138,10 @@ PropertyValue SymbolLayer::getIconOptional() const { } void SymbolLayer::setIconOptional(PropertyValue value) { + if (value == getIconOptional()) + return; impl->layout.iconOptional.set(value); + impl->observer->onLayerLayoutPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultIconRotationAlignment() { return { AlignmentType::Viewport }; @@ -133,7 +152,10 @@ PropertyValue SymbolLayer::getIconRotationAlignment() const { } void SymbolLayer::setIconRotationAlignment(PropertyValue value) { + if (value == getIconRotationAlignment()) + return; impl->layout.iconRotationAlignment.set(value); + impl->observer->onLayerLayoutPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultIconSize() { return { 1 }; @@ -144,7 +166,10 @@ PropertyValue SymbolLayer::getIconSize() const { } void SymbolLayer::setIconSize(PropertyValue value) { + if (value == getIconSize()) + return; impl->layout.iconSize.set(value); + impl->observer->onLayerLayoutPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultIconTextFit() { return { IconTextFitType::None }; @@ -155,7 +180,10 @@ PropertyValue SymbolLayer::getIconTextFit() const { } void SymbolLayer::setIconTextFit(PropertyValue value) { + if (value == getIconTextFit()) + return; impl->layout.iconTextFit.set(value); + impl->observer->onLayerLayoutPropertyChanged(*this); } PropertyValue> SymbolLayer::getDefaultIconTextFitPadding() { return { {{ 0, 0, 0, 0 }} }; @@ -166,7 +194,10 @@ PropertyValue> SymbolLayer::getIconTextFitPadding() const { } void SymbolLayer::setIconTextFitPadding(PropertyValue> value) { + if (value == getIconTextFitPadding()) + return; impl->layout.iconTextFitPadding.set(value); + impl->observer->onLayerLayoutPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultIconImage() { return { "" }; @@ -177,7 +208,10 @@ PropertyValue SymbolLayer::getIconImage() const { } void SymbolLayer::setIconImage(PropertyValue value) { + if (value == getIconImage()) + return; impl->layout.iconImage.set(value); + impl->observer->onLayerLayoutPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultIconRotate() { return { 0 }; @@ -188,7 +222,10 @@ PropertyValue SymbolLayer::getIconRotate() const { } void SymbolLayer::setIconRotate(PropertyValue value) { + if (value == getIconRotate()) + return; impl->layout.iconRotate.set(value); + impl->observer->onLayerLayoutPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultIconPadding() { return { 2 }; @@ -199,7 +236,10 @@ PropertyValue SymbolLayer::getIconPadding() const { } void SymbolLayer::setIconPadding(PropertyValue value) { + if (value == getIconPadding()) + return; impl->layout.iconPadding.set(value); + impl->observer->onLayerLayoutPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultIconKeepUpright() { return { false }; @@ -210,7 +250,10 @@ PropertyValue SymbolLayer::getIconKeepUpright() const { } void SymbolLayer::setIconKeepUpright(PropertyValue value) { + if (value == getIconKeepUpright()) + return; impl->layout.iconKeepUpright.set(value); + impl->observer->onLayerLayoutPropertyChanged(*this); } PropertyValue> SymbolLayer::getDefaultIconOffset() { return { {{ 0, 0 }} }; @@ -221,7 +264,10 @@ PropertyValue> SymbolLayer::getIconOffset() const { } void SymbolLayer::setIconOffset(PropertyValue> value) { + if (value == getIconOffset()) + return; impl->layout.iconOffset.set(value); + impl->observer->onLayerLayoutPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultTextPitchAlignment() { return { AlignmentType::Undefined }; @@ -232,7 +278,10 @@ PropertyValue SymbolLayer::getTextPitchAlignment() const { } void SymbolLayer::setTextPitchAlignment(PropertyValue value) { + if (value == getTextPitchAlignment()) + return; impl->layout.textPitchAlignment.set(value); + impl->observer->onLayerLayoutPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultTextRotationAlignment() { return { AlignmentType::Viewport }; @@ -243,7 +292,10 @@ PropertyValue SymbolLayer::getTextRotationAlignment() const { } void SymbolLayer::setTextRotationAlignment(PropertyValue value) { + if (value == getTextRotationAlignment()) + return; impl->layout.textRotationAlignment.set(value); + impl->observer->onLayerLayoutPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultTextField() { return { "" }; @@ -254,7 +306,10 @@ PropertyValue SymbolLayer::getTextField() const { } void SymbolLayer::setTextField(PropertyValue value) { + if (value == getTextField()) + return; impl->layout.textField.set(value); + impl->observer->onLayerLayoutPropertyChanged(*this); } PropertyValue> SymbolLayer::getDefaultTextFont() { return { { "Open Sans Regular", "Arial Unicode MS Regular" } }; @@ -265,7 +320,10 @@ PropertyValue> SymbolLayer::getTextFont() const { } void SymbolLayer::setTextFont(PropertyValue> value) { + if (value == getTextFont()) + return; impl->layout.textFont.set(value); + impl->observer->onLayerLayoutPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultTextSize() { return { 16 }; @@ -276,7 +334,10 @@ PropertyValue SymbolLayer::getTextSize() const { } void SymbolLayer::setTextSize(PropertyValue value) { + if (value == getTextSize()) + return; impl->layout.textSize.set(value); + impl->observer->onLayerLayoutPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultTextMaxWidth() { return { 10 }; @@ -287,7 +348,10 @@ PropertyValue SymbolLayer::getTextMaxWidth() const { } void SymbolLayer::setTextMaxWidth(PropertyValue value) { + if (value == getTextMaxWidth()) + return; impl->layout.textMaxWidth.set(value); + impl->observer->onLayerLayoutPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultTextLineHeight() { return { 1.2 }; @@ -298,7 +362,10 @@ PropertyValue SymbolLayer::getTextLineHeight() const { } void SymbolLayer::setTextLineHeight(PropertyValue value) { + if (value == getTextLineHeight()) + return; impl->layout.textLineHeight.set(value); + impl->observer->onLayerLayoutPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultTextLetterSpacing() { return { 0 }; @@ -309,7 +376,10 @@ PropertyValue SymbolLayer::getTextLetterSpacing() const { } void SymbolLayer::setTextLetterSpacing(PropertyValue value) { + if (value == getTextLetterSpacing()) + return; impl->layout.textLetterSpacing.set(value); + impl->observer->onLayerLayoutPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultTextJustify() { return { TextJustifyType::Center }; @@ -320,7 +390,10 @@ PropertyValue SymbolLayer::getTextJustify() const { } void SymbolLayer::setTextJustify(PropertyValue value) { + if (value == getTextJustify()) + return; impl->layout.textJustify.set(value); + impl->observer->onLayerLayoutPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultTextAnchor() { return { TextAnchorType::Center }; @@ -331,7 +404,10 @@ PropertyValue SymbolLayer::getTextAnchor() const { } void SymbolLayer::setTextAnchor(PropertyValue value) { + if (value == getTextAnchor()) + return; impl->layout.textAnchor.set(value); + impl->observer->onLayerLayoutPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultTextMaxAngle() { return { 45 }; @@ -342,7 +418,10 @@ PropertyValue SymbolLayer::getTextMaxAngle() const { } void SymbolLayer::setTextMaxAngle(PropertyValue value) { + if (value == getTextMaxAngle()) + return; impl->layout.textMaxAngle.set(value); + impl->observer->onLayerLayoutPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultTextRotate() { return { 0 }; @@ -353,7 +432,10 @@ PropertyValue SymbolLayer::getTextRotate() const { } void SymbolLayer::setTextRotate(PropertyValue value) { + if (value == getTextRotate()) + return; impl->layout.textRotate.set(value); + impl->observer->onLayerLayoutPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultTextPadding() { return { 2 }; @@ -364,7 +446,10 @@ PropertyValue SymbolLayer::getTextPadding() const { } void SymbolLayer::setTextPadding(PropertyValue value) { + if (value == getTextPadding()) + return; impl->layout.textPadding.set(value); + impl->observer->onLayerLayoutPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultTextKeepUpright() { return { true }; @@ -375,7 +460,10 @@ PropertyValue SymbolLayer::getTextKeepUpright() const { } void SymbolLayer::setTextKeepUpright(PropertyValue value) { + if (value == getTextKeepUpright()) + return; impl->layout.textKeepUpright.set(value); + impl->observer->onLayerLayoutPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultTextTransform() { return { TextTransformType::None }; @@ -386,7 +474,10 @@ PropertyValue SymbolLayer::getTextTransform() const { } void SymbolLayer::setTextTransform(PropertyValue value) { + if (value == getTextTransform()) + return; impl->layout.textTransform.set(value); + impl->observer->onLayerLayoutPropertyChanged(*this); } PropertyValue> SymbolLayer::getDefaultTextOffset() { return { {{ 0, 0 }} }; @@ -397,7 +488,10 @@ PropertyValue> SymbolLayer::getTextOffset() const { } void SymbolLayer::setTextOffset(PropertyValue> value) { + if (value == getTextOffset()) + return; impl->layout.textOffset.set(value); + impl->observer->onLayerLayoutPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultTextAllowOverlap() { return { false }; @@ -408,7 +502,10 @@ PropertyValue SymbolLayer::getTextAllowOverlap() const { } void SymbolLayer::setTextAllowOverlap(PropertyValue value) { + if (value == getTextAllowOverlap()) + return; impl->layout.textAllowOverlap.set(value); + impl->observer->onLayerLayoutPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultTextIgnorePlacement() { return { false }; @@ -419,7 +516,10 @@ PropertyValue SymbolLayer::getTextIgnorePlacement() const { } void SymbolLayer::setTextIgnorePlacement(PropertyValue value) { + if (value == getTextIgnorePlacement()) + return; impl->layout.textIgnorePlacement.set(value); + impl->observer->onLayerLayoutPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultTextOptional() { return { false }; @@ -430,7 +530,10 @@ PropertyValue SymbolLayer::getTextOptional() const { } void SymbolLayer::setTextOptional(PropertyValue value) { + if (value == getTextOptional()) + return; impl->layout.textOptional.set(value); + impl->observer->onLayerLayoutPropertyChanged(*this); } // Paint properties @@ -444,7 +547,10 @@ PropertyValue SymbolLayer::getIconOpacity(const optional& kl } void SymbolLayer::setIconOpacity(PropertyValue value, const optional& klass) { + if (value == getIconOpacity(klass)) + return; impl->paint.iconOpacity.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultIconColor() { @@ -456,7 +562,10 @@ PropertyValue SymbolLayer::getIconColor(const optional& klas } void SymbolLayer::setIconColor(PropertyValue value, const optional& klass) { + if (value == getIconColor(klass)) + return; impl->paint.iconColor.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultIconHaloColor() { @@ -468,7 +577,10 @@ PropertyValue SymbolLayer::getIconHaloColor(const optional& } void SymbolLayer::setIconHaloColor(PropertyValue value, const optional& klass) { + if (value == getIconHaloColor(klass)) + return; impl->paint.iconHaloColor.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultIconHaloWidth() { @@ -480,7 +592,10 @@ PropertyValue SymbolLayer::getIconHaloWidth(const optional& } void SymbolLayer::setIconHaloWidth(PropertyValue value, const optional& klass) { + if (value == getIconHaloWidth(klass)) + return; impl->paint.iconHaloWidth.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultIconHaloBlur() { @@ -492,7 +607,10 @@ PropertyValue SymbolLayer::getIconHaloBlur(const optional& k } void SymbolLayer::setIconHaloBlur(PropertyValue value, const optional& klass) { + if (value == getIconHaloBlur(klass)) + return; impl->paint.iconHaloBlur.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue> SymbolLayer::getDefaultIconTranslate() { @@ -504,7 +622,10 @@ PropertyValue> SymbolLayer::getIconTranslate(const optional } void SymbolLayer::setIconTranslate(PropertyValue> value, const optional& klass) { + if (value == getIconTranslate(klass)) + return; impl->paint.iconTranslate.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultIconTranslateAnchor() { @@ -516,7 +637,10 @@ PropertyValue SymbolLayer::getIconTranslateAnchor(const opt } void SymbolLayer::setIconTranslateAnchor(PropertyValue value, const optional& klass) { + if (value == getIconTranslateAnchor(klass)) + return; impl->paint.iconTranslateAnchor.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultTextOpacity() { @@ -528,7 +652,10 @@ PropertyValue SymbolLayer::getTextOpacity(const optional& kl } void SymbolLayer::setTextOpacity(PropertyValue value, const optional& klass) { + if (value == getTextOpacity(klass)) + return; impl->paint.textOpacity.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultTextColor() { @@ -540,7 +667,10 @@ PropertyValue SymbolLayer::getTextColor(const optional& klas } void SymbolLayer::setTextColor(PropertyValue value, const optional& klass) { + if (value == getTextColor(klass)) + return; impl->paint.textColor.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultTextHaloColor() { @@ -552,7 +682,10 @@ PropertyValue SymbolLayer::getTextHaloColor(const optional& } void SymbolLayer::setTextHaloColor(PropertyValue value, const optional& klass) { + if (value == getTextHaloColor(klass)) + return; impl->paint.textHaloColor.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultTextHaloWidth() { @@ -564,7 +697,10 @@ PropertyValue SymbolLayer::getTextHaloWidth(const optional& } void SymbolLayer::setTextHaloWidth(PropertyValue value, const optional& klass) { + if (value == getTextHaloWidth(klass)) + return; impl->paint.textHaloWidth.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultTextHaloBlur() { @@ -576,7 +712,10 @@ PropertyValue SymbolLayer::getTextHaloBlur(const optional& k } void SymbolLayer::setTextHaloBlur(PropertyValue value, const optional& klass) { + if (value == getTextHaloBlur(klass)) + return; impl->paint.textHaloBlur.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue> SymbolLayer::getDefaultTextTranslate() { @@ -588,7 +727,10 @@ PropertyValue> SymbolLayer::getTextTranslate(const optional } void SymbolLayer::setTextTranslate(PropertyValue> value, const optional& klass) { + if (value == getTextTranslate(klass)) + return; impl->paint.textTranslate.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } PropertyValue SymbolLayer::getDefaultTextTranslateAnchor() { @@ -600,7 +742,10 @@ PropertyValue SymbolLayer::getTextTranslateAnchor(const opt } void SymbolLayer::setTextTranslateAnchor(PropertyValue value, const optional& klass) { + if (value == getTextTranslateAnchor(klass)) + return; impl->paint.textTranslateAnchor.set(value, klass); + impl->observer->onLayerPaintPropertyChanged(*this); } } // namespace style diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index bb0e2b61f..99333b4a7 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -167,6 +167,8 @@ Layer* Style::addLayer(std::unique_ptr layer, optional befor customLayer->impl->initialize(); } + layer->baseImpl->setObserver(this); + return layers.emplace(before ? findLayer(*before) : layers.end(), std::move(layer))->get(); } @@ -481,6 +483,19 @@ void Style::onSpriteError(std::exception_ptr error) { observer->onResourceError(error); } +void Style::onLayerFilterChanged(Layer&) { + // TODO: reload source +} + +void Style::onLayerPaintPropertyChanged(Layer&) { + observer->onUpdate(Update::RecalculateStyle | Update::Classes); +} + +void Style::onLayerLayoutPropertyChanged(Layer&) { + observer->onUpdate(Update::RecalculateStyle); + // TODO: reload source +} + void Style::dumpDebugLogs() const { for (const auto& source : sources) { source->baseImpl->dumpDebugLogs(); diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp index ca6526478..9e9ec1a03 100644 --- a/src/mbgl/style/style.hpp +++ b/src/mbgl/style/style.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -35,6 +36,7 @@ class QueryParameters; class Style : public GlyphStoreObserver, public SpriteStoreObserver, public SourceObserver, + public LayerObserver, public util::noncopyable { public: Style(FileSource&, float pixelRatio); @@ -129,6 +131,11 @@ private: void onTileError(Source&, const OverscaledTileID&, std::exception_ptr) override; void onTileUpdated(Source&, const OverscaledTileID&) override; + // LayerObserver implementation. + void onLayerFilterChanged(Layer&) override; + void onLayerPaintPropertyChanged(Layer&) override; + void onLayerLayoutPropertyChanged(Layer&) override; + Observer nullObserver; Observer* observer = &nullObserver; diff --git a/test/src/mbgl/test/stub_layer_observer.hpp b/test/src/mbgl/test/stub_layer_observer.hpp new file mode 100644 index 000000000..500103055 --- /dev/null +++ b/test/src/mbgl/test/stub_layer_observer.hpp @@ -0,0 +1,28 @@ +#pragma once + +#include + +using namespace mbgl; +using namespace mbgl::style; + +/** + * An implementation of style::LayerObserver that forwards all methods to dynamically-settable lambas. + */ +class StubLayerObserver : public style::LayerObserver { +public: + void onLayerFilterChanged(Layer& layer) override { + if (layerFilterChanged) layerFilterChanged(layer); + } + + void onLayerPaintPropertyChanged(Layer& layer) override { + if (layerPaintPropertyChanged) layerPaintPropertyChanged(layer); + } + + void onLayerLayoutPropertyChanged(Layer& layer) override { + if (layerLayoutPropertyChanged) layerLayoutPropertyChanged(layer); + } + + std::function layerFilterChanged; + std::function layerPaintPropertyChanged; + std::function layerLayoutPropertyChanged; +}; diff --git a/test/style/style_layer.cpp b/test/style/style_layer.cpp index 9c6a6e924..0d2ed88ed 100644 --- a/test/style/style_layer.cpp +++ b/test/style/style_layer.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -210,3 +211,46 @@ TEST(Layer, RasterProperties) { layer->setRasterFadeDuration(duration); EXPECT_EQ(layer->getRasterFadeDuration().asConstant(), duration.asConstant()); } + +TEST(Layer, Observer) { + auto layer = std::make_unique("line", "source"); + StubLayerObserver observer; + layer->baseImpl->setObserver(&observer); + + // Notifies observer on filter change. + bool filterChanged = false; + observer.layerFilterChanged = [&] (Layer& layer_) { + EXPECT_EQ(layer.get(), &layer_); + filterChanged = true; + }; + layer->setFilter(NullFilter()); + EXPECT_TRUE(filterChanged); + + // Notifies observer on paint property change. + bool paintPropertyChanged = false; + observer.layerPaintPropertyChanged = [&] (Layer& layer_) { + EXPECT_EQ(layer.get(), &layer_); + paintPropertyChanged = true; + }; + layer->setLineColor(color); + EXPECT_TRUE(paintPropertyChanged); + + // Notifies observer on layout property change. + bool layoutPropertyChanged = false; + observer.layerLayoutPropertyChanged = [&] (Layer& layer_) { + EXPECT_EQ(layer.get(), &layer_); + layoutPropertyChanged = true; + }; + layer->setLineCap(lineCap); + EXPECT_TRUE(layoutPropertyChanged); + + // Does not notify observer on no-op paint property change. + paintPropertyChanged = false; + layer->setLineColor(color); + EXPECT_FALSE(paintPropertyChanged); + + // Does not notify observer on no-op layout property change. + layoutPropertyChanged = false; + layer->setLineCap(lineCap); + EXPECT_FALSE(layoutPropertyChanged); +}