Select to view content in your preferred language

Want dynamic map service layer to appear in layer list widget

2721
7
02-20-2013 06:45 AM
SteveFudge
Emerging Contributor
I'm using Flex Viewer 3.0, and have built a geoprocessing service widget that invokes a geoprocessing service which in turn creates a map service on our server.  The output from the geoprocessing service is the REST url of the map service.  The widget takes the returned url string and adds the dynamic map service layer to the flex viewer map.  This part all works fine.  What I would like to have happen is that new dynamic map layer appear in the toc of the layerlist widget.  Right now it's not showing up.  I'm pretty much of a newbie when it comes to actionscript programming, so I don't know how this is to work.  As best I can tell the layerlist widget is being driven by it's config xml file which currently has no operational layers listed.  How do you get a layer to appear in the toc of the layerlist widget when that layer was added to the map via another widget?  Thanks.
Tags (2)
0 Kudos
7 Replies
DougBrowning
MVP Esteemed Contributor
This works for MapSwitcher and may work for layer list also.  After the map is for sure added run this command toc.validateNow();

If that does not work I did this in another part to force MapSwitcher to be rebuilt
toc.includeLayers.addItem("dummy");
toc.includeLayers.removeItemAt(toc.includeLayers.getItemIndex("dummy"));

You could probably kick off a COLLECTION_CHANGE event i think it is but seem harder to figure out.
0 Kudos
SteveFudge
Emerging Contributor
Thanks Doug.  As I said, I really don't know much about Flex programming.  I don't quite understand how to implement your idea.  Does this command go into my geoprocessing widget or is it in the LayerList widget?  In my case, I open my gp widget, click a submit button, and then the output window in the widget will display the returned rest url.  At the same time, the dynamic map service layer has been added on top of the base map in the flex viewer.  I close my gp widget and open the layerlist widget, but no layers are there.  In my case, I don't have any operational layers pre-defined in the flex viewer so mapswitcher isn't showing up either.

Thanks for you help.
0 Kudos
DougBrowning
MVP Esteemed Contributor
Yes there is code in there to hide MapSwitcher if there are no op layers specified.  I edited that line out.  I can tell you where it is but now I am not sure if you are editing the code at all in Flash builder?

If you can it is in MapSwitcherWidget.mxml in the initTOC function.  The line to comment out is opLayersButton.visible = tocLayers.length ? true : false;


After rereading your post my option in my other post may not work since it is based on the maps being all loaded but then not displayed by setting toc.includelayers = [].  But you say it is displaying so it must be adding it but not adding it to the toc for some reason.  If you are editing the code you could try my post by putting the code at the end of the geoprocessing widget you made.  But I do not have high hopes it will work.  Adding it to toc.includedlayers may also worth a try.

Sorry I am new also so that is all i know.
0 Kudos
GISDev1
Deactivated User
have built a geoprocessing service widget that invokes a geoprocessing service which in turn creates a map service on our server.  The output from the geoprocessing service is the REST url of the map service.  The widget takes the returned url string and adds the dynamic map service layer to the flex viewer map.  This part all works fine. 


This is pretty cool. Can you share the code or general ideas/workflow used to make this work?
0 Kudos
SteveFudge
Emerging Contributor
Sorry it took me so long to respond.  The basic idea of the custom widget is to: 1) accept user input that the geoprocessing service needs; 2) send user input to the server and the geoprocessing service; 3) accept back the output of the geoprocessing service which is the rest url of the map service that the geoprocessing service created; 4) display the dynamic map service layer on top of the flex viewer base map.  The custom widget was built by slightly modifying the basic flex viewer geoprocessing widget.  I've attached the source code.  As I said, I really don't know what I'm doing when it comes to programming in actionscript so this has all been a work in progress.
0 Kudos
DougBrowning
MVP Esteemed Contributor
I see you are adding the layer to the map using map.addLayer( which is good.  I think that the toc is never getting this change.

Right after each map.addLayer( in your code first try adding the line toc.validateNow();.  My guess is no.

Next try rerunning the init of the layer list widget so it reloads it.  You might be able to just use the toc.map = map line but that may mess some stuff up. 

(Would also need the functions that go in here like getExludeLayers.  Or kick an even off over to layer list that runs initTOC again on a change.  If you need help with kicking an event it is actually something i can do.)

In LayerListWidget.mxml
           private function initTOC(expandLayerItems:Boolean = false):void
            {
                toc.map = map;
                toc.isMapServiceOnly = false; //gotta get this from the config file
                toc.excludeLayers = getExcludeLayers();
                toc.basemapLayers = getBasemapLayers();
                toc.excludeGraphicsLayers = true;
                if (expandLayerItems)
                {
                    toc.expandLayerItems();
                }
            }
0 Kudos
SteveFudge
Emerging Contributor
Thank you Doug.  I'll see what I can do with your ideas and post back here.
0 Kudos