2011-01-28 112 views
4

私はDirectionsRendererを使用してパスを表示していますが、これでポリラインを削除して、物事を続行したいと思います。私は、この関数によって作成されたマーカーとポリラインを制御できないようです。Googleマップからポリラインを削除する

誰もそのようなポリラインを削除する方法を知っていますか、それが可能でない場合は、他の提案ですか?

私は今、あなたが最初の段階でポリラインを使用しているので、suppressプロパティを使うことができますが、これは本当に何も解決しません。

ひどく不満です。 乾杯!

答えて

0

Googleマップv3からポリラインを削除する方法です。それがあなたを助けることを願ってください。

var line = []; 
var flightPath = new google.maps.Polyline({ 
     path: flightPlanCoordinates, //create an array of LatLng objects 
     strokeColor: "#FF0000", 
     strokeOpacity: 1.0, 
     strokeWeight: 2 
    }); 
line.push(flightPath); 

ここで、すべてのポリラインオブジェクトを配列行にプッシュします。あなたはそれが見えない作るかのようにそれをループすることにより、マップから削除することができます:

for (i=0; i<line.length; i++) 
{       
    line[i].setMap(null); //or line[i].setVisible(false); 
} 
0

使用

[self.polylineのてsetMap:nilを];

1

ここではあなたの問題を解決する:suppressPolylinesオプションを使用するか、マップ

var directionsDisplay; 
 
var directionsService = new google.maps.DirectionsService(); 
 
var map; 
 
var time; 
 

 
var pointA = new google.maps.LatLng(48.86, 2.35); 
 
var pointB = new google.maps.LatLng(33.7167, 73.0667); 
 

 
function initialize() { 
 

 
    var rendererOptions = { 
 
     map: map, 
 
     draggable: true 
 
    } 
 
    // Instantiate a directions service. 
 
    directionsDisplay = new google.maps.DirectionsRenderer(rendererOptions); 
 

 
    // Create a map and center it on islamabad. 
 
    var islamabad = new google.maps.LatLng(33.7167, 73.0667); 
 
    var mapOptions = { 
 
    zoom: 13, 
 
    center: islamabad 
 
    } 
 
    map = new google.maps.Map(document.getElementById('map'), mapOptions); 
 
    directionsDisplay.setMap(map); 
 
    calcRoute(); 
 
} 
 

 
function calcRoute() { 
 
    var start = pointA; 
 
    var end = pointB; 
 
    var request = { 
 
    origin: start, 
 
    destination: end, 
 
    travelMode: google.maps.TravelMode.DRIVING 
 
    }; 
 
    directionsService.route(request, function(response, status) { 
 
    if (status == google.maps.DirectionsStatus.OK) { 
 
     directionsDisplay.setDirections(response); 
 
    } 
 
    }); 
 
}; 
 

 
function removeRoute() { 
 
    directionsDisplay.setOptions({ 
 
    suppressPolylines: true 
 
    }); 
 
    // this "refreshes" the renderer 
 
    directionsDisplay.setMap(map); 
 
}; 
 

 
function removeRouteNull() { 
 
    directionsDisplay.setMap(null); 
 
}; 
 
google.maps.event.addDomListener(window, 'load', initialize);
#map { 
 
    height: 280px; 
 
}
<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script> 
 
<button onclick="removeRoute()">Remove route (suppressPolylines)</button> 
 
<button onclick="removeRouteNull()">Remove route (setMap(null))</button> 
 
<button onclick="initialize()">Undo all</button> 
 
<section id="map"></section>

からレンダラを削除するのいずれか
関連する問題