高得地图计算区域面积

使用 AMap.GeometryUtil.ringArea 计算区域,返回数据以平方米为单位。

https://developer.amap.com/demo/javascript-api/example/calcutation/ring-area

<!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>
    <link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css" type="text/css">
    <style>
      html,body,#container{
        height: 100%
      }
    </style>
</head>
<body>
<div id="container"></div>
<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=您申请的key值"></script>
<script type="text/javascript">
    //初始化地图对象,加载地图
    var map = new AMap.Map("container", {
        resizeEnable: true,
        zoom: 10
    });
    var path = [
        [116.169465,39.932670],
        [116.160260,39.924492], 
        [116.150625,39.710019],
        [116.183198,39.709920], 
        [116.226950,39.777616], 
        [116.442621,39.799892],
        [116.463478,39.790066], 
        [116.588276,39.809551],
        [116.536091,39.808859],
        [116.573856,39.839643], 
        [116.706380,39.916740],
        [116.600293,39.937770],
        [116.514805,39.982375],
        [116.499935,40.013710],
        [116.546520,40.030443], 
        [116.687668,40.129961], 
        [116.539697,40.080659],
        [116.503390,40.058474],
        [116.468800,40.052578]
    ];
    var polygon = new AMap.Polygon({
        map: map,
        fillOpacity:0.4,
        path: path
    });
    // 计算区域面积
    var area = Math.round(AMap.GeometryUtil.ringArea(path));
    var text = new AMap.Text({
        position: new AMap.LngLat(116.468800,40.052578),
        text: '区域面积' + area + '平方米',
        offset: new AMap.Pixel(-20, -20)
    })
    map.add(text);
    map.setFitView();
</script>
</body>
</html>

 

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值