Using the Callback control framework with a map resource
Let's build on the sample that Ryan put together and use the callback control framework to refresh a map control. In this case we need to send back callback results of the map control to the control being called back to (the callback button). To illustrate this lets add a map, map control, and a couple of Callback Button controls to the map design time in Microsoft's Visual Studio 2005. We want to give the user the ability to add and remove a dynamic dataset via the CallbackButtonCustomControl.
To do this we need a method that adds a dynamic resource to the MapResourceManagerInstance.
private void createAndAddResource(string
resourceName, GISResourceItemDefinition
definition, bool insertIntoBeginning)
{
MapResourceItem
resourceItem = new MapResourceItem();
resourceItem.Definition = definition;
resourceItem.Name = resourceName;
resourceItem.DisplaySettings = new ESRI.ArcGIS.ADF.Web.DisplaySettings();
resourceItem.DisplaySettings.Visible = true;
resourceItem.DisplaySettings.Transparency = 20;
resourceItem.DisplaySettings.DisplayInTableOfContents
= false;
resourceItem.DisplaySettings.ImageDescriptor.TransparentBackground = true;
resourceItem.DisplaySettings.ImageDescriptor.TransparentColor =
System.Drawing.Color.FromArgb(1, 2, 3);
if
(insertIntoBeginning)
{
Map1.MapResourceManagerInstance.ResourceItems.Insert(0, resourceItem);
}
else
{
Map1.MapResourceManagerInstance.ResourceItems.Add(resourceItem);
}
resourceItem.CreateResource();
Map1.InitializeFunctionalities();
}
Within the CallbackButton1_Clicked event we call the method to create and display the dynamic resource and then use the callback control framework to pass the CallbackResults from the map to the control.
string resourceName = "Dynamic Data";
GISResourceItemDefinition
definition = null;
definition = new
GISResourceItemDefinition();
definition.ResourceDefinition = "(default)@DGCountyAerialPhotos";
definition.DataSourceDefinition = "http://localhost/arcgis/services";
definition.DataSourceType = "ArcGIS Server Internet";
definition.DataSourceShared = true;
createAndAddResource(resourceName,
definition, false);
if
(Map1.ImageBlendingMode == ImageBlendingMode.WebTier)
{
Map1.Refresh();
}
else
{
Map1.RefreshResource(resourceName);
}
CallbackButton1.CallbackResults.CopyFrom(Map1.CallbackResults);
So now we can add dynamic data to a map on a callback.
Try the sample app out here: http://serverx.esri.com/callbackbuttonsample/map.aspx
Jeremy