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