好吧即時嘗試做的是添加一個重置按鈕到我的谷歌地圖的頂部。它是如此,當你打電話的方向,並希望擺脫目前的方向,或者只是清除這裏的出發點在地圖和recenter是使用刪除一個事件監聽器
controlUI.addEventListener('click', function() {
map.setCenter(pyrmont),
\t \t map.setZoom(14),
\t \t directionsDisplay.setPanel(null),
\t \t directionsDisplay.setMap(null); \t \t \t \t
});
和它所有的事件偵聽器的IM工作正常,但按下'重置'按鈕後,你不能再做任何的方向,我猜測這是因爲我調用了我的兩個方向var的.setPanel和.setMap,並將它們都設置爲null,但它沒有清除它們之後,問題是一個簡單的刪除事件偵聽器的工作?!如果是這樣,我怎麼會寫出來我曾嘗試過幾種方法,他們都沒有正常工作。任何幫助或指針都會非常有幫助。
謝謝你在前進,
特拉維斯
哦,這裏是我在這裏呼籲
function CenterControl(controlDiv, map) {
// Set CSS for the control border.
var controlUI = document.createElement('div');
controlUI.style.backgroundColor = '#fff';
controlUI.style.border = '2px solid #fff';
controlUI.style.borderRadius = '3px';
controlUI.style.boxShadow = '0 2px 6px rgba(0,0,0,.3)';
controlUI.style.cursor = 'pointer';
controlUI.style.marginBottom = '22px';
controlUI.style.textAlign = 'center';
controlUI.title = 'Click to reset the map';
controlDiv.appendChild(controlUI);
// Set CSS for the control interior.
var controlText = document.createElement('div');
controlText.style.color = 'rgb(25,25,25)';
controlText.style.fontFamily = 'Roboto,Arial,sans-serif';
controlText.style.fontSize = '16px';
controlText.style.lineHeight = '38px';
controlText.style.paddingLeft = '5px';
controlText.style.paddingRight = '5px';
controlText.innerHTML = 'Reset Map';
controlUI.appendChild(controlText);
// Setup the click event listeners: simply set the map to default.
controlUI.addEventListener('click', function() {
map.setCenter(pyrmont),
\t \t map.setZoom(14),
\t \t directionsDisplay.setPanel(null),
\t \t directionsDisplay.setMap(null); \t \t \t \t
});
}