Hi,
I'm trying to emulate the screen cap below into some JS.
In the SDK for Project there is no parameter specified for the Input Spatial Reference like there in the above screen cap of the Geometry Service I am using, so I'm not quite sure how I specify that in my JS. Here is what I have so far:
view.on("click", function (event) {
event.stopPropagation(); // overwrite default click-for-popup behavior
// Get the coordinates of the click on the view
var northing = event.mapPoint.y;
var easting = event.mapPoint.x;
var geomSer = new GeometryService("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/Geometry/GeometryServer");
var params = new ProjectParameters();
params.geometries = [event];
params.outSpatialReference = 4326;
var newPoint = geomSer.project(params);
view.popup.open({
// Set the popup's title to the coordinates of the location
title: "Latitiude: " + newPoint.y + ", Longitude: " + newPoint.x,
content: "Northing: " + northing + ", Easting: " + easting,
location: event.mapPoint // Set the location of the popup to the clicked location
});
});
Any guidance is appreciated.
Solved! Go to Solution.
OK. That seems to be working. At least I am past all of the errors now. Still not getting the expected result, but at least I am closer. See below for final code and what I am seeing. Not sure why the Lat/Long is 'undefined'.
view.on("click", function (event) {
event.stopPropagation(); // overwrite default click-for-popup behavior
// Get the coordinates of the click on the view
var northing = event.mapPoint.y;
var easting = event.mapPoint.x;
var geomSer = new GeometryService("https://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/Geometry/GeometryServer");
var params = new ProjectParameters();
params.geometries = [event.mapPoint];
var id = new SpatialReference();
id.wkid = 4326;
params.outSpatialReference = id;
geomSer.project(params).then(function(projectedPoint){
view.popup.open({
//Set the popup's title to the coordinates of the location
title: "Latitude: " + projectedPoint.y + ", Longitude: " + projectedPoint.x,
content: "Northing: " + northing + ", Easting: " + easting,
location: event.mapPoint // Set the location of the popup to the clicked location
});
}, function(error) {
console.error(error)
});
Yes!! I finally got it:
title: "Latitude: " + projectedPoint[0].x + ", Longitude: " + projectedPoint[0].y,
Wow....that was a lot of work.