Translation of leaflet routing

0

I am trying to translate the leaflet routing component. Currently my code is the following. With the instruction language: 'sp' it does not work very well since only translates the form but not the instructions of the route. I know I must use formatter, but I've tried it on several sites and it never works. When I put it the map is not shown

const createRoutingControl = () => {
L.Routing.control({      
  router: L.Routing.mapbox(config.features.routing.key),      
  plan: new (L.Routing.Plan.extend({
    createGeocoders: function () {
      let container = L.Routing.Plan.prototype.createGeocoders.call(this)
      let reverseRoute = createButton('↑↓', container)
      let copyToClipboard = createButton('5', container, true)       

      return container
    }
  }))([], {
    geocoder: geocoder,
    language: 'sp'
  }),
  units: config.features.routing.units,
  showAlternatives: true,
  autoRoute: true,
  routeWhileDragging: true,      
}).addTo(map)

}

    
asked by ABT 18.04.2018 в 11:49
source

1 answer

0

The trick is in language: 'es'

var map = L.map('map');

L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}{r}.png', {
    attribution: '© OpenStreetMap contributors'
}).addTo(map);

var router = L.Routing.control({
    waypoints: [
        L.latLng(-34.60, -58.37),
        L.latLng(-34.57, -58.42)
    ],
    language: 'es', 
    routeWhileDragging: true
}).addTo(map);
.map {
    position: absolute;
    width: 100%;
    height: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<link rel="stylesheet" href="https://unpkg.com/leaflet-routing-machine@latest/dist/leaflet-routing-machine.css" />
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<script src="https://unpkg.com/leaflet-routing-machine@latest/dist/leaflet-routing-machine.js"></script>

<div id="map" class="map"></div>
    
answered by 18.04.2018 в 15:00