不能清除以前的方向gmap3 jquery



我正在尝试生成按钮单击的方向。用户选择位置a点和b点,然后按下按钮,代码绘制从a点到b点的方向。我已经成功完成了这段代码,但我无法删除之前在地图上绘制的方向。请参阅图片链接https://i.stack.imgur.com/z1fqo.png。我想从地图上删除a,b方向,因为它是最后一个方向。

$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=341Gmap3清晰方向

请帮帮我。由于

你应该给directionsrenderer函数一个ID ("whatEverYourID"),这样当clear函数被调用时它就会被识别出来:

$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"
                 }
            });
        }
    }
});

我希望这对你有帮助

我需要更新我的gmap3库。对于那些想要解决这个问题的人,只需将gmap3.js更新到5.1.1版本。

最新更新