Latlong is null on mouse click

132
1
08-25-2020 09:24 PM
IndikaGayashan
New Contributor

The basemap of my application is created from tiled service which is published in our own server, like below

const mapBaseLayer = new TileLayer({
   url: `${MAP_SVC_URL}/MapServer`
})

const baseMap = new Basemap({
   baseLayers: [this.mapBaseLayer],
   title: "Test",
   id: "test",
})

const map = new ArcGISMap({
   basemap: baseMap,
   layers : [this.SatLayer, this.FeaturesLayer]
})

let view = new MapView({
   container: 'map-base',
   map: map,
   center: [103.85, 1.29],
   zoom: 13,
   constraints: {
      lods: TileInfo.create().lods
   }
})

I'm having an issue when getting lat long on mouse click. It's always null. I don't have an idea how to resolve this.

view.on("click", evt=> {

   let point = view.toMap({ x: evt.x, y: evt.y })

   console.log(point.latitude)

   console.log(point.longitude)
})

Can somebody help me with this issue ? I have been trying fro 2 days. No luck so far. 

0 Kudos
1 Reply
RobertScheitlin__GISP
MVP Esteemed Contributor

Indika,

   The view on click event already ha s a mapPoint property which is a Point geometry. So you code should look like this:

view.on("click", evt=> {

   console.log(evt.mapPoint.latitude);

   console.log(evt.mapPoint.longitude);
});

0 Kudos