I have a google map using API v3 which gets directions from one location to another. The app works great but the window which gets the directions is an overlay on the map. I'd like it so when this window is closed directions are removed from the map but other markers remain.
我有一个使用API v3的谷歌地图,它可以获取从一个位置到另一个位置的路线。该应用程序运行良好,但获取方向的窗口是地图上的叠加。我喜欢它,所以当这个窗口关闭时,方向将从地图上移除,但其他标记仍然存在。
I have tried the following:
我尝试过以下方法:
$('#content .close').live('click', function() {
$('#content').hide();
directionDisplay = new google.maps.DirectionsRenderer();
directionDisplay.suppressMarkers = true;
directionDisplay.setMap(map);
return false;
});
This seems to hide the window as expected but doesn't do anything regards with removing directions from the map.
这似乎隐藏了预期的窗口,但没有做任何关于从地图中删除方向的问题。
Any help is much appreciated.
任何帮助深表感谢。
Dave.
戴夫。
6 个解决方案
#1
47
You can change the map binding for the DirectionsRenderer to "null" to remove the direction overlay
您可以将DirectionsRenderer的地图绑定更改为“null”以删除方向叠加
directionDisplay.setMap(null);
#2
39
You can try this, and not lose reference to the map
你可以尝试这个,而不是丢失对地图的引用
directionDisplay.set('directions', null);
#3
6
You can also use : directionsDisplay.setDirections({routes: []});
您还可以使用:directionsDisplay.setDirections({routes:[]});
#4
1
That should read as:
这应该是:
directionDisplay.setMap(null);
#5
1
None of the above worked for me, this is what I needed:
以上都不适合我,这是我需要的:
// Clear past routes
if (directionsDisplay != null) {
directionsDisplay.setMap(null);
directionsDisplay = null;
}
#6
0
Using directionDisplay.setMap(null);
will remove the whole directions renderer overlay, including markers. If you just want to remove the routes keeping the markers you can use setOptions
to change the options settings of DirectionsRenderer for suppressPolylines
after initialization
使用directionDisplay.setMap(null);将删除整个方向渲染器叠加,包括标记。如果您只想删除保留标记的路径,可以使用setOptions在初始化后更改suppressRolylines的DirectionsRenderer的选项设置
directionsDisplay.setOptions({
suppressPolylines: true
});
(see also my other similar answer)
(另见我的其他类似答案)
#1
47
You can change the map binding for the DirectionsRenderer to "null" to remove the direction overlay
您可以将DirectionsRenderer的地图绑定更改为“null”以删除方向叠加
directionDisplay.setMap(null);
#2
39
You can try this, and not lose reference to the map
你可以尝试这个,而不是丢失对地图的引用
directionDisplay.set('directions', null);
#3
6
You can also use : directionsDisplay.setDirections({routes: []});
您还可以使用:directionsDisplay.setDirections({routes:[]});
#4
1
That should read as:
这应该是:
directionDisplay.setMap(null);
#5
1
None of the above worked for me, this is what I needed:
以上都不适合我,这是我需要的:
// Clear past routes
if (directionsDisplay != null) {
directionsDisplay.setMap(null);
directionsDisplay = null;
}
#6
0
Using directionDisplay.setMap(null);
will remove the whole directions renderer overlay, including markers. If you just want to remove the routes keeping the markers you can use setOptions
to change the options settings of DirectionsRenderer for suppressPolylines
after initialization
使用directionDisplay.setMap(null);将删除整个方向渲染器叠加,包括标记。如果您只想删除保留标记的路径,可以使用setOptions在初始化后更改suppressRolylines的DirectionsRenderer的选项设置
directionsDisplay.setOptions({
suppressPolylines: true
});
(see also my other similar answer)
(另见我的其他类似答案)