I am having a really difficult time trying to project the map extent (WGS84) into an envelope of a different spatial reference (Web Mercator or UTM). I have tried multiple ways of changing the spatial reference of an envelope, but none of them are working. I know they aren't working because I am drawing a graphic on the screen for the envelope, but nothing appears when changing the envelope to a different spatial reference. Using the map's spatial reference of WGS84 for the envelope works perfectly and it is drawn to the screen.
As an fyi, I am converting the envelope into a polygon, which I am using for the graphic.
The following are four different code attempts that I have made using Web Mercator. I have also tried with UTM:
SpatialReference sr3857 = SpatialReferenceBuilder.CreateSpatialReference(3857);
// Builder constructors need to run on the MCT.
using (SpatialReferenceBuilder srBuilder = new SpatialReferenceBuilder(3857))
{
// do something with the builder
sr3857 = srBuilder.ToSpatialReference();
}
ArcGIS.Core.Geometry.Polygon envPoly = null;
Envelope mapExtent = (Envelope)GeometryEngine.Instance.Project(MapView.Active.Extent, sr3857);
private Envelope BuildEnvelope(MapPoint mapPt, Envelope inputEnvelope)
{
EnvelopeBuilder envelopeBuilder = new EnvelopeBuilder(SpatialReferences.WebMercator);
envelopeBuilder.XMin = inputEnvelope.XMin;
envelopeBuilder.YMin = inputEnvelope.YMin;
envelopeBuilder.XMax = inputEnvelope.XMax;
envelopeBuilder.YMax = inputEnvelope.YMax;
return envelopeBuilder.ToGeometry();
}
Envelope mapExtent = BuildEnvelope(MapView.Active.Extent)
Envelope mapExtent = EnvelopeBuilder.CreateEnvelope(MapView.Active.Extent, SpatialReferences.WebMercator);
Envelope mapExtent = EnvelopeBuilder.CreateEnvelope(MapView.Active.Extent, SpatialReferences.WebMercator);