Leaflet plugin route and markers

2 posts / 0 new
Last post
Leaflet plugin route and markers

How can I remove the route and marker features?  I'm trying to create a "reset" function.

Here is how I did it. You can
Here is how I did it. You can assign the layer to a variable before adding to the map and then remove that layer.   <html>     <head>         <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.5/leaflet.css" />         <script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.5/leaflet.js"></script>         <script src="https://www.mapquestapi.com/sdk/leaflet/v2.s/mq-map.js?key=Kmjtd%7Cluua2..."></script>         <script src="https://www.mapquestapi.com/sdk/leaflet/v2.s/mq-routing.js?key=Kmjtd%7Cl..."></script>         <script type="text/javascript">           var mql,map;             window.onload = function() {                 var dir;                 map = L.map('map', {                   layers: MQ.mapLayer(),                   center: [ 38.895345, -77.030101 ],                   zoom: 15                 });                 dir = MQ.routing.directions();                 dir.route({                     locations: [                         '1600 pennsylvania ave, washington dc',                         '935 pennsylvania ave, washington dc'                     ]                 });                 mql=MQ.routing.routeLayer({                     directions: dir,                     fitBounds: true                 });               map.addLayer(mql);             }         </script>     </head>     <body style='border:0; margin: 0'>         <div id='map' style='width:1100px; height:530px;'></div>       <input type='button' onclick='map.removeLayer(mql);' value='remove'/>     </body> </html>