繁体   English   中英

Leaflet - 如何在拖放 #2 时匹配标记和折线(单击按钮删除最后一个标记和折线)

[英]Leaflet - How to match marker and polyline on drag and drop #2 (delete the last marker and polyline with button click)

我又卡住了。 放置标记并连接它们正在工作。 感谢“Falke Design”:-) 现在,当我单击“删除最后一个航点”按钮时,我想删除最后一个标记(航点)。 我设法做到了并且工作得很好,但最后一行没有被删除。 完整代码您可以在这里找到:演示代码

此问题应在 function delteLastWp() 行 # 218 中

function delteLastWp(id) { 

    var new_markers = []
    marker_new.forEach(function(marker) {
        if (marker._id == id) {
            map.removeLayer(marker);
        }
        else new_markers.push(marker)
    })
    marker_new = new_markers

    // remove the last point/line in the polyline as well ! 
    var new_polylines = []  
    tempLine.forEach(function(polyline) {
        if (polyline._id == id) {
            map.removeLayer(polyline); //*** This si not working ****
            // remove the last point in the polyline as well !
        }
        else new_polylines.push(polyline)
    })      
}

请帮助我:非常感谢您提前:-)

将您的代码更改为:

function delteLastWp()  // ## with the last segment of the polyline 
{ //marker_new[lineCount]

    var new_markers = []
    marker_new.forEach(function(marker) {
        if (marker._id == lineCount) {
            map.removeLayer(marker);  // Working :-)
      lineCount--;
        }
        else new_markers.push(marker)
    })
    marker_new = new_markers;

    var latlngs = tempLine.getLatLngs()
    latlngs.splice(-1); 
    tempLine.setLatLngs(latlngs);
        
}

您从该行加载 latlng,然后删除最后一个 latlng,然后将其再次添加到 tempLine

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM