Select to view content in your preferred language

Loading custom mpk

3233
3
12-29-2013 04:46 AM
Labels (1)
eranz
by
Emerging Contributor
Hi all,

I am developing a generic map loader which get as a parameter a path to a MPK file (i don't know what each MPK consists of)
I am trying to load a custom MPK with its features Layers, and i have encountered several problems:
1. if i load the mpk to ArcGISLocalDynamicMapServiceLayer the map displaying well but i can't interact with map (Clicking ect..)
2. If i load the mpk according to ArcGISLocalDynamicMapServiceLayer.Layers (Attached code) - each one of the layers into FeatureLayer it is not displaying well (polygons of some layers are not seen).
3. A Graphic Symbol of each one of the featureLayer.Graphics return null (this did not happen with 10.1)
What is the best way to load a custom local map and its features?

if (layer is ArcGISLocalDynamicMapServiceLayer)
{    
LocalMapService.GetServiceAsync(layerURI, (localMapService) =>
{

     ArcGISLocalDynamicMapServiceLayer localLayer = layer as ArcGISLocalDynamicMapServiceLayer;
     localLayer.EnableDynamicLayers = true;
     localLayer.Service = localMapService;

           localLayer.Initialize();

           localLayer.Initialized += new EventHandler<EventArgs>(localLayer_Initialized);
}
}

void localLayer_Initialized(object sender, EventArgs e)
{
            ArcGISLocalDynamicMapServiceLayer localMapService = sender as ArcGISLocalDynamicMapServiceLayer;

            if (localMapService != null)
            {
                List<LayerInfo> layers = localMapService.Layers.Reverse().ToList();

                foreach (LayerInfo layerInfo in layers)
                {
                    if (layerInfo.SubLayerIds == null || layerInfo.SubLayerIds.Length == 0)
                    {
                        ArcGISLocalFeatureLayer ftLayer= new ArcGISLocalFeatureLayer(localMapService.Service, layerInfo.ID);

                        //this is not affecting visibility of the layer ??? why?
                        ftLayer.Visible = layerInfo.DefaultVisibility;
                       
                        ftLayer.OutFields = new ESRI.ArcGIS.Client.Tasks.OutFields() { "*" };

                        ftLayer.Initialized += new EventHandler<EventArgs>(ftLayer_Initialized);
                        ftLayer.InitializationFailed += new EventHandler<EventArgs>(ftLayer_InitializationFailed);
                        ftLayer.UpdateCompleted += new EventHandler(ftLayer_UpdateCompleted);
                        ftLayer.MouseRightButtonUp += new GraphicsLayer.MouseButtonEventHandler(ftLayer_MouseRightButtonUp);
                        ftLayer.MouseLeftButtonDown += new GraphicsLayer.MouseButtonEventHandler(ftLayer_MouseLeftButtonDown);
                        ftLayer.MouseLeftButtonUp += new GraphicsLayer.MouseButtonEventHandler(ftLayer_MouseLeftButtonUp);
               

                        _map.Layers.Add(childLayer);
                    }
                }
            }
}

void ftLayer_UpdateCompleted(object sender, EventArgs e)
{
             GraphicsLayer graphicLayer = layer as GraphicsLayer;

              foreach (var graphic in graphicLayer.Graphics)
                {
//graphic.Symbol returns null in 10.2 (in 10.1 returned the Symbol value)?????????
                    if (graphic.Symbol is PictureMarkerSymbol)
                    {
                        if (dicLayerGraphics.ContainsKey(layerId.ToString()) == false)
                        {
                            dicLayerGraphics[layerId.ToString()] = new List<Graphic>();
                            dicLayers[layerId.ToString()] = graphicLayer;
                        }

                        dicLayerGraphics[layerId.ToString()].Add(graphic);
                    }
                }
}
0 Kudos
3 Replies
BKuiper
Frequent Contributor
didn't read your post extensively, but i was just curious if you are aware of the existing example. it worked for me:

http://www.arcgis.com/home/item.html?id=953a530ada30477d95cc69e788268bc9
0 Kudos
eranz
by
Emerging Contributor
Thank you for responding,

Yes i am familiar with this example, but it does not meet my requirements.

Lets make the question simple...

I want to load mpk file to my MapControl and having the ability to know when the user clicked on Graphic.
How do i do that?
0 Kudos
MichaelBranscomb
Esri Frequent Contributor
Hi,

In reference to your questions:


1. if i load the mpk to ArcGISLocalDynamicMapServiceLayer the map displaying well but i can't interact with map (Clicking ect..)

- An ArcGISLocalDynamicMapServiceLayer represents a map image dynamically renderered on a per-request basis by the LocalServer. It is possible to perform identify and query operations as well as alter the datasource/rendering properties if required. However, FeatureLayers do provide greater client-side interaction.


2. If i load the mpk according to ArcGISLocalDynamicMapServiceLayer.Layers (Attached code) - each one of the layers into FeatureLayer it is not displaying well (polygons of some layers are not seen).

- Is it possible some of the polygons are not displayed because you have exceeded the default 1000 feature response limit? This can be modified by setting the MaxRecords property on the LocalService either directly or via the overloaded GetServiceAsync e.g.

 
LocalMapService.GetServiceAsync(layerURI, 1000000, (localMapService) =>
{
    ...



3. A Graphic Symbol of each one of the featureLayer.Graphics return null (this did not happen with 10.1)

- The individual Graphic symbol is null because the FeatureLayer has a Renderer (check the Renderer property). This was actually a bug at 10.1.1 and was addressed for the 10.2 release.


What is the best way to load a custom local map and its features?


- You could consider is to use the ArcGISLocalDynamicMapServiceLayer to visually represent the map package but additionally add each vector layer as a FeatureLayer with the Mode property set to QueryMode.SelectionOnly (http://resources.arcgis.com/en/help/runtime-wpf/apiref/index.html?ESRI.ArcGIS.Client~ESRI.ArcGIS.Cli...). This can provide you with the client-side interaction you require as well as ensuring a good display experience.
- Note you should set the Map.UseAcceleratedDisplay mode to True to ensure the best performance when working with FeatureLayers and GraphicsLayers.
- Note you only need to specify EnableDynamicLayers = true if you intend to make datasouce and/or renderer changes to layers within the dynamic map service. Otherwise you may leave it false, although there's no significant overhead.

Cheers

Mike
0 Kudos