Hi

the layers's initial state (selected, frozen, ..) are used in ClientLayers.php 
function createSession.

        if (!is_null($initialMapState->layers)) {
            foreach ($initialMapState->layers as $initialLayerState) {
                $this->layersData[$initialLayerState->id] = $initialLayerState;
            }
        }

check if the some initialMapState have been set and if so, set the layersData 
array with the values.

replacing/modifying the existing initialMapState process seems a bit tricky so 
I would suggest to insert a new piece of code just after the $initialMapState 
handling but this time you would simply get the values you want for your 
dynamicaly selected layers.

            foreach ($dynamicInitialMapStates as $dynamicInitialMapState) {
                $this->layersData[$dynamicInitialMapState->id] = 
$dynamicInitialMapState;
            }

you simply have to be sure to have the correct content in your 
$dynamicInitialMapState variable

dynamicInitialMapState should be a array of InitialMapState object
InitialMapState->id
InitialMapState->location
InitialMapState->layers where layers is a LayerState object
LayerState->id
LayerState->hidden
LayerState->frozen
LayerState->selected
LayerState->unfolded

$dynamicInitialMapStates should be generated by you. You can do it directly in 
the (extended) layers plugin or in another plugin (in which case you have to 
use 
$this->cartoclient->getPluginManager()->getPlugin('your_plugin_name')->dynamicInitialMapStates
 to access it)

regards
Oliver
  ----- Original Message ----- 
  From: Alessandro Muzzetta 
  To: cartoweb-users@lists.maptools.org 
  Sent: Wednesday, January 23, 2008 1:25 AM
  Subject: [Cartoweb-users] Changing selected layers in code


  Hello,

  is it possible to change the layers that are activated by default directly in 
code instead of having to change the layers.ini file?

  I have several dozen layers of which only two will be active at any given 
time.  Deciding which two layers will be displayed is going to be decided by an 
algorithm written in php, not by the user.  At every page refresh, the 
algorithm, based on several parameters, will set just two layers to selected. 
  Is there a way to do this within Cartoweb in php?

  The only ugly solution I have thought of so far is to overwrite the 
layers.ini file with a new one and having the pertinent layers marked as 
selected.  However, aside being ugly, this runs into problems with caching. 

  Any help would be appreciated.

  Thanks

  -- 
  Alessandro Muzzetta
  IES Solutions Srl
  Catania Office
  Via Vulcano 10 - I-95030 Gravina di Catania, Italy
  Email: [EMAIL PROTECTED]
  Phone/Fax: +39 095211640
  Skype: alex-tecnia 


------------------------------------------------------------------------------


  _______________________________________________
  Cartoweb-users mailing list
  Cartoweb-users@lists.maptools.org
  http://lists.maptools.org/mailman/listinfo/cartoweb-users
_______________________________________________
Cartoweb-users mailing list
Cartoweb-users@lists.maptools.org
http://lists.maptools.org/mailman/listinfo/cartoweb-users

Reply via email to