0

I am trying to load a cacheDataset that was created using the MapCookerClass as shown in the Multithreaded MapCruncher example at the URL below. In arcMap it is possible to connect/add this cache using the Add Data dialog. The ArcEngine Add Data dialog does not seem to support this structure so I am trying to do it programmatically.

Does anyone have a working workflow/sample that I could go on? I've started in many directions, all of which are wrong. A similiar post mentions that this is possible, but not how.

Similiar post How to connect to bundle files?

Mapcruncher sample: http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/Sample_Multithreaded_MapCruncher/000100000mmm000000/

1
  • Why do you want to use dynamic display? I went down that rabbit hole and I ran into a zillion problems. To answer the question, I think you have to just turn dynamic display on, load a shapefile, save the shapefile as a layer file, then later reload the created layer file which should know where its tiles reside.
    – patrick
    Dec 2, 2011 at 15:27

1 Answer 1

2

This mostly works for me. Things to note:

  1. You must be in dynamic mapping mode when you save the map.
  2. All of the layers must be visible.
  3. You will have to save the map every time you exit to prevent the cache from being deleted when you open up the map again. (and this doesn't always work)

Good luck.

namespace MapControlApplication
{
    public sealed partial class MainForm : Form
    {
        #region class private members
        private IMapControl3 m_mapControl = null;
        private IDynamicMap m_dynamicMap;
        private System.Collections.Generic.List<IDynamicCacheLayerManager> m_dynamicCacheLayerManagerList;
        private System.Collections.Generic.List<ILayer> m_mapLayerList;
        #endregion

        #region class constructor
        public MainForm()
        {
            InitializeComponent();
        }
        #endregion

        private void MainForm_Load(object sender, EventArgs e)
        {
            System.Threading.Thread thread = new System.Threading.Thread(loadMap);
            thread.Priority = System.Threading.ThreadPriority.Highest;
            thread.Name = "Map Loading Thread";
            thread.Start();
        }

        private void loadMap()
        {
            #region Load the map document
            m_mapControl = (IMapControl3)axMapControl1.Object;
            string mapDocumentName = config.mapDocumentName;
            try
            {
                if (m_mapControl.CheckMxFile(mapDocumentName))
                {
                    m_mapControl.LoadMxFile(mapDocumentName, null, null);
                }
            }
            catch (Exception _ex)
            {
                System.Windows.Forms.MessageBox.Show(_ex.Message);
            }
            #endregion
        }

        public void saveMap()
        {
            IMapDocument mapDocument = new MapDocumentClass();
            mapDocument.Open(@"[path to your .mxd]", string.Empty);
            if (mapDocument.get_IsReadOnly(@"[path to your .mxd]"))
            {
                System.Windows.Forms.MessageBox.Show("Map document \"" + @"[path to your .mxd]" + "\" is read only!");
                mapDocument.Close();
                return;
            }
            mapDocument.ReplaceContents((IMxdContents)m_mapControl.Map);
            mapDocument.Save(mapDocument.UsesRelativePaths, true);
            mapDocument.Close();
        }

        //listen to MapReplaced event
        private void axMapControl1_OnMapReplaced(object sender, IMapControlEvents2_OnMapReplacedEvent e)
        {
            #region Create the dynamic cache layer manager
            m_dynamicCacheLayerManagerList = new System.Collections.Generic.List<IDynamicCacheLayerManager>();
            #endregion

            #region Enable dynamic map
            m_dynamicMap = m_mapControl.Map as IDynamicMap;
            if (m_dynamicMap == null)
            {
                Close();
                return;
            }
            m_dynamicMap.DynamicDrawRate = 15;
            m_dynamicMap.DynamicMapEnabled = true;
            #endregion

            System.Collections.Generic.List<string> layerNames = new System.Collections.Generic.List<string>();
            m_mapLayerList = new System.Collections.Generic.List<ILayer>();
            IMap map = m_mapControl.Map;
            for (int i = 0; i < map.LayerCount; i++)
            {
                ILayer layer = map.get_Layer(i);
                if (layer is IDynamicLayer)
                {
                    continue;
                }
                m_mapLayerList.Add(layer);

                IDynamicCacheLayerManager dynamicCacheLayerManager = new DynamicCacheLayerManagerClass();
                m_dynamicCacheLayerManagerList.Add(dynamicCacheLayerManager);
                m_dynamicCacheLayerManagerList[i].Init(map, layer);
                m_dynamicCacheLayerManagerList[i].AlwaysDrawCoarsestLevel = false;
                string layerName = layer.Name.Replace(' ', '_');
                layerName = layerName.Replace(':', '_');
                layerNames.Add(layerName);
                if (m_dynamicCacheLayerManagerList[i].FolderPath.ToLower().CompareTo(@"[path to your cache]") != 0)
                {
                    try
                    {
                        m_dynamicCacheLayerManagerList[i].Connect(@"[path to your cache]", m_dynamicCacheLayerManagerList[i].FolderName);
                    }
                    catch (Exception _ex)
                    {
                        System.Windows.Forms.MessageBox.Show(_ex.Message);
                    }
                }
            }
            saveMap();
            for (int i = 0; i < map.LayerCount; i++)
            {
                if (m_dynamicCacheLayerManagerList[i].FolderPath.ToLower().CompareTo(@"[path to your cache]") != 0)
                {
                    try
                    {
                        m_dynamicCacheLayerManagerList[i].Connect(@"[path to your cache]", m_dynamicCacheLayerManagerList[i].FolderName);
                    }
                    catch (Exception _ex)
                    {
                        System.Windows.Forms.MessageBox.Show(String.Format("Failed to connect to map cach for {0}", m_dynamicCacheLayerManagerList[i].FolderName));
                    }
                }
            }
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.