Search code examples
javascriptleafletmapsmarkersmapquest

MapQuest, Leaflet - disable marker on directions layer


Is there a way to hide markers generated at directions layer ? I'd like to draw only route. Or is there a way to set custom icon instead of build ones ?

According to docs:

https://developer.mapquest.com/documentation/mapquest-js/v1.3/l-mapquest-directions-layer/

I can only change style of start-marker / end-marker, but I don't want it at all.

Or maybe there is a way to extend directionLayer, and somehow override markers ?


Solution

  • That was my first question at SO, a this is my first answer :)

    var icoEmpty = L.icon({iconUrl: 'a'});
    
    var directions = L.mapquest.directions();
    directions.route({
      start: 'San Francisco, CA',
      waypoints: ['Palo Alto, CA'],
      end: 'San Jose, CA'
    }, createMap);
    
    var DirectionsLayerWithEmptyMarkers = L.mapquest.DirectionsLayer.extend({
        createStartMarker: function(location, stopNumber) {return L.marker(location.latLng, {icon: icoEmpty});},
        createWaypointMarker: function(location, stopNumber) {return L.marker(location.latLng, {icon: icoEmpty});},
        createEndMarker: function(location, stopNumber) {return L.marker(location.latLng, {icon: icoEmpty});},
      });
    
    function createMap(err, response) {
      var directionsLayer = new DirectionsLayerWithEmptyMarkers({
        directionsResponse: response
      }).addTo(map);
    }