1

I'm trying to migrate from mapbox-sdk-3.7 to mapbox-sdk-4.0.

I can't understand how to convert this syntax with MGLConstantStyleValue to NSExpression.

let layer = style.layer(withIdentifier: "milestones") as? MGLSymbolStyleLayer
let styledValues: [String: MGLStyleValue<NSString>] = ...

layer.iconImageName = MGLConstantStyleValue(interpolationMode: .identity,
                    sourceStops: styledValues,
                    attributeName: "imageId")
Serge Maslyakov
  • 1,410
  • 1
  • 17
  • 23

1 Answers1

3

Identity interpolation mode uses the value for a feature attribute as a style value. Therefore, a stops dictionary should be unnecessary. In the case you outlined, looked like it used the value for imageId.

With NSExpression, you may want to try layer.iconImageName = NSExpression(forKeyPath: "imageId")

If you would like a stops dictionary to be taken to account, you may want to consider using MGL_MATCH, which takes an initial condition, this is followed by possible matches for that key and a corresponding value to assign to the layer property if there is a match. The final argument can be a default style value that is to be used if none of the specified values match.

layer.iconImageName = NSExpression(format: "MGL_MATCH(imageID, 'imageID1', 'nameForImageID1', 'defaultImageName')")

You may find these guides helpful:

Minh Nguyễn
  • 861
  • 7
  • 18
jmkiley
  • 976
  • 5
  • 8