Friday, February 8, 2008

Using a ScaleDependentRenderer in a FeatureGraphicsLayer?

I was looking for a relationship between the classes FeatureGraphicsLayer and ScaleDependentRenderer. I could not find it in the EDN website. This is why I was looking for this: say you have a FeatureGraphicsLayer in which you want to draw features using a ValueMapRenderer. This is all OK since a ValueMapRenderer is "type of" IRenderer which is used by the FeatureGraphicsLayer.

However, what if you want to draw those features with a height/width that changes according to the scale? There is no IScaleDependentRenderer in the WebADF API. Philip Thompson posted a suggestion here:

http://forums.esri.com/Thread.asp?c=158&f=2276&t=245890#751096

Basically, we can extend his code snippet to set the Renderer on-the-fly everytime the ScaleChanged() method of the class Map is triggered. In this case, the Renderer will be set according to the scale. Thanks Philip!

protected void Map1_ScaleChanged(object sender, ESRI.ArcGIS.ADF.Web.UI.WebControls.ScaleEventArgs args)
{
if (args.NewScale > 4000)
{
foreach (MapResourceItem item1 in this.MapResourceManager1.ResourceItems)
{
if (item1.Definition.DataSourceType == "GraphicsLayer")
{
item1.DisplaySettings.Visible = false;
// OR RESET THE RENDERER AS WELL
}
}
}
if (args.NewScale < 4000)
{
foreach (MapResourceItem item1 in this.MapResourceManager1.ResourceItems)
{
if (item1.Definition.DataSourceType == "GraphicsLayer")
{
item1.DisplaySettings.Visible = true;
}
}
}
}

No comments: