tileserver-gl icon indicating copy to clipboard operation
tileserver-gl copied to clipboard

Unknown expression "slice"

Open mrvipchien opened this issue 2 years ago • 3 comments

I tried to style some layer with "slice" expression but it's not working

mrvipchien avatar Mar 11 '22 02:03 mrvipchien

Can you update mapbox-gl-js to 1.10.0 or more? Currently tileserver is using mapbox-gl-js version 1.6.1 and that doesn't contain expression "slice"

mrvipchien avatar Mar 11 '22 02:03 mrvipchien

Is this issue still relevant since the last update to v4?

boldtrn avatar Oct 08 '22 11:10 boldtrn

Guessing it should be resolved by the maplibre-gl-js 2.4.0 used now, since that was forked from mapbox-gl-js 1.14 I think.

acalcutt avatar Oct 08 '22 13:10 acalcutt

I also have this problem, maybe the update didn't resolve the issue. I will look at maplibre and see if the problem is fixed yet

I am using Maputnik to create/edit my style, and the expression is working fine there

mmc1718 avatar Jun 14 '23 10:06 mmc1718

Does anyone have any example style we could test with?

acalcutt avatar Jun 14 '23 14:06 acalcutt

According to the maplibre style-spec docs, it should be supported https://maplibre.org/maplibre-style-spec/expressions/#slice

acalcutt avatar Jun 14 '23 14:06 acalcutt

The style I am working on is not mine so I am hesitant to share the entire style, but the part I am working on is the text field.

In Maputnik the following layer works:

{
  "filter": [
    "all",
    ["==", "class", "country"],
    ["==", "rank", 2],
    ["has", "iso_a2"]
  ],
  "id": "place-country-2",
  "layout": {
    "text-field": [
      "coalesce",
      [
        "get",
        [
          "concat",
          "name:",
          [
            "slice",
            [
              "resolved-locale",
              ["collator", {}]
            ],
            0,
            2
          ]
        ]
      ],
      ["get", "name:int"],
      [
        "concat",
        ["get", "name:latin"],
        ["literal", "\n"],
        ["get", "name:nonlatin"]
      ]
    ],
    "text-font": ["Noto Sans Bold"],
    "text-max-width": 6.25,
    "text-padding": 0,
    "text-size": {
      "stops": [[1, 11], [4, 15]]
    },
    "text-transform": "none",
    "visibility": "visible"
  },
  "maxzoom": 7,
  "metadata": {
    "mapbox:group": "1444849242106.713"
  },
  "paint": {
    "text-color": {
      "stops": [
        [4, "rgba(83, 83, 100, 1)"],
        [7, "rgba(200, 200, 200, 1)"]
      ]
    },
    "text-halo-blur": 1,
    "text-halo-color": "rgba(255,255,255,0.8)",
    "text-halo-width": 2
  },
  "source": "openmaptiles",
  "source-layer": "place",
  "type": "symbol"
}

When I start tileserver I get the following error

mlgl: {
  class: 'ParseStyle',
  severity: 'WARNING',
  text: '[1][1][2][0]: Unknown expression "slice". If you wanted a literal array, use ["literal", [...]].'
}

I am using the latest Docker image to run Tileserver

mmc1718 avatar Jun 14 '23 14:06 mmc1718

It seems actually that the error messages aren't really a problem. I have checked again after restarting and the style is showing in the browser now with the new labels, despite the warnings in the terminal.

The warning messages are misleading but actually the problem appears to be resolved.

Thanks for looking at this

mmc1718 avatar Jun 14 '23 20:06 mmc1718

I just realized that error is a Maplibre-Native error. It looks like 'slice' is not yet implemented in Maplibre Native https://github.com/maplibre/maplibre-native/issues/264

That means this will probably look ok in the 'View' and 'Vector', which don't do any rendering and just use Maplibre-gl-js. The rendered views like 'Raster' view and WMTS, which use maplibre-native may be missing support for this feature at this time.

acalcutt avatar Jun 15 '23 00:06 acalcutt

Thanks for the explanation, good to know

mmc1718 avatar Jun 16 '23 18:06 mmc1718

Just an FYI, Maplibre Native 5.3.1 now includes 'slice' and 'index-of' expressions. this is included in TileServer-GL 4.10.0

acalcutt avatar Feb 01 '24 13:02 acalcutt