Skip to content
Advertisement

Access geometry coordinates with Mapbox expressions somehow?

Every now and then I encounter a code like this:

var mapboxDrawStylesCustom = [
    {
      'id': 'custom-point-inactive',
      'type': 'circle',
      'filter': ['all',
        ['==', 'active', 'false'],
        ['==', '$type', 'Point'],
        ['==', 'meta', 'feature'],
        ['!=', 'mode', 'static']
      ],
      'paint': paintPropertyPoint
    }
]

I wonder about '$type' accessor here. Like obviously it allows to grab the type of geometry. But I haven’t seen it mentioned anywhere in the docs. I personally need to access latitude/longitude of the Point geometry. According to documentation it is not something that Mapbox supports. However is it maybe possible somehow using this kind of dollar-sign syntax?

Advertisement

Answer

$type is an older, deprecated expression. Its modern successor is ['geometry-type']: https://docs.mapbox.com/mapbox-gl-js/style-spec/expressions/#geometry-type

AFAIK the older syntax doesn’t give you extra access to anything. So, no, you can’t access geometry coordinates that way.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement