高德地图只展示某个区域的人流量,遮盖其他区域

2 篇文章 0 订阅

思路:

用AMap.DistrictSearch搜索某个(省份、城市、县)返回它的边界坐标集合,使用这个结果,用AMap.Polygon绘制边界线和遮盖,最后使用AMap.Heatmap绘制热力图

高德地图api参考链接:

AMap.DistrictSearch:

https://lbs.amap.com/api/javascript-api/reference/search#m_AMap.DistrictSearch

AMap.Polygon

https://lbs.amap.com/api/javascript-api/reference/overlay#polygon

AMap.Heatmap

https://lbs.amap.com/api/javascript-api/reference/layer#m_AMap.Heatmap

以下是使用北京市做的例子的完整代码


<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title></title>
    <style>
        html,body{
            background-image: linear-gradient(#D4EBFF, #F4F8FB);
            height:100%;
        }
        .wrap_map{
            position: relative;
            margin:0 auto;
            width:1200px;
            height:100%;
        }
        .map_tips{
            position: absolute;
            right:80px;
            bottom:50px;
        }
        .map_tips .tips_scroll{
            width:155px;
            height:13px;
            border-radius:7px;
            background-image: linear-gradient(to right,#FF0000, #FFD800,#55e12f,#2BE145,#65e96a,#BBF087);
        }
        .map_tips .tips_text{
            display: flex;
            color:#545454;
            font-size:12px;
            margin-top:15px;
        }
        .tips_text>div{
            flex-grow: 1;
        }
        .tips_text>div:nth-of-type(2){
            flex-grow:2;
            text-align: center;
        }
        .tips_text>div:last-child{
            text-align: right;
        }
        #container {
            width:100%;
            height:100%;
        }
    </style>
</head>
<body>
    <div class="wrap_map">
        <div id="container"></div>
        <div class="map_tips">
            <div class="tips_scroll"></div>
            <div class="tips_text">
                <div>拥挤</div>
                <div>正常</div>
                <div>稀疏</div>
            </div>
        </div>
    </div>
<script src="https://webapi.amap.com/maps?v=1.4.15&key=您申请的key值&plugin=AMap.DistrictSearch,AMap.Heatmap"></script>
<script src="https://a.amap.com/jsapi_demos/static/resource/heatmapData.js"></script><!--北京市热力图数据-->
<script>
    // //热力图数据结构
    // let heatmapData = [
    //     {"lng":经度,"lat":纬度,"count":人数},
    // ];

    var map = new AMap.Map('container', {
        zoom:9,
        center:[116.44923,40.207714],
        pitch: 0,
        viewMode: '3D',
    });
    new AMap.DistrictSearch({
        extensions:'all',
        subdistrict:0,
        level: 'district'
    }).search('北京市',function(status,result){ 
        // 外多边形坐标数组和内多边形坐标数组
        var outer = [
            new AMap.LngLat(-360,90,true),
            new AMap.LngLat(-360,-90,true),
            new AMap.LngLat(360,-90,true),
            new AMap.LngLat(360,90,true),
        ]; // 使得遮盖填充反向
        var holes = result.districtList[0].boundaries // 得到该区域的边界坐标集合
 
        var pathArray = [
            outer
        ];
        pathArray.push.apply(pathArray,holes)
        var polygon = new AMap.Polygon( {
            pathL:pathArray,
            //线条颜色,使用16进制颜色代码赋值。默认值为#006600
            strokeColor: '#6e93f9',
            strokeWeight: 2,
            fillColor: 'rgba(255,255,255)',
            fillOpacity: 1,
            strokeStyle:'dashed',
            strokeDasharray:[2,2]
        });
        polygon.setPath(pathArray);
        map.add(polygon);
    })
    //设置热力图
    var heatmap = new AMap.Heatmap(map, {
        radius: 60, //给定半径
        opacity: [0, 0.8],
        gradient:{
            0: '#BBF087',
            0.5: '#2BE145',
            0.75: '#FFD800',
            1.0: '#FF0000'
        }
    });
    heatmap.setDataSet({
        data: heatmapData,  //对应数据
        max: 100  //设置景区人流量最大值
    });
    map.add(heatmap)
</script>
</body>
</html>

结果:

 

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
高德地图提供了一个行政区域查询的API,可以用来获取中国的行政区域信息。在使用该API时,可以通过传入adcode作为keywords来指定某个行政区。API的具体使用方法可以参考\[1\]中的代码示例。 根据\[2\]的引用内容,中国的行政区域可以分为23个省、5个自治区、4个直辖市和2个特别行政区。每个行政区域都有一个唯一的adcode,可以用来查询该行政区域的详细信息。 如果你想获取中国的全部行政区域信息,可以使用高德地图的行政区域查询API,并设置extensions参数为all,这样接口会返回我们需要的区域边界数据。 总结起来,要使用高德地图获取中国的行政区域,你可以使用行政区域查询API,并传入adcode或设置extensions参数为all来获取详细信息。具体的代码示例可以参考\[1\]中的内容。 #### 引用[.reference_title] - *1* *3* [使用高德地图服务获取全部行政区划与各个省市的地理坐标](https://blog.csdn.net/weixin_42763696/article/details/109274193)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [如何获取全国省市区行政边界数据](https://blog.csdn.net/WenWu_Both/article/details/122990606)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值