in the below posted code i am trying to access the e.coordinate from outside the callback listener this.map.on('pointermove'...)
as shown below.
the method routeToField()
is invoked on a button click. inside this method i am trying to access the values of this.mousePointerLonLat
. the log statement inside the callback listener this.map.on(...)
are displayed and contain
values in type of array with two elements.
the problem is, despite this.mousePointerLonLat
is initialized, when it is accessed inside the method routeToField()
i receive
ERROR TypeError: Cannot read property '0' of undefined
at SiteMapComponent.push.zIrq.SiteMapComponent.routeToFiel
please let me know how to access the values in the array this.mousePointerLonLat
from inside the methos routeToField
code:
this.map.on('pointermove', (e)=>{
this.mousePointerLonLat = toLonLat(e.coordinate);
});
this.mousePointerLonLat = this.map.on.bind(this.mousePointerLonLat)
console.log("this.mousePointerLonLat: ", this.mousePointerLonLat);
console.log("this.mousePointerLonLat[0]: ", this.mousePointerLonLat[0]);
console.log("this.mousePointerLonLat[1]: ", this.mousePointerLonLat[1]);
var startLongitude = SynopsWebAppComponent.USER_COORDINATES.longitude;
var startLatitude = SynopsWebAppComponent.USER_COORDINATES.latitude;
var endLongitude = this.mousePointerLonLat[0];
var endLatitude = this.mousePointerLonLat[1];
this.openRouteServiceAPIService.getRouteAsVectorLayerBetweenStartEndLocations(startLongitude,startLatitude,endLongitude,endLatitude);