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 

This entry was posted in Services and tagged , . Bookmark the permalink.

Leave a Reply

2 Comments

  1. Bryan Baker says:

    The CallbackResult class is part of the Web ADF. It builds on the client callback framework that is part of ASP.NET 2.0. It makes transferring information between server and browser easier.

    The WebControl abstract class, in the ESRI.ArcGIS.Web.UI.WebControls assembly, extends the ASP.NET WebControl class by adding the CallbackResults property. So any control that extends the Web ADF’s WebControl can take advantage of the CallbackResults to send data.

  2. karimhamdy says:

    This method works fine with the map control only if i made a sipmle proccessing at the server ,but if i made something which takes time (5 sec) or i made a big change to the map sometimes it dosen’t work.
    my case is generating a service area which takes about 3 or 4 sec but most probably it dosen’t work “no change in the map unless i made any action on it like zomming ”