2017-04-20 2 views
0

Je suis en train de router vers un marqueur, mais je veux être en mesure de choisir un autre itinéraire et le marqueur actuel sera alors redirigé.Dépliant retirer le marqueur actuel et en ajouter un nouveau au clic

L'image 1 montre le routage actuel.

En cliquant sur le bouton 'Route to here', le marqueur actuel doit être retiré et remplacé par le nouveau marqueur.

Image current routing

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: '&copy; <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); 
} 

Répondre

0

Le développeur de la bibliothèque de la machine de routage dépliant travaille toujours sur le code pour y parvenir, si une solution a été fait. Si une route a déjà été faite, je joint le waypoint et en ajoute un nouveau.

var routing =''; 
var been_routed=false; 
function route_to_station(point_lat_coords, point_lng_coords, x1, y1) { 
       users_lat_coords = point_lat_coords; 
       users_lng_coords = point_lng_coords; 
       x = x1; 
       y = y1; 

       if (x !== '') { 
        if (been_routed === true) { 
         routing.spliceWaypoints(0, 1); 
        } 
        routing = L.Routing.control({ 
          waypoints: [L.latLng(users_lat_coords, users_lng_coords), L.latLng(x, y)], 
          lineOptions: {addWaypoints: false} 

         } 
        ); 
        routing.addTo(map); 
        been_routed = true; 

       } 
      }