ThinkGeo.com    |     Documentation    |     Premium Support

Redrawing only specified overlays via javascript

Greetings,


I've gone through all the forum posts about refreshing layers/markers using javascript, and it has been very helpful.  I have a map which has FeatureLayers on it, which is being populated froma database.  By creating a timer and placing it in an update panel, and by putting the map control in an update panel, I have been able to have the map refresh its data from the database.


My question is this:  each time I call redraw in the javascript code on a certain layer, the entire map redraws tile by tile, including the base layers in other overlays.  Is this the correct behavior or am I doing something wrong?  What I would like to happen is for the base layer to stay and have only the layers or overlays I specified redraw, making it less noticable to the user that anything is happening.


Any help or insight would be appreciated.  Thank you very much for your time and help.


 


Ryan






 


Ryan,


I'm not very sure about your scenario, as you need to refresh map's data from database, I think you will refresh the map on server side. So I'm a bit confused when you mentioned redrawing the map on client side with javascript. Can you let me know more about your scenario?


Anyway, here is a sample showing how to refresh a specific overlay on client side using javascript.


Thanks,


Ben 


 




531-Post5469.zip (95.2 KB)

I’m sorry, let me give you more detail.  I have data in a database which I have displayed on the map, which is achieved by creating m own layer extending from FeatureLayer.  This data can be updated by other sources, and those changes should be seen on the map.  What I have done so far is put a Timer in a UpdatePanel and put my Map on another UpdatePanel.  On the Timer.Tick event, I call overlay.Redraw() and then invoke some javascript using ScriptManager.RegisterStartupScript.  Within that javascript, I get the layer and call redraw(true) on it.  This works in that it causes the map to be refreshed with all the changes made in the database being shown. 
  
 However, what happens is on the refresh, it appears that all layers are being redrawn.  I’m not sure if this is actually the case, but on refresh, the map goes the background color (blue for water), and each tile is then drawn on top of it.  What I would like to happen (if it is possible), is for my base layers to redraw, but only for the overlay containing my database data to appear to redraw.  As I have it now, every 30 seconds it looks like my map blinks because all the overlays appear to be redrawing rather than just the overlay I specify.  I’d like the map to not blink if possible. 
  
 I hope that I have better explained myself.  Thank you for your time and help. 
  
 -Ryan-




 


Ryan,


I think you can put the Server side Timer to Update Panel and do NOT put the map in an update panel. In Timer.Tick event, we update the data of the feature layer. But as we didn't redraw the map, nothing visually changed. On client side, we redraw the overlay every 30 seconds, as the data has been updated by the server side Timer, changes will take affect on map when we redraw on client.


Please take the demo (Post5469.zip in my last message) for example. “Change Renderer” is a ASP.NET button and it is in an Update Panel. Map is not within an UP and the “Refresh DynamicOverlay Only” is a client side button. After clicking “Change Render”, new feature is added but as we didn't redraw the map, nothing changed. Then we click the client side button “Refresh DynamicOverlay Only”, as the Overlay redraws, the added feature takes effects on the map.



In this way, the map should not blink any more :) Have a try and let us know what you find out.


Thanks,


Ben




Thank you for your help.  I figured out that my issue was that when I called olMap.getLayer(…), I was passing in the name of the layer I wanted to refresh rather than passing in was the name of the overlay I wanted to refresh.

That’s great, let me know if you have more issues.