【问题标题】:Leaflet - How to match marker and polyline on drag and drop #2 (delete the last marker and polyline with button click)传单 - 如何在拖放 #2 时匹配标记和折线(单击按钮删除最后一个标记和折线)
【发布时间】:2020-10-27 10:52:37
【问题描述】:

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

这个问题应该在 函数 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)
    })      
}

请帮帮我!非常感谢你:-)

【问题讨论】:

    标签: javascript leaflet drag marker polyline


    【解决方案1】:

    将您的代码更改为:

    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

    【讨论】:

      猜你喜欢
      • 2016-02-04
      • 2020-10-20
      • 1970-01-01
      • 2020-04-26
      • 2018-01-30
      • 1970-01-01
      • 2016-01-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多