从经度和纬度确定哪个是多边形 [英] identify which is the polygon from latitude and longitude

查看:124
本文介绍了从经度和纬度确定哪个是多边形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张使用leaflet.js绘制的地图.如果我输入经度和纬度值作为输入 我可以识别多边形吗?我可以为此获得客户端脚本吗?

I have a map drawn using leaflet.js. If I give longitude and latitude value as input Can I identify the polygon? Can I get a client side script for this?

推荐答案

回答如下:

//这是基于多边形中的点算法"

//This is based on 'point in polygon algorithm'

function getPoint () {
     float x=-89.82421875;     //x and y represents the lat and lng values
     float y= 40.18307014852533;
    var a = boundaries;    //the coordinates used to draw the map
    for (i = 0; i < a.features.length; i++) {
        PointInPolygon(x,y, a.features[i].geometry.coordinates[0], i);
    }
};

function PointInPolygon(pointX, pointY, _vertices, number) {
        var j = _vertices.length - 1;
        var oddNodes = false;
        var polyX, polyY,polyXJ,polyYJ;

        for (var i = 0; i < _vertices.length; i++) {
            polyY = parseFloat(_vertices[i].toString().split(",")[1]);
            polyX = parseFloat(_vertices[i].toString().split(",")[0]);
            polyXJ = parseFloat(_vertices[j].toString().split(",")[0]);
            polyYJ = parseFloat(_vertices[j].toString().split(",")[1]);
            if (polyY < pointY && polyYJ >= pointY ||
                polyYJ < pointY && polyY >= pointY) {
                if (polyX +
                    (pointY - polyY) / (polyYJ - polyY) * (polyXJ - polyX) < pointX)  
                {  
                    oddNodes = !oddNodes;  
                }  
            }  
            j = i;
        }
        if (oddNodes == true) {
             map._layers[number+1].fire('click');             //fire the map click event
        } 
    }

这篇关于从经度和纬度确定哪个是多边形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