I've got a custom map tool that allows the user to select a point on the map to be used to create a feature with some domain-specific business logic attached to the creation process. This works excellently; however, we have a need to record these coordinates to be stored in an external system. I'm able to get the map coordinates using the MapView.ClientToMap function, however, after using these coordinates to create a feature, the features output geometry does not match the coordinates that I supply.
My guess is that this has to do with the spatial reference XY Resolution for the layer. I would expect the ClientToMap function to go ahead and "snap" to a valid x/y coordinate based on the maps spatial resolution. I should add that in our use case, the layer's spatial reference may not actually match the map's spatial reference in all cases.
Since it doesn't do this, the only thing I can think to do is to create the feature with the desired geometry, then after the feature is created, query the layer to get the "real" coordinates. This is far less than ideal, since this adds an extra step to our workflow.
Ideally, there'd be some SDK function already to allow me to calculate the valid coordinate. As far as I can tell, no such function exists. I tried the GeometryEngine.Project method, but that gave wildly unexpected results.
I also tried to write a simple "snap" function myself, but I couldn't quite get that to work as expected either. I presume that the true value would be the nearest factor of the XY Resolution value, so I would think this would work:
var x = Math.Round(point.X / resolution) * resolution;
var y = Math.Round(point.Y / resolution) * resolution;