AnsweredAssumed Answered

Add Photo Overlay in ArcGIS SDK for .NET

Question asked by jasonMDSP on Aug 3, 2015
Latest reply on Aug 4, 2015 by jasonMDSP

I am new to the ArcGIS SDK and I can't seem to find how to add a picture on top of the map, using 4-coner coordinates. In the snippet below, coords has the coordiantes for 4 points. I know all I try to do in this example is to fill a polygon with a picture, so if anyone has an example on how to overlay a picture over the map, I would appreciate it. Thanks.

 

System.Uri myPictureUri = new System.Uri("https://upload.wikimedia.org/wikipedia/commons/0/03/Piwnice_aerial_view.jpg");

Esri.ArcGISRuntime.Symbology.PictureFillSymbol pictureFillSymbol = new Esri.ArcGISRuntime.Symbology.PictureFillSymbol();
pictureFillSymbol.SetSourceAsync(myPictureUri);

var graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as Esri.ArcGISRuntime.Layers.GraphicsLayer;
if (graphicsLayer == null)
{
  graphicsLayer = new Esri.ArcGISRuntime.Layers.GraphicsLayer();
  graphicsLayer.ID = "MyGraphicsLayer";
  MyMap.Layers.Add(graphicsLayer);
}

System.Collections.ObjectModel.ObservableCollection<Esri.ArcGISRuntime.Geometry.PointCollection> rings =
  new System.Collections.ObjectModel.ObservableCollection<Esri.ArcGISRuntime.Geometry.PointCollection>();
Esri.ArcGISRuntime.Geometry.PointCollection pointCollection = new Esri.ArcGISRuntime.Geometry.PointCollection(MyMapView.SpatialReference);

for (int i = 0; i < coords.Length-2; i = i + 2)
{
  Esri.ArcGISRuntime.Geometry.MapPoint point;
  point = Esri.ArcGISRuntime.Geometry.ConvertCoordinate.FromDecimalDegrees(coords[i].ToString() + " " + coords[i + 1].ToString(), MyMapView.SpatialReference);
  pointCollection.Add(point);
}

rings.Add(pointCollection);

//Set Geometry
Esri.ArcGISRuntime.Geometry.Polygon p = new Esri.ArcGISRuntime.Geometry.Polygon(rings, MyMap.SpatialReference);
var overlayGraphic = new Esri.ArcGISRuntime.Layers.Graphic();
overlayGraphic.Geometry = p;
overlayGraphic.Symbol = pictureFillSymbol;

graphicsLayer.Graphics.Add(overlayGraphic);

Outcomes