ThinkGeo.com    |     Documentation    |     Premium Support

Layer not refresh

I have 2 button with following action:


(i) button A: Clear  internal features on InMemoryFeatureLayer. Then, add 3 new point on InMemoryFeatureLayer in Location A. After that, zoom to Location A by using InMemoryFeatureLayer.FeatureSource.GetBoundingBox().


(ii) button B: Clear  internal features on InMemoryFeatureLayer. Then, add 4 new point on InMemoryFeatureLayer in Location B. After that, zoom to Location B by using InMemoryFeatureLayer.FeatureSource.GetBoundingBox().


First, press the button A. The map show or zoom to location A with 3 points. After that, press button B, the map zoom at location B with 4 points. Then repeat press the button A,  the map show 3 points but the layer NOT Refresh. It still show the location B with 3 points? if i pan the map, the map will refresh to location A with 3 points.


May i know why this event happend?



Bv,


Thanks for your post!
 
Can you past the codes in this two button click events? It is probably you did not use the lock system correctly.
 
If you want to know more about the lock system, please take a look at the following video.
 
gis.thinkgeo.com/Support/Dis...fault.aspx
 
Let me know if you have any problems.
 
Thanks.
 
Yale

Hi Yale, below is my code: 
  
 private void button1_Click(object sender, EventArgs e) 
  { 
             RenderMap(1); 
             RectangleShape rectangle = this.ZoomToMarker(); 
             mapControl.CurrentExtent = rectangle.GetBoundingBox(); 
             mapControl.Refresh(); 
 } 
  
 private void button2_Click(object sender, EventArgs e) 
 { 
             RenderMap(2); 
             RectangleShape rectangle = this.ZoomToMarker(); 
             mapControl.CurrentExtent = rectangle.GetBoundingBox(); 
             mapControl.Refresh(); 
 } 
  
 public void RenderMap(int type) 
  { 
             //// Clear the Layer 
             InMemoryFeatureLayer inMemoryLayer = (InMemoryFeatureLayer)mapControl.FindFeatureLayer("MarkerLayer"); 
             mapControl.Overlays["MarkerOverlay"].Lock.EnterWriteLock(); 
             try 
             { 
                 inMemoryLayer.InternalFeatures.Clear(); 
             } 
             finally 
             { 
                mapControl.Overlays["MarkerOverlay"].Lock.ExitWriteLock(); 
             } 
             this.DrawSingleEquipmentLocationsOnMap(inMemoryLayer, type); 
  } 
  
  private void DrawSingleEquipmentLocationsOnMap(InMemoryFeatureLayer markerLayer, int type) 
  { 
             Overlay markerOverlay = mapControl.Overlays["MarkerOverlay"]; 
             markerOverlay.Lock.EnterWriteLock(); 
             try 
             { 
                 List<Feature> features = new List<Feature>(); 
                 // The "ID" Column for these feature are "Truck1" and "Truck2"  
                 if (type == 1) 
                 { 
                     features.Add(new Feature(118.08696, 5.860553, "feature4", new string[] { "ID:Truck1" })); 
                     features.Add(new Feature(118.08520, 5.834, "feature5", new string[] { "ID:Truck2" })); 
                 } 
                 else 
                 { 
                     features.Add(new Feature(118.07896, 5.860553, "feature4", new string[] { "ID:Truck1" })); 
                     features.Add(new Feature(118.08300, 5.832, "feature5", new string[] { "ID:Truck2" })); 
                     features.Add(new Feature(118.08200, 5.801, "feature5", new string[] { "ID:Truck3" })); 
                 } 
                 foreach (Feature f in features) 
                 { 
                     markerLayer.InternalFeatures.Add(f); 
                 } 
             } 
             finally 
             { 
                 // Release the lock on the overlay 
                 markerOverlay.Lock.ExitWriteLock(); 
             } 
         } 
  
 public RectangleShape ZoomToMarker(string featureId, bool allMarkers) 
         { 
             InMemoryFeatureLayer inMemoryLayer = (InMemoryFeatureLayer)mapControl.FindFeatureLayer("MarkerLayer"); 
             RectangleShape rectangle = null; 
             Overlay markerOverlay = mapControl.Overlays["MarkerOverlay"]; 
             try 
             { 
                 inMemoryLayer.FeatureSource.Open(); 
                 rectangle = inMemoryLayer.FeatureSource.GetBoundingBox(); 
                 inMemoryLayer.FeatureSource.Close(); 
             } 
             finally 
             { 
             } 
             return rectangle; 
         }

bv,


Thank you for your sharing code.
 
We made a sample based on your code and full tested it, it works fine both in latest version and RC 3.0.307. Attachments contain some screenshots for different button click as well as the sample we used.
 
Let me know if you have problems with the sample attached, I guess you are using the version 3.0.307 RC.
 
Thanks.
 
Sun

902-Post5983.zip (10.5 KB)
907-Post_5983_ScreenShot.zip (64.7 KB)

Hi,


I have shape file as my background image in map. Location for each point render from Location A and Location B is correct.


The problem is the background image not render properly. When i repeat the same step for location A to location B and back to location A, the shape file layer not render properly. For example, When i press location B, all the point render correct, but the background shape file still maintance in background A in location A. If i drag or move my image, then the background will refresh to background B in location B. Can anybody help me why my background map not refresh properly?


As i noticed, after success render the map in button 1 or button 2, if i drag or move the map, it will doing a refresh on map and seen like clear all my point and redraw. But if i drag or move the map again, then i dont see any resfresh on the map like clear all the point and redraw. may i know this is the behaviour of the map?


 



bv,


About the background image not render properly problem, this is a known issue for the latest public release version 3.0.307. We have solved this problem in the latest version and you can use it when the next public release.
 
About your second question, this behavior is normal for the WnformsMap control. We have a local cache system build in the map control, and it will be cleared if you call redraw on the map. So the local cache will be generated again when you drag the map after redraw it. Then if you drag and move the map again, the map will just use the local cache and needs not to redraw.
 
Let me know if you have more problems.
 
Thanks.
 
Sun