2
votes

How does step function work in Mapbox fill-color property of an array?? While:

R=[ 'interpolate', ['linear'],['number',['get', dim_properties.name]], -150, "#800026", -133, "#bd0026", -116, "#e31a1c", -100, "#fc4e2a", -83, "#fd8d3c", -66, "#feb24c", -50, "#fed976", -33, "#ffeda0", -16, "#ffffcc", 0, "#ffffff"]

map.addLayer({
            id: 'er',
            type: 'fill',
            source: {
              type: 'vector',
              url: pixelling_url
            },
            'source-layer':pixelling_source_layer,
                paint: {

        'fill-color':R
    }

works perfect,

this other code does not.

R=[ 'step',['get', dim_properties.name]], -150, "#800026", -133, "#bd0026", -116, "#e31a1c", -100, "#fc4e2a", -83, "#fd8d3c", -66, "#feb24c", -50, "#fed976", -33, "#ffeda0", -16, "#ffffcc", 0, "#ffffff"]

map.addLayer({
            id: 'er',
            type: 'fill',
            source: {
              type: 'vector',
              url: pixelling_url
            },
            'source-layer':pixelling_source_layer,
                paint: {

        'fill-color':R
    }

The error message being: "paint.fill-color: Expected an even number of arguments

Notice that the difference between the 2 pices of code lays only in the definition of R.

1

1 Answers

4
votes

With step expressions, you need to set a base value. Simply removing the first break value, if you will, should resolve your issue. Right now Mapbox is only reading three arguments (expression type, property, collection of break points) when it is looking for four (expression type, property value, base value, collection of break points). Basically, you do not need to define the minimum value. Mapbox GL will infer that the base value should be assigned to any features that are below the first break point. In this case, it will be any features that meet the condition dim_properties.name < -133

    R = [
      'step', // arg 1
      ['get', 'dim_properties.name'], // arg 2
      '#800026', // arg 3
      -133, '#bd0026', // rest of the expression is arg 4
      -116, '#e31a1c',
      -100, '#fc4e2a',
      -83, '#fd8d3c',
      -66, '#feb24c',
      -50, '#fed976',
      -33, '#ffeda0',
      -16, '#ffffcc',
      0, '#ffffff'
     ]