繁体   English   中英

mapbox:填充颜色表达式取决于来自 geojson 的值(不是颜色值)

[英]mapbox : fill-color expression depending of a value (not a color value) from the geojson

如何根据 geoJson 中的一个属性的值设置形状的颜色?

假设我有这个功能集合:

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {
        "district_type": "foo"
      },
      "geometry": {
        "coordinates": [...],
        "type": "Polygon"
      }
    },
    {
      "type": "Feature",
      "properties": {
        "district_type": "bar"
      },
      "geometry": {
        "coordinates": [...],
        "type": "Polygon"
      }
    }
  ]
}

而这个数组要匹配 colors:

    var colors = {
      foo:'#111111',
      bar:'#222222',
    }

现在,我想添加一个图层,其中形状的颜色来自我的colors var,与特征的distric_type属性相匹配。

map.addLayer({
  'id': 'districts-fill',
  'type': 'fill',
  'source': 'geo-districts',
  'paint': {
    'fill-color': ..., //which expression here ?
    'fill-opacity': 0.4
  }
});

谢谢 !

我发现……太好了!

map.addLayer({
  'id': 'districts-fill',
  'type': 'fill',
  'source': 'geo-districts',
  'paint': {
    'fill-color': [
      'match', ['get', 'district_type'],
      'foo', '#111111',
      'bar', '#222222',
      'white'// otherwise
   ],
   'fill-opacity': 0.4
  },

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM