ThinkGeo.com    |     Documentation    |     Premium Support

Problem in loading Shapefile layers from two different control events

I am facing problem in loading the layers in the ThinkGeo Map Control. I am using the ThinkGeo Mapsuite Desktop Evalution version 3.0(Beta). 

The product version of DesktopEdition.dll is 3.0.362 and of MapsuiteCore.dll is 3.1.182.

I have three Shapefiles(Countries, MajorCities and WorldCapitals) and loading two files i.e. Countries and MajorCities at form_load event and the third shapefile i.e WorldCapitals loading through a button click event after the form gets loaded. The map control displays the data correctly after the form_load event is fired i.e two layers are displayed on the map control where as when I click on the button to load the third layer on top of the two layers in the control it is not getting displayed. After doing some analysis, I came to know that the problem is due to the WinformMap control Refresh method. If I call WinformMap1.Refresh() together for all the layers i.e. after the button_click event not in the form_load then all the three layers are drawing on the Map at the same time. But if I call WinformMap1.Refresh() method individually after the form_load and button_click events then the third layer i.e. the WorldCapitals is not getting displayed on the map. And if I perform Pan operation on the map after clicking on the button, then the third layer is getting displayed. Kindly, help me in solving this problem. The below code helps you to understand my task and the code to Pan the map is commented( it is a workaround):-


  private void Form1_Load(object sender, EventArgs e)

        {

            winformsMap1.MapUnit = GeographyUnit.Meter;

            winformsMap1.CurrentExtent = new RectangleShape(-126.4, 48.8, -67.0, 19.0);


            string[] shapefiles = new string[] { @"C:\Program Files\ThinkGeo\Map Suite Desktop Evaluation Edition 3.0 (BETA)\Samples\SampleData\Data\Countries02.shp", @"C:\Program Files\ThinkGeo\Map Suite Desktop Evaluation Edition 3.0 (BETA)\Samples\SampleData\Data\MajorCities.shp" };


            AddShapeFileFeatureLayers(shapefiles);

  }

  

  private void button1_Click(object sender, EventArgs e)

        {

   string[] shapefiles = new string[] { @"C:\Program Files\ThinkGeo\Map Suite Desktop Evaluation Edition 3.0 (BETA)\Samples\SampleData\Data\WorldCapitals.shp" };


            AddShapeFileFeatureLayers(shapefiles);

  }

  

   private void AddShapeFileFeatureLayers(string[] shapeFilePaths)

        {

            // If the shapefile array paths has no elements, then return.

            if (shapeFilePaths.GetLength(0) <= 0) return;


            try

            {

                // Add all the shape files to the map.

                foreach (string shapeFile in shapeFilePaths)

                {

                    if (!System.IO.File.Exists(shapeFile))

                    {

                        continue;

                    }

                    ShapeFileFeatureLayer operationalLayer = new ShapeFileFeatureLayer(shapeFile);

                    

                    // TODO - check if the layer is point, line or polygon and then set the style.??

                    string name = System.IO.Path.GetFileNameWithoutExtension(shapeFile);

                    if (name.ToUpper()=="COUNTRIES02")

                        operationalLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle  = AreaStyles.Country1;

                    else if(name.ToUpper()=="MAJORCITIES")

                        operationalLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle  = PointStyles.City1;

                    else if (name.ToUpper() == "WORLDCAPITALS")

                        operationalLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.Capital1 ;

                    

                    operationalLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

                    operationalLayer.Name = System.IO.Path.GetFileNameWithoutExtension(shapeFile);

                  

                    LayerOverlay staticOverlay = new LayerOverlay();

                    staticOverlay.Layers.Add(System.IO.Path.GetFileNameWithoutExtension(shapeFile), operationalLayer);

                    winformsMap1.Overlays.Add(staticOverlay);                

                    

                }

            }

            catch (Exception ex)

            {

                string errMssg = ex.Message;

            }

            finally

            {

                winformsMap1.Refresh();

                //winformsMap1.Pan(PanDirection.Left, 1);

                //winformsMap1.Pan(PanDirection.Right, 1);

            }

        }



Hi Nitish,


your code is missing lock/unlock.


please try to add


staticOverlay.lock.enterwritelock() before the add

and staticOverlay.lock.exitwritelock() just after.

 


Patrick.



Yale, 
  
 It would be a good idea that MS raise an exception when the lock is missing (as you do when a open is missing), this would definitively help in maintenance. 
  
 Patrick.

Thanx Patrick…your code worked

Patrick thanks for your sharing and suggestions! 
  
 I will report your suggestions to my director (Dave)! 
  
 Any more questions just let me know. 
  
 Thanks. 
  
 Yale