0

So i am trying to use an ESRI Route service in a Leaflet map using https://github.com/jgravois/lrm-esri and am getting an error that maybe someone can help me with. Even using the code provided at git, i still seem to get the error, it would seem it worked at one time.

{status: -3, message: "TypeError: Cannot read property 'lat' of undefined"}

here is the js

var control = L.Routing.control({
waypoints: [
    L.latLng(28.4644,-99.0236),
    L.latLng(28.4758,-98.6424)
],
router: L.Routing.esri({
//this is a sample service, i am using one i created using private roads
  serviceUrl: 'https://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Network/USA/NAServer/Route'

}),
  geocoder: L.Control.Geocoder.nominatim(),
  routeWhileDragging: true,
  reverseWaypoints: true
}).addTo(map);

L.Routing.errorControl(control).addTo(map);

Has anyone gotten the lrm-esri to work recently? The service is working for solve route, but it must be a way the js is passing the lat longs to the service?

1 Answer 1

1

it might be a typo, but your lat/longs are reversed

L.latLng(28.4644,-99.0236),
L.latLng(28.4758,-98.6424)

once that's fixed, you're correct that sampleserver3 is solving the route, but for some reason cors-lite throws an error immediately, before the response can even be parsed.

one thing i know about that server is that it does not actually support CORS. i'm just guessing, but perhaps the support for cross domain requests it allows for in ancient browsers requires CORS support on the server (and it just so happens to be missing from your own internal service as well).

because of this, your best bet would be to try to either add support for CORS to your own routing service or substitute another dependency in place of cors-lite.

2
  • i went ahead and ripped out cors-lite in favor of 'xhr' in the lib to enable support for POST, but the changes still require CORS support in both the server and browser. Commented Jun 8, 2018 at 19:32
  • Yes, that was a typo, sorry about that. I didn't even think to look at cors. I will give that a try and let you know if that solves it.
    – Messak
    Commented Jun 8, 2018 at 21:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.