perliedman / leaflet-routing-machine

Control for routing in Leaflet
https://www.liedman.net/leaflet-routing-machine/
Other
1.08k stars 350 forks source link

Routing to bindpopup #590

Closed bur4k58 closed 4 years ago

bur4k58 commented 4 years ago

I want a route to bindpop's location through a button in the bindpopup . Everything works fine, but when I press the button It doesn't work, can someone help me?

//function route popup function routeFunction(e){ let control = L.Routing.control({ waypoints: [ L.latLng(latitude,longitude) ]}) let buttonRouting = document.getElementById("idRoute") L.DomEvent.on(buttonRouting, 'click', function() { control.spliceWaypoints(control.getWaypoints().length - 1, 1, e.latlng); }); }

for (let i = 0; i < arrayDistrict.length; i++) {
  baklava = L.geoJSON(data, {
    onEachFeature: (features, layer) => {
      let naam = features.properties.NAAM;
      let postcode = features.properties.POSTCODE;
      let district = features.properties.DISTRICT;
      let omschrijving = features.properties.OMSCHRIJVING;
      layer.setStyle(myStyleStadsdeel);
      layer.bindPopup(`<div class = 'popup'>${naam}</div> <br> <div class = 'popup'>${postcode}</div> 
      <div class = 'popup'>${district}</div> <br> <div class = 'popup'>${omschrijving}</div><br>
      <button id= "idRoute" onclick="routeFunction()"> Klik voor route </button>`)
    }
bur4k58 commented 4 years ago

I get this message when i press the button. "leaflet.js:106 Uncaught TypeError: Cannot read property 'latlng' of undefined at routeFunction (leaflet.js:106) at HTMLButtonElement.onclick ((index):1)"