mapbox-gl 同一layer下将一个数据源分不同的icon显示

效果图:

实现代码:

//加载img 
map.loadImage(fangmu, function (error, image) {
          if (error) throw error
          map.addImage('fangmu', image, { sdf: true })
        })
        map.loadImage(wushuichuli, function (error, image) {
          if (error) throw error
          map.addImage('wushuichuli', image, { sdf: true })
        })
        map.loadImage(hedaolaji, function (error, image) {
          if (error) throw error
          map.addImage('hedaolaji', image, { sdf: true })
        })
    
map.addSource('questionMapData', {
          type: 'geojson',
          data: questionMapData, //数据源
        })

        map.addLayer({
          id: 'questionMapData', //图层id
          type: 'symbol',
          source: 'questionMapData',
          layout: {
            visibility: 'visible',
            // 'text-field': ['get', 'name'],
            'text-font': ['Open Sans Semibold', 'Arial Unicode MS Bold'],
            'text-offset': [0, 1],
            'text-anchor': 'top',
            'icon-image': [ // icon图标,做判断,type_name为后端回传字段,判断type_name是否相等去显示图层
              'case',
              ['==', ['get', 'type_name'], '污水处理设施'], 
              'wushuichuli', //图层名称
              ['==', ['get', 'type_name'],'河道垃圾'],
              'hedaolaji',
              ['==', ['get', 'type_name'], '污水直排'],
              'wushuizhipai',
              ['==', ['get', 'type_name'], '牲畜尸体倾倒'],
              'shiti',
             

              'buming', // default
            ],

            'icon-size': 0.15,
          },
          // 修改文字颜色
          paint: {
            'icon-color': ['match', ['get', 'rectification_type'], 1, '#FFD700', 2, '#DC143C', 3, '#008000', '#D8BFD8'],
          },
        })

 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值