[fusion-commits] r2215 - sandbox/jxlib-3.0/layers/MapServer/php

svn_fusion at osgeo.org svn_fusion at osgeo.org
Thu Sep 2 13:20:20 EDT 2010


Author: pagameba
Date: 2010-09-02 17:20:19 +0000 (Thu, 02 Sep 2010)
New Revision: 2215

Modified:
   sandbox/jxlib-3.0/layers/MapServer/php/GetAttributes.php
   sandbox/jxlib-3.0/layers/MapServer/php/LegendIcon.php
   sandbox/jxlib-3.0/layers/MapServer/php/LoadMap.php
Log:
fixing some annoying php notice and warning messages, get loadmap to work correctly again when using a file-based map file.

Modified: sandbox/jxlib-3.0/layers/MapServer/php/GetAttributes.php
===================================================================
--- sandbox/jxlib-3.0/layers/MapServer/php/GetAttributes.php	2010-09-02 14:21:53 UTC (rev 2214)
+++ sandbox/jxlib-3.0/layers/MapServer/php/GetAttributes.php	2010-09-02 17:20:19 UTC (rev 2215)
@@ -1,120 +1,121 @@
-<?php
-/**
- * GetAttributes
- *
- * $Id: GetAttributes.php 1972 2009-11-11 20:47:47Z pagameba $
- *
- * 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: create a new selection based on one or more attribute filters and
- *          a spatial filter
- *****************************************************************************/
-
-/* set up the session */
-include ("Common.php");
-include('../../../common/php/Utilities.php');
-
-//header('Content-type: application/json');
-//header('X-JSON: true');
-
-/* the name of the layer in the map to query */
-if ($_REQUEST['layers'] != '') {
-    $layers = explode(',',$_REQUEST['layers']);
-} else {
-    $layers = array();
-}
-
-//echo "<!--";
-//print_r($_REQUEST);
-//echo "-->";
-
-if (!isset($mapName)) {
-    die('mapname not set');
-}
-if (isset($_SESSION['maps']) && isset($_SESSION['maps'][$mapName])) {
-    $oMap = ms_newMapObj($_SESSION['maps'][$mapName]);
-}
-
-$bAllLayers = false;
-$nLayers = count($layers);
-if ($nLayers == 0) {
-    $nLayers = $oMap->numlayers;
-    $bAllLayers = true;
-}
-
-/*holds selection array*/
-$properties = NULL;
-$properties->layers = array();
-    echo "/* nLayers: ".$nLayers." */";
-
-for ($i=0; $i<$nLayers; $i++) {
-    if (!$bAllLayers) {
-        $oLayer = $oMap->GetLayerByName($layers[$i]);
-    } else {
-        $oLayer = $oMap->GetLayer($i);
-    }
-    
-    $selectable = strtolower($oLayer->getMetaData('selectable'));
-    if ( $selectable == 'true' ) {
-       
-       
-      $oLayer->open();
-      $layerName = $oLayer->name != "" ? $oLayer->name : "Layer_".$i; 
-      echo "/* layername: ".$layerName." */";
-      
-      array_push($properties->layers, $layerName);
-  
-      $properties->$layerName->propertynames = array();
-      $properties->$layerName->propertyvalues = array();
-      $properties->$layerName->propertytypes = array();
-  
-      /*get first shape to get the attributes*/
-      //$oRes = $oLayer->getResult(0);
-      //$oShape = $oLayer->getShape($oRes->tileindex,$oRes->shapeindex);
-      $oShape = $oLayer->getFeature(0);
-      
-      while ( list($key,$val) = each($oShape->values) ) {
-              array_push($properties->$layerName->propertynames, $key);
-              //TODO : we should define away to give alias to field names
-              array_push($properties->$layerName->propertyvalues, $key);
-              //TODO we do not know the types of the attributes in MS. Just output 0
-              //we shouls possibly use OGR to get the attributes
-              array_push($properties->$layerName->propertytypes, 0);
-      }
-      
-      $oLayer->close();
-    }
-/*
-	if(isset($_SESSION['selection_array']->$layerName)){
-		if(isset($_SESSION['selection_array']->$layerName->values)){
-			$properties->$layerName->values = $_SESSION['selection_array']->$layerName->values;
-		}
-	}
-*/
-}
-
-/*save selection in the session*/
-//$_SESSION['selection_array'] = $properties; 
-
-echo var2json($properties);
-
-?>
+<?php
+/**
+ * GetAttributes
+ *
+ * $Id: GetAttributes.php 1972 2009-11-11 20:47:47Z pagameba $
+ *
+ * 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: create a new selection based on one or more attribute filters and
+ *          a spatial filter
+ *****************************************************************************/
+
+/* set up the session */
+include ("Common.php");
+include('../../../common/php/Utilities.php');
+
+//header('Content-type: application/json');
+//header('X-JSON: true');
+
+/* the name of the layer in the map to query */
+if (isset($_REQUEST['layers']) && $_REQUEST['layers'] != '') {
+    $layers = explode(',',$_REQUEST['layers']);
+} else {
+    $layers = array();
+}
+
+//echo "<!--";
+//print_r($_REQUEST);
+//echo "-->";
+
+if (!isset($mapName)) {
+    die('mapname not set');
+}
+if (isset($_SESSION['maps']) && isset($_SESSION['maps'][$mapName])) {
+    $oMap = ms_newMapObj($_SESSION['maps'][$mapName]);
+}
+
+$bAllLayers = false;
+$nLayers = count($layers);
+if ($nLayers == 0) {
+    $nLayers = $oMap->numlayers;
+    $bAllLayers = true;
+}
+
+/*holds selection array*/
+$properties = NULL;
+$properties->layers = array();
+    echo "/* nLayers: ".$nLayers." */";
+
+for ($i=0; $i<$nLayers; $i++) {
+    if (!$bAllLayers) {
+        $oLayer = $oMap->GetLayerByName($layers[$i]);
+    } else {
+        $oLayer = $oMap->GetLayer($i);
+    }
+    
+    $selectable = strtolower($oLayer->getMetaData('selectable'));
+    if ( $selectable == 'true' ) {
+       
+       
+      $oLayer->open();
+      $layerName = $oLayer->name != "" ? $oLayer->name : "Layer_".$i; 
+      echo "/* layername: ".$layerName." */";
+      
+      array_push($properties->layers, $layerName);
+  
+      $properties->$layerName->propertynames = array();
+      $properties->$layerName->propertyvalues = array();
+      $properties->$layerName->propertytypes = array();
+  
+      /*get first shape to get the attributes*/
+      //$oRes = $oLayer->getResult(0);
+      //$oShape = $oLayer->getShape($oRes->tileindex,$oRes->shapeindex);
+      $oShape = $oLayer->getFeature(0);
+      if ($oShape) {
+        while ( list($key,$val) = each($oShape->values) ) {
+                array_push($properties->$layerName->propertynames, $key);
+                //TODO : we should define away to give alias to field names
+                array_push($properties->$layerName->propertyvalues, $key);
+                //TODO we do not know the types of the attributes in MS. Just output 0
+                //we shouls possibly use OGR to get the attributes
+                array_push($properties->$layerName->propertytypes, 0);
+        }
+      }
+      
+      $oLayer->close();
+    }
+/*
+	if(isset($_SESSION['selection_array']->$layerName)){
+		if(isset($_SESSION['selection_array']->$layerName->values)){
+			$properties->$layerName->values = $_SESSION['selection_array']->$layerName->values;
+		}
+	}
+*/
+}
+
+/*save selection in the session*/
+//$_SESSION['selection_array'] = $properties; 
+
+echo var2json($properties);
+
+?>

