您当前的位置: 首页 > 

漏刻有时

暂无认证

  • 0浏览

    0关注

    717博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

高德地图进阶开发实战案例(7):点是否在多边形内和内外部的数量统计的解决方案

漏刻有时 发布时间:2021-05-02 14:43:34 ,浏览量:0

在这里插入图片描述

外部文件引入
    
    
    
CSS样式表
        html, body, #container {
            height: 100%
        }

        .amap-marker-label {
            border: 0;
            background-color: #FFF;
        }

        .info >span{
            margin: auto 10px;
        }
HTML容器



核心代码
 //初始化地图对象,加载地图
    var map = new AMap.Map("container", {
        center: [121.548181, 29.806906],
        zoom: 15,
        resizeEnable: true,
    });

    //数据格式化;
    var data = "121.546266,29.80975;121.54543,29.806845;121.548713,29.806752;121.549957,29.809508";
    var points = data.split(";");
    var path = [];
    for (var i = 0; i  item =="0").length;//外部;
    //console.log('内部数量:'+inRing);
    document.getElementById("inRing").innerHTML='内部数量:'+inRing;
    //console.log('外部数量:'+outRing);
    document.getElementById("outRing").innerHTML='外部数量:'+outRing;


    //添加标注;
    function addMaker(marker) {
        var newMaker = new AMap.Marker({
            map: map,
            //icon: marker.icon,
            //draggable: true,
            position: [marker.position[0], marker.position[1]],
            offset: new AMap.Pixel(-13, -30)
        });
        return newMaker;
    }

    //判断是否在围栏内;
    function compute(marker) {
        var point = marker.getPosition();
        var isPointInRing = AMap.GeometryUtil.isPointInRing(point, path);
        // label默认蓝框白底左上角显示,样式className为:amap-marker-label
        marker.setLabel({
            content: isPointInRing ? '内部' : '外部',
            offset: new AMap.Pixel(-5, 35)
        });

        //返回状态,予以统计;
        if (isPointInRing == true) {
            return 1;
        } else {
            return 0;
        }
    }

lockdatav Done !

关注
打赏
1661217259
查看更多评论
立即登录/注册

微信扫码登录

0.0379s