Welcome to ESRI Blogs

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 

Published Monday, December 18, 2006 3:51 PM by Jeremy
Filed under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Using the Callback control framework with a map resource

please where i can find callback control framework ?
Tuesday, December 26, 2006 2:29 AM by Mohamed Moustafa

# re: Using the Callback control framework with a map resource

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.

Wednesday, December 27, 2006 11:01 AM by

# re: Using the Callback control framework with a map resource

This method works fine against the map control, but against other controls, it doesn't work. For instance, the scalebar control, lets say you update the units from miles to kilometers in code. That doesn't produce item in the callbacklist on the scalebar, so there is no way of causing it to redraw without having something happen to the map (such as zoom in in, which does cause a item to be added to the scalebars callbackresults list). Perhaps I am wrong, but I would think that updating the units would then create a call back result because the scalebar would need to be redrawn. Code: protected void CallbackButton1_Clicked(object sender, EventArgs args) { ScaleBar1.BarUnits = ScaleBarUnits.Kilometers; ScaleBar1.BarColor = System.Drawing.Color.BlueViolet; ScaleBar1.BarHeight = 50; ScaleBar1.Refresh(); CallbackButton1.CallbackResults.CopyFrom(ScaleBar1.CallbackResults); //doesn't do anything, no call back result on scalebar. }
Monday, January 08, 2007 6:37 AM by David Jones

# re: Using the Callback control framework with a map resource

That is a good find. We have logged a bug for this problem in the ScaleBar.Refresh() method. There are 2 things you need to do to work around this problem. First of all, you need to call InitializeFunctionalities() on the Map control you are working with. This is because the ScaleBar.Refresh() checks to see if there are functionalities associated with the map and it assumes they will be initialized first. This will allow the scalebar image to refresh in a callback. The second thing you should do to workaround the background color is use a similar method for refreshing a control’s html when working with non-ADF controls. 

Here is such a method:

 

    private CallbackResult RefreshControlHtml(Control control)

    {
        System.IO.StringWriter sw = new System.IO.StringWriter();
        HtmlTextWriter writer = new HtmlTextWriter(sw);

        control.RenderControl(writer);

        string htmlContent = sw.ToString();

        sw.Close();

        return new CallbackResult(control, "content", htmlContent);

    }

 
You should add this result to the callback results of your ScaleBar. Note, you can use the RefreshControlHtml function with many different controls, like GridView, etc. Your code will end up looking something like this:

 
    protected void CallbackButton1_Clicked(object sender, EventArgs args)

    {

        Map1.InitializeFunctionalities();

        ScaleBar1.BackColor = System.Drawing.Color.Lime;

        ScaleBar1.BarUnits = ESRI.ArcGIS.ADF.Web.ScaleBarUnits.Feet;

        // the following line is necessary to change the back color because that is not part of the image

 CallbackButton1.CallbackResults.Add(RefreshControlHtml(ScaleBar1));

       ScaleBar1.Refresh();

      CallbackButton1.CallbackResults.CopyFrom(ScaleBar1.CallbackResults);

    }

 

    private CallbackResult RefreshControlHtml(Control control)

    {

        System.IO.StringWriter sw = new System.IO.StringWriter();

        HtmlTextWriter writer = new HtmlTextWriter(sw);

        control.RenderControl(writer);

        string htmlContent = sw.ToString();

        sw.Close();

        return new CallbackResult(control, "content", htmlContent);

    }

Monday, January 08, 2007 11:34 AM by Ryan Olson

# re: Using the Callback control framework with a map resource

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 "    

Wednesday, January 10, 2007 12:53 AM by karimHamdy

Leave a Comment

(required) 
required 
(required)