[fusion-commits] r1972 - in sandbox/jxlib-3.0: . layers/MapGuide layers/MapServer layers/MapServer/php lib widgets

svn_fusion at osgeo.org svn_fusion at osgeo.org
Wed Nov 11 15:47:49 EST 2009


Author: pagameba
Date: 2009-11-11 15:47:47 -0500 (Wed, 11 Nov 2009)
New Revision: 1972

Modified:
   sandbox/jxlib-3.0/
   sandbox/jxlib-3.0/build.xml
   sandbox/jxlib-3.0/config_dist.json
   sandbox/jxlib-3.0/layers/MapGuide/
   sandbox/jxlib-3.0/layers/MapServer/
   sandbox/jxlib-3.0/layers/MapServer/php/LegendIcon.php
   sandbox/jxlib-3.0/layers/MapServer/php/LoadMap.php
   sandbox/jxlib-3.0/layers/MapServer/php/LoadScaleRanges.php
   sandbox/jxlib-3.0/layers/MapServer/php/Query.php
   sandbox/jxlib-3.0/lib/fusion.js
   sandbox/jxlib-3.0/widgets/Legend.js
Log:
merge with trunk, update for mapserver's new qy extension on query files


Property changes on: sandbox/jxlib-3.0
___________________________________________________________________
Added: svn:mergeinfo
   + /trunk:1958-1971

Modified: sandbox/jxlib-3.0/build.xml
===================================================================
--- sandbox/jxlib-3.0/build.xml	2009-11-11 15:57:55 UTC (rev 1971)
+++ sandbox/jxlib-3.0/build.xml	2009-11-11 20:47:47 UTC (rev 1972)
@@ -215,7 +215,6 @@
                           fusion.js
                           OpenLayers/OpenLayers.js
                           jxlib.uncompressed.js
-                          proj4js-compressed.js
                           Error.js
                           EventMgr.js
                           ApplicationDefinition.js


Property changes on: sandbox/jxlib-3.0/config_dist.json
___________________________________________________________________
Deleted: svn:mergeinfo
   - 


Property changes on: sandbox/jxlib-3.0/layers/MapGuide
___________________________________________________________________
Deleted: svn:mergeinfo
   - 


Property changes on: sandbox/jxlib-3.0/layers/MapServer
___________________________________________________________________
Deleted: svn:mergeinfo
   - 

Modified: sandbox/jxlib-3.0/layers/MapServer/php/LegendIcon.php
===================================================================
--- sandbox/jxlib-3.0/layers/MapServer/php/LegendIcon.php	2009-11-11 15:57:55 UTC (rev 1971)
+++ sandbox/jxlib-3.0/layers/MapServer/php/LegendIcon.php	2009-11-11 20:47:47 UTC (rev 1972)
@@ -1,125 +1,130 @@
-<?php
-/**
- * LegendIcon
- *
- * $Id$
- *
- * 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.
- */
+<?php
+/**
+ * LegendIcon
+ *
+ * $Id$
+ *
+ * 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.
+ */
+
+/*****************************************************************************
+ * Purpose: Draw a legend icon
+ *****************************************************************************/
+
+/* set up the session */
+include(dirname(__FILE__).'/../../../common/php/Utilities.php');
+include(dirname(__FILE__).'/Common.php');
+include(dirname(__FILE__).'/Utilities.php');
 
-/*****************************************************************************
- * Purpose: Draw a legend icon
- *****************************************************************************/
-
-include(dirname(__FILE__).'/Common.php');
-
-if (!isset($mapName)) {
-    die('mapname not set');
-}
-
-$legendIconCacheFile = "";
-
-if (isset($_SESSION['maps']) && isset($_SESSION['maps'][$mapName])) {
-      $configObj = $_SESSION['fusionConfig'];
-      /* if the legendIconCache dir is set */
-      if (isset($configObj->mapserver->legendIconCacheDir)) {
-        $legendIconCacheDir = $configObj->mapserver->legendIconCacheDir;
-
-        // check for closing '/'
-        $legendIconCacheDir = str_replace( '\\', '/', trim( $legendIconCacheDir ) );
-        if ( substr( $legendIconCacheDir, -1 ) != '/' )
-        {
-            $legendIconCacheDir .= '/';
-        }
-
-        $cacheLegendIcons = true;
-        $str = file_get_contents($_SESSION['maps'][$mapName]);
-        /* create a unique location for the map icons based on
-         * the content of the of map file.  If the content changes
-         * then the icons should be rebuilt anyway
-         */
-        $legendIconCacheDir = $legendIconCacheDir.md5($str)."/";
-        if (!is_dir($legendIconCacheDir)) {
-          mkdir($legendIconCacheDir);
-        }
-        /* TODO: can we figure out what the content type is? */
-        $legendIconCacheFile = $legendIconCacheDir."_".$REQUEST_VARS['layername']."_".$REQUEST_VARS['classindex'].".png";
-        /* if the icon exists, return it */
-        if (file_exists($legendIconCacheFile)) {
-            /* TODO: can we figure out what the content type is? */
-            header('Content-type: image/png');
-            $etag = '"' . md5_file($legendIconCacheFile) . '"';
-            header ("ETag: " . $etag );
-            $cache_time = mktime(0, 0, 0, 1, 1, 2004);
-            $expires = 3600 * 256;
-            header("last-modified: " . gmdate("D, d M Y H:i:s",$cache_time) . " GMT");
-            $inm = split(',', getenv("HTTP_IF_NONE_MATCH"));
-            $send_body = true;
-            foreach ($inm as $i) {
-            	  if (trim($i) == $etag || trim($i) == $cache_time) {
-            		    header ("HTTP/1.0 304 Not Modified");
-            		    $send_body = false;
-            		}
-          	}
-            //last modified test
-            if(getenv("HTTP_IF_MODIFIED_SINCE") == gmdate("D, d M Y H:i:s",$cache_time). " GMT") {
-              	header ("HTTP/1.0 304 Not Modified"); 
-              	$send_body = false;
-          	}
-            //more headers
-            header("Expires: " . gmdate("D, d M Y H:i:s",$cache_time+$expires) . " GMT");
-            header("Cache-Control: max-age=$expires, must-revalidate");
-            //header('Content-Length: ' . strlen($body));
-            //if we're not cacheing
-            if ($send_body) {
-                readfile($legendIconCacheFile);
-            }
-            exit;
-        }
-    }
-
-    $oMap = ms_newMapObj($_SESSION['maps'][$mapName]);
-    $oLayer = $oMap->getLayerByName($REQUEST_VARS['layername']);
-    $oClass = $oLayer->getClass($REQUEST_VARS['classindex']);
-    $width = $oMap->legend->keysizex;
-    $height = $oMap->legend->keysizey;
-    if ($width <=0) {
-        $width = 16;
-    }
-    if ($height <=0) {
-        $height = 16;
-    }
-    $oImg = $oClass->createLegendIcon($width, $height);
-    /* TODO: can we figure out what the content type is? */
-    header('Content-type: image/png');
-    if ($cacheLegendIcons) {
-        $oImg->saveImage($legendIconCacheFile);
-        $etag = '"' . md5_file($legendIconCacheFile) . '"';
-        header ("ETag: " . $etag );
-        $cache_time = mktime(0, 0, 0, 1, 1, 2004);
-        $expires = 3600 * 256;
-        header("last-modified: " . gmdate("D, d M Y H:i:s",$cache_time) . " GMT");
-        readfile($legendIconCacheFile);
-    } else {
-      $oImg->saveImage("");
-    }
-    $oImg->free();
-}
-?>
+if (!isset($mapName)) {
+    die('mapname not set');
+}
+
+$mapFile = getSessionSavePath().$mapName.".map";
+$str = file_get_contents($mapFile);
+$legendIconCacheFile = "";
+
+if ($str) {
+      $configObj = $_SESSION['fusionConfig'];
+      /* if the legendIconCache dir is set */
+      if (isset($configObj->mapserver->legendIconCacheDir)) {
+        $legendIconCacheDir = $configObj->mapserver->legendIconCacheDir;
+
+        // check for closing '/'
+        $legendIconCacheDir = str_replace( '\\', '/', trim( $legendIconCacheDir ) );
+        if ( substr( $legendIconCacheDir, -1 ) != '/' )
+        {
+            $legendIconCacheDir .= '/';
+        }
+
+        $cacheLegendIcons = true;
+        //$str = file_get_contents($_SESSION['maps'][$mapName]);
+        /* create a unique location for the map icons based on
+         * the content of the of map file.  If the content changes
+         * then the icons should be rebuilt anyway
+         */
+        $legendIconCacheDir = $legendIconCacheDir.md5($str)."/";
+        if (!is_dir($legendIconCacheDir)) {
+          mkdir($legendIconCacheDir);
+        }
+        /* TODO: can we figure out what the content type is? */
+        $legendIconCacheFile = $legendIconCacheDir."_".$REQUEST_VARS['layername']."_".$REQUEST_VARS['classindex'].".png";
+        /* if the icon exists, return it */
+        if (file_exists($legendIconCacheFile)) {
+            /* TODO: can we figure out what the content type is? */
+            header('Content-type: image/png');
+            $etag = '"' . md5_file($legendIconCacheFile) . '"';
+            header ("ETag: " . $etag );
+            $cache_time = mktime(0, 0, 0, 1, 1, 2004);
+            $expires = 3600 * 256;
+            header("last-modified: " . gmdate("D, d M Y H:i:s",$cache_time) . " GMT");
+            $inm = split(',', getenv("HTTP_IF_NONE_MATCH"));
+            $send_body = true;
+            foreach ($inm as $i) {
+            	  if (trim($i) == $etag || trim($i) == $cache_time) {
+            		    header ("HTTP/1.0 304 Not Modified");
+            		    $send_body = false;
+            		}
+          	}
+            //last modified test
+            if(getenv("HTTP_IF_MODIFIED_SINCE") == gmdate("D, d M Y H:i:s",$cache_time). " GMT") {
+              	header ("HTTP/1.0 304 Not Modified"); 
+              	$send_body = false;
+          	}
+            //more headers
+            header("Expires: " . gmdate("D, d M Y H:i:s",$cache_time+$expires) . " GMT");
+            header("Cache-Control: max-age=$expires, must-revalidate");
+            //header('Content-Length: ' . strlen($body));
+            //if we're not cacheing
+            if ($send_body) {
+                readfile($legendIconCacheFile);
+            }
+            exit;
+        }
+    }
+
+    $oMap = ms_newMapObj($mapFile);
+    $oLayer = $oMap->getLayerByName($REQUEST_VARS['layername']);
+    $oClass = $oLayer->getClass($REQUEST_VARS['classindex']);
+    $width = $oMap->legend->keysizex;
+    $height = $oMap->legend->keysizey;
+    if ($width <=0) {
+        $width = 16;
+    }
+    if ($height <=0) {
+        $height = 16;
+    }
+    $oImg = $oClass->createLegendIcon($width, $height);
+    /* TODO: can we figure out what the content type is? */
+    header('Content-type: image/png');
+    if ($cacheLegendIcons) {
+        $oImg->saveImage($legendIconCacheFile);
+        $etag = '"' . md5_file($legendIconCacheFile) . '"';
+        header ("ETag: " . $etag );
+        $cache_time = mktime(0, 0, 0, 1, 1, 2004);
+        $expires = 3600 * 256;
+        header("last-modified: " . gmdate("D, d M Y H:i:s",$cache_time) . " GMT");
+        readfile($legendIconCacheFile);
+    } else {
+      $oImg->saveImage("");
+    }
+    $oImg->free();
+}
+?>


Property changes on: sandbox/jxlib-3.0/layers/MapServer/php/LegendIcon.php
___________________________________________________________________
Deleted: svn:eol-style
   - native

Modified: sandbox/jxlib-3.0/layers/MapServer/php/LoadMap.php
===================================================================
--- sandbox/jxlib-3.0/layers/MapServer/php/LoadMap.php	2009-11-11 15:57:55 UTC (rev 1971)
+++ sandbox/jxlib-3.0/layers/MapServer/php/LoadMap.php	2009-11-11 20:47:47 UTC (rev 1972)
@@ -1,419 +1,420 @@
-<?php
-/**
- * LoadMap
- *
- * $Id$
- *
- * 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.
- */
-
-/*****************************************************************************
- * Purpose: Load a mapfile into the session and return information about the
- *          map to the client
- *****************************************************************************/
-
-/* Common starts the session */
-include(dirname(__FILE__).'/../../../common/php/Utilities.php');
-include(dirname(__FILE__).'/Common.php');
-include(dirname(__FILE__).'/Utilities.php');
-
-/* if scales are not set, these become the default values */
-define('MIN_SCALE', 1);
-define('MAX_SCALE', 1000000000);
-
-/* could potentially make this optional */
-$moveToSession = true;
-
-/**
-   TODO make it possible to specify only a relative path
-   in the WebLayout and have this code know where to
-   look for it on the server somehow
- */
-
-/* only do something if a mapfile was requested */
-if (isset($_REQUEST['mapfile'])) {
-
-    /* look for mapFileRoot specified in config.json and test to see if the map path in appdef is realitive to it.*/
-    $configObj = $_SESSION['fusionConfig'];
-    $szFusionRoot = dirname(__FILE__).'/../../../'; // TODO : not a very elegant way of doing this
-    $szDblSeparator = DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR;
-
-    $szMapFromFusionRoot = str_replace($szDblSeparator,DIRECTORY_SEPARATOR,$szFusionRoot.DIRECTORY_SEPARATOR.$_REQUEST['mapfile']);
-    $szMapFileRoot = str_replace($szDblSeparator,DIRECTORY_SEPARATOR,$configObj->mapserver->mapFileRoot.DIRECTORY_SEPARATOR.$_REQUEST['mapfile']);
-
-    if( file_exists($szMapFileRoot) ) {
-        /* use the realitive path specified in config.json */
-        $szMapFile = $szMapFileRoot;
-    }
-    else
-    {
-        if( file_exists($szMapFromFusionRoot) ) {
-            /* use the realitive path from fusion install root */
-            $szMapFile = $szMapFromFusionRoot;
-        }
-        else
-        {
-            /* use absolute path from appdef */
-            $szMapFile = $_REQUEST['mapfile'];
-        }
-    }
-
-    $oMap = ms_newMapObj($szMapFile);
-
-    /* optionally move the mapfile to the session */
-    if ($moveToSession) {
-        //path to map file in the session is used by the client
-        $mapId = getSessionSavePath().($oMap->name).".map";
-        //modify various paths if necessary
-        $pathToMap = dirname($szMapFile);
-        $cwd = getcwd();
-        chdir($pathToMap);
-        $shapePath = $oMap->shapepath;
-        $oMap->set('shapepath', realpath($shapePath));
-        $symbolSet = $oMap->symbolsetfilename;
-        if ($symbolSet != '') {
-            $oMap->setSymbolSet(realpath($symbolSet));
-        }
-        $fontSet = $oMap->fontsetfilename;
-        if ($fontSet != '') {
-            $oMap->setFontSet(realpath($fontSet));
-        }
-        /* need to modify all image symbols reference in the map file
-         eg STYLE
-             SYMBOL "../etc/markers/target-7.gif" : this is relative to the map file
-        */
-
-        for ($i=0; $i<$oMap->numlayers; $i++)
-        {
-            $oLayer = &$oMap->GetLayer($i);
-            /* check layername for invalid URI characters and replace */
-            $oLayer->set("name",replaceInvalidLayerName($oLayer->name));
-
-            for ($j=0; $j<$oLayer->numclasses; $j++)
-            {
-                $oClass = $oLayer->GetClass($j);
-                /* if keyimage is defined, change the path*/
-                if ($oClass->keyimage && strlen($oClass->keyimage) > 0)
-                {
-                     $oClass->set("keyimage", realpath($oClass->keyimage));
-                }
-                for ($k=0; $k<$oClass->numstyles; $k++)
-                {
-                    $oStyle = $oClass->getStyle($k);
-                    if ($oStyle->symbolname != "")
-                    {
-                        if (file_exists(realpath($oStyle->symbolname)))
-                        {
-                            $oStyle->set("symbolname", realpath($oStyle->symbolname));
-                        }
-                    }
-                }
-            }
-        }
-        $oMap->save($mapId);
-        chdir($cwd);
-    } else {
-        $mapId = $_REQUEST['mapfile'];
-    }
-} elseif (isset($_SESSION['maps']) && isset($_SESSION['maps'][$mapName])) {
-    $oMap = ms_newMapObj($_SESSION['maps'][$mapName]);
-    $mapId = getSessionSavePath().($oMap->name).".map";
-}
-
-$mapObj = NULL;
-if ($oMap) {
-    header('Content-type: application/json');
-    header('X-JSON: true');
-    $mapObj->sessionId = $sessionID;
-    $mapObj->mapId = $mapId;
-
-    $mapObj->metadata = NULL;
-    if (isset($_REQUEST['map_metadata'])) {
-        $mapMetadataKeys = explode(',',$_REQUEST['map_metadata']);
-        foreach($mapMetadataKeys as $key) {
-            $mapObj->metadata->$key = $oMap->getMetadata($key);
-        }
-    }
-
-    $mapObj->projString = $oMap->getProjection();
-    $mapObj->metersPerUnit = GetMetersPerUnit($oMap->units);
-
-    $mapObj->dpi = $oMap->resolution;
-    $mapObj->imagetype = $oMap->imagetype;
-    $mapObj->mapName = $oMap->name;
-    if (!isset($_SESSION['maps'])) {
-        $_SESSION['maps'] = array();
-    }
-    if (!isset($_SESSION['maps'][$mapObj->mapName])) {
-        $_SESSION['maps'][$mapObj->mapName] = $mapId;
-    }
-    $mapObj->extent = array( $oMap->extent->minx, $oMap->extent->miny,
-                             $oMap->extent->maxx, $oMap->extent->maxy );
-    $minScale = $oMap->web->minscale == -1 ? MIN_SCALE : $oMap->web->minscale;
-    $maxScale = $oMap->web->maxscale == -1 ? MAX_SCALE : $oMap->web->maxscale;
-    $title = $oMap->getmetadata('legend_title');
-    $mapObj->mapTitle = $title == "" ? $mapObj->mapName : $title;
-    //layers
-    $mapObj->layers = array();
-    for ($i=0;$i<$oMap->numlayers;$i++)
-    {
-        $layer=$oMap->getLayer($i);
-        $layerObj = NULL;
-
-        /* Status Default - If a layer is status Default trac it in layerObj */
-        if($layer->status == MS_DEFAULT)
-            $layerObj->statusdefault = true;
-         else
-            $layerObj->statusdefault = false;
-
-        /* rename layes names with invalid characters */
-        $layer->set("name",replaceInvalidLayerName($layer->name));
-
-        $layerObj->metadata = NULL;
-        if (isset($_REQUEST['layer_metadata'])) {
-            $layerMetadataKeys = explode(',',$_REQUEST['layer_metadata']);
-            foreach($layerMetadataKeys as $key) {
-                $layerObj->metadata->$key = $layer->getMetadata($key);
-            }
-        }
-
-        //$extent = $layer->getExtent();
-        $layerObj->extent = NULL;
-        $layerObj->extent->minx = NULL;
-        $layerObj->extent->maxx = NULL;
-        $layerObj->extent->miny = NULL;
-        $layerObj->extent->maxy = NULL;
-
-         // only proceed if extent is valid
-        if( isset($GLOBALS["extent"]) )
-        {
-            $layerObj->extent->minx = $extent->minx;
-            $layerObj->extent->maxx = $extent->maxx;
-            $layerObj->extent->miny = $extent->miny;
-            $layerObj->extent->maxy = $extent->maxy;
-        }
-
-         $layerObj->propertyMappings = '';
-         $layerObj->uniqueId = $i;
-         $layerObj->layerName = $layer->name;
-         switch($layer->type) {
-             case MS_LAYER_POINT:
-                $type = 0;
-                break;
-             case MS_LAYER_LINE:
-                $type = 1;
-                break;
-             case MS_LAYER_POLYGON:
-                $type = 2;
-                break;
-             case MS_LAYER_RASTER:
-                $type = 4;
-                break;
-             case MS_LAYER_ANNOTATION:
-                $type = 8;
-                break;
-             default:
-                $type = 0;
-         }
-         $layerObj->layerTypes = array($type);
-
-         $displayInLegend = strtolower($layer->getMetaData('displayInLegend'));
-         $layerObj->displayInLegend = $displayInLegend == 'false' ? false : true;
-
-         $expandInLegend = strtolower($layer->getMetaData('expandInLegend'));
-         $layerObj->expandInLegend = $expandInLegend == 'false' ? false : true;
-         $layerObj->resourceId = $layer->name;
-         $layerObj->parentGroup = $layer->group;
-
-         $legendLabel = $layer->getMetaData('legendLabel');
-         if ($legendLabel == '') {
-             $legendLabel = $layer->name;
-         }
-         $layerObj->legendLabel = $legendLabel;
-
-         $selectable = strtolower($layer->getMetaData('selectable'));
-         $layerObj->selectable = $selectable == 'true' ? true : false;
-
-         $layerObj->visible = ($layer->status == MS_ON || $layer->status == MS_DEFAULT);
-         $layerObj->actuallyVisible = true;
-
-         $editable = strtolower($layer->getMetaData('editable'));
-         $layerObj->editable = $editable == 'true' ? true : false;
-
-         /* process the classes.  The legend expects things
-          * organized by scale range so we have to first
-          * find all the scale breaks, then create ranges
-          * for each scale break pair, then slot the classes
-          * into the scale ranges that they apply to.
-          */
-
-         $aScaleRanges = array();
-         //create a default scale range for the layer as a whole
-         $layerMin = $layer->minscale == -1 ? $minScale : $layer->minscale;
-         $layerMax = $layer->maxscale == -1 ? $maxScale : $layer->maxscale;
-
-        /* check to see that the layer has a vaild scale range
-         * inside the defined map's main min max scale ranges
-         * set them to the maps scale ranges if they exceede 
-         */
-        if($layer->minscale != -1 && $layerMin < $minScale)
-            $layerMin = $minScale;
-
-        if($layer->maxscale != -1 && $layerMax > $maxScale)
-            $layerMax = $maxScale;
-
-         //find all the unique scale breaks in this layer
-         $aScaleBreaks = array($layerMin, $layerMax);
-         for ($j=0; $j<$layer->numclasses; $j++) {
-             $oClass = $layer->getClass($j);
-             $classMin = $oClass->minscale == -1 ? $layerMin : max($oClass->minscale, $layerMin);
-             $classMax = $oClass->maxscale == -1 ? $layerMax : min($oClass->maxscale, $layerMax);
-             if (!in_array($classMin, $aScaleBreaks)) {
-                 array_push($aScaleBreaks, $classMin);
-             }
-             if (!in_array($classMax, $aScaleBreaks)) {
-                 array_push($aScaleBreaks, $classMax);
-             }
-         }
-         //sort them
-         sort($aScaleBreaks);
-
-         //create scale ranges for each pair of breaks
-         for ($j=0; $j<count($aScaleBreaks)-1; $j++) {
-             $scaleRange = NULL;
-             $scaleRange->minScale = $aScaleBreaks[$j];
-             $scaleRange->maxScale = $aScaleBreaks[$j+1];
-             $scaleRange->styles = array();
-             array_push($aScaleRanges, $scaleRange);
-         }
-
-         //create classes and slot them into the scale breaks
-         for ($j=0; $j<$layer->numclasses; $j++) {
-             $oClass = $layer->getClass($j);
-             $classObj = NULL;
-             $classObj->legendLabel = $oClass->name;
-             $classObj->filter = $oClass->getExpression();
-             $classMin = $oClass->minscale == -1 ? $layerMin : max($oClass->minscale, $layerMin);
-             $classMax = $oClass->maxscale == -1 ? $layerMax : min($oClass->maxscale, $layerMax);
-             $classObj->minScale = $classMin;
-             $classObj->maxScale = $classMax;
-             $classObj->index = $j;
-             for ($k=0; $k<count($aScaleRanges); $k++) {
-                 if ($classMin < $aScaleRanges[$k]->maxScale &&
-                     $classMax > $aScaleRanges[$k]->minScale) {
-                     array_push($aScaleRanges[$k]->styles, $classObj);
-                 }
-             }
-         }
-         //$layerObj->scaleRanges = $aScaleRanges;
-         $_SESSION['scale_ranges'][$i] = $aScaleRanges;
-         /*get the min/max scale for the layer*/
-        $nCount = count($aScaleRanges);
-        $layerObj->minScale = $aScaleRanges[0]->minScale;
-        $layerObj->maxScale = $aScaleRanges[0]->maxScale;
-        for ($j=1; $j<$nCount; $j++)
-        {
-            $layerObj->minScale = min($layerObj->minScale, $aScaleRanges[$j]->minScale);
-            $layerObj->maxScale = max($layerObj->maxScale, $aScaleRanges[$j]->maxScale);
-        }
-        array_push($mapObj->layers, $layerObj);
-    }
-    $mapObj->groups = array();
-    $aGroups = $oMap->getAllGroupNames();
-    foreach($aGroups as $groupName) {
-        $aLayerIndexes = $oMap->getLayersIndexByGroup($groupName);
-        if (count($aLayerIndexes) > 0) {
-            array_push($mapObj->groups, getGroupObject($oMap->getLayer($aLayerIndexes[0])));
-        }
-    }
-    echo var2json($mapObj);
-}
-
-function getGroupObject($layer) {
-    $group = NULL;
-    $group->groupName = $layer->group;
-    $ll = $layer->getMetaData('groupLegendLabel');
-    $group->legendLabel = $ll != '' ? $ll : $group->groupName;
-    $group->uniqueId = $group->groupName;
-    $b = $layer->getMetaData('groupDisplayInLegend');
-    $group->displayInLegend = ($b == 'false') ? false : true;
-    $b = $layer->getMetaData('groupExpandInLegend');
-    $group->expandInLegend = ($b == 'false') ? false : true;
-    $group->layerGroupType = '';
-    /* parent is always not set for mapserver since we can't have nested groups */
-    $group->parentUniqueId = '';
-    $group->parent = '';
-    $b = $layer->getMetaData('groupVisible');
-    $group->visible = ($b == 'false') ? false : true;
-    $group->actuallyVisible = $layer->isVisible();
-    $group->groupParent = $layer->getMetaData('groupParent');
-
-    return $group;
-}
-
-function GetMetersPerUnit($unit)
-{
-    if ($unit == MS_INCHES)
-      return 0.0254;
-    else if ($unit == MS_FEET)
-      return 0.3048;
-    else if ($unit == MS_MILES)
-      return 1609.344;
-    else if ($unit == MS_METERS)
-      return 1;
-    else if ($unit == MS_KILOMETERS)
-      return 1000;
-    else if ($unit == MS_DD)
-      return 111118.7516;
-    else if ($unit == MS_PIXELS)
-      return 1;
-
-}
-
-function replaceInvalidLayerName($szLayerName){
-    /*
-    bug http://trac.osgeo.org/fusion/ticket/96 - Invalid characters in layer name (pdeschamps)
-
-    Fusion requests the map imavge via the Mapserver CGI to toggle the layer visibility.
-    The layer paramerter for the cgi uses spaces as a delimiter for the layer names this creates
-    an issue for the mapserver binary to toggle layers that have these reserved URI characters.
-    also removing characters that could pose potential issues with json.
-    */
-    $aInvalidLayerNameCharacters = array();
-    $aInvalidLayerNameCharacters[0] ="&";
-    $aInvalidLayerNameCharacters[1] =" ";
-    $aInvalidLayerNameCharacters[2] ="#";
-    $aInvalidLayerNameCharacters[3] ="\\";
-    $aInvalidLayerNameCharacters[4] ="=";
-    $aInvalidLayerNameCharacters[5] ="/";
-    $aInvalidLayerNameCharacters[6] ="'";
-
-    $aReplace[0] = "_";
-    $aReplace[1] = "_";
-    $aReplace[2] = "_";
-    $aReplace[3] = "_";
-    $aReplace[4] = "_";
-    $aReplace[5] = "_";
-    $aReplace[6] = "_";
-
-    return str_replace($aInvalidLayerNameCharacters,$aReplace,$szLayerName);
-}
-
-?>
+<?php
+/**
+ * LoadMap
+ *
+ * $Id$
+ *
+ * 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.
+ */
+
+/*****************************************************************************
+ * Purpose: Load a mapfile into the session and return information about the
+ *          map to the client
+ *****************************************************************************/
+
+/* Common starts the session */
+include(dirname(__FILE__).'/../../../common/php/Utilities.php');
+include(dirname(__FILE__).'/Common.php');
+include(dirname(__FILE__).'/Utilities.php');
+
+/* if scales are not set, these become the default values */
+define('MIN_SCALE', 1);
+define('MAX_SCALE', 1000000000);
+
+/* could potentially make this optional */
+$moveToSession = true;
+
+/**
+   TODO make it possible to specify only a relative path
+   in the WebLayout and have this code know where to
+   look for it on the server somehow
+ */
+
+/* only do something if a mapfile was requested */
+if (isset($_REQUEST['mapfile'])) {
+
+    /* look for mapFileRoot specified in config.json and test to see if the map path in appdef is realitive to it.*/
+    $configObj = $_SESSION['fusionConfig'];
+    $szFusionRoot = dirname(__FILE__).'/../../../'; // TODO : not a very elegant way of doing this
+    $szDblSeparator = DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR;
+
+    $szMapFromFusionRoot = str_replace($szDblSeparator,DIRECTORY_SEPARATOR,$szFusionRoot.DIRECTORY_SEPARATOR.$_REQUEST['mapfile']);
+    $szMapFileRoot = str_replace($szDblSeparator,DIRECTORY_SEPARATOR,$configObj->mapserver->mapFileRoot.DIRECTORY_SEPARATOR.$_REQUEST['mapfile']);
+
+    if( file_exists($szMapFileRoot) ) {
+        /* use the realitive path specified in config.json */
+        $szMapFile = $szMapFileRoot;
+    }
+    else
+    {
+        if( file_exists($szMapFromFusionRoot) ) {
+            /* use the realitive path from fusion install root */
+            $szMapFile = $szMapFromFusionRoot;
+        }
+        else
+        {
+            /* use absolute path from appdef */
+            $szMapFile = $_REQUEST['mapfile'];
+        }
+    }
+
+    $oMap = ms_newMapObj($szMapFile);
+
+    /* optionally move the mapfile to the session */
+    if ($moveToSession) {
+        //path to map file in the session is used by the client
+        $mapId = getSessionSavePath().($oMap->name).".map";
+        //modify various paths if necessary
+        $pathToMap = dirname($szMapFile);
+        $cwd = getcwd();
+        chdir($pathToMap);
+        $shapePath = $oMap->shapepath;
+        $oMap->set('shapepath', realpath($shapePath));
+        $symbolSet = $oMap->symbolsetfilename;
+        if ($symbolSet != '') {
+            $oMap->setSymbolSet(realpath($symbolSet));
+        }
+        $fontSet = $oMap->fontsetfilename;
+        if ($fontSet != '') {
+            $oMap->setFontSet(realpath($fontSet));
+        }
+        /* need to modify all image symbols reference in the map file
+         eg STYLE
+             SYMBOL "../etc/markers/target-7.gif" : this is relative to the map file
+        */
+
+        for ($i=0; $i<$oMap->numlayers; $i++)
+        {
+            $oLayer = &$oMap->GetLayer($i);
+            /* check layername for invalid URI characters and replace */
+            $oLayer->set("name",replaceInvalidLayerName($oLayer->name));
+
+            for ($j=0; $j<$oLayer->numclasses; $j++)
+            {
+                $oClass = $oLayer->GetClass($j);
+                /* if keyimage is defined, change the path*/
+                if ($oClass->keyimage && strlen($oClass->keyimage) > 0)
+                {
+                     $oClass->set("keyimage", realpath($oClass->keyimage));
+                }
+                for ($k=0; $k<$oClass->numstyles; $k++)
+                {
+                    $oStyle = $oClass->getStyle($k);
+                    if ($oStyle->symbolname != "")
+                    {
+                        if (file_exists(realpath($oStyle->symbolname)))
+                        {
+                            $oStyle->set("symbolname", realpath($oStyle->symbolname));
+                        }
+                    }
+                }
+            }
+        }
+        $oMap->save($mapId);
+        chdir($cwd);
+    } else {
+        $mapId = $_REQUEST['mapfile'];
+    }
+} elseif (isset($_SESSION['maps']) && isset($_SESSION['maps'][$mapName])) {
+    $oMap = ms_newMapObj($_SESSION['maps'][$mapName]);
+    $mapId = getSessionSavePath().($oMap->name).".map";
+}
+
+$mapObj = NULL;
+if ($oMap) {
+    header('Content-type: application/json');
+    header('X-JSON: true');
+    $mapObj->sessionId = $sessionID;
+    $mapObj->mapId = $mapId;
+
+    $mapObj->metadata = NULL;
+    if (isset($_REQUEST['map_metadata'])) {
+        $mapMetadataKeys = explode(',',$_REQUEST['map_metadata']);
+        foreach($mapMetadataKeys as $key) {
+            $mapObj->metadata->$key = $oMap->getMetadata($key);
+        }
+    }
+
+    $mapObj->projString = $oMap->getProjection();
+    $mapObj->metersPerUnit = GetMetersPerUnit($oMap->units);
+
+    $mapObj->dpi = $oMap->resolution;
+    $mapObj->imagetype = $oMap->imagetype;
+    $mapObj->mapName = $oMap->name;
+    if (!isset($_SESSION['maps'])) {
+        $_SESSION['maps'] = array();
+    }
+    if (!isset($_SESSION['maps'][$mapObj->mapName])) {
+        $_SESSION['maps'][$mapObj->mapName] = $mapId;
+    }
+    $mapObj->extent = array( $oMap->extent->minx, $oMap->extent->miny,
+                             $oMap->extent->maxx, $oMap->extent->maxy );
+    $minScale = $oMap->web->minscale == -1 ? MIN_SCALE : $oMap->web->minscale;
+    $maxScale = $oMap->web->maxscale == -1 ? MAX_SCALE : $oMap->web->maxscale;
+    $title = $oMap->getmetadata('legend_title');
+    $mapObj->mapTitle = $title == "" ? $mapObj->mapName : $title;
+    //layers
+    $mapObj->layers = array();
+    for ($i=0;$i<$oMap->numlayers;$i++)
+    {
+        $layer=$oMap->getLayer($i);
+        $layerObj = NULL;
+
+        /* Status Default - If a layer is status Default trac it in layerObj */
+        if($layer->status == MS_DEFAULT)
+            $layerObj->statusdefault = true;
+         else
+            $layerObj->statusdefault = false;
+
+        /* rename layes names with invalid characters */
+        $layer->set("name",replaceInvalidLayerName($layer->name));
+
+        $layerObj->metadata = NULL;
+        if (isset($_REQUEST['layer_metadata'])) {
+            $layerMetadataKeys = explode(',',$_REQUEST['layer_metadata']);
+            foreach($layerMetadataKeys as $key) {
+                $layerObj->metadata->$key = $layer->getMetadata($key);
+            }
+        }
+
+        //$extent = $layer->getExtent();
+        $layerObj->extent = NULL;
+        $layerObj->extent->minx = NULL;
+        $layerObj->extent->maxx = NULL;
+        $layerObj->extent->miny = NULL;
+        $layerObj->extent->maxy = NULL;
+
+         // only proceed if extent is valid
+        if( isset($GLOBALS["extent"]) )
+        {
+            $layerObj->extent->minx = $extent->minx;
+            $layerObj->extent->maxx = $extent->maxx;
+            $layerObj->extent->miny = $extent->miny;
+            $layerObj->extent->maxy = $extent->maxy;
+        }
+
+         $layerObj->propertyMappings = '';
+         $layerObj->uniqueId = $i;
+         $layerObj->layerName = $layer->name;
+         switch($layer->type) {
+             case MS_LAYER_POINT:
+                $type = 0;
+                break;
+             case MS_LAYER_LINE:
+                $type = 1;
+                break;
+             case MS_LAYER_POLYGON:
+                $type = 2;
+                break;
+             case MS_LAYER_RASTER:
+                $type = 4;
+                break;
+             case MS_LAYER_ANNOTATION:
+                $type = 8;
+                break;
+             default:
+                $type = 0;
+         }
+         $layerObj->layerTypes = array($type);
+
+         $displayInLegend = strtolower($layer->getMetaData('displayInLegend'));
+         $layerObj->displayInLegend = $displayInLegend == 'false' ? false : true;
+
+         $expandInLegend = strtolower($layer->getMetaData('expandInLegend'));
+         $layerObj->expandInLegend = $expandInLegend == 'false' ? false : true;
+         $layerObj->resourceId = $layer->name;
+         $layerObj->parentGroup = $layer->group;
+
+         $legendLabel = $layer->getMetaData('legendLabel');
+         if ($legendLabel == '') {
+             $legendLabel = $layer->name;
+         }
+         $layerObj->legendLabel = $legendLabel;
+
+         $selectable = strtolower($layer->getMetaData('selectable'));
+         $layerObj->selectable = $selectable == 'true' ? true : false;
+
+         $layerObj->visible = ($layer->status == MS_ON || $layer->status == MS_DEFAULT);
+         $layerObj->actuallyVisible = true;
+
+         $editable = strtolower($layer->getMetaData('editable'));
+         $layerObj->editable = $editable == 'true' ? true : false;
+
+         /* process the classes.  The legend expects things
+          * organized by scale range so we have to first
+          * find all the scale breaks, then create ranges
+          * for each scale break pair, then slot the classes
+          * into the scale ranges that they apply to.
+          */
+
+         $aScaleRanges = array();
+         //create a default scale range for the layer as a whole
+         $layerMin = $layer->minscale == -1 ? $minScale : $layer->minscale;
+         $layerMax = $layer->maxscale == -1 ? $maxScale : $layer->maxscale;
+
+        /* check to see that the layer has a vaild scale range
+         * inside the defined map's main min max scale ranges
+         * set them to the maps scale ranges if they exceede 
+         */
+        if($layer->minscale != -1 && $layerMin < $minScale)
+            $layerMin = $minScale;
+
+        if($layer->maxscale != -1 && $layerMax > $maxScale)
+            $layerMax = $maxScale;
+
+         //find all the unique scale breaks in this layer
+         $aScaleBreaks = array($layerMin, $layerMax);
+         for ($j=0; $j<$layer->numclasses; $j++) {
+             $oClass = $layer->getClass($j);
+             $classMin = $oClass->minscale == -1 ? $layerMin : max($oClass->minscale, $layerMin);
+             $classMax = $oClass->maxscale == -1 ? $layerMax : min($oClass->maxscale, $layerMax);
+             if (!in_array($classMin, $aScaleBreaks)) {
+                 array_push($aScaleBreaks, $classMin);
+             }
+             if (!in_array($classMax, $aScaleBreaks)) {
+                 array_push($aScaleBreaks, $classMax);
+             }
+         }
+         //sort them
+         sort($aScaleBreaks);
+
+         //create scale ranges for each pair of breaks
+         for ($j=0; $j<count($aScaleBreaks)-1; $j++) {
+             $scaleRange = NULL;
+             $scaleRange->minScale = $aScaleBreaks[$j];
+             $scaleRange->maxScale = $aScaleBreaks[$j+1];
+             $scaleRange->styles = array();
+             array_push($aScaleRanges, $scaleRange);
+         }
+
+         //create classes and slot them into the scale breaks
+         for ($j=0; $j<$layer->numclasses; $j++) {
+             $oClass = $layer->getClass($j);
+             $classObj = NULL;
+             // Use formatted legend label as defined by CLASS->TITLE
+             $classObj->legendLabel = $oClass->title != '' ? $oClass->title : $oClass->name;
+             $classObj->filter = $oClass->getExpression();
+             $classMin = $oClass->minscale == -1 ? $layerMin : max($oClass->minscale, $layerMin);
+             $classMax = $oClass->maxscale == -1 ? $layerMax : min($oClass->maxscale, $layerMax);
+             $classObj->minScale = $classMin;
+             $classObj->maxScale = $classMax;
+             $classObj->index = $j;
+             for ($k=0; $k<count($aScaleRanges); $k++) {
+                 if ($classMin < $aScaleRanges[$k]->maxScale &&
+                     $classMax > $aScaleRanges[$k]->minScale) {
+                     array_push($aScaleRanges[$k]->styles, $classObj);
+                 }
+             }
+         }
+         //$layerObj->scaleRanges = $aScaleRanges;
+         $_SESSION['scale_ranges'][$mapName][$layer->name] = $aScaleRanges;
+         /*get the min/max scale for the layer*/
+        $nCount = count($aScaleRanges);
+        $layerObj->minScale = $aScaleRanges[0]->minScale;
+        $layerObj->maxScale = $aScaleRanges[0]->maxScale;
+        for ($j=1; $j<$nCount; $j++)
+        {
+            $layerObj->minScale = min($layerObj->minScale, $aScaleRanges[$j]->minScale);
+            $layerObj->maxScale = max($layerObj->maxScale, $aScaleRanges[$j]->maxScale);
+        }
+        array_push($mapObj->layers, $layerObj);
+    }
+    $mapObj->groups = array();
+    $aGroups = $oMap->getAllGroupNames();
+    foreach($aGroups as $groupName) {
+        $aLayerIndexes = $oMap->getLayersIndexByGroup($groupName);
+        if (count($aLayerIndexes) > 0) {
+            array_push($mapObj->groups, getGroupObject($oMap->getLayer($aLayerIndexes[0])));
+        }
+    }
+    echo var2json($mapObj);
+}
+
+function getGroupObject($layer) {
+    $group = NULL;
+    $group->groupName = $layer->group;
+    $ll = $layer->getMetaData('groupLegendLabel');
+    $group->legendLabel = $ll != '' ? $ll : $group->groupName;
+    $group->uniqueId = $group->groupName;
+    $b = $layer->getMetaData('groupDisplayInLegend');
+    $group->displayInLegend = ($b == 'false') ? false : true;
+    $b = $layer->getMetaData('groupExpandInLegend');
+    $group->expandInLegend = ($b == 'false') ? false : true;
+    $group->layerGroupType = '';
+    /* parent is always not set for mapserver since we can't have nested groups */
+    $group->parentUniqueId = '';
+    $group->parent = '';
+    $b = $layer->getMetaData('groupVisible');
+    $group->visible = ($b == 'false') ? false : true;
+    $group->actuallyVisible = $layer->isVisible();
+    $group->groupParent = $layer->getMetaData('groupParent');
+
+    return $group;
+}
+
+function GetMetersPerUnit($unit)
+{
+    if ($unit == MS_INCHES)
+      return 0.0254;
+    else if ($unit == MS_FEET)
+      return 0.3048;
+    else if ($unit == MS_MILES)
+      return 1609.344;
+    else if ($unit == MS_METERS)
+      return 1;
+    else if ($unit == MS_KILOMETERS)
+      return 1000;
+    else if ($unit == MS_DD)
+      return 111118.7516;
+    else if ($unit == MS_PIXELS)
+      return 1;
+
+}
+
+function replaceInvalidLayerName($szLayerName){
+    /*
+    bug http://trac.osgeo.org/fusion/ticket/96 - Invalid characters in layer name (pdeschamps)
+
+    Fusion requests the map imavge via the Mapserver CGI to toggle the layer visibility.
+    The layer paramerter for the cgi uses spaces as a delimiter for the layer names this creates
+    an issue for the mapserver binary to toggle layers that have these reserved URI characters.
+    also removing characters that could pose potential issues with json.
+    */
+    $aInvalidLayerNameCharacters = array();
+    $aInvalidLayerNameCharacters[0] ="&";
+    $aInvalidLayerNameCharacters[1] =" ";
+    $aInvalidLayerNameCharacters[2] ="#";
+    $aInvalidLayerNameCharacters[3] ="\\";
+    $aInvalidLayerNameCharacters[4] ="=";
+    $aInvalidLayerNameCharacters[5] ="/";
+    $aInvalidLayerNameCharacters[6] ="'";
+
+    $aReplace[0] = "_";
+    $aReplace[1] = "_";
+    $aReplace[2] = "_";
+    $aReplace[3] = "_";
+    $aReplace[4] = "_";
+    $aReplace[5] = "_";
+    $aReplace[6] = "_";
+
+    return str_replace($aInvalidLayerNameCharacters,$aReplace,$szLayerName);
+}
+
+?>


Property changes on: sandbox/jxlib-3.0/layers/MapServer/php/LoadMap.php
___________________________________________________________________
Deleted: svn:eol-style
   - native

Modified: sandbox/jxlib-3.0/layers/MapServer/php/LoadScaleRanges.php
===================================================================
--- sandbox/jxlib-3.0/layers/MapServer/php/LoadScaleRanges.php	2009-11-11 15:57:55 UTC (rev 1971)
+++ sandbox/jxlib-3.0/layers/MapServer/php/LoadScaleRanges.php	2009-11-11 20:47:47 UTC (rev 1972)
@@ -32,53 +32,165 @@
  *****************************************************************************/
 
 /* set up the session */
-include ("Common.php");
-include('../../../common/php/Utilities.php');
-include ("Utilities.php");
+include(dirname(__FILE__).'/../../../common/php/Utilities.php');
+include(dirname(__FILE__).'/Common.php');
+include(dirname(__FILE__).'/Utilities.php');
 
+/*if (isset($_SESSION['maps']) && isset($_SESSION['maps'][$mapName])) {
+    $oMap = ms_newMapObj($_SESSION['maps'][$mapName]);
+}*/
+
+/* if scales are not set, these become the default values */
+define('MIN_SCALE', 1);
+define('MAX_SCALE', 1000000000);
+
+$oMap = ms_newMapObj(getSessionSavePath().$mapName.".map");
+
+if ($oMap) {
+	$minScale = $oMap->web->minscale == -1 ? MIN_SCALE : $oMap->web->minscale;
+	$maxScale = $oMap->web->maxscale == -1 ? MAX_SCALE : $oMap->web->maxscale;
+	//layers
+	for ($i=0;$i<$oMap->numlayers;$i++) {
+		$layer=$oMap->getLayer($i);
+		
+		/* rename layes names with invalid characters */
+		$layer->set("name",replaceInvalidLayerName($layer->name));
+		
+		switch($layer->type) {
+			case MS_LAYER_POINT:
+				$type = 0;
+				break;
+			case MS_LAYER_LINE:
+				$type = 1;
+				break;
+			case MS_LAYER_POLYGON:
+				$type = 2;
+				break;
+			case MS_LAYER_RASTER:
+				$type = 4;
+				break;
+			case MS_LAYER_ANNOTATION:
+				$type = 8;
+				break;
+			default:
+				$type = 0;
+		}
+		
+		$displayInLegend = strtolower($layer->getMetaData('displayInLegend'));
+		$expandInLegend = strtolower($layer->getMetaData('expandInLegend'));
+		$legendLabel = $layer->getMetaData('legendLabel');
+		if ($legendLabel == '') {
+			$legendLabel = $layer->name;
+		}
+		
+		$selectable = strtolower($layer->getMetaData('selectable'));
+		$editable = strtolower($layer->getMetaData('editable'));
+		
+		/* process the classes.  The legend expects things
+		* organized by scale range so we have to first
+		* find all the scale breaks, then create ranges
+		* for each scale break pair, then slot the classes
+		* into the scale ranges that they apply to.
+		*/
+		
+		$aScaleRanges = array();
+		//create a default scale range for the layer as a whole
+		$layerMin = $layer->minscale == -1 ? $minScale : $layer->minscale;
+		$layerMax = $layer->maxscale == -1 ? $maxScale : $layer->maxscale;
+		
+		/* check to see that the layer has a vaild scale range
+		 * inside the defined map's main min max scale ranges
+		 * set them to the maps scale ranges if they exceede 
+		 */
+		if($layer->minscale != -1 && $layerMin < $minScale)
+			$layerMin = $minScale;
+		
+		if($layer->maxscale != -1 && $layerMax > $maxScale)
+			$layerMax = $maxScale;
 
-if (isset($_SESSION['maps']) && isset($_SESSION['maps'][$mapName])) {
-    $oMap = ms_newMapObj($_SESSION['maps'][$mapName]);
-}
+		//find all the unique scale breaks in this layer
+		$aScaleBreaks = array($layerMin, $layerMax);
+		for ($j=0; $j<$layer->numclasses; $j++) {
+			$oClass = $layer->getClass($j);
+			$classMin = $oClass->minscale == -1 ? $layerMin : max($oClass->minscale, $layerMin);
+			$classMax = $oClass->maxscale == -1 ? $layerMax : min($oClass->maxscale, $layerMax);
+			if (!in_array($classMin, $aScaleBreaks)) {
+				array_push($aScaleBreaks, $classMin);
+			}
+			if (!in_array($classMax, $aScaleBreaks)) {
+				array_push($aScaleBreaks, $classMax);
+			}
+		}
+		//sort them
+		sort($aScaleBreaks);
+		
+		//create scale ranges for each pair of breaks
+		for ($j=0; $j<count($aScaleBreaks)-1; $j++) {
+			$scaleRange = NULL;
+			$scaleRange->minScale = $aScaleBreaks[$j];
+			$scaleRange->maxScale = $aScaleBreaks[$j+1];
+			$scaleRange->styles = array();
+			array_push($aScaleRanges, $scaleRange);
+		}
+		
+		//create classes and slot them into the scale breaks
+		for ($j=0; $j<$layer->numclasses; $j++) {
+			$oClass = $layer->getClass($j);
+			$classObj = NULL;
+			// Use formatted legend label as defined by CLASS->TITLE
+			$classObj->legendLabel = $oClass->title != '' ? $oClass->title : $oClass->name;
+			//$classObj->legendLabel = $oClass->name;
+			$classObj->filter = $oClass->getExpression();
+			$classMin = $oClass->minscale == -1 ? $layerMin : max($oClass->minscale, $layerMin);
+			$classMax = $oClass->maxscale == -1 ? $layerMax : min($oClass->maxscale, $layerMax);
+			$classObj->minScale = $classMin;
+			$classObj->maxScale = $classMax;
+			$classObj->index = $j;
+			for ($k=0; $k<count($aScaleRanges); $k++) {
+				if ($classMin < $aScaleRanges[$k]->maxScale &&
+					$classMax > $aScaleRanges[$k]->minScale) {
+					array_push($aScaleRanges[$k]->styles, $classObj);
+				}
+			}
+		}
+		//$layerObj->scaleRanges = $aScaleRanges;
+		$_SESSION['scale_ranges'][$mapName][$layer->name] = $aScaleRanges;
+	}
 
-$scaleObj = NULL;
-$scaleObj->layers = array();
+	$scaleObj = NULL;
+	$scaleObj->layers = array();
 
-define('ICON_SIZE', 16);
-$nIconWidth = $oMap->legend->keysizex;
-$nIconHeight = $oMap->legend->keysizey;
-if ($nIconWidth <=0)
+	define('ICON_SIZE', 16);
+	$nIconWidth = $oMap->legend->keysizex;
+	$nIconHeight = $oMap->legend->keysizey;
+	if ($nIconWidth <=0)
   $nIconWidth = ICON_SIZE;
-if ($nIconWidth <=0)
+	if ($nIconWidth <=0)
   $nIconWidth = ICON_SIZE;
-$nTotalClasses=0;
-$aIcons = array();
+	$nTotalClasses=0;
+	$aIcons = array();
 
-
-/*special case to force the the legend icons to be drawn using a gd driver
+	/*special case to force the the legend icons to be drawn using a gd driver
   This was fixed in ticket http://trac.osgeo.org/mapserver/ticket/2682 which
   will be available for mapserver version 5.2.1 and 5.4
   Note that we do not check the outputformat of the map (assuming that we are 
   using GD or AGG renderers)
-*/
-$nVersion = ms_GetVersionInt();
-if ($nVersion <= 50200) /*5.2 and before*/
+	*/
+	$nVersion = ms_GetVersionInt();
+	if ($nVersion <= 50200) /*5.2 and before*/
   $oMap->selectOutputFormat("png24");
 
 
-for($i=0;$i<$oMap->numlayers;$i++) 
-{    
-    if (isset($_SESSION['scale_ranges']) && isset($_SESSION['scale_ranges'][$i]))
+	for($i=0;$i<$oMap->numlayers;$i++) 
     {
         $layer = $oMap->getLayer($i);
-        $scaleranges = $_SESSION['scale_ranges'][$i];
-        //print_r($scaleranges);
-        //echo "aaa <br>";
+		if (isset($_SESSION['scale_ranges']) && isset($_SESSION['scale_ranges'][$mapName]) && isset($_SESSION['scale_ranges'][$mapName][$layer->name]))
+		{
+			$scaleranges = $_SESSION['scale_ranges'][$mapName][$layer->name];
         $layerObj = NULL;
         $layerObj->uniqueId = $i;
 
         /*generate the legend icons here*/
-        //echo count($scaleranges) . "<br>\n";
         $nScaleRanges = count($scaleranges);
         for ($j=0; $j<$nScaleRanges; $j++)
         {
@@ -102,8 +214,7 @@
     }
  }  
 
-if ($nTotalClasses > 0)
- {
+	if ($nTotalClasses > 0) {
      //set the image path and image dir based on what fusion config file
      $configObj = $_SESSION['fusionConfig'];
 
@@ -130,19 +241,47 @@
      for ($i=0; $i<$nTotalClasses;$i++)
        $oImage->pasteImage($aIcons[$i], -1, $i*$nIconWidth, 0);
 
-
      $scaleObj->icons_url = $oImage->saveWebImage();
      $scaleObj->icons_width = $nIconWidth;
      $scaleObj->icons_height = $nIconHeight;
 
       $oMap->web->set("imagepath", $original_imagepath);
       $oMap->web->set("imageurl", $original_imageurl);
+	}
+}
+
+function replaceInvalidLayerName($szLayerName){
+    /*
+    bug http://trac.osgeo.org/fusion/ticket/96 - Invalid characters in layer name (pdeschamps)
+
+    Fusion requests the map imavge via the Mapserver CGI to toggle the layer visibility.
+    The layer paramerter for the cgi uses spaces as a delimiter for the layer names this creates
+    an issue for the mapserver binary to toggle layers that have these reserved URI characters.
+    also removing characters that could pose potential issues with json.
+    */
+    $aInvalidLayerNameCharacters = array();
+    $aInvalidLayerNameCharacters[0] ="&";
+    $aInvalidLayerNameCharacters[1] =" ";
+    $aInvalidLayerNameCharacters[2] ="#";
+    $aInvalidLayerNameCharacters[3] ="\\";
+    $aInvalidLayerNameCharacters[4] ="=";
+    $aInvalidLayerNameCharacters[5] ="/";
+    $aInvalidLayerNameCharacters[6] ="'";
+
+    $aReplace[0] = "_";
+    $aReplace[1] = "_";
+    $aReplace[2] = "_";
+    $aReplace[3] = "_";
+    $aReplace[4] = "_";
+    $aReplace[5] = "_";
+    $aReplace[6] = "_";
       
- }
+    return str_replace($aInvalidLayerNameCharacters,$aReplace,$szLayerName);
+}
 
 header('Content-type: application/json');
 header('X-JSON: true');
 
 echo var2json($scaleObj);
 exit;
-
+?>
\ No newline at end of file

Modified: sandbox/jxlib-3.0/layers/MapServer/php/Query.php
===================================================================
--- sandbox/jxlib-3.0/layers/MapServer/php/Query.php	2009-11-11 15:57:55 UTC (rev 1971)
+++ sandbox/jxlib-3.0/layers/MapServer/php/Query.php	2009-11-11 20:47:47 UTC (rev 1972)
@@ -74,7 +74,7 @@
 $versArray = explode(" ",$msVersion);
 $versNumber = $versArray[2];
 $versParts = explode(".", $versNumber);
-$queryTemplate = "query.qry";
+$queryTemplate = "query.qy";
 //convert to an integer value to make the comparison easier
 $versValue = $versParts[0]*100 + $versParts[1]*10 + $versParts[2];
 if ($versValue >= 522) {
@@ -91,7 +91,7 @@
 $bExtendSelection = isset($_REQUEST['extendselection']) && strcasecmp($_REQUEST['extendselection'], 'true') == 0;
 if ($bExtendSelection) {
     //TODO figure out how to load an existing selection here
-    $oMap->loadquery(getSessionSavePath()."query.qry");
+    $oMap->loadquery(getSessionSavePath()."query.qy");
 }
 
 $bComputedProperties = isset($_REQUEST['computed']) && strcasecmp($_REQUEST['computed'], 'true') == 0; 
@@ -138,8 +138,8 @@
 header('Content-type: application/json');
 header('X-JSON: true');
 if ($result->hasSelection) {
-    $oMap->savequery(getSessionSavePath()."query.qry");
-    $result->queryFile = getSessionSavePath()."query.qry";
+    $oMap->savequery(getSessionSavePath()."query.qy");
+    $result->queryFile = getSessionSavePath()."query.qy";
 
     /*holds selection array*/
     $properties = NULL;

Modified: sandbox/jxlib-3.0/lib/fusion.js
===================================================================
--- sandbox/jxlib-3.0/lib/fusion.js	2009-11-11 15:57:55 UTC (rev 1971)
+++ sandbox/jxlib-3.0/lib/fusion.js	2009-11-11 20:47:47 UTC (rev 1972)
@@ -227,7 +227,8 @@
         initialize : function(options) {
             options = options || {};
             var sessionIdParam = this.getQueryParam('Session');
-            this.sessionId = sessionIdParam || (options.sessionId || null);
+			// Override the pre-created sessionId by user specified sessionId(if exist)
+			this.sessionId = sessionIdParam || options.sessionId || this.sessionId;
         
             if (options.applicationDefinitionURL) {
                 this.applicationDefinitionURL = options.applicationDefinitionURL;            
@@ -252,11 +253,11 @@
             this.sScriptLang = "";
 
             /*
-                     * if the application has been loaded from the same host as
-                     * fusion is installed in, then technically we don't need to
-                     * use the redirect script because we conform to the 
-                     * Same Origin Policy for XmlHttpRequest to work.
-                     */
+			 * if the application has been loaded from the same host as
+			 * fusion is installed in, then technically we don't need to
+			 * use the redirect script because we conform to the 
+			 * Same Origin Policy for XmlHttpRequest to work.
+			 */
             var test = window.location.protocol+'//'+window.location.host;
             var configUrl = 'config.json';
             //if (this.fusionURL.indexOf(test,0) == 0) {
@@ -1148,7 +1149,7 @@
     
         var fusionURL = r + Fusion.getFusionURL() + configUrl; 
     
-        var xhr = new XMLHttpRequest(); 
+        var xhr = getXmlHttpRequest(); 
         xhr.open("GET", fusionURL, false); 
         xhr.send(null); 
     
@@ -1175,7 +1176,7 @@
         } 
         Fusion.configuration.mapguide.mapAgentUrl = s + 'mapagent/mapagent.fcgi'; 
         return Fusion.configuration.mapguide.mapAgentUrl; 
-    } 
+    }
     
     var addElement = function(element) { 
         if (!element) { 
@@ -1189,29 +1190,50 @@
         } 
     
         document.writeln('<script src="' + src + '"><\/script>'); 
-    } 
+    }
 
-	if(navigator.userAgent.indexOf("MSIE")>0 || navigator.userAgent.indexOf("Firefox")>0){
-		var appDefUrl = Fusion.getQueryParam('ApplicationDefinition'); 
-		if(appDefUrl){
-			
-			var xhr = new XMLHttpRequest(); 
-			var mapAgentUrl = getAgentUrl(); 
-			xhr.open("GET", mapAgentUrl + "?OPERATION=GETRESOURCECONTENT&VERSION=1.0.0&LOCALE=en&CLIENTAGENT=MapGuide+Developer&RESOURCEID=" + appDefUrl + "&FORMAT=text%2Fxml", false); 
-			xhr.send(null); 
-			var appDefXML = xhr.responseXML.documentElement; 
-			
-			if(appDefXML){
-				var googleElement = appDefXML.getElementsByTagName("GoogleScript")[0]; 
-				var yahooElement = appDefXML.getElementsByTagName("YahooScript")[0]; 
-				var veElement = appDefXML.getElementsByTagName("VirtualEarthScript")[0]; 
+	var getXmlHttpRequest = function(){	
+        try { return new XMLHttpRequest(); }
+		catch (e) { try { return new ActiveXObject('Msxml2.XMLHTTP'); } 
+		catch (e) { try { return new ActiveXObject('Microsoft.XMLHTTP'); }
+		catch (e) { return  null; }}}
+	}
+	
+	/**
+	 * Function: createSessionId
+	 *
+	 * Pre-create a session to avoid the 401 Unauthorized dialog
+	 *
+	 */
+	var createSessionId = function(){
+		var xhr = getXmlHttpRequest();
+		xhr.open("GET", Fusion.fusionURL+"layers/MapGuide/php/CreateSession.php",false);
+		xhr.send(null); 
+		var o;
+		eval('o='+xhr.responseText);
+		Fusion.sessionId = o.sessionId;
+	}
+	
+	createSessionId();	
+	var appDefUrl = Fusion.getQueryParam('ApplicationDefinition'); 
+	if(appDefUrl){
+		var xhr = new getXmlHttpRequest(); 
+		var mapAgentUrl = getAgentUrl(); 
+		xhr.open("GET", mapAgentUrl + "?OPERATION=GETRESOURCECONTENT&VERSION=1.0.0&LOCALE=en&CLIENTAGENT=MapGuide+Developer&RESOURCEID=" + appDefUrl + "&FORMAT=text%2Fxml&SESSION="+ Fusion.sessionId, false); 
+		xhr.send(null); 
+		var appDefXML = xhr.responseXML.documentElement; 
+		
+		if(appDefXML){
+			var googleElement = appDefXML.getElementsByTagName("GoogleScript")[0]; 
+			var yahooElement = appDefXML.getElementsByTagName("YahooScript")[0]; 
+			var veElement = appDefXML.getElementsByTagName("VirtualEarthScript")[0]; 
 
-				addElement(googleElement); 
-				addElement(yahooElement); 
-				addElement(veElement);
-			}
+			addElement(googleElement); 
+			addElement(yahooElement); 
+			addElement(veElement);
 		}
 	}
+	
     
 })();
 


Property changes on: sandbox/jxlib-3.0/widgets/Legend.js
___________________________________________________________________
Deleted: svn:eol-style
   - native



More information about the fusion-commits mailing list