0
我目前正在路由到標記,但我希望能夠選擇另一條路線並且當前標記將被重新路由。單擊刪除當前標記並在點擊時添加一個新標記
圖1顯示了當前路由。
點擊'路由到此處'按鈕,當前標記必須被移除並被新標記替換。
OnClick this should remove the current marker and add a new marker
function showPosition(position)
{
//Set the map view to be the users location
//
var map = L.map('map').setView([position.coords.latitude, position.coords.longitude], 14);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
//Change the users marker to a unique red & show users location on click
//
L.marker([position.coords.latitude, position.coords.longitude], {
icon: L.AwesomeMarkers.icon({prefix: 'fa', markerColor: 'red'})
}).addTo(map).bindPopup("<b>Your location: </b>" + position.coords.latitude + "," + position.coords.longitude);
//Routing users location to the desired route
//
L.Routing.control({
waypoints: [L.latLng(users_lat_coords, users_lng_coords), L.latLng(x, y)],
lineOptions: {addWaypoints: false}
}
).addTo(map);
}