I have a MapActionFilter where i updated one layer’s styling such fill colors dynamically, then called staticOverlay.Redraw(). THis function will update the polygon.
I did update my legend adornment layer’s colors because if i manually pan/zoom the map and force redraw everything and the legend was updated.
How can i update the legend layer automatically by codes?
Could not find any redraw on map.adornmentlayer, or any legendlayer.
Help!
How to programmatically update legend layer (or adornment layer)?
Guangming,
In the ajax callback, please try the blow codes to redrew the Lagendlayer:
Map1.getOpenLayersMap().getLayer("AdornmentOverlayID").redraw(true);
Hope it helps.
Regards,
Troy
that does not work!
Also weird: the main map did not change accordingly unless i zoomed to different scales. Even worse, when i zoomed back to the previous scale, the tiles were not updated.
How can i force map to reload all tiles in this case because i change the styling settings of spatial features?
Thanks,
Hi Guangming,
Sorry to say it proves a bug in AdornmentLayer, but here is a workaround to make the refresh work:
controller side, :
public
ActionResult DisplayASimpleMap()
{
…
map.AdornmentOverlay.Layers.Add(legendLayer);
return
View(map);
}
[MapActionFilter]
public
void
ClickEvent(Map map, GeoCollection<
object
> args)
{
LegendAdornmentLayer legendLayer = map.AdornmentOverlay.Layers[0]
as
LegendAdornmentLayer;
legendLayer.LegendItems[0].TextStyle =
new
TextStyle(
“Borders”
,
new
GeoFont(
“Arial”
, 10),
new
GeoSolidBrush(GeoColor.SimpleColors.Blue));
}
Client side:
function
ChangeColor() {
Map1.ajaxCallAction(
’@ViewContext.RouteData.Values[“Controller”].ToString()’
,
‘ClickEvent’
, {}, mapCallback);
}
function
mapCallback(result) {
Map1.getOpenLayersMap().pan(0, 0.1);
Map1.redrawLayer(
‘AdornmentOverlay’
);
}
There are several codes you may notice:
1. we are using the default AdornmentOverlay in the map.
2. we need to pan a little to make the redraw work before we find a way to fix this bug.
3. The default AdornmentOverlay key named “AdornmentOverlay”, which is a hard code.
One more thing is I can’t recreate the problem that the map uses the previous legend tiles after we zoom back. would you please clear the cache and then have a try? or may be there is anything i missed.
Hope it helps.
Thanks,
Troy
this works for both:
Map1.getOpenLayersMap().pan(0, 0.1);
Map1.redrawLayer(“StaticOverlay”);
Map1.redrawLayer(‘AdornmentOverlay’);
guangming,
Good to hear it works for you.
Any question, don’t hesitate to let us know.
Thanks,
Troy