Skip to content
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

Leaflet Routing Machine: How to add my own data between starting and end point in a route #663

Open
antonioOrtiz opened this issue Jul 3, 2022 · 1 comment
Labels

Comments

@antonioOrtiz
Copy link

Sorry to ask this as it's a question.

In the docs under IRoute (describes a route through a number of waypoints), there is a property called coordinates

array of L.LatLngs that can be used to visualize the route; the level of detail should be high, since Leaflet will simplify the line appropriately when it is displayed

I have a starting and end point:

  const instance = L.Routing.control({
    waypoints: [
      L.latLng(
        startingPoints[0]?.highestEl?.latlng?.lat,
        startingPoints[0]?.highestEl?.latlng?.lng),
      L.latLng(
        startingPoints[0]?.lowestEl?.latlng?.lat,
        startingPoints[0]?.lowestEl?.latlng?.lng
      ),
    ],
  });

What I would like to do is:

coordinates	: [start, L.latLng(), L.latLng(), L.latLng(), L.latLng(), L.latLng(), L.latLng(), end]

So how do I add custom Latitude and Longitude between the starting and end waypoints?

Is that indeed what coordinates is for? If so how do you access it?

Thank you in advance!

@curtisy1
Copy link
Collaborator

curtisy1 commented Jul 4, 2022

Sorry to ask this as it's a question.

No worries! We have a question tag specifically for this. I still need to integrate checking StackOverflow for lrm tags regularly into my routine, so for now it's actually better to ask here for visibility.

You could change the coordinates directly, however, it's probably best to interact directly on the waypoints, since this would also update the instructions. You can do that by either using spliceWaypoints as shown in the example here or using setWaypoints directly

const start = L.latLng(
        startingPoints[0]?.highestEl?.latlng?.lat,
        startingPoints[0]?.highestEl?.latlng?.lng);
const end =  L.latLng(
        startingPoints[0]?.lowestEl?.latlng?.lat,
        startingPoints[0]?.lowestEl?.latlng?.lng
      );
const middle =  L.latLng(
        startingPoints[0]?.middleEl?.latlng?.lat,
        startingPoints[0]?.middleEl?.latlng?.lng
      );
const instance = L.Routing.control({
    waypoints: [
     start,
      end,
    ],
  });

instance.setWaypoints([start, middle, end]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants