Select to view content in your preferred language

Can the config file be changed dynamically?

536
4
10-17-2013 01:23 PM
BartPosselt
Emerging Contributor
I want to change the config file that gets loaded depending on a user's action. My Flex application has a master view with a large map that has several widgets. I want a details view popup to include the same map, but smaller, zoomed in, and with a different config that removes all the widgets.

I've seen a handful of similar posts like http://forums.arcgis.com/threads/42344-How-do-I-manage-multiple-flex-sites?highlight=multiple+config... and http://forums.arcgis.com/threads/23260-Very-basic-Flex-Veiwer-question.?highlight=multiple+config+fi... but those deal with passing the config file name in a URL parameter. My Flex application includes the ViewerContainer in two different Spark Panels, one in the main application and a second in a TitleWindow.

I'd like to pass in the name of the config file to use depending on which view is presented. Is that possible, or is there a different way I should approach this? I'm using Flex Viewer 3.5.
Tags (2)
0 Kudos
4 Replies
YohanBienvenue
Frequent Contributor
The name of the config file used is set in com.esri.viewer.ViewerContainer.mxml in the setConfigFile function:

private function setConfigFile():void
{
    //retrieve FlashVars.
    var flashvarConfig:String = FlexGlobals.topLevelApplication.parameters.config;
    if (flashvarConfig)
    {
        configFile = flashvarConfig;
    }

    //retrieve config from URL and override FlashVar
    if (urlConfigParams.config)
    {
       configFile = urlConfigParams.config;
    }
}


If you don't pass a config parameter in the URL then flashvarConfig is used, which represents config.xml

You can change things in this function.
For example here's my own setConfigFile function where I've added a section to get the config from a Cookie.

private function setConfigFile():void
{
    //retrieve FlashVars.
    var flashvarConfig:String = FlexGlobals.topLevelApplication.parameters.config;
    if (flashvarConfig)
    {
        configFile = flashvarConfig;
    }

    //retrieve config from Cookie and override FlashVar
    var cookie:Object = CookieUtil.getCookie("config");
    if (cookie){
       configFile = cookie.toString();
       CookieUtil.deleteCookie("config");
    }
    
    //retrieve config from URL and override FlashVar and Cookie
    if (urlConfigParams.config)
    {
       configFile = urlConfigParams.config;
    }
}



So you need to change the value of the configFile variable for your ViewerContainer somehow. Maybe what you could do is hardcode it in setConfigFile(), use a specific config-abc.xml depending on the id of each ViewerContainer.
0 Kudos
BartPosselt
Emerging Contributor


So you need to change the value of the configFile variable for your ViewerContainer somehow. Maybe what you could do is hardcode it in setConfigFile(), use a specific config-abc.xml depending on the id of each ViewerContainer.


That's pretty close to what I was looking for. A quick test shows that it works just like you said, but it would be good to be able to set the config file from the parent application, rather than hardcoding in the Flex viewer's source, which will be overwritten when updated.

My map needs are quite simple, so I'm going to explore using the Flex API directly.
0 Kudos
GeorgeHaskett
Deactivated User
Have you looked into the following User Config Selection Widget:

http://www.arcgis.com/home/item.html?id=a28b758b3fc14c5794b30d5c230713fb

It seems like it might do what you are looking for.
0 Kudos
BartPosselt
Emerging Contributor
Have you looked into the following User Config Selection Widget:

http://www.arcgis.com/home/item.html?id=a28b758b3fc14c5794b30d5c230713fb

It seems like it might do what you are looking for.


I only took a quick look at that widget, but it appears to be loading the .html file with the ?config=value based on what role is selected. So I don't think that would work in my case.
0 Kudos