Modified: sandbox/jxlib-3.0/layers/MapServer/php/LegendIcon.php
===================================================================
--- sandbox/jxlib-3.0/layers/MapServer/php/LegendIcon.php	2010-09-02 14:21:53 UTC (rev 2214)
+++ sandbox/jxlib-3.0/layers/MapServer/php/LegendIcon.php	2010-09-02 17:20:19 UTC (rev 2215)
@@ -1,130 +1,135 @@
-<?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
- *****************************************************************************/
-
+<?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__).'/Common.php');
 include(dirname(__FILE__).'/Utilities.php');
 
-if (!isset($mapName)) {
-    die('mapname not set');
-}
-
+if (!isset($mapName)) {
+    die('mapname not set');
+}
+
 $mapFile = getSessionSavePath().$mapName.".map";
 $str = file_get_contents($mapFile);
-$legendIconCacheFile = "";
-
+$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;
+      $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;
-        }
-    }
-
+        /* 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();
-}
-?>
+    $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;
+    }
+    if ($oClass) {
+      $oImg = $oClass->createLegendIcon($width, $height);
+    } else {
+      $oMap->setSize($width,$height);
+      $oImg = $oMap->prepareImage();
+    }
+    /* 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();
+}
+?>

Modified: sandbox/jxlib-3.0/layers/MapServer/php/LoadMap.php
===================================================================
--- sandbox/jxlib-3.0/layers/MapServer/php/LoadMap.php	2010-09-02 14:21:53 UTC (rev 2214)
+++ sandbox/jxlib-3.0/layers/MapServer/php/LoadMap.php	2010-09-02 17:20:19 UTC (rev 2215)
@@ -89,10 +89,11 @@
                 $sMapFileContents = $result->Get('MAPDATA');
             }
         }
-    } else {
-        $sMapFileContents = file_get_contents($szMapFile);
+        $oMap = ms_newMapObjFromString($sMapFileContents);
+    } else if (file_exists($szMapFile)) {
+        $modifyPaths = true;
+        $oMap = ms_newMapObj($szMapFile);
     }
-    $oMap = ms_newMapObjFromString($sMapFileContents);
 
     /* optionally move the mapfile to the session */
     if ($moveToSession) {
@@ -158,6 +159,8 @@
 
 $mapObj = NULL;
 if ($oMap) {
+    $mapName = $oMap->name;
+    
     header('Content-type: application/json');
     header('X-JSON: true');
     $mapObj->sessionId = $sessionID;



More information about the fusion-commits mailing list