You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.
NSColor and UIColor objects used as attribute values of MGLFeature are no longer automatically premultiplied the correct number of times, so an MGLFillStyleLayer.fillColor expression based on a feature attribute would render features with the wrong fill color.
In addition to the Foundation types, you may also set an attribute to an NSColor (macOS) or UIColor (iOS), which will be converted into its CSS string representation when the feature is added to an MGLShapeSource. This can be convenient when using the attribute to supply a value for a color-typed layout or paint attribute via a key path expression.
The developer would expect this conversion to be accurate, so that the result of setting the MGLFillStyleLayer.fillColor property would match the normal appearance of the NSColor or UIColor that was stored in the feature attribute. For example, the following code should result in a translucent, light blue fill:
The convenience conversion works by stuffing the NSColor or UIColor in a constant value expression and converting the expression to a JSON-formatted object:
From mapbox/mapbox-gl-native#8025 until #266, this conversion from NSColor/UIColor to JSON premultiplied the color, based on a historical expectation that mbgl::Color was always premultiplied:
Even if the change in #266 was correct in the usual case when converting expressions from NSExpression to JSON format, for code that uses the feature attribute convenience conversion, the change affected it twice over.
Workaround
A workaround is to circumvent the any color-related conversions in the platform-specific SDK code by specifying a CSS-style rgba(145.0, 174.0, 255.0, 0.5) string directly as the attribute value:
Performance-wise, this should be equivalent to the convenience conversion provided by the SDK, or even more performant in the case that the feature is reused multiple times in the same shape source or by multiple shape sources.
/cc @mapbox/maps-ios
The text was updated successfully, but these errors were encountered:
NSColor and UIColor objects used as attribute values of MGLFeature are no longer automatically premultiplied the correct number of times, so an
MGLFillStyleLayer.fillColor
expression based on a feature attribute would render features with the wrong fill color.Expected behavior
For convenience’s sake, MGLFeature automatically converts attribute values of type NSColor (on macOS) or UIColor (iOS) to a CSS-formatted
rgba()
string, which happens to be compatible with color-typed paint properties in the style specification:The developer would expect this conversion to be accurate, so that the result of setting the
MGLFillStyleLayer.fillColor
property would match the normal appearance of the NSColor or UIColor that was stored in the feature attribute. For example, the following code should result in a translucent, light blue fill:Actual behavior
The code actually results in a drab gray fill.
Diagnosis
The convenience conversion works by stuffing the NSColor or UIColor in a constant value expression and converting the expression to a JSON-formatted object:
mapbox-gl-native-ios/platform/darwin/src/MGLFeature.mm
Line 539 in 6a5db0b
mapbox-gl-native-ios/platform/darwin/src/NSDictionary+MGLAdditions.mm
Lines 17 to 18 in 6a5db0b
The conversion to JSON takes the four color channels as is without premultiplying the alpha channel into the red, green, and blue channels:
mapbox-gl-native-ios/platform/darwin/src/NSExpression+MGLAdditions.mm
Lines 320 to 322 in 6a5db0b
mapbox-gl-native-ios/platform/ios/src/UIColor+MGLAdditions.mm
Lines 15 to 21 in 6a5db0b
From mapbox/mapbox-gl-native#8025 until #266, this conversion from NSColor/UIColor to JSON premultiplied the color, based on a historical expectation that
mbgl::Color
was always premultiplied:mapbox-gl-native-ios/platform/darwin/src/NSExpression+MGLAdditions.mm
Lines 310 to 312 in 23b5b46
mapbox-gl-native-ios/platform/ios/src/UIColor+MGLAdditions.mm
Lines 5 to 13 in 6a5db0b
Even if the change in #266 was correct in the usual case when converting expressions from NSExpression to JSON format, for code that uses the feature attribute convenience conversion, the change affected it twice over.
Workaround
A workaround is to circumvent the any color-related conversions in the platform-specific SDK code by specifying a CSS-style
rgba(145.0, 174.0, 255.0, 0.5)
string directly as the attribute value:Performance-wise, this should be equivalent to the convenience conversion provided by the SDK, or even more performant in the case that the feature is reused multiple times in the same shape source or by multiple shape sources.
/cc @mapbox/maps-ios
The text was updated successfully, but these errors were encountered: