Hello,
I'm currently working on integrating arcgis runtime in our software and I have encountered an impediment wherein whenever I set the viewpoint, it seems after calling UpdateLayout, the Y values set in MapView.VisibleArea is entirely different.
Here's my code:
var tl = new MapPoint(x1, y1, CurrentSpatialReference);
var br = new MapPoint(x2, y2, CurrentSpatialReference);
if(CurrentSpatialReference != null)
{
var projTl = (MapPoint)tl.Project(SpatialReferences.WebMercator);
var projBr = (MapPoint)br.Project(SpatialReferences.WebMercator);
Trace.WriteLine("Mercator coord hand calc: " + projTl.ToString() +
" " + projBr.ToString());
var backTl = (MapPoint)projTl.Project(CurrentSpatialReference);
var backBr = (MapPoint)projBr.Project(CurrentSpatialReference);
Trace.WriteLine("Source coord hand calc: " + backTl.ToString() +
" " + backBr.ToString());
BoundingBox = new Envelope(projTl, projBr);
}
var vp = new Viewpoint(BoundingBox);
MapView.SetViewpoint(vp);
MapView.UpdateLayout();
var geom = MapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry);
The initialization of MapView happens during the construction of my WPF window.
int width = 1200, height = 700;
MyMapView.SetDimension(width, height);
MyMapView.DrawStatusChanged += MyMapView_DrawStatusChanged;
MyMapView.GeoViewTapped += MyMapView_GeoViewTapped;
MyMapView.Map = new Map(BasemapStyle.OSMStandard);
Here's a sample run that I did. This is using British national grid as the spatial reference from the source. The spatial reference used by MyMapView is SpatialReferences.WebMercator. Current Viewpoint's value is fetched using the GetCurrentViewpoint(Viewpoint.Type.BoundingGeometry).
Thank you!
ExecuteCommand: Update|643332.964833|262073.813165|645936.153221|263557.442529
Mercator coord hand calc: MapPoint[X=173625.12544513, Y=6836938.46023434, Wkid=3857] MapPoint[X=177976.921476025, Y=6839147.08684191, Wkid=3857]
Source coord hand calc: MapPoint[X=643332.965807652, Y=262073.812804036, Wkid=27700] MapPoint[X=645936.154196948, Y=263557.442169608, Wkid=27700]
Current Viewpoint: MapPoint[X=173625.12544513, Y=6836857.60963878, Wkid=3857] MapPoint[X=177976.921476025, Y=6839227.93743747, Wkid=3857]
Projected Viewpoint: MapPoint[X=643335.398222287, Y=262024.325764331, Wkid=27700] MapPoint[X=645933.695298256, Y=263606.914711113, Wkid=27700]