Hello every one ;I have a feature class named departementalLevel , that contains layers , i need to display these layers using on a map suing arcGis runtime version 100.1 , so i generated a .mpk file from my feature class and now i need to display these layers from this mpk file , can i do this task ? and how i can do it need a sample code please that explainsthanks in advanced
Hello every one ;
I have a feature class named departementalLevel , that contains layers , i need to display these layers using on a map suing arcGis runtime version 100.1 , so i generated a .mpk file from my feature class and now i need to display these layers from this mpk file , can i do this task ? and how i can do it need a sample code please that explains
thanks in advanced
Your answer helped me a lot thanks
Hi Manel,
I have created a small application that starts the Local Server and add a mpk as an ArcGISMapImageLayer. It is pretty straight forward. Attached is the screen shot and project file. The mpk is located under the "bin\MPK" folder.
Hope that helps.
Nagma
There are a few ways you can troubleshoot a layer that is not loading. One of them is using LayerViewStateChanged. For ArcGISMapImageLayer, you can check sublayer load errors this way.
<SPAN class="keyword token">public</SPAN> <SPAN class="token function">MainWindow</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="token function">InitializeComponent</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> MyMapView<SPAN class="punctuation token">.</SPAN>LayerViewStateChanged <SPAN class="operator token">+</SPAN><SPAN class="operator token">=</SPAN> MyMapView_LayerViewStateChanged<SPAN class="punctuation token">;</SPAN> MyMapView<SPAN class="punctuation token">.</SPAN>Map <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Map</SPAN><SPAN class="punctuation token">(</SPAN>Basemap<SPAN class="punctuation token">.</SPAN><SPAN class="token function">CreateTopographic</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">private</SPAN> <SPAN class="keyword token">async</SPAN> <SPAN class="keyword token">void</SPAN> <SPAN class="token function">MyMapView_LayerViewStateChanged</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">object</SPAN> sender<SPAN class="punctuation token">,</SPAN> LayerViewStateChangedEventArgs e<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">var</SPAN> error <SPAN class="operator token">=</SPAN> e<SPAN class="punctuation token">.</SPAN>LayerViewState<SPAN class="punctuation token">.</SPAN>Error <SPAN class="operator token">?</SPAN><SPAN class="operator token">?</SPAN> e<SPAN class="punctuation token">.</SPAN>Layer<SPAN class="punctuation token">.</SPAN>LoadError<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>error <SPAN class="operator token">!=</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">)</SPAN> MessageBox<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Show</SPAN><SPAN class="punctuation token">(</SPAN>error<SPAN class="punctuation token">.</SPAN>Message<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">if</SPAN><SPAN class="punctuation token">(</SPAN>e<SPAN class="punctuation token">.</SPAN>Layer <SPAN class="keyword token">is</SPAN> ArcGISMapImageLayer<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">var</SPAN> layer <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>ArcGISMapImageLayer<SPAN class="punctuation token">)</SPAN>e<SPAN class="punctuation token">.</SPAN>Layer<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">try</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">foreach</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">var</SPAN> sublayer <SPAN class="keyword token">in</SPAN> layer<SPAN class="punctuation token">.</SPAN>Sublayers<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">await</SPAN> sublayer<SPAN class="punctuation token">.</SPAN><SPAN class="token function">LoadAsync</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">catch</SPAN><SPAN class="punctuation token">(</SPAN>Exception ex<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> MessageBox<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Show</SPAN><SPAN class="punctuation token">(</SPAN>ex<SPAN class="punctuation token">.</SPAN>Message<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
If it were a rendering issue, you can supply a different renderer provided it matches the geometry type of your service. In snippet below, I only wanted to display the line geometry so I cleared the rest of the sublayers.
<SPAN class="keyword token">var</SPAN> layer <SPAN class="operator token">=</SPAN><SPAN class="punctuation token">(</SPAN>ArcGISMapImageLayer<SPAN class="punctuation token">)</SPAN> MyMapView<SPAN class="punctuation token">.</SPAN>Map<SPAN class="punctuation token">.</SPAN>OperationalLayers<SPAN class="punctuation token">.</SPAN><SPAN class="token function">FirstOrDefault</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> layer<SPAN class="punctuation token">.</SPAN>Sublayers<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Clear</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> layer<SPAN class="punctuation token">.</SPAN>Sublayers<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Add</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">ArcGISMapImageSublayer</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> Renderer <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">SimpleRenderer</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> Symbol <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">SimpleLineSymbol</SPAN><SPAN class="punctuation token">(</SPAN>SimpleLineSymbolStyle<SPAN class="punctuation token">.</SPAN>DashDotDot<SPAN class="punctuation token">,</SPAN> Colors<SPAN class="punctuation token">.</SPAN>Blue<SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
You can enable debugging from your ArcGIS Runtime Local Server Utility and use Fiddler or any web debugging tool.
When using ArcGISMapImageLayer from a LocalServer, one of the requests should look like this which returns you an image. You should see the same image rendered in your runtime map.
Hello Nagma yasmin ;
Here's is my code that i've done :
using System;using System.Collections.Generic;using System.ComponentModel;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Runtime.CompilerServices;using Esri.ArcGISRuntime.Data;using Esri.ArcGISRuntime.Geometry;using Esri.ArcGISRuntime.Location;using Esri.ArcGISRuntime.Mapping;using Esri.ArcGISRuntime.Security;using Esri.ArcGISRuntime.Symbology;using Esri.ArcGISRuntime.Tasks;using Esri.ArcGISRuntime.UI;namespace RecuperCommune{ /// <summary> /// Provides map data to an application /// </summary> public class MapViewModel : INotifyPropertyChanged { public MapViewModel() {}private Map _map = new Map();/// <summary> /// Gets or sets the map /// </summary> public Map Map { get { return _map; } set { _map = value; OnPropertyChanged(); } }/// <summary> /// Raises the <see cref="MapViewModel.PropertyChanged" /> event /// </summary> /// <param name="propertyName">The name of the property that has changed</param> protected void OnPropertyChanged([CallerMemberName] string propertyName = null) { var propertyChangedHandler = PropertyChanged; if (propertyChangedHandler != null) propertyChangedHandler(this, new PropertyChangedEventArgs(propertyName)); }public event PropertyChangedEventHandler PropertyChanged; }}
using System;using System.Collections.Generic;using System.ComponentModel;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Runtime.CompilerServices;using Esri.ArcGISRuntime.Data;using Esri.ArcGISRuntime.Geometry;using Esri.ArcGISRuntime.Location;using Esri.ArcGISRuntime.Mapping;using Esri.ArcGISRuntime.Security;using Esri.ArcGISRuntime.Symbology;using Esri.ArcGISRuntime.Tasks;using Esri.ArcGISRuntime.UI;
namespace RecuperCommune{ /// <summary> /// Provides map data to an application /// </summary> public class MapViewModel : INotifyPropertyChanged { public MapViewModel() {
}
private Map _map = new Map();
/// <summary> /// Gets or sets the map /// </summary> public Map Map { get { return _map; } set { _map = value; OnPropertyChanged(); } }
/// <summary> /// Raises the <see cref="MapViewModel.PropertyChanged" /> event /// </summary> /// <param name="propertyName">The name of the property that has changed</param> protected void OnPropertyChanged([CallerMemberName] string propertyName = null) { var propertyChangedHandler = PropertyChanged; if (propertyChangedHandler != null) propertyChangedHandler(this, new PropertyChangedEventArgs(propertyName)); }
public event PropertyChangedEventHandler PropertyChanged; }}
using Esri.ArcGISRuntime.LocalServices;using Esri.ArcGISRuntime.Mapping;using Esri.ArcGISRuntime.UI;using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Navigation;using System.Windows.Shapes;namespace RecuperCommune{ /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { private MapViewModel _mapViewModel ; public MainWindow() { InitializeComponent(); _mapViewModel = this.FindResource("MapViewModel") as MapViewModel;}private Esri.ArcGISRuntime.LocalServices.LocalServer _localServer;private async void StartLocalServer() { //get the singleton LocalServer object using the static instance property _localServer = Esri.ArcGISRuntime.LocalServices.LocalServer.Instance;//Handle the statusChanged event to react when the server is started_localServer.StatusChanged += ServerStatusChanged;//Start the local server instanceawait _localServer.StartAsync();}private async void ServerStatusChanged(object sender, Esri.ArcGISRuntime.LocalServices.StatusChangedEventArgs e) { // Check if the server started successfully if (e.Status == Esri.ArcGISRuntime.LocalServices.LocalServerStatus.Started) { var mapService = new LocalMapService(@C:\Users\mkeddar\Documents\ArcGIS\niveauDepartemental.mpk); mapService.StatusChanged += (svc, args) => { //si a demaré correctement if (args.Status == LocalServerStatus.Started) { var mapServiceUrl = (svc as LocalMapService).Url; //Create a new ArcGISMapImageLayer ArcGISMapImageLayer localServiceLayer = new Esri.ArcGISRuntime.Mapping.ArcGISMapImageLayer(mapServiceUrl); //set layer opacity to semi-transparent localServiceLayer.Opacity = 0.5; //add the layer to the map _mapViewModel.Map.OperationalLayers.Add(localServiceLayer);} };//start the local map serviceawait mapService.StartAsync();} } // Map initialization logic is contained in MapViewModel.cs }}
using Esri.ArcGISRuntime.LocalServices;using Esri.ArcGISRuntime.Mapping;using Esri.ArcGISRuntime.UI;using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Navigation;using System.Windows.Shapes;
namespace RecuperCommune{ /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window
{ private MapViewModel _mapViewModel ; public MainWindow() { InitializeComponent(); _mapViewModel = this.FindResource("MapViewModel") as MapViewModel;
private Esri.ArcGISRuntime.LocalServices.LocalServer _localServer;
private async void StartLocalServer() { //get the singleton LocalServer object using the static instance property _localServer = Esri.ArcGISRuntime.LocalServices.LocalServer.Instance;
//Handle the statusChanged event to react when the server is started
_localServer.StatusChanged += ServerStatusChanged;
//Start the local server instance
await _localServer.StartAsync();
private async void ServerStatusChanged(object sender, Esri.ArcGISRuntime.LocalServices.StatusChangedEventArgs e) { // Check if the server started successfully if (e.Status == Esri.ArcGISRuntime.LocalServices.LocalServerStatus.Started) { var mapService = new LocalMapService(@C:\Users\mkeddar\Documents\ArcGIS\niveauDepartemental.mpk); mapService.StatusChanged += (svc, args) => { //si a demaré correctement if (args.Status == LocalServerStatus.Started) { var mapServiceUrl = (svc as LocalMapService).Url; //Create a new ArcGISMapImageLayer ArcGISMapImageLayer localServiceLayer = new Esri.ArcGISRuntime.Mapping.ArcGISMapImageLayer(mapServiceUrl); //set layer opacity to semi-transparent localServiceLayer.Opacity = 0.5; //add the layer to the map _mapViewModel.Map.OperationalLayers.Add(localServiceLayer);
} };
//start the local map service
await mapService.StartAsync();
} }
// Map initialization logic is contained in MapViewModel.cs }}
And my code doesn't do any thing , actually i have to display the France departements as layers , i have joind a picture of my layers that is supposed to be displayed
but my code doesn't show any thing
please help me
To add a mpk layer on the map, you could use ArcGISMapImageLayer. The service uri for this layer will be available once you start the LocalMapService. Please look at the link below :
Local Server --> Run map image layer services
Local Server—ArcGIS Runtime SDK for .NET (WPF) | ArcGIS for Developers
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.