Copyright (c) 2002, DM Solutions Group Inc. * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ include_once(dirname(__FILE__)."/../Widget.php"); /** * SelectLayers * * @desc SelectLayers widget. */ class SelectLayers extends CWCWidget { /** * SelectLayers * * Constructor. Set the default values. */ function SelectLayers() { // invoke constructor of parent parent::CWCWidget(); // set the description for this widget $this->szWidgetDescription = <<mnMaturityLevel = MATURITY_BETA; } /** * GetHTMLHiddenVariables * * return the NAV_CMD varaiable. * * @return NAV_CMD variable. */ function GetHTMLHiddenVariables() { $szSelectedLayers = ""; $szSep = ""; $oMap = $this->moMapObject->oMap; for($i=0; $i<$oMap->numlayers; $i++) { $oLayer = $oMap->getLayer($i); if ($oLayer->getMetaData( "selected" ) == "1") { $szSelectedLayers .= $szSep.($oLayer->name); $szSep = ","; } } //get selected layers here. $szVariable = "SELECTED_LAYERS"; $szValue = " \n"; $aReturn[$szVariable] = $szValue; return $aReturn; } /** * javascript include files */ function GetJavascriptIncludeFunctions() { $aReturn = parent::GetJavascriptIncludeFunctions(); $szVar = "cwc_events.js"; $aReturn[$szVar] = ''; return $aReturn; } /** * GetJavascriptOnLoadFunctions */ function GetJavascriptInitFunctions() { $aResult = array(); $aResult['SelectLayersRegisterEvent'] = "goEventManager.registerEventID( 'LAYER_SELECTION_CHANGED' );\n"; return $aResult; } /** * GetJavascriptFunctions * * Return the Javacriptfunctions needed by the widget. * * @return Javacriptfunctions needed by the widget. */ function GetJavascriptFunctions() { $szJsFunctionName = "CWCSelectLayer"; $szFunction = <<mszHTMLForm}) { var aszLayers; if (bSingle) { aszLayers = new Array(); } else { aszLayers = SELECTED_LAYERS.value.split( "," ); } var aszNewLayers = new Array(); var i; var bNewLayer = true; for (i=0; i < aszLayers.length; i++) { if (szLayerName == aszLayers[i]) { bNewLayer = false; } else { aszNewLayers[aszNewLayers.length] = aszLayers[i]; } } if (bNewLayer) { aszNewLayers[aszNewLayers.length] = szLayerName; } SELECTED_LAYERS.value = aszNewLayers.toString(); } goEventManager.triggerEvent( 'LAYER_SELECTION_CHANGED' ); return bNewLayer; } EOT; $aReturn[$szJsFunctionName] = $szFunction; return $aReturn; } /** * ParseURL * * Look for selected layers and mark them as such. */ function ParseURL() { $oMap = $this->moMapObject->oMap; if ($this->isVarSet( 'SELECTED_LAYERS' )) { $aszSelectedLayers = array(); if (strlen($this->getVar( 'SELECTED_LAYERS' )) > 0) { $aszSelectedLayers = explode( ",", $this->getVar( 'SELECTED_LAYERS' ) ); } for($i=0; $i<$oMap->numlayers; $i++) { $oLayer = $oMap->getLayer($i); if (in_array( $oLayer->name, $aszSelectedLayers )) { $oLayer->setMetaData( "selected", "1" ); } else { $oLayer->setMetaData( "selected", "0" ); } } } else { $bHasSelected = false; for($i=0; $i<$oMap->numlayers; $i++) { $oLayer = $oMap->getLayer($i); $szSelected = $oLayer->getMetaData( "selected" ); if ($szSelected != "") { $bHasSelected = true; break; } } if (!$bHasSelected && $oMap->numlayers > 0) { $oLayer = $oMap->getLayer( 0 ); $oLayer->setMetaData( "selected", "1" ); } } // return success return true; } } ?>