Open Nikelsj opened 3 years ago
I want to export the route between the waypoints as geojson so that i can buffer and add it as a line layer Here is my code :
`var route = L.Routing.control({ waypoints: [null], collapsible: true, show: false, router: new L.Routing.graphHopper('key'), position: 'bottomleft', geocoder: L.Control.Geocoder.nominatim({}), createMarker: function(i,wp) { return L.marker(wp.latLng, {icon: redIcon, draggable:true }); }, }).addTo(map);
route.on('routeselected', function(e) { var r = e.route; var lineCoordinates = [], i, latLng; for (i = 0; i < r.coordinates.length; i++) { latLng = L.latLng(r.coordinates[i]); lineCoordinates.push([latLng.lng, latLng.lat]); } return { type: 'LineString', coordinates: lineCoordinates } let lineString = turf.lineString(lineCoordinates); var buffered = turf.buffer(lineString, 500, {units: 'miles'}); var bufferedLayer = L.geoJSON(null); bufferedLayer.addData(buffered); bufferedLayer.addTo(map); });`
I want to know if I am in the right way? i am not getting any coordinates from the route
I want to export the route between the waypoints as geojson so that i can buffer and add it as a line layer Here is my code :
`var route = L.Routing.control({ waypoints: [null], collapsible: true, show: false, router: new L.Routing.graphHopper('key'), position: 'bottomleft', geocoder: L.Control.Geocoder.nominatim({}), createMarker: function(i,wp) { return L.marker(wp.latLng, {icon: redIcon, draggable:true }); }, }).addTo(map);
route.on('routeselected', function(e) { var r = e.route; var lineCoordinates = [], i, latLng; for (i = 0; i < r.coordinates.length; i++) { latLng = L.latLng(r.coordinates[i]); lineCoordinates.push([latLng.lng, latLng.lat]); } return { type: 'LineString', coordinates: lineCoordinates } let lineString = turf.lineString(lineCoordinates); var buffered = turf.buffer(lineString, 500, {units: 'miles'}); var bufferedLayer = L.geoJSON(null); bufferedLayer.addData(buffered); bufferedLayer.addTo(map); });`
I want to know if I am in the right way? i am not getting any coordinates from the route