map相关使用笔记

本文介绍了如何使用Mapbox进行地图操作,包括区域图层颜色过滤的代码实现、监听地图点击事件来判断点击对象,以及层级控制、添加标记和图层、地图定位等技巧。
摘要由CSDN通过智能技术生成

Mapbox

对于区域图层颜色过滤

代码操作

let fillColor = ['match', ['get', 'name'],'杭州市','red','yellow']
let fillOpacity: any = ['match', ['get', 'name'],'杭州市',0.5, 0]
// 最后一位 yellow 和 0分别代表没有标记的城市默认颜色和默认透明的
if (window.glMap.getLayer('county-boundary')) {
   
        window.glMap.setPaintProperty('county-boundary', 'fill-color', fillColor)
        window.glMap.setPaintProperty('county-boundary', 'fill-opacity', fillOpacity) 
        // 当然必须设置图层为visible(显示),不然如果是none就不会显示了
         window.glMap.setLayoutProperty('county-boundary', 'visibility','visible')
} else {
   
    window.glMap.addLayer(
        {
   
            id: 'county-boundary',
            source: 'water_bou',
            'source-layer': 'hy_water_bou',
            type: 'fill',
            paint: {
   
                'fill-color': fillColor,
                'fill-opacity': fillOpacity,
                "fill-outline-color": "red"// 边框线颜色
            }
        },
        'JN1'
    ) //JN1为style文件中的第一个点图层,确保面图层在点图层下面
}

Json文件

当然在地图的json文件内会有相应的该图层的信息


"town_bou": {
   
      "type": "vector",
      "tiles": [
"https://gis-dev.fpi-inc.site/fpi-geo-server/gwc/service/wmts?layer=fpi-inc:hy_town_bou&style=&tilematrixset=EPSG:4490&Service=WMTS&Request=GetTile&Version=1.0.0&Format=application/vnd.mapbox-vector-tile&TileMatrix={z}&TileCol={x}&TileRow={y}"
      ]
    },
{
   
      "id": "county-boundary", // 图层名称
      "source": "town_bou", // 资源
      "type": "fill", // 类型也有line类型
      "source-layer": "hy_town_bou",
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Freedom风间

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值