Mapbox gl js-基于多个条件的自定义图标

Mapbox gl js-基于多个条件的自定义图标,mapbox,mapbox-gl-js,mapbox-marker,Mapbox,Mapbox Gl Js,Mapbox Marker,我目前正在尝试使用mapbox gl js构建一个客户web地图,并努力解决如何最好地构造代码,以便基于多个属性在地图层上显示geojson数据的问题 特性如下: 类型:包括具有3个值的标记的属性:静态, 飞机、轮船 名称:包括标记的名称,可以是船舶和船舶的任何名称 飞机,但定义了静态的子类型:机场、建筑、桥梁 国家:包括基于上述项目所属国家的数值:0、1、2 类型和名称将定义图标类型、图标颜色(图标为sdf格式) 我现在有下面的代码,它可以工作,但是没有考虑静态对象的名称子类。关于如何包含

我目前正在尝试使用mapbox gl js构建一个客户web地图,并努力解决如何最好地构造代码,以便基于多个属性在地图层上显示geojson数据的问题

特性如下:

  • 类型:包括具有3个值的标记的属性:静态, 飞机、轮船
  • 名称:包括标记的名称,可以是船舶和船舶的任何名称 飞机,但定义了静态的子类型:机场、建筑、桥梁
  • 国家:包括基于上述项目所属国家的数值:0、1、2
类型和名称将定义图标类型、图标颜色(图标为sdf格式)

我现在有下面的代码,它可以工作,但是没有考虑静态对象的名称子类。关于如何包含这个子类匹配的任何建议,以便我可以显示静态+机场、静态+建筑、静态+桥梁的不同图标,但不关心飞机和船舶类型的名称

map.addLayer({
        'id': 'marker',
        'type': 'symbol',
        'source': 'db-json',
        'layout': {
            'icon-image': [
                    'match', // Use the 'match' expression: https://docs.mapbox.com/mapbox-gl-js/style-spec/#expressions-match
                    ['get', 'type'], // Use the result 'coalition' property
                    'airplane', 'plane-icon',
                    'static', 'circle-stroked-15',
                    'ship', 'harbor-15',
                    'airfield-15' // any other type
                    ]
            },
            'paint': {
                'icon-color': [
                    'match', // Use the 'match' expression: https://docs.mapbox.com/mapbox-gl-js/style-spec/#expressions-match
                    ['get', 'nation'], // Use the result 'nation' property
                    0, '#808080',
                    1, '#FF0000',
                    2, '#0000FF',
                    '#00FF00' // any other nation
                    ]
                }
        });

万分感谢

来回答我自己的问题。当然,可以堆叠多个级别。可能不是最理想的解决方案(相对于同时检查和比较两个变量的查询),但它可以工作

例如:

map.addLayer({
        'id': 'marker',
        'type': 'symbol',
        'source': 'db-json',
        'layout': {
            'icon-image': [
                    'match', 
                    ['get', 'type'], // Use the result 'type' property
                    'airplane', 'plane-icon',
                    'static', [
                       'match', 
                        ['get', 'name'], // Use the result 'name' property
                        'airport', 'airport-icon',
                        'building', 'building-icon',
                        'bridge', 'bridge-icon',
                        '' // none for any other type
                         ],
                    'ship', 'harbor-15',
                    'airfield-15' // any other type
                    ]
            },
            'paint': {
                'icon-color': [
                    'match', 
                    ['get', 'nation'], // Use the result 'nation' property
                    0, '#808080',
                    1, '#FF0000',
                    2, '#0000FF',
                    '#00FF00' // any other nation
                    ]
                }
        });

感谢您抽出时间与我们分享。