[fusion-commits] r2008 - in sandbox/jxlib-3.0/widgets: . AddWMSLayer

svn_fusion at osgeo.org svn_fusion at osgeo.org
Fri Dec 4 13:00:26 EST 2009


Author: madair
Date: 2009-12-04 13:00:25 -0500 (Fri, 04 Dec 2009)
New Revision: 2008

Added:
   sandbox/jxlib-3.0/widgets/AddWMSLayer.js
   sandbox/jxlib-3.0/widgets/AddWMSLayer/
   sandbox/jxlib-3.0/widgets/AddWMSLayer/AddWMSLayer.css
   sandbox/jxlib-3.0/widgets/AddWMSLayer/AddWMSLayer.html
   sandbox/jxlib-3.0/widgets/AddWMSLayer/AddWMSLayer.php
   sandbox/jxlib-3.0/widgets/AddWMSLayer/wms-parser.php
Log:
add WMS layer for MapServer widget

Added: sandbox/jxlib-3.0/widgets/AddWMSLayer/AddWMSLayer.css
===================================================================
--- sandbox/jxlib-3.0/widgets/AddWMSLayer/AddWMSLayer.css	                        (rev 0)
+++ sandbox/jxlib-3.0/widgets/AddWMSLayer/AddWMSLayer.css	2009-12-04 18:00:25 UTC (rev 2008)
@@ -0,0 +1,30 @@
+/* SHEET STYLES */
+
+.addWMSDialog {
+  padding: 5px;
+  font-size: 12px;
+  line-height: 18px;
+  font-family: Arial, Helvetica, sans-serif;
+}
+
+.addWMSDialog label {
+  display: block;
+  float: left;
+  clear: left;
+  background-color:transparent;
+  color:#000000;
+}
+
+.addWMSDialog select, 
+.addWMSDialog textarea,
+.addWMSDialog input {
+  float: left;
+}
+
+#AddWMSLayersContent {
+  overflow: auto;
+  border: 1px solid #999;
+  background-color: #fff;
+  height: 200px;
+}
+

Added: sandbox/jxlib-3.0/widgets/AddWMSLayer/AddWMSLayer.html
===================================================================
--- sandbox/jxlib-3.0/widgets/AddWMSLayer/AddWMSLayer.html	                        (rev 0)
+++ sandbox/jxlib-3.0/widgets/AddWMSLayer/AddWMSLayer.html	2009-12-04 18:00:25 UTC (rev 2008)
@@ -0,0 +1,14 @@
+<div id="AddWMSLayerDialog" class="addWMSDialog">
+  <div>
+      WMS Server URL
+      <input type="text" id="wmsServerName" style="width:300px;"/>
+      <div id="listLayersButton"></div>
+  </div>
+  <span class="jxClearer">&nbsp;</span>
+  <div id="AddWMSLayerList">
+    Select a layer from the list
+    <div id="AddWMSLayersContent" class=""></div>
+  </div>
+  <span class="jxClearer">&nbsp;</span>
+</div>
+

Added: sandbox/jxlib-3.0/widgets/AddWMSLayer/AddWMSLayer.php
===================================================================
--- sandbox/jxlib-3.0/widgets/AddWMSLayer/AddWMSLayer.php	                        (rev 0)
+++ sandbox/jxlib-3.0/widgets/AddWMSLayer/AddWMSLayer.php	2009-12-04 18:00:25 UTC (rev 2008)
@@ -0,0 +1,182 @@
+<?php
+
+include "../../layers/MapServer/php/Common.php";
+include "../../common/php/Utilities.php";
+
+isset($_GET["wmsservicetitle"])?$gwmsServiceTitle = $_GET["wmsservicetitle"] : $wmsservicetitle = NULL;
+
+
+if (!isset($mapName)) {
+    die('mapname not set');
+}
+
+if (isset($_SESSION['maps']) && isset($_SESSION['maps'][$mapName])) {
+    
+     switch($_REQUEST["action"]){
+        case "listLayersWMS":{
+            $szObject = getLayerListFromWMS($_REQUEST["server"]);
+            break;
+        }
+        case "addLayer":{
+            $szObject = addLayer($_REQUEST["value"]);
+            break;
+        }    
+    }
+
+$szJsonData =  var2json($szObject);
+
+header('Content-type: text/plain');
+header('X-JSON: true');
+echo $szJsonData;
+
+}
+
+function getLayerListFromWMS($szServerName){
+    include ('wms-parser.php');
+    global $gszWMSServerName;
+    global $gwmsServiceTitle;
+    
+    // add serverName as a global
+    $gszWMSServerName = $szServerName;
+    
+    //$wmsServer = "http://atlas.gc.ca/cgi-bin/atlaswms_en?VERSION=1.1.1&REQUEST=GetCapabilities&SERVICE=WMS";
+    $join = strpos($szServerName,'?')?'&':'?';
+    $getCapRequest = $join."VERSION=1.1.1&REQUEST=GetCapabilities&SERVICE=WMS";
+    //$xmlData = readData($gszWMSServerName.$getCapRequest);
+    //echo "issuing request -:".$gszWMSServerName.$getCapRequest;
+    $xmlData = file_get_contents($gszWMSServerName.$getCapRequest);
+    //echo $xmlData;
+    
+    if ($xmlData) {
+      //check that it is a valid WMS capabiltities response
+      $check = stripos($xmlData, 'WMT_MS_Capabilities');
+
+      if ($check !== false) {
+        $xmlParse = simplexml_load_string($xmlData);
+        if ($xmlParse) {
+          $gwmsServiceTitle = $xmlParse->Service->Title;
+          $szGetCapabilities = & new CapabilitiesParser();
+          $szGetCapabilities->parse($xmlData);
+          $szGetCapabilities->free_parser();
+          $oReturn = prepareWMS($szGetCapabilities);
+        } else {
+          $oReturn->error = 'Error with GetCapabilities request: '.$gszWMSServerName.$getCapRequest;
+          $oReturn->message = 'Response is not valid XML: \n'.$xmlData;
+        }
+      } else {
+        $oReturn->error = 'Error with GetCapabilities request: '.$gszWMSServerName.$getCapRequest;
+        $oReturn->message = 'Response is not a WMS capabilities document: \n'.$xmlData;
+      }
+    } else {
+      $oReturn->error = 'Error with GetCapabilities request: '.$gszWMSServerName.$getCapRequest;
+      $oReturn->message = 'No response from server';
+    }
+    
+    return $oReturn;
+}
+
+function prepareWMS($szObj){
+    global $gszWMSServerName;
+    global $gwmsServiceTitle;
+    $nCount=0;
+
+      //print_r($szObj);
+    foreach($szObj->layers as $key=>$value){
+      if ( isset($value["Name"]) && $value["layer_id"]>0 ) {
+        $oTmp = NULL;
+        $oTmp->layertype     = 'wms';
+
+        $oTmp->wmsservicetitle = strval($gwmsServiceTitle[0]);
+        $oTmp->name         = $value["Name"];
+        $oTmp->owstitle     = $value["Title"];
+        $oTmp->srs            = $value["SRS"];
+        $oTmp->group         = "null";
+        // setting to image/png for now should be looked into upon later.
+        $oTmp->imageformat  = "image/png";
+        $oTmp->servername   = $gszWMSServerName;
+        $oTmp->queryable    = $value["queryable"]?$value["queryable"]:"0";
+        $bbox         = $value["LatLonBoundingBox"];
+        $oTmp->minx   = $bbox["minx"];
+        $oTmp->miny   = $bbox["miny"];
+        $oTmp->maxx   = $bbox["maxx"];
+        $oTmp->maxy   = $bbox["maxy"];
+        $oTmp->metadataurl = $value["MetadataURL"]?$value["MetadataURL"]:"";
+        
+        $oReturn[$nCount++] = $oTmp;
+      }
+    }
+
+return $oReturn;
+}
+
+function addLayer($szValue){
+    global $mapName;
+    global $gwmsServiceTitle;
+    
+    $szReturn->addedLayer = false;
+    
+    // adding a layer from the atlas
+    if($_REQUEST["layertype"]== 'atlas'){
+        $oMap = ms_newMapObj($_SESSION['maps'][$mapName]);
+        $oCatalogMapFile = ms_newMapObj(APP_LAYER_CATALOG);
+        
+         for($i = 0; $i < $oCatalogMapFile->numlayers; $i++){
+            $oLayer = $oCatalogMapFile->getLayer( $i );
+            
+            if($oLayer->name == $_REQUEST["layername"] && $oLayer->group == $_REQUEST["group"]){
+                //found layer clone it.
+                ms_newLayerObj( $oMap, $oLayer );
+                $szReturn->addedLayer = true;
+                }
+            }
+        // save map file.
+        $oMap->save($_SESSION['maps'][$mapName]);    
+        }
+        
+    // adding a layer from a wms server
+    if($_REQUEST["layertype"]== 'wms'){
+        $oMap = ms_newMapObj($_SESSION['maps'][$mapName]);
+        $oLayer = ms_newLayerObj($oMap);
+        
+        if ($_REQUEST["metadataurl"]) {
+          $metadataurl = $_REQUEST["metadataurl"];
+        } else {
+          $join = strpos($_REQUEST["servername"],"?")?"&":"?";
+          $metadataurl = $_REQUEST["servername"].$join."request=GetCapabilities&service=WMS&version=1.1.1";
+        }
+
+        $oLayer->set("name",$_REQUEST["layername"]);
+        $oLayer->set("status", MS_ON );
+        $oLayer->set("connectiontype",MS_WMS);
+        $oLayer->set("connection", $_REQUEST["servername"]);
+        $oLayer->set("type",MS_LAYER_RASTER);
+        $oLayer->setMetaData("legendLabel",$_REQUEST["owstitle"]);
+        
+        $aSRS = split(" ",$_REQUEST["srs"]);
+        
+        $oLayer->setMetaData("ows_name",$_REQUEST["layername"]);
+        $oLayer->setMetaData("ows_format",$_REQUEST["imageFormat"]);
+        $oLayer->setMetaData("ows_server_version","1.1.1");
+        $oLayer->setMetaData("ows_srs",$aSRS[0]);
+        $oLayer->setMetaData("wms_metadataurl_href", $metadataurl);
+        $oLayer->setMetaData("selectable",$_REQUEST["queryable"]=='1'?'true':'false');
+        
+        $oLayer->setprojection("+init=".strtolower($aSRS[0]));
+        
+        $oMap->save($_SESSION['maps'][$mapName]);    
+        
+        $szReturn->wms_connection = $_REQUEST["servername"];
+        $szReturn->wms_format = $_REQUEST["imageFormat"];
+        $szReturn->wms_name = $_REQUEST["layername"];
+        $szReturn->wms_title = $_REQUEST["owstitle"];
+        $szReturn->wms_version = "1.1.1";
+        $szReturn->wms_srs =$aSRS[0];
+        $szReturn->wmsservicetitle = $gwmsServiceTitle;
+
+        $szReturn->addedLayer = true;
+        }
+        
+    return $szReturn;
+    }
+    
+?>
\ No newline at end of file

Added: sandbox/jxlib-3.0/widgets/AddWMSLayer/wms-parser.php
===================================================================
--- sandbox/jxlib-3.0/widgets/AddWMSLayer/wms-parser.php	                        (rev 0)
+++ sandbox/jxlib-3.0/widgets/AddWMSLayer/wms-parser.php	2009-12-04 18:00:25 UTC (rev 2008)
@@ -0,0 +1,252 @@
+<?php
+// $Id: wms-parser.php,v 1.1 2007/10/28 05:41:11 pdeschamps Exp $
+
+// CubeWerx requires at least 10M for wms capabilities
+ini_set( 'memory_limit', '20M' );
+
+/**
+ *
+ * inherited: +style, +crs, =latlonboundingbox, =boundingbox, +authorityurl
+ *   =dimension, =attribution, =min/maxscaledenominator, =queryable, =cascaded
+ *   =opaque
+ * attribution: title, onlineresource->xlink:href, logourl(format,onlineresource)
+ * style: name, title, legendurl(format,onlineresource->xlink:href)
+ */
+class CapabilitiesParser
+{
+    var $parser;
+
+    var $version = NULL; // wms version
+    var $root = NULL; // root element name (depends on wms version)
+    var $path = ''; // current path (excluding root)
+
+    var $layers = array();
+    var $layer_level = 0;
+    var $layer_props;
+    var $inAttribution = false;
+    var $inStyle = false;
+    var $inMetadata = false;
+
+    var $element = ''; // current element
+    var $cbLayer = NULL;
+    var $cbLayerParams = NULL;
+    var $numLayers = 0;
+    
+    function CapabilitiesParser( )
+    {
+        $this->parser = xml_parser_create( "UTF-8" );
+        xml_parser_set_option( $this->parser, XML_OPTION_CASE_FOLDING, 0 );
+        xml_set_element_handler( $this->parser, array(&$this,"_startElement"), array(&$this,"_endElement") );
+        xml_set_character_data_handler( $this->parser, array(&$this,"_characterData") );
+        $this->layer_level = 0;
+        $this->layer_props = array();
+        $this->layer_props[ $this->layer_level ] = array( );
+        $this->layers = array( );
+    }
+    
+    function free_parser( )
+    {
+        xml_parser_free( $this->parser );
+    }
+    
+    function inSomething()
+    {
+        return $this->inAttribution || $this->inStyle !== false;
+    }
+    
+    function parse( $capabilities, $cbLayer = NULL, $cbLayerParams = NULL )
+    {
+        $this->cbLayer = $cbLayer;
+        $this->cbLayerParams = $cbLayerParams;
+        return xml_parse( $this->parser, $capabilities, TRUE );
+    }
+    
+    function _startElement( $parser, $name, $attrs )
+    {
+//print '_startElement ' . $name . "\n";
+        if( ! $this->root )
+        {
+            $this->root = $name;
+            $this->version = $attrs['version'];
+            $this->layer_props[ $this->layer_level ]['wms_version'] = $this->version;
+        }
+        else
+        {
+            $this->path .= '/' . $name;
+        }
+        $this->element = $name;
+        
+        switch( $name )
+        {
+            case 'Attribution':
+                $this->inAttribution = true;
+                break;
+            case 'Style':
+                $this->inStyle = true;
+//                $this->layer_props[ $this->layer_level ]['Style'] = array( );
+                break;
+            case 'MetadataURL':
+                $this->inMetadata = true;
+                break;
+            case 'OnlineResource':
+                if( $this->inStyle !== false )
+                {
+                    $this->layer_props[ $this->layer_level ]['Style'][ $this->inStyle ] = $attrs['xlink:href'];
+                    break;
+                }
+                if( $this->inMetadata !== false )
+                {
+                    $this->layer_props[ $this->layer_level ]['MetadataURL'] = $attrs['xlink:href'];
+                }
+                break;
+            case 'Layer':
+                // the previous layer is a parent layer of the new one
+                if( ! isset($this->layer_props[ $this->layer_level ]['layer_id']) )
+                {
+                    $this->layer_props[ $this->layer_level ]['layer_id'] = $this->numLayers++;
+                    if( $this->cbLayer )
+                        eval( $this->cbLayer . "(\$this->layer_props[\$this->layer_level], \$this->cbLayerParams );" );
+                    else
+                    {
+//                    print $this->layer_level . ' : ' . var_export($this->layer_props[ $this->layer_level ],true) . '<br>';
+                        $this->layers[] = $this->layer_props[ $this->layer_level ];
+                    }
+                }
+                else
+                {
+                    // adjust layer of $this->layer_props[ $this->layer_level ]
+                    // count child layers?
+                }
+                $this->layer_level += 1;
+                // copy layer_props for new layer level and merge new attrs
+                // @todo: merge only inherited props!
+                $inherited_values = array();
+                $inherited_properties = array( 'Style', 'SRS', 'LatLonBoundingBox', 'BoundingBox', 'queryable', 'opaque', 'cascaded' );
+                foreach( $inherited_properties as $prop )
+                {
+                    if( isset($this->layer_props[ $this->layer_level - 1 ][$prop]) )
+                        $inherited_values[$prop] = $this->layer_props[ $this->layer_level - 1 ][$prop];
+                }
+                $this->layer_props[ $this->layer_level ] = array_merge( $inherited_values, $attrs );
+                
+//                print var_export( array($name,$attrs,$this->layer_level), true ) . '<br>';
+                break;
+            case 'LatLonBoundingBox';
+                if( $this->layer_level > 0 )
+                    $this->layer_props[ $this->layer_level][ $name ] = $attrs;
+                break;
+            case 'BoundingBox':
+                if( $this->layer_level > 0 )
+                {
+                    if( ! isset($this->layer_props[ $this->layer_level][ $name ]) )
+                        $this->layer_props[ $this->layer_level][ $name ] = array();
+                    $SRS = $attrs['SRS'];
+                    unset( $attrs['SRS'] );
+                    $this->layer_props[ $this->layer_level][ $name ][$SRS] = $attrs;
+                }
+                break;
+            default:
+//                print $this->path . ':' . var_export($attrs,true) . '<br>';
+                break;
+        }
+//        print $this->path . ': attrs = ' . var_export($attrs,true) . '<br>';
+    }
+    
+    function _characterData( $parser, $data )
+    {
+//print '_characterData ' . $this->element . ':' . $data . "\n";
+        if( $this->element != '' )
+        {
+            $text = trim($data);
+            if( $this->layer_level == 0 )
+            {
+                switch( $this->element )
+                {
+                    case 'Title':
+                    case 'Name':
+                    case 'Abstract':
+    //print 'abstract=' . $test . '<br/>';
+                        $this->layer_props[ $this->layer_level][ $this->element ] .= $text;
+                        break;
+                }
+            }
+            if( $this->layer_level > 0 && ! $this->inSomething() )
+            {
+                switch( $this->element )
+                {
+                    case 'Title':
+                    case 'Name':
+                        // if not a style name!!
+                        $this->layer_props[ $this->layer_level][ $this->element ] .= $text;
+                        break;
+                    case 'Abstract':
+    //print 'abstract=' . $test . '<br/>';
+                        // if not a style name!!
+                        $this->layer_props[ $this->layer_level][ $this->element ] .= $text;
+                        break;
+                    case 'SRS':
+                        if( isset($this->layer_props[ $this->layer_level][ $this->element ]) 
+                        && $this->layer_props[ $this->layer_level][ $this->element ] != '' )
+                        {
+                            $this->layer_props[ $this->layer_level][ $this->element ] .= ' ';
+                        }
+                        $this->layer_props[ $this->layer_level][ $this->element ] .= $text;
+                        break;
+                }
+            }
+            else if( $this->inStyle !== false )
+            {
+                switch( $this->element )
+                {
+                    case 'Name':
+                        $this->inStyle .= $text;
+                        break;
+                }
+            }
+//            print $this->path . ':<b>' . $this->element . '=' . $text . '|</b><br>';
+//            print '---> ' . $this->layer_level . '/' . var_export($this->layer_props[ $this->layer_level],true) . '<br>';
+            
+            //$this->element = ''; // previously here instead of at start of _endElement
+        }
+    }
+    
+    function _endElement( $parser, $name )
+    {
+//print '_endElement ' . $name . "\n";
+        $this->element = ''; // instead of at end of _characterData function
+        
+        $this->path = substr( $this->path, 0, -(1+strlen($name)) );
+        switch( $name )
+        {
+            case 'Layer':
+                if( ! $this->layer_props[ $this->layer_level ]['layer_id'] )
+                {
+                    $this->layer_props[ $this->layer_level ]['layer_id'] = $this->numLayers++;
+                    if( $this->cbLayer )
+                        eval( $this->cbLayer . "(\$this->layer_props[\$this->layer_level], \$this->cbLayerParams );" );
+                    else
+                    {
+//                    print $this->layer_level . ' : ' . var_export($this->layer_props[ $this->layer_level ],true) . '<br>';
+                        $this->layers[] = $this->layer_props[ $this->layer_level ];
+                    }
+                }
+                $this->layer_level -= 1;
+                array_pop( $this->layer_props );
+                break;
+            case 'Attribution':
+                $this->inAttribution = false;
+                break;
+            case 'Style':
+                $this->inStyle = false;
+                break;
+            case 'Metadata':
+                $this->inMetadata = false;
+                break;
+            default:
+                break;
+        }
+    }
+    
+} // CapabilitiesParser
+
+?>

Added: sandbox/jxlib-3.0/widgets/AddWMSLayer.js
===================================================================
--- sandbox/jxlib-3.0/widgets/AddWMSLayer.js	                        (rev 0)
+++ sandbox/jxlib-3.0/widgets/AddWMSLayer.js	2009-12-04 18:00:25 UTC (rev 2008)
@@ -0,0 +1,232 @@
+/**
+ * Fusion.Widget.AddWMSLayer
+ *
+ * $Id: Print.js 1906 2009-09-23 22:07:49Z chrisclaydon $
+ *
+ * Copyright (c) 2007, 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.
+ */
+
+ /********************************************************************
+ * Class: Fusion.Widget.AddWMSLayer
+ *
+ * Opens a dialog box with a list of layers from a WMS server that can be added
+ * to the map.
+ *
+ * **********************************************************************/
+
+Fusion.Widget.AddWMSLayer = OpenLayers.Class(Fusion.Widget, {
+    uiClass: Jx.Button,
+    initializeWidget: function(widgetTag) {
+        var json = widgetTag.extension;
+        
+        this.button = document.getElementById('AddWMSLayer');
+        this.button.addEvent('click', OpenLayers.Function.bind(this.activate, this));
+        
+        this.serviceURL = json.ServiceURL ? json.ServiceURL[0] : '';
+        
+        this.dialogContentURL = Fusion.getFusionURL() + widgetTag.location + 'AddWMSLayer/AddWMSLayer.html';
+        this.addWMSLayerURL = widgetTag.location + 'AddWMSLayer/AddWMSLayer.php';
+        Fusion.addWidgetStyleSheet(widgetTag.location + 'AddWMSLayer/AddWMSLayer.css');
+    },
+    
+    /**
+     * load an interface that list the layers available from a WMS server 
+     */
+    activate: function() {
+        if (!this.dialog) {
+            this.dialog = new Jx.Dialog(
+                {
+                    label: 'Add WMS Layer',
+                    modal: false,
+                    contentURL: this.dialogContentURL,
+                    width: 415,
+                    height: 420,
+                    resizeable: true,
+                    onContentLoaded: OpenLayers.Function.bind(this.contentLoaded, this)
+                }
+            );
+        }
+        this.dialog.show();
+    },
+    
+    contentLoaded: function(dialog) {
+        this.outputDiv = dialog.domObj.getElementById('AddWMSLayersContent');
+        this.urlInput = dialog.domObj.getElementById('wmsServerName');
+        if (this.serviceURL != '') {
+          this.urlInput.value = this.serviceURL;
+        }
+        var listButton = new Jx.Button({
+            label: 'List Layers',
+            onClick: OpenLayers.Function.bind(this.initializeWMS, this)
+        }).addTo(dialog.domObj.getElementById('listLayersButton'));
+    },
+    
+    initializeWMS: function() {
+        this.listLayersWait();
+        //prep the server URL to remove WMS params
+        var serverURL = this.urlInput.value;
+        if (serverURL.length >0) {
+          var newParams = [];
+          var urlParams = serverURL.split('?')
+          if (urlParams.length > 1) {
+            var params = urlParams[1].split('&');
+            for (var j=0; j<params.length; ++j) {
+              if (params[j].toLowerCase().indexOf('request')!=-1) continue;
+              if (params[j].toLowerCase().indexOf('version')!=-1) continue;
+              newParams.push(params[j]);
+            }
+            urlParams[1] = newParams.join('&');
+          }
+          serverURL = urlParams.join('?');
+          
+          var maps = this.oMap.getAllMaps(); 
+          var map = maps[0];
+          
+           var opts = {
+              parameters: {
+                  session: map.getSessionID(),
+                  mapname: map._sMapname,
+                  action: 'listLayersWMS',
+                  server: serverURL
+              }, 
+              onComplete: OpenLayers.Function.bind(this.wmsListLayers, this)
+          };
+          Fusion.ajaxRequest(this.addWMSLayerURL, opts);
+        }
+    },
+    
+/* 
+function catalogListLayers - CB from catalogManagerInitialize() with object create the html
+                             required to add the layers to the map. clicking on image spawns
+                             addCatalogLayer which inturn add's the clicked layer to the map.
+*/    
+    wmsListLayers: function(r) {
+      if (r.responseText) {
+        var gCatalogLayersObj;
+        try {
+          eval('gCatalogLayersObj='+r.responseText);
+        } catch (e) {
+          gCatalogLayersObj = {'error': e.stack};
+        }
+        if (gCatalogLayersObj) {
+        
+          this.outputDiv.innerHTML = '';
+            
+          if (gCatalogLayersObj.error) {
+            this.outputDiv.innerHTML = gCatalogLayersObj.error + '<br>' + gCatalogLayersObj.message;
+            return;
+          }
+            
+          var ul = document.createElement('ul');
+          ul.id = 'catalogListLayerUL';
+          this.outputDiv.appendChild(ul);
+      
+          for(var i=0;i<gCatalogLayersObj.length;i++){
+              var szOwsTitle = gCatalogLayersObj[i].owstitle;
+              if (szOwsTitle.length < 1) {
+                szOwsTitle = gCatalogLayersObj[i].name;
+              }
+              var li = document.createElement('li');
+              ul.appendChild(li);
+              
+              var a = document.createElement('a');
+              a.href = "javascript:void(0)";
+              a.layertype = gCatalogLayersObj[i].layertype;
+              a.layername =  gCatalogLayersObj[i].name;
+              a.owstitle =  gCatalogLayersObj[i].owstitle;
+              a.group =  gCatalogLayersObj[i].group;
+              a.srs = gCatalogLayersObj[i].srs;
+              a.imageFormat = gCatalogLayersObj[i].imageformat;
+              a.servername = gCatalogLayersObj[i].servername;
+              a.wmsservicetitle = gCatalogLayersObj[i].wmsservicetitle;
+              a.queryable = gCatalogLayersObj[i].queryable;
+              a.metadataurl = gCatalogLayersObj[i].metadataurl;
+              a.minx = gCatalogLayersObj[i].minx;
+              a.miny = gCatalogLayersObj[i].miny;
+              a.maxx = gCatalogLayersObj[i].maxx;
+              a.maxy = gCatalogLayersObj[i].maxy;
+              
+              a.onclick = OpenLayers.Function.bind(this.addWMSLayer, this, a);
+              
+              li.appendChild(a);
+              
+              a.innerHTML = szOwsTitle;
+              li.appendChild(a);
+          }
+        }
+      }
+    },
+    
+    listLayersWait: function() {
+        this.outputDiv.innerHTML = 'Request in progress...';
+    },
+    
+    /* 
+    function addWMSLayer - adds the clicked layer from the interface created by catalogListLayers
+                               then loads browseCatalog.php to add the clicked layer to the current 
+                               session map file. calls addCatalogLayerCB for a return responce.
+    
+    */    
+    addWMSLayer: function(cb){
+        var maps = this.oMap.getAllMaps(); 
+        var map = maps[0];
+        
+        //prep the servername to remove existing WMS params
+        var params = {
+            session: map.getSessionID(),
+            mapname: map._sMapname,
+            action: 'addLayer',
+            layertype: cb.layertype,
+            layername: cb.layername,
+            group: cb.group,
+            owstitle: cb.owstitle,
+            srs: map.projCode.indexOf("APP-DEF-PROJ") < 0 ? map.projCode:'EPSG:4326',
+            imageFormat: cb.imageFormat,
+            servername: cb.servername,
+            wmsservicetitle: cb.wmsservicetitle,
+            queryable: cb.queryable,
+            metadataurl: cb.metadataurl ? cb.metadataurl : ''
+        }
+        
+        // switch image to a different src.
+        //cb.src = 'images/icons/legend-layer.png';
+        var opts = {parameters: params, onComplete: OpenLayers.Function.bind(this.addWMSLayerCB, this)};
+        Fusion.ajaxRequest(this.addWMSLayerURL, opts);
+    },
+    
+    /* 
+    function addWMSLayerCB - CB func from addWMSLayer. The Layer is now added to mapfile, 
+                                 if o.addedLayer = true else something when wrong.
+    */    
+    addWMSLayerCB: function(r) {
+        var o = '';
+        eval('o='+r.responseText);    
+
+        if(o.addedLayer == true){
+          var map = this.oMap; 
+          var maps = map.getAllMaps();
+          map.triggerEvent(Fusion.Event.WMS_LAYER_ADDED, new Array(o));
+          maps[0].reloadMap();
+        } else {
+           // d.log('addCatalogLayerCB:could not add layer');
+        }
+    }
+    
+});



More information about the fusion-commits mailing list