Abstract Final - Rendezvous with Keyur Shah

Abstract Final - Rendezvous with Keyur Shah

All XML General XML Java XML ESRI XML
« ArcGIS Server 9.2 (Java): Comi... | Weblog | Inversion of Control in the Ar... »

20050802 Tuesday August 02, 2005

Adding layers dynamically in the ArcGIS Java ADFCategory: ESRI

There have been many questions about adding layers dynamically in the ADF... And of course the requirement is that the added layer will reflect not only on the map but also on the TOC, layer drop downs, etc...

When working with non-pooled objects, there's a straightforward way of doing this. Look at the source code below:

AGSWebContext agsCtx = ...; //get hold of the AGSWebContext
AGSWebMap agsMap = (AGSWebMap)agsCtx.getWebMap();

//Step 1
agsCtx.applyDescriptions();

//Step 2
MapServer mapso = new MapServer(agsCtx.getServer());
IMap map = mapso.getMap(agsMap.getFocusMapName());
ILayer layer = ...; //create the layer
map.addLayer(layer);

//Step 3
agsCtx.reloadDescriptions();

Let's discuss the 3 steps now:

And that's about it! This sequence of steps holds true for any stateful changes that you want to make to non-pooled objects. The 3-word mantra is APPLY-CHANGE-RELOAD.

If you wanted to work with dynamic layers (or make any stateful changes) in the pooled context, there's indeed more work to do because you are now sharing the server object with others and you want to return the object back to the pool in the same state that you had received it. You need to get access to the server object, apply the current MapDescriptions to the object graph, make the changes to the object graph, reflect the changes in the MapDescriptions and the web controls, undo the changes to the graph and then return the object back to the pool. You can check out the dynamic layers sample on EDN to see this use case in action.

( Aug 02 2005, 08:52:53 PM PDT ) Permalink Comments [3]

Trackback URL: http://jroller.com/trackback/javanoid/Weblog/adding_layers_in_the_arcgis
Comments:

[Trackback] Link - Adding layers dynamically in the ArcGIS Java ADF Keyur's latest blog post is the perfect example for ESRI bloggers to follow. You don't have to worry about posting tidbits of the lasted secret ArcExplorer features, just post like...

Posted by Spatially Adjusted - Blog about ESRI and GIS on August 02, 2005 at 10:14 PM PDT
Website: http://www.spatiallyadjusted.com/2005/08/keyur_shah__pos.html #

[Trackback] Prodded by Keyur’s excellent post, and Jame’s nice kudos for Keyur, I am going to start posting more code examples. Most of my examples will actually be showing ArcObjects since this is the part I am focusing on for the next couple of week...

Posted by My Own Little World on August 03, 2005 at 12:21 PM PDT
Website: http://www.molw.org/blog/?p=94 #

Hello

I've done same as you told for adding layer dynamically. I'm able to add the layer successfully(I'm able to see that from map.getlayercount()). But even after calling agscxt.reloaddescriptions() ..the new layer is not reflecting in the mapviewer and TOC in JSP page. Please let me know what I'm doing wrong..

my-email aditya.tadakaluru-AT-gmail-DOT-com

thanks
Regards
dutch

Posted by aditya on March 11, 2006 at 09:00 PM PST #

Post a Comment:

Name:
E-Mail:
URL:

Your Comment:

HTML Syntax: On

Please answer this simple math question

5 + 13 =