【问题标题】:Longitude and Latitude of polyline : Leaflet折线的经度和纬度:传单
【发布时间】:2017-08-22 17:59:24
【问题描述】:

他们是一种获取折线经纬度的方法吗?

var firstpolyline = new L.Polyline(pointList, {      
    color: 'black',        
    opacity: 5,       
    smoothFactor: 1,    
    weight: 3,
})

map.addLayer(firstpolyline);
firstpolyline.getLatLng();

这里 firstpolyline 给出“getLatLng() 不是函数”的错误。我想检查折线是否在地图范围内或不像这样

var bounds = map.getBounds();
if(bounds.contains(firstpolyline.getLatLng())){
    ......
}

【问题讨论】:

标签: javascript leaflet


【解决方案1】:

你必须使用getLatLngs() 函数。所以试试这个:

var firstpolyline = new L.Polyline(pointList, {
    color: 'black',
    opacity: 5,
    smoothFactor: 1,
    weight: 3,
})
map.addLayer(firstpolyline);
var arrayOfPoints = firstpolyline.getLatLngs();

然后您可以轻松地遍历点数组并获取纬度和对数或检查点是否在多边形范围内。

for(var i=0; i < arrayOfPoints.length; i++) {
    if(map.getBounds().contains(arrayOfPoints[i])) {
        console.log('is in bounds');
    };
}  

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-05
    • 2013-07-05
    相关资源
    最近更新 更多