-
Notifications
You must be signed in to change notification settings - Fork 353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WayPoints from GeoJson #709
Comments
Hey @Didier-W var control = L.Routing.control({
waypoints: [
L.latLng(43.27493085740852, 5.695082510623004),
...sites_culture.features.map(x => L.latlng(x.geometry.coordinates))
L.latLng(43.27493085740852, 5.695082510623004)
],
router: new L.Routing.osrmv1({
language: 'en',
profile: 'car'
}),
geocoder: L.Control.Geocoder.nominatim({}),
routeWhileDragging: true,
reverseWaypoints: true,
fitSelectedRoutes: true
}).addTo(map); You might have to do some more manipulation if your GeoJson has other types than points (with more than one coordinate) If you don't know them when initializing the routing machine, you can call const waypoints = control.getWaypoints();
control.setWaypoints([waypoints[0], ...sites_culture.features.map(x => L.latlng(x.geometry.coordinates)), waypoints[waypoints.length - 1]]); I hope this helps. If you need further help, feel free to let me know |
Good evening,
console.log(mymap); var sites_culture = { var control = L.Routing.control({ Thanks again for the help you can all give me. |
Hello,
Is it possible to add a filter like this one : filter: function(feature, layer) { Thank you. |
Do you only want to add the waypoints if they are of politique "Routes"? sites_routes.features.forEach(function(feature) {
var coords = feature.geometry.coordinates;
if (feature.properties.politique === "Routes") {
waypoints.push(L.latLng(coords[1], coords[0])); // Inverser latitude et longitude
}
}); |
Bonjour,
Bonne journée. |
De rien. Si je peux vous recommander une petite amélioration du code, vous pouvez utiliser la variable if (
properties[jour] === passage &&
properties.secteur === secteur
) {
waypoints.push(L.latLng(coords[1], coords[0])); // Ajouter le point correspondant
} I hope my French was not too bad 😆 it's been a few years since I've spoken French |
Bonsoir, |
Hello,
I want to use the LeafLet Routing Machine solution with a fixed starting point that will be the same as the arrival point whose coordinates I know. For this, no problem.
I want the intermediate WayPoints coordinates to come from a GeoJson structure of the following type:
const sites_culture = {
"type": "FeatureCollection",
"name": "sites_culture",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature", "properties": { "name": "MUSEON ARLATEN", "address": "29 Rue de la République", "commune": "13200 ARLES", "tel": "04 13 31 51 79/99", "policy": "Culture" }, "geometry": { "type": "Point", "coordinates": [ 4.626015921662016, 43.676486873401274 ] } },
{ "type": "Feature", "properties": { "name": "MDAA - ARLES", "address": "29 Rue de la République", "municipality": "13200 ARLES", "tel": "04 13 31 51 03", "politics": "Culture" }, "geometry": { "type": "Point", "coordinates": [ 4.616614226966669, 43.67205666986852 ] } },
{ "type": "Feature", "properties": { "name": "Etang des Aulnes - SAINT-MARTIN-DE-CRAU", "address": "1676 Chemin d'Istres à l'Etang des Aulnes", "municipality": "13310 SAINT-MARTIN-DE-CRAU", "tel": "04 13 31 63 96", "politics": "Culture" }, "geometry": { "type": "Point", "coordinates": [ 4.78871613086454, 43.59676153502288 ] } },
{ "type": "Feature", "properties": { "name": "Château d'Avignon - SAINTES-MARIES-DE-LA-MER", "address": "RD 570", "municipality": "13460 SAINTES-MARIES-DE-LA-MER", "tel": "04 13 31 13 13", "politics": "Culture" }, "geometry": { "type": "Point", "coordinates": [ 4.411424362314144, 43.55804568265447 ] } },
{ "type": "Feature", "properties": { "name": "Archives et Bibliothèque Départementales des Bouches-du Rhône", "adresse": "18 - 20 Rue Mirès", "commune": "13003 MARSEILLE", "tel": "04 13 31 82 00", "politique": "Culture" }, "geometry": { "type": "Point", "coordinates": [ 5.369675449734724, 43.31173470954983 ] } }
]
}
How should I call these coordinates in the intermediate WayPoints?
var control = L.Routing.control({
waypoints: [
L.latLng(43.27493085740852, 5.695082510623004),
L.latLng(?, ?),
...
L.latLng(?, ?),
L.latLng(43.27493085740852, 5.695082510623004)
],
router: new L.Routing.osrmv1({
language: 'en',
profile: 'car'
}),
geocoder: L.Control.Geocoder.nominatim({}),
routeWhileDragging: true,
reverseWaypoints: true,
fitSelectedRoutes: true
}).addTo(map);
Thank you in advance for your help.
Didier
The text was updated successfully, but these errors were encountered: