如何从Google地图中删除/删除折线?

时间:2015-01-22 13:08:22

标签: javascript google-maps

  

我试图删除/删除该行。   但是flightPath.setMap(null)不起作用。   我发送了JSFiddle链接,它将为您提供完整的详细信息。我的代码   jsfiddle.net/rb9w8o5c/5/

function initialize() {
     google.maps.event.addListener(map, 'click', addLatLng);
 }
function addLatLng(event) {
        var path = poly.getPath();
        path.push(event.latLng);
        marker = new google.maps.Marker({
            position: event.latLng,
            title: '#' + path.getLength(),
            map: map
        })
        markers.push(marker);
        for (var key in markers) {
            flightPlanCoordinates.push(markers[key].position);
            positions.push(markers[key].position);
        }
        flightPath = new google.maps.Polyline({
                path: flightPlanCoordinates,
                strokeColor: "#FF0000",
                strokeOpacity: 1.0,
                strokeWeight: 2
            });    
    }
    function removePolyline(){
         flightPath.setMap(null);
    }

1 个答案:

答案 0 :(得分:0)

function removePolyline(){
        var path = poly.getPath();
        path.pop();
        marker = markers.pop();
        marker.setMap(null);
        for (var key in markers) {
            flightPlanCoordinates.push(markers[key].position);
            positions.push(markers[key].position);
        }
        flightPath = new google.maps.Polyline({
                path: flightPlanCoordinates,
                strokeColor: "#FF0000",
                strokeOpacity: 1.0,
                strokeWeight: 2
            });

}
相关问题