AnsweredAssumed Answered

How Run ArcGIS RunTime Map With C# Code on WPF

Question asked by behClevest on Feb 9, 2017
Latest reply on Feb 10, 2017 by JNery-esristaff

I have a WPF application called WpfApplication1. In ManiWindow.xaml I have a

 

Snippet

 

<esri:MapView x:Name="MyMapView">            

</esri:MapView>

 

and in ManiWindow.xmal.cs I only have

 

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {

            InitializeComponent();

        }

    }
}

 

 

 

According to ESRI we can add the Map to the MapView as as long as we have an empty MapView has been added to the page at design time and has been given the name MyMapView (<esri:MapView x:Name="MyMapView"/>.

 

Now my question is how/ where should I add this code to get map running? 

 

// create a new Map 
var myMap = new Esri.ArcGISRuntime.Controls.Map();

// create a new layer (world street map tiled layer)
var uri = new Uri("http://services.arcgisonline.com/arcgis/rest/services/World_Street_Map/MapServer");
var baseLayer = new Esri.ArcGISRuntime.Layers.ArcGISTiledMapServiceLayer(uri);
// (give the layer an ID so it can be found later)
baseLayer.ID = "BaseMap";

// add the layer to the Map
myMap.Layers.Add(baseLayer);

// set the initial view point
var mapPoint = new Esri.ArcGISRuntime.Geometry.MapPoint(-117.445, 33.9,
    Esri.ArcGISRuntime.Geometry.SpatialReferences.Wgs84);
var initViewPoint = new Esri.ArcGISRuntime.Controls.ViewpointCenter(mapPoint, 250000);

myMap.InitialViewpoint = initViewPoint;

// assign the Map to the MapView's Map property
this.MyMapView.Map = myMap;

Outcomes