[fusion-commits] r1432 - sandbox/legendImage/MapServer/php
svn_fusion at osgeo.org
svn_fusion at osgeo.org
Thu Jul 3 19:51:00 EDT 2008
Author: Assefa
Date: 2008-07-03 19:51:00 -0400 (Thu, 03 Jul 2008)
New Revision: 1432
Modified:
sandbox/legendImage/MapServer/php/LoadMap.php
Log:
Initial pass to generate class icons inside one image
Modified: sandbox/legendImage/MapServer/php/LoadMap.php
===================================================================
--- sandbox/legendImage/MapServer/php/LoadMap.php 2008-07-02 18:47:43 UTC (rev 1431)
+++ sandbox/legendImage/MapServer/php/LoadMap.php 2008-07-03 23:51:00 UTC (rev 1432)
@@ -37,6 +37,7 @@
/* if scales are not set, these become the default values */
define('MIN_SCALE', 1);
define('MAX_SCALE', 1000000000);
+define('ICON_SIZE', 16);
/* could potentially make this optional */
$moveToSession = true;
@@ -142,6 +143,15 @@
$mapObj->mapTitle = $title == -1 ? $mapObj->mapName : $title;
//layers
$mapObj->layers = array();
+ $nTotalClasses=0;
+ $aIcons = array();
+ $nIconWidth = $oMap->legend->keysizex;
+ $nIconHeight = $oMap->legend->keysizey;
+ if ($nIconWidth <=0)
+ $nIconWidth = ICON_SIZE;
+ if ($nIconHeight <=0)
+ $nIconHeight = ICON_SIZE;
+
for ($i=0;$i<$oMap->numlayers;$i++)
{
$layer=$oMap->getLayer($i);
@@ -241,6 +251,8 @@
if (!in_array($classMax, $aScaleBreaks)) {
array_push($aScaleBreaks, $classMax);
}
+
+
}
//sort them
sort($aScaleBreaks);
@@ -256,6 +268,8 @@
//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;
@@ -271,6 +285,20 @@
array_push($aScaleRanges[$k]->styles, $classObj);
}
}
+ /*generate icons for each class and set it's position*/
+ $width = $oMap->legend->keysizex;
+ $height = $oMap->legend->keysizey;
+ if ($width <=0)
+ $width = 16;
+ if ($height <=0)
+ $height = 16;
+
+ $oImg = $oClass->createLegendIcon($nIconWidth, $nIconHeight);
+ array_push($aIcons, $oImg);
+
+ $classObj->icon_x=$nTotalClasses*$nIconWidth;
+ $classObj->icon_y=0;
+ $nTotalClasses++;
}
$layerObj->scaleRanges = $aScaleRanges;
array_push($mapObj->layers, $layerObj);
@@ -283,6 +311,23 @@
array_push($mapObj->groups, getGroupObject($oMap->getLayer($aLayerIndexes[0])));
}
}
+
+ /*build and image containing all the icons and return url*/
+ $nTmpWidth = $oMap->width;
+ $nTmpHeight = $oMap->height;
+
+ $oMap->set("width", $nTotalClasses*$nIconWidth);
+ $oMap->set("height", $nIconHeight);
+ $oImage = $oMap->prepareImage();
+
+ $oMap->set("width", $nTmpWidth);
+ $oMap->set("height", $nTmpHeight);
+
+ for ($i=0; $i<$nTotalClasses;$i++)
+ $oImage->pasteImage($aIcons[$i], -1, $i*$nIconWidth, 0);
+ $mapObj->icons_url = $oImage->saveWebImage();
+
+
echo var2json($mapObj);
}
More information about the fusion-commits
mailing list