Hello everyone, I added a snippet of code that allows for displaying the coordinates on the map as the cursor moves. Right now, the existing coordinates are on OK State Plane North Coordinates. I want to project these coordinates to a WGS 1984 or a Web Mercator (3857) - (see image below and coordinated within red box):
I have tried a number of things to reproject these coordinates, but cannot get this to work. I do have a geometry service defined within the application. Things I have tried include:
new ProjectParameters
also something like this:
var geomSer = new GeometryService( ... );
var params = new ProjectParameters({
geometries: [point],
outSpatialReference:
outSpatialReference,
transformation: transformation
});
Overall, the API documentation isn't that great or are there any good examples to follow to see how this is done.
Here is my current code snippet:
// Map - Display Coordinates in Lower Left of Map
function displayMapCoords(evt) {
var coordinatePoints = mapView.toMap({x: evt.x, y: evt.y});
var XCoordinates = coordinatePoints.x.toFixed(6);
var YCoordinates = coordinatePoints.y.toFixed(6);
var combinedXYCoordinates = XCoordinates + ", " + YCoordinates;
console.log("Oklahoma State Plane North coordinates are (X, Y): ", combinedXYCoordinates);
// Display Map Coordinates in Map
dom.byId("mapCoordinates").innerHTML = XCoordinates + ", " + YCoordinates;
}
// Update Coordinates as Mouse Moves
mapView.when(function(){
mapView.on("pointer-move", displayMapCoords);
});
Are there any suggestions on how to return the coordinates back to a WGS 1984 or Web Mercator projection?
Ian,
Why not use the CoordinateConversion widget?
https://developers.arcgis.com/javascript/latest/sample-code/widgets-coordinateconversion/index.html
Hello Robert. I was looking at that widget yesterday and it is really nice, but takes up a little too much real-estate. I really like what I came up with for the app. I do want to get this to work, just so I know it can be done.
With that said, I may end up looking at it again and add it as a tool with the measurement widget...perhaps up here (see red box)?
Ian,
If that is the case then you should look at using the projection class. It allows for re-projecting geometries clientside without a round trip to the server.