diff options
author | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2018-08-08 15:09:27 +0300 |
---|---|---|
committer | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2018-08-23 19:01:40 +0300 |
commit | fb5afd34b9b25e993a4b109385215eba0b83923f (patch) | |
tree | 61474b72e7d099808eb85ea60275e58da11bdd39 /platform/darwin | |
parent | 52275f835a38897ebf1aeb2158ccfca2272e4770 (diff) | |
download | qtlocation-mapboxgl-fb5afd34b9b25e993a4b109385215eba0b83923f.tar.gz |
[core] Add `line-gradient` property
Porting of https://github.com/mapbox/mapbox-gl-js/pull/6303
See the link above for the description of the feature and
its limitations).
Based on patch from @lbud (Lauren Budorick).
Diffstat (limited to 'platform/darwin')
-rwxr-xr-x | platform/darwin/scripts/generate-style-code.js | 2 | ||||
-rw-r--r-- | platform/darwin/src/MGLLineStyleLayer.h | 44 | ||||
-rw-r--r-- | platform/darwin/src/MGLLineStyleLayer.mm | 17 | ||||
-rw-r--r-- | platform/darwin/src/MGLStyleLayer.mm.ejs | 2 |
4 files changed, 64 insertions, 1 deletions
diff --git a/platform/darwin/scripts/generate-style-code.js b/platform/darwin/scripts/generate-style-code.js index e89a4e29a3..bc676e9cba 100755 --- a/platform/darwin/scripts/generate-style-code.js +++ b/platform/darwin/scripts/generate-style-code.js @@ -367,6 +367,8 @@ global.propertyReqs = function (property, propertiesByName, type) { return '`' + camelizeWithLeadingLowercase(req['!']) + '` is set to `nil`'; } else { let name = Object.keys(req)[0]; + if (name === 'source') + return 'the data source requirements are met'; return '`' + camelizeWithLeadingLowercase(name) + '` is set to an expression that evaluates to ' + describeValue(req[name], propertiesByName[name], type); } }).join(', and ') + '. Otherwise, it is ignored.'; diff --git a/platform/darwin/src/MGLLineStyleLayer.h b/platform/darwin/src/MGLLineStyleLayer.h index 1080244bdb..a7ac7f1462 100644 --- a/platform/darwin/src/MGLLineStyleLayer.h +++ b/platform/darwin/src/MGLLineStyleLayer.h @@ -366,6 +366,50 @@ MGL_EXPORT */ @property (nonatomic) MGLTransition lineGapWidthTransition; +#if TARGET_OS_IPHONE +/** + Defines a gradient with which to color a line feature. Can only be used with + GeoJSON sources that specify `"lineMetrics": true`. + + This property is only applied to the style if `lineDasharray` is set to `nil`, + and `linePattern` is set to `nil`, and the data source requirements are met. + Otherwise, it is ignored. + + You can set this property to an expression containing any of the following: + + * Constant `UIColor` values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$lineProgress` variable + + This property does not support applying interpolation or step functions to + feature attributes. + */ +@property (nonatomic, null_resettable) NSExpression *lineGradient; +#else +/** + Defines a gradient with which to color a line feature. Can only be used with + GeoJSON sources that specify `"lineMetrics": true`. + + This property is only applied to the style if `lineDasharray` is set to `nil`, + and `linePattern` is set to `nil`, and the data source requirements are met. + Otherwise, it is ignored. + + You can set this property to an expression containing any of the following: + + * Constant `NSColor` values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$lineProgress` variable + + This property does not support applying interpolation or step functions to + feature attributes. + */ +@property (nonatomic, null_resettable) NSExpression *lineGradient; +#endif + /** The line's offset. For linear features, a positive value offsets the line to the right, relative to the direction of the line, and a negative value to the diff --git a/platform/darwin/src/MGLLineStyleLayer.mm b/platform/darwin/src/MGLLineStyleLayer.mm index 3bad2a8b98..5cf0762475 100644 --- a/platform/darwin/src/MGLLineStyleLayer.mm +++ b/platform/darwin/src/MGLLineStyleLayer.mm @@ -306,6 +306,23 @@ namespace mbgl { return transition; } +- (void)setLineGradient:(NSExpression *)lineGradient { + MGLAssertStyleLayerIsValid(); + + auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toPropertyValue<mbgl::style::ColorRampPropertyValue>(lineGradient); + self.rawLayer->setLineGradient(mbglValue); +} + +- (NSExpression *)lineGradient { + MGLAssertStyleLayerIsValid(); + + auto propertyValue = self.rawLayer->getLineGradient(); + if (propertyValue.isUndefined()) { + propertyValue = self.rawLayer->getDefaultLineGradient(); + } + return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toExpression(propertyValue); +} + - (void)setLineOffset:(NSExpression *)lineOffset { MGLAssertStyleLayerIsValid(); diff --git a/platform/darwin/src/MGLStyleLayer.mm.ejs b/platform/darwin/src/MGLStyleLayer.mm.ejs index 0707e573c4..49ac04ce05 100644 --- a/platform/darwin/src/MGLStyleLayer.mm.ejs +++ b/platform/darwin/src/MGLStyleLayer.mm.ejs @@ -169,7 +169,7 @@ namespace mbgl { <% switch (property['property-type']) { case 'color-ramp': -%> - auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toPropertyValue<mbgl::style::ColorRampPropertyValue>(heatmapColor); + auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toPropertyValue<mbgl::style::ColorRampPropertyValue>(<%- objCName(property) %>); <% break case 'data-driven': case 'cross-faded-data-driven': -%> |