Hi,
I am showing the wells on the map based on the longitude and latitude values. These longitude and latitude values have been fetched from the database. After displaying the wells, when any particular well is clicked, I am getting the longitude and latitude which is different from what I am showing. So, how to get the exact value of the point that already shown on the Map? Because, if I will get the exact value that I have been displayed, then I will do the next task based on that value.
Example:
value displayed :longitude:8.945 and Latitude:50.893
after clicking the point I am getting in the console:
longitude:8.53 and Latitude:50.87
How will I get the exact value i.e 8.945 and 50.893 after clicking?
Below is my code:
Solved! Go to Solution.
Your code
view.on("click", function (evt) {
var longitude = evt.mapPoint.longitude;
var latitude = evt.mapPoint.latitude;
// Round the coordinates for visualization purposes
var lon = Math.round(longitude * 1000) / 1000;
var lat = Math.round(latitude * 1000) / 1000;
console.log(lat);
console.log(lon);
});
is just getting the point that the user clicks on the view and is not attempting to get the exact well point. You need to do a view hitTest to see if the user clicked on an actual graphic in the view.
view.on("click", function (evt) {
view.hitTest(evt)
.then(function (response) {
const result = response.results[0];
if (result) {
let long = result.graphic.attributes.longitude;
let lat = result.graphic.attributes.latitude;
console.info(long, lat);
}
...
Your code
view.on("click", function (evt) {
var longitude = evt.mapPoint.longitude;
var latitude = evt.mapPoint.latitude;
// Round the coordinates for visualization purposes
var lon = Math.round(longitude * 1000) / 1000;
var lat = Math.round(latitude * 1000) / 1000;
console.log(lat);
console.log(lon);
});
is just getting the point that the user clicks on the view and is not attempting to get the exact well point. You need to do a view hitTest to see if the user clicked on an actual graphic in the view.
view.on("click", function (evt) {
view.hitTest(evt)
.then(function (response) {
const result = response.results[0];
if (result) {
let long = result.graphic.attributes.longitude;
let lat = result.graphic.attributes.latitude;
console.info(long, lat);
}
...
Hi Robert,
Thanks for your quick reply. It is working as I am expecting.
Thank you very much and you saved my Saturday
Regards,
SK