Google maps api 3 如何使用gmap3插件删除渲染路由?
我使用GMAP3插件来渲染驾驶方向。我想添加一个clear按钮,这样就可以很清楚了,但是我还没有在GMAP3中找到正确的语法。这是我的js代码,根据gmap3.net中的示例进行了修改。我已经绘制了标记,并且从绘制的标记而不是从地图上的单击位置检索了latlngGoogle maps api 3 如何使用gmap3插件删除渲染路由?,google-maps-api-3,jquery-gmap3,Google Maps Api 3,Jquery Gmap3,我使用GMAP3插件来渲染驾驶方向。我想添加一个clear按钮,这样就可以很清楚了,但是我还没有在GMAP3中找到正确的语法。这是我的js代码,根据gmap3.net中的示例进行了修改。我已经绘制了标记,并且从绘制的标记而不是从地图上的单击位置检索了latlng function removePath() { $(mapID).gmap3({ action: 'clear', name: 'directionRenderer' // tag
function removePath() {
$(mapID).gmap3({
action: 'clear',
name: 'directionRenderer'
// tag: 'path' // works too with tag instead of name
});
function updatePath() {
$(mapID).gmap3({
action: 'getRoute',
options: {
origin: m1.getPosition(),
destination: m2.getPosition(),
travelMode: google.maps.DirectionsTravelMode.DRIVING
},
callback: function (results) {
if (!results) return;
$(mapID).gmap3({
action: 'setDirections',
directions:results,
});
}
});
};
function updateDirection(mm) { // Directions between m1 and m2
var mmID = $(mm).prop('id');
...
if (mmID == 'clearDirection') {
...
removePath();
return;
};
...
if (m1 && m2) { updatePath(); };
};
function initmap() {
$(mapID).gmap3(
{
action: 'init',
options: defaultMapOptions
},
// add direction renderer to configure options (else, automatically created with default options)
{ action: 'addDirectionsRenderer',
preserveViewport: true,
markerOptions: { visible: false },
options: {draggable:true},
tag: 'path'
},
// add a direction panel
{ action: 'setDirectionsPanel',
id: 'directions'
}
);
})
HTML文档中有一个指示面板。它有一个包装器,当使用jquery css属性更改清除路由时,该包装器被隐藏。每当值分配给m1或m2时,包装器div的display属性将更改回“block”
<body>
...
<div id="direction_container" class="shadowSE">
....
<div id="directions"></div>
....
</div>
</body>
...
....
....
使用以下方法:
$(mapID).gmap3({action:"clear", name:"directionRenderer"});
它绝对工作正常
$map.gmap3({ action: 'clear', name: 'directionRenderer' });
*指示-
如果以后绘制路线,则必须编写以下代码,否则无法显示方向
$map.gmap3({ action: 'addDirectionsRenderer', preserveViewport: true,
markerOptions: { visible: false} },
{ action: 'setDirectionsPanel', id: 'directions' });
谢谢…上面选择的答案对我不起作用。我不确定它是否与版本相关,但我使用的解决方案更简单:
$(your-selector).gmap3({clear: {}});
之后,您可以绘制一条新路线,而无需重新连接地图上显示的方向。谢谢您的建议。它删除了路由,我可以在之后使用新选择的m1和m2添加路由,但是,setDirections在使用后停止工作。如果我不清楚,只需选择不同的m1或m2,路线和方向都可以。