【问题标题】:Leaftlet- Draw Polyline or Draw Ploygon not working传单 - 绘制折线和绘制多边形不起作用
【发布时间】:2021-12-12 09:32:12
【问题描述】:

我有以下脚本使用保存在用户上一个会话中的 latlang 点添加动态折线。脚本正在执行且没有任何错误,但折线未在地图上绘制。

  var latLonArray = item.points[0];
            pointList = [];
            for (var i = 0; i < latLonArray.length; i++) {
                var item = latLonArray[i];
                var pnt = new L.LatLng(item[0], item[1]);
                pointList.push(pnt);
            }
            var firstpolyline = new L.Polyline(pointList, {
                color: 'blue',
                weight: 3,
                opacity: 0.5,
                smoothFactor: 1
            });
            //var polygonObj = simeObj.DrawPolygon(points);
            //polygonObj.addTo(mapObject);
            //var firstpolyline = new L.Polygon(item.points, item.layer);
            firstpolyline.addTo(mapObject);

我也尝试过 DrawPolygon 方法。它也没有在地图上绘制多边形。

【问题讨论】:

  • 您确定L.LatLng(item[0], item[1]); 是latlng 格式吗?试试L.LatLng(item[1], item[0]))。否则检查数组中是否有项目console.log(latLonArray)
  • @FalkeDesign 感谢您的回复,您的建议奏效了,我将 point val 替换为 item[1],然后 item[0] 即可。谢谢

标签: leaflet leaflet.draw


【解决方案1】:

问题在cmets中解决了,结果:

问题在于 latlng 值是 lnglat 格式:

改变

var pnt = new L.LatLng(item[0], item[1]);

var pnt = new L.LatLng(item[1], item[0]);

工作。

【讨论】:

    猜你喜欢
    • 2022-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-14
    • 2013-10-22
    • 2021-01-16
    相关资源
    最近更新 更多