afcon

Loading custom mpk

Discussion created by afcon on Dec 29, 2013
Latest reply on Jan 6, 2014 by MBranscomb-esristaff
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);
                    }
                }
}

Outcomes