Hi there,
thanks for your hint.
take a look to my code (Angular):
const apiUrl = 'https://api.openrouteservice.org/optimization';
let jobsBody = [];
let vehiclesBody = [];
for (let i = 0; i < 6; i++) {
const jobsLocations = [
[12.0202443, 42.039349],
[14.5911201, 40.8209326],
[12.5902917, 43.0957988],
[12.5454813, 42.89363],
[12.6587053, 42.9745784],
[12.7339929, 43.3330812]
]
const vehiclesLocations = [12.8059101, 43.4353756]
jobsBody = [...jobsBody, {
id: i,
service: 300,
location: jobsLocations[i],
skills: [1],
time_windows: [[32400, 36000]]
}]
if (i < 2) {
vehiclesBody = [...vehiclesBody, {
id: i,
profile: 'driving-car',
start: vehiclesLocations,
end: vehiclesLocations,
capacity: [4],
skills: [1, 14],
time_window: [28800, 43200]
}]
}
}
const body = {
jobs: jobsBody,
vehicles: vehiclesBody,
options: {
g:
true
}
}
this.http.post<any>(apiUrl, body).subscribe(data => {
let step = [];
let featureObj = [];
data.routes.map(route => {
let location = [];
route.steps.forEach(place => location = [...location, place.location])
step = [...step, location]
});
for (const index in step) {
if (index) {
featureObj = [...featureObj, {
type: 'Feature',
geometry: {
type: 'LineString',
coordinates: step[index]
},
properties: {
color: this.getRandomColor()
}
}]
}
}
console.log(featureObj)
this.layers = [...this.layers, L.geoJSON({
type: 'FeatureCollection',
features: featureObj
}, {
onEachFeature(feature, layer) {
if (layer instanceof L.Polyline) layer.setStyle({ color: feature.properties.color })
}
})]
})
and to my map:
I’m noticing that the routing pass throug steps but not respect street directions, cut the streets over.
Where I’m failing?
thanks a lot.