2013-05-28 24 views
0

我想要生成按鈕單擊方向。用戶選擇位置點a和點b,然後按下按鈕並從該點a到點b繪製代碼方向。我已成功完成此代碼,但我無法刪除在地圖上繪製的以前的方向。請參閱圖片鏈接http://i.stack.imgur.com/z1fqo.png 。我想從地圖中刪除a,b方向,因爲它是最後的方向。無法清除先前的方向gmap3 jquery

$et_main_map.gmap3({ 
getroute:{ 
    options:{ 
      origin:org, 
      destination:dest, 
      travelMode: google.maps.DirectionsTravelMode.DRIVING 
     }, 
     callback: function(results){ 
      console.log(results); 
      if (!results) return; 
      $(this).gmap3({ 
       directionsrenderer:{ 
        divId:'directionPath', 
        options:{ 
        directions:results, 
        suppressMarkers: true 
        } 
       } 
      });  
     } 
     } 
}); 

上面的代碼添加了指示。 以下代碼不會刪除地圖上的指示。

$et_main_map.gmap3({ 
    clear: { 
     name:["directionRenderer"] 
    } 
}); 

我已經嘗試了很多事情,例如,下面的鏈接下面。 http://gmap3.net/forum/viewtopic.php?id=341 Gmap3 Clear Directions

請幫幫我。 謝謝

回答

0

我需要更新我的gmap3庫。對於那些想要解決此問題的人,只需將gmap3.js更新至版本5.1.1。這將解決這個問題。

1

你應該給的DirectionsRenderer功能的ID(「whatEverYourID」),這樣,當明確函數被調用,將予以確認:

$et_main_map.gmap3({ 
    getroute:{ 
     options:{ 
      origin: org, 
      destination: dest, 
      travelMode: google.maps.DirectionsTravelMode.DRIVING 
     }, 
     callback: function(results){ 
      console.log(results); 
      if (!results) return; 
      // this is addition lines for handling directions container------ 
      if (!$("#dircontainer").length>0) { 
       $("<div id='dircontainer' class='googlemap'></div>").insertAfter("#map"); 
      } else { 
       // this will clear previous the googlemap directions html container 
       $("#dircontainer").html(""); 
      } 
      // -------------------------------------------------------------- 
      $(this).gmap3({ 
       // clear previous direction 
       clear: { 
        id: "whatEverYourID" 
       }, 
       map:{ 
        options:{ 
         center:[tolat, tolong], 
         zoom: 10 
        } 
       }, 
       directionsrenderer:{ 
        container: $("#dircontainer"), 
        options:{ 
         directions:results 
        }, 
        // this is the ID you have to add 
        id: "whatEverYourID" 
       } 
      }); 
     } 
    } 
}); 

我希望這將有助於