ArcGIS Runtime SDK for WPF - Library Reference
LocalMapService Class
Members  Example  See Also 
ESRI.ArcGIS.Client.Local Namespace : LocalMapService Class

The LocalMapService class represents a map service hosted by the LocalServer.

Object Model

LocalMapService ClassWorkspaceInfoCollection ClassWorkspaceInfo ClassEnvelope ClassEnvelope ClassSpatialReference Class

Syntax

Visual Basic (Declaration) 
Public Class LocalMapService 
   Inherits LocalService
C# 
public class LocalMapService : LocalService 

Remarks

A local map service provides access to maps, features, and attribute data contained within a Map Package. Local map services are typically used to display operational or business data on top of a tiled basemap layer. Map images from local map services are dynamically rendered from the data with each request (e.g. when the user pans the map). Local map services do not support caching in the same way as other server-based map services. To use local cached maps in your application you should use the ArcGISLocalTiledLayer class. Local map services have built-in capabilities that allow each layer's behavior and appearance to be changed dynamically. These dynamic layers can increase the amount of interaction that users are able to have with maps within your application. For more information see the ArcGISDynamicMapServiceLayer class documentation.

Local map services don't always need to display images. You can create a local map service for the purpose of returning a set of features to work within your application. You retrieve these features through tasks that you add to your application. For example, you might want to query a map service and display the resulting features as graphics in the map. Local map services always have their Query and Data operations enabled in contrast to map services hosted by ArcGIS for Server where these operations can be explicitly enabled or disabled by the server administrator.

To start a LocalMapService you can either create a new instance of a LocalMapService object via the default constructor then set the path property or use the overloaded constructor. Once the path property has been set by either approach above, the StartAsync method should be called to start the LocalMapService which will be hosted by the LocalServer. When the LocalMapService creation completes the StartCompleted event will be raised. The StartCompleted even will always fire regardless of whether the service creation was successful or unsuccessful. Therefore you should check the Error property to confirm the service creation was successful. Additionally the Status property can be checked to determine the LocalServiceStatus state.

Alternatively the overloaded StartAsync method can be called with an Action callback delegate. In the same pattern as the StartAsync method, the callback will always happen whether the LocalMapService creation was successful or not.

Finally, there is one other convenience method for obtaining a LocalMapService object. Based on the supplied path to a Map Package the GetServiceAsync method will either start a new LocalMapService or return a reference to an existing LocalMapService if one has previously been created for that particular Map Package resource with the same service properties. The second parameter of this method is an Action callback delegate which will return a reference to a LocalMapService. As with the other approaches to starting LocalMapServices, the Error property should be checked to confirm a successful or unsuccessful service creation.

It is not necessary to work with the LocalMapService class directly. Instead the overloaded ArcGISLocalDynamicMapServiceLayer constructor takes a System.String representing the path to a Map Package and will handle the creation of the underlying LocalMapService. The path string can either refer to a Map Package on disk or on ArcGIS.com. The ArcGISLocalDynamicMapServiceLayer can be added to a ESRI.ArcGIS.Client.Map in this state, without waiting for the LocalMapService creation to complete. Once the LocalMapService initialization is complete, the Url property of the ArcGISLocalDynamicMapServiceLayer will be set and the ArcGISLocalDynamicMapServiceLayer will begin to draw. If using this approach the InitializationFailed event should be listened for to determine whether the layer initialization failed. In the case of a failure the InitializationFailure property will contain the Exception. Another more granular approach is to create a new ArcGISLocalDynamicMapServiceLayer object and explicitly set the path property then call the Initialize method which again will handle the creation of the supporting LocalMapService.

Example

The following code shows the recommended approach to explicitly starting a LocalMapService using the StartAsync method with an Action delegate. The following example shows the static convenience method GetServiceAsync on the LocalMapService class. This is an alternative and in many cases simpler approach to using the StartAsync method.
C#Copy Code
string mpkPath = @"Path to Map Package (.mpk)";
LocalMapService localMapService = new LocalMapService()
{
    Path=mpkPath,
    MaxRecords=100000
};
localMapService.StartAsync(localService =>
{
    if (localService.Error != null)
        return;
    ArcGISLocalDynamicMapServiceLayer layer = new ArcGISLocalDynamicMapServiceLayer(localMapService);
    _map.Layers.Add(layer);
});
VB.NETCopy Code
Dim mpkPath As String = "Path to Map Package (.mpk)"
Dim _localMapService As New LocalMapService()
_localMapService.Path = mpkPath#
_localMapService.MaxRecords = 100000
            
_localMapService.StartAsync(Function(localService)
    If localService.Error IsNot Nothing Then
        Exit Function
    End If
    Dim layer As New ArcGISLocalDynamicMapServiceLayer(_localMapService)
    _map.Layers.Add(layer)
End Function)
C#Copy Code
LocalMapService.GetServiceAsync(@"Path to Map Package (.mpk)", (serviceDelegate) =>
{
   // GetServiceAsync returns once the service has started.
   // Declare a new ArcGISLocalDynamicMapServiceLayer.
   ArcGISLocalDynamicMapServiceLayer localArcGISDynamicMapServiceLayer = new ArcGISLocalDynamicMapServiceLayer()
   {
       // Set the service property (must be done before layer is initialized).
       Service = serviceDelegate, 
       // Give the layer an identifier.
       ID = "operationalLayer", 
       // Set the image format to PNG 32 for highest quality.
       ImageFormat = ArcGISDynamicMapServiceLayer.RestImageFormat.PNG32, 
   };
   // Add the layer to the map.
   _map.Layers.Add(localArcGISDynamicMapServiceLayer); 
   });
VB.NETCopy Code
LocalMapService.GetServiceAsync("Path to Map Package (.mpk)", _
    Function(serviceDelegate)
        ' Declare a new ArcGISLocalDynamicMapServiceLayer
        Dim localArcGISDynamicMapServiceLayer As New ArcGISLocalDynamicMapServiceLayer()
        ' Set the service property (must be done before layer is initialized)
        localArcGISDynamicMapServiceLayer.Service = serviceDelegate
        ' Give the layer an identifier
        localArcGISDynamicMapServiceLayer.ID = "operationalLayer"
        ' Set the image format to PNG 32 for highest quality
        localArcGISDynamicMapServiceLayer.ImageFormat = ArcGISDynamicMapServiceLayer.RestImageFormat.PNG32
        ' Add the layer to the map
        _map.Layers.Add(localArcGISDynamicMapServiceLayer)
    End Function)

Inheritance Hierarchy

System.Object
   ESRI.ArcGIS.Client.Local.LocalService
      ESRI.ArcGIS.Client.Local.LocalMapService
         ESRI.ArcGIS.Client.Local.LocalFeatureService

Requirements

Target Platforms: Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family, Windows 7, Windows 8

See Also

© ESRI, Inc. All Rights Reserved.