mapbox/minemap 改变选中矢量的颜色

1记录两个知识点,一个是数据驱动渲染矢量。paint的模式line-color设置为get模式。

'line-color': ['get', 'color'],

会自动从数据的属性里面读取。

layer.paint={
  'line-color': ['get', 'color'],
  "line-width": {
    'property': 'flow',
    'stops': [
      [100, 20],
      [200, 30],
      [300, 40],
      [400, 50],
      [500, 60]
    ]
  },
}

2 步入正题:

点击事件放在click中

map.on("click",function (e) {
  var features = map.queryRenderedFeatures(e.point, { layers: ['line-layer'] });
 
  features.map( feature => {

    map.setPaintProperty('line-layer','line-color',[
      'match',//匹配模式
      ['get','id'],//匹配的属性值名称,id,可以从feature的属性得到
      'sss', //要匹配的值
      'rgb(255,0,0)',//匹配中的颜色
      'rgb(255,0,0)'//未匹配上的颜色
    ])

  })
 
})

match的使用参见style Specification中的expressions

 

https://docs.mapbox.com/mapbox-gl-js/example/data-driven-circle-colors/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值