0

ボタンクリックで方向を生成しようとしています。ユーザーはポイント a とポイント b の位置を選択し、ボタンを押して、そのポイント a からポイント b への描画方向をコードします。このコードを正常に完了しましたが、地図に描かれた以前の方向を削除できません。画像リンクhttp://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=341 Gmap3 明確なルート案内

私を助けてください。ありがとう

4

2 に答える 2

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

それが役立つことを願っています

于 2015-05-06T05:50:46.487 に答える
0

gmap3 ライブラリを更新する必要がありました。この問題を修正したい場合は、gmap3.js をバージョン 5.1.1 に更新してください。これで問題は解決します。

于 2013-05-30T14:05:04.000 に答える