Zooming to task results automatically

In this post, Tom Brenneman and Rex Hansen share a control they created that allows you to automatically zoom to the results of a .Net Web ADF task.

Magnifying glassThis control, called ZoomToResults, enables you to automatically zoom to the result set returned from a task instead of requiring you to navigate through tree-view results in a standard TaskResults control. By default, this control is not visible at runtime. It is designed to simply zoom to the result set in the map if the number of features returned is less than the MaxResultsForMapZoom property. You will need to add this control to a task’s TaskResultsContainers collection to take advantage of these features. Note that this control must be listed before any other container in the collection (e.g. an out-of-the-box TaskResults control). This control was built with version 9.2, Service Pack 3 of the .Net Web ADF.

Follow these steps to use the control in your application.

  1. In Visual Studio, right click in the Toolbox and click Choose Items.
  2. Click Browse and navigate to ZoomToResults.dll and click OK.
  3. Drag the ZoomToResults control onto your web page.
  4. Set the following properties for ZoomToResults control:

    MaxResultsForAutoSelect – this is the maximum result set that will be selected. The results will only be selected if a result set contains this value or less. Set this property to 0 to disable the auto selection capability.

    MaxResultsForMapZoom – this is the maximum result set that will be zoomed to. The map will only be zoomed to the result set if it is less than or equal to this value. Set this property to 0 to disable the auto zoom capability.

    MinWidthOfZoom – this is the minimum width (or height actually) in map units of the extent rectangle that will be zoomed to. This is particularly useful if the result set is a single point or a very small feature. In this case you could set the minimum extent that the map will zoom to. If you are working with geographic data you may want to make this significantly smaller than the default of 10.

    ZoomExtentExpansionPercent – this is the expansion percentage around the extent of the result set for the map to zoom to. This is useful for defining a margin around the extent of features returned in a result set.

    DisplayTaskResult – display task results like an out-of-the-box TaskResults control. By default, this property is false.

    ShowTaskActivityIndicator – display activity indicator when a task is processing, like an out-of-the-box TaskResults control. By default, this property is false.

  5. To associate this container with a task, at design-time in design view click on the smart tag on the task and select Choose Task Results container.
  6. Click Add. Set the Name property of the new BuddyControl to the name of the ZoomToResult control (e.g. ZoomtoResults1).
  7. In the BuddyControl Collection Editor click the up arrow to move the ZoomToResults buddy control to the top of the list.
  8. Click OK to dismiss the BuddyControl Collection Editor.
  9. Try out the app!

Download the 9.2 control (The compressed folder contains the code with extensive comments from Tom and Rex, as well as a Readme file with the above instructions.)

Updated download for ArcGIS Server 9.3

Download the 9.3 control

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

Leave a Reply

27 Comments

  1. sterlingdq says:

    Riyazuddin-

    Not sure what the issue is here, but you may have better luck with this question on the ArcGIS Explorer Forums http://forums.esri.com/forums.asp?c=184 or the ArcGIS Explorer Blog http://blogs.esri.com/Info/blogs/arcgisexplorerblog/

  2. royjackson says:

    Does anyone know of any documentation that can be used to help me create context menus for the task results?

    With the out of the box tasks, you get built in functionality where you can right click on a result and get a menu where you can zoom to/pan to a result, remove a result…

    The OOB Find task didnt work for my customer because they wanted some different functionality, with search criteria being dynamically added/removed to the search panel UI with callbacks… Also customized HTML results, not just the standard table. Got the UI working, trying to give them the functionality they want for the results…

    Reading This Article…

    ,and it seems after trying a couple methods that with a taskresultnode, you dont get any automatic context menus. With a dataset, you get the context menu to remove the result, but no panning/zooming tools.

    How would I go about adding the rightclick context menus for panning/zooming etc? If I can at least get the menu setup I can figure out the callback js and server functions…

    Appreciate any help I can get on this…

    Thx!

  3. royjackson says:

    How would someone use this sample with a custom task? What data has to be contained within the taskresult dataset for it to work properly?

    Thx!

  4. rexhansen says:

    The ZoomToResults control expects the Results property of a custom task to be either a System.Data.Dataset that contains DataTables of type ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicsLayer

    -or-

    a ESRI.ArcGIS.ADF.Web.UI.WebControls.GraphicsLayerNode.

    Thanks,
    -Rex

  5. rexhansen says:

    Hi Roy,

    The only SDK doc that demonstrates the use of ContextMenus is the Common_AddDynamicData sample where a ContextMenu is configured on a Map:

    http://edndoc.esri.com/arcobjects/9.2/NET_Server_Doc/developer/samples/Web_Applications/Common_AddDynamicData/f80sedfd-ac48-4c81-ba00-5a17e1b09c4b.htm

    A full discussion of the ContextMenu control and its usage will be provided in 9.2 sp4 and 9.3. I’ll write up a blog post on this topic shortly – so look for it coming soon.

    Thanks,
    -Rex

  6. tbrenneman@esri.com says:

    Could it be that this web application was created with an earlier version of the Web ADF? If so, you may need to update your assembly references in that web application. Do you get the same results when you try it with a new web application? –Tom

  7. royjackson says:

    Rex-

    Havent changed anything with the class library project…. Ill check the Register tag this evening and get back to you. If it isnt added automatically, I doubt it is in there.

    Thanks!

  8. japete02 says:

    Thanks for the post and the control. Will this zoom to a feature returned by a geoprocessing task or is that beyond its intentions? I have a simple geoprocessing task that returns a buffer feature and would like apply this zoom control so that the viewer is zoomed to the feature that is returned in the results area and displayed on the map. It was set up in ArcMap and published as suggested in the samples with the only modification happening to the model itself…I have tried the suggested implementation above with no luck (it works great for my geocoding service though!). Thanks for any suggestions.

  9. ksgizmo says:

    Thanks for the control. It’s been working great, but now I have users wanting to see a different marker symbol used for the selection graphic. They don’t like the pushpin. I assume that can be done by extending the control similar to the zooming, but I’m at a loss as to where that would be. I hope it isn’t something trivial that I’ve just overlooked. Thanks

  10. esrijay says:

    Got it, I forgot to register the .dll in th GAC. It’s Friday. NICE TOOL. Thanks

  11. svaddadi says:

    This control is not working with PS4. Giving a object reference not set to instance of an object error.

  12. tesladaman says:

    First of all, thank you for a very useful tool, easy to install, good instructions.

    I am having a problem though. When I use it, it works like a charm, zooming to the property queried, but nothing but the highlight of the selection and my roads layer is showing up (aerials for example). All my services are cached, and I think it is zooming to the extent that is “between” caches’ specified extents. How can I limit this tool to zoom in only to zoom levels specified by cache scale levels? Thank you for help.

  13. KingNothing says:

    Hi.

    1. Im using search attributes task to find some data.
    2. The data shows in a grid result (includes a check box for make a ZOOM to feature)
    3. I need when the web page loads recive a parameter maybe in a
    REQUEST.QUERYSTRING["parameter"]; and it makes an autoZOOM to the feature, instead using the procedures shown above (SearchAttributesTask, or the gridresults checkbox).

    How can i do this automatic…?
    Where do i have to pass the parameter, or wich function may recive the parameter to process the autoZOOM?

    thanks.

    Jose

  14. hazelton_glenn says:

    thanks for the response. i am afraid i dont see the system.web.extensions. when i type into VS2008 the .web shows up the dropdown list for system but when i type the ‘.’ after web i dont not see ‘extensions’ in the list.

  15. hazelton_glenn says:

    HI AGAIN,
    sorry to be a pain.
    i did figure out how to open the zoom project.
    i did figure out how to add the reference. i rebuilt the project.
    dropped the old .dll in the VS2008 toolbox, and added the new one (seems to have saved in the objdebug directory.
    sadly it still doesnt work.
    if you can get it to work let me know. thanks.

  16. hazelton_glenn says:

    maybe i missed something but the download zip file doesnt contain a .dll file.

  17. sterlingdq says:

    The 9.3 download has been updated to include a dll

    -Sterling

  18. hazelton_glenn says:

    Q714: the smart tags are in your query task. you add the zoomto as a results container.
    hope that helps.

    Sterling–
    thanks for posting the dll. i have to report that it still doesnt zoom to. i have attached it as results container to a geocoding tool.
    the address is found, and it does zoomto automatically THE SECOND time. i also notice that the ‘clear all’ in the resultstask is not listed the first time but it is the second. ideas?

  19. hazelton_glenn says:

    one more note for today. the zoomto tool is working with address finder every time. with the queryfind it will only work AFTER the addressfind has been run (or the zoomto feature on a query result). something must get loaded and once the zoom is loaded it will run. way beyond me to understand what is happening. would be nice to get a fix.

  20. xyzgis1 says:

    After following the steps, the application returns the error below:

    Application Error

    Page_Error
    Object reference not set to an instance of an object.

    at CustomControls.ZoomToResults.processDataTable(Boolean doSelect, Boolean doZoom, DataTable dt, Envelope& pEnv) in C:InetpubwwwrootZoomToResultsZoomToResults.cs:line 394 at …….

    It worked for a while when I was runing 9.2 version of the control. I am runing ArcGIS Server 9.3 and just installed 9.3 version of this control.

  21. azatrain says:

    My users love this tool, but we have a need to set the map to a specified scale on a zoom. I have it working fine, but it is essentially zooming to 2 map extents every time. One that this control creates and then the extent that we end up at when the map is set to the zoom scale. So now when I zoom previous I get that extra extent in there. I think the default code doesn’t do this because it takes an envelope and expands it by a certain percentage so the map extent doesn’t change twice. Whereas I am taking the map extent from this tool and setting it to a specified scale. Is there any way I can force the map extent to a certain scale using this tool, but only have the map extent change once? Thanks in advance for any help …

  22. azatrain says:

    Let me explain this another way. I need to tie into the context menu’s ItemClicked event. The way I currently have it set up, it seems like I’ve added a new ItemClicked event, which always runs after the context menu’s real ItemClicked event. That’s why I’m getting two extents generated for each ZoomTo request. So how can I get access to that original ItemClicked event for the context menu? I can attach some code to show what I’m currently doing if necessary.

  23. rexhansen says:

    Hi Andy,

    Try calling Refresh on the ZoomToResults control after an explicit call to DisplayResults in the base class (TaskResults). Add the lines in the following code block to the appropriate location in the ZoomToResults ITaskResultsContainer.DisplayResults implementation (the “if” statement is already there):

    if (DisplayTaskResults)
    {
    Nodes.Clear();

    base.DisplayResults(task, taskJobID, taskInputs, taskResults);

    this.Refresh();
    }

    -Rex

  24. rexhansen says:

    Another note: if you want to remove both the node and the graphics layer associated with the node, you’ll need to do a little more work. Here’s an update to the “if” statement above, and two additional methods you’ll need to add:

    if (DisplayTaskResults)
    {
    foreach (TreeViewPlusNode node in Nodes)
    {
    removeResultsFromMap(node);
    }

    Nodes.Clear();

    base.DisplayResults(task, taskJobID, taskInputs, taskResults);

    this.Refresh();
    }

    private void removeResultsFromMap(TreeViewPlusNode treeViewPlusNode)
    {
    if (this.MapInstance == null) return;

    List resourcesToRefresh = new List();
    removeResultsFromMapRecursive(treeViewPlusNode, ref resourcesToRefresh);

    foreach (string resource in resourcesToRefresh)
    {
    this.MapInstance.RefreshResource(resource);
    }

    }

    private void removeResultsFromMapRecursive(TreeViewPlusNode node, ref List resources)
    {
    string resultItem = null;

    if (node is MapDisplayNode)
    {
    MapDisplayNode mapNode = node as MapDisplayNode;
    resultItem = mapNode.RemoveFromMap(this);
    if (resultItem != null && !resources.Contains(resultItem))
    resources.Add(resultItem);
    }

    if (node.Nodes.Count > 0)
    {
    foreach (TreeViewPlusNode childNode in node.Nodes)
    {
    removeResultsFromMapRecursive(childNode, ref resources);
    }
    }
    }

  25. TJBNC says:

    I have tried to add this control to a website (Web Mapping Application template), and am getting the same error reported by another user (Noran Badawi) in November 2007 for 9.2: “An unhandled exception has occurred: There was an error in callback.”

    Any reasons for this behavior? What should I be looking at?

    Thank you.

    TJ

  26. SteveAdams says:

    I have it up and working great. The only problem is that it zooms in too close. I have to use the zoom out a few times to see anything around. I have tried changing a number of the settings and nothing seems to make a difference.

  27. tbrenneman@esri.com says:

    Some of the issues discussed above with regard to this control not working correctly with cached map services and zooming on the second set of results have been fixed with a 9.3.1 version of the control. It is available on the resource center code gallery here: http://resources.esri.com/arcgisserver/adf/dotnet/index.cfm?fa=codeGalleryDetails&scriptID=16660