mapbox 控制图层显示层级 | 将某个图层置于另一个图层的上方,或者置于最顶层

在地图开发中,经常会需要将某个图层置于某个图层的上方,或者最顶层,这篇文章列举了三种方法供大家参考。

一、在添加时可以控制它的图层顺序:addLayer( id, beforeId )

beforeId :现有层(beforeId)之前插入新图层(id),导致新图层(id)现有层(beforeId)的下方显示。如果未指定此参数,该层将被附加到layers数组的末尾,并显示在所有其他层之上。

// Add a new symbol layer before an existing layer
map.addLayer({
  id: 'states',
  // References a source that's already been defined
  source: 'state-data',
  type: 'symbol',
  layout: {
    // Set the label content to the
    // feature's `name` property
    'text-field': ['get', 'name']
  }
  // Add the layer before the existing `cities` layer
}, 'cities');

二、使用moveLayer( id, beforeId )

id:要移动的层id。

beforeId: 插入新层的现有层的ID。当查看地图时,id层将出现在beforeId层的下面。如果beforeId被省略,该层将被添加到layers数组的末尾,并出现在地图上的所有其他层之上

map.moveLayer('point', 'polygon');
map.moveLayer('polygon', 'point');

三、第三种方法比较繁琐,根据需求将图层列表排序,使用setStyle()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值