Beispiel #1
0
 /// <summary>
 /// Projects the specified geometry.
 /// </summary>
 /// <param name="geometry">The geometry.</param>
 /// <param name="outSpatialReference">The out spatial reference.</param>
 /// <returns></returns>
 private static Geometry.Geometry Project(Geometry.Geometry geometry, SpatialReference outSpatialReference)
 {
     var toMercator = outSpatialReference.WKID != 4326;
     if (geometry != null && geometry.SpatialReference != null &&
         !geometry.SpatialReference.Equals(outSpatialReference))
     {
         Projection.WebMercator projector = new Projection.WebMercator();
         if (toMercator && geometry.SpatialReference.WKID == 4326)
             //Data is 4326 and must projected to webmercator
             return projector.FromGeographic(geometry);
         if (!toMercator && MercatorSref.Equals(geometry.SpatialReference))
             //Data is in webmercator and must be projected to 4326
             return projector.ToGeographic(geometry);
     }
     // Other cases : geometry without SR, geometry already in the right SR, unsupported SR -> return the input geometry
     return geometry;
 }
Beispiel #2
0
 private static void ProjectGroundOverlays(ElementLayer layer, SpatialReference sref)
 {
     var proj = new Projection.WebMercator();
     var webMercatorSR = new SpatialReference(102100);
     var wgs84SR = new SpatialReference(4326);
     foreach (UIElement elt in layer.Children)
     {
         var envelope = elt.GetValue(ElementLayer.EnvelopeProperty) as Envelope;
         if (envelope != null)
         {
             if (webMercatorSR.Equals(envelope.SpatialReference) && wgs84SR.Equals(sref))
             {
                 var env = proj.ToGeographic(envelope) as Envelope;
                 elt.SetValue(ElementLayer.EnvelopeProperty, env);
             }
             else if (wgs84SR.Equals(envelope.SpatialReference) && webMercatorSR.Equals(sref))
             {
                 var env = proj.FromGeographic(envelope) as Envelope;
                 elt.SetValue(ElementLayer.EnvelopeProperty, env);
             }
         }
     }
 }