1

I am trying to add waypoints from a variable to a leaflet map. The resulting variable split_route1 is formatted correctly and when I hard-code the waypoints from the console log results, the waypoints render fine. When I try to use the var splitroute1 I get an error: TypeError: t is null (leaflet.js (line 6, col 17396))

 function splitroute(route1){

 split_route1 = '';

 for (x = 0; x < route1.length  ; x++) { 

            split_route1 +='L.latLng(' +      route1[x].ordered_locs.displayLatLng.lat + ',' + route1[x].ordered_locs.displayLatLng.lng + '),'
    }
console.log(split_route1)
L.Routing.control({
   waypoints:   [  

          split_route1

    ],
    routeWhileDragging: true
}).addTo(map2);

     }
  • You might want to use the uncompressed leaflet.js so you can see what the error really is? – John Powell Jul 14 '15 at 12:52
1

I'd look here:

+= 'L.latLng('`

What is split_route meant to be? A multi-point array? Can you just construct this as an array and pass this in as waypoints?

var split_route = [];

for (x = 0; x < route1.length  ; x++) { 
    var coords = []; 
    coords.push(route1[x].ordered_locs.displayLatLng.lat, route1[x].ordered_locs.displayLatLng.lng);
    split_route.push(coords);
}
  • Thanks for the help but your answer gave the same error. The console log of split_route1 is L.latLng(43.517533,-79.697975),L.latLng(43.541817,-79.740245),L.latLng(43.547941,-79.740029),L.latLng(43.565396,-79.765799),L.latLng(43.517533,-79.697975), When I cut and paste the console log as waypoints the map renders just fine. When I use the variable I get the error. – i mean come on now Jul 14 '15 at 14:56
  • skip L.latLng(), instead try just pushing these as raw coords. I've edited my answer – toms Jul 14 '15 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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