[fusion-commits] r1340 - in trunk/MapServer: . php
svn_fusion at osgeo.org
svn_fusion at osgeo.org
Wed Mar 26 11:12:59 EDT 2008
Author: wbronsema
Date: 2008-03-26 11:12:59 -0400 (Wed, 26 Mar 2008)
New Revision: 1340
Modified:
trunk/MapServer/MapServer.js
trunk/MapServer/php/LoadMap.php
Log:
Fixes #38 - Updated to allow map and layer level metadata to be accessible via the javascript map and layer objects
Modified: trunk/MapServer/MapServer.js
===================================================================
--- trunk/MapServer/MapServer.js 2008-03-25 19:47:19 UTC (rev 1339)
+++ trunk/MapServer/MapServer.js 2008-03-26 15:12:59 UTC (rev 1340)
@@ -48,6 +48,8 @@
bMapLoaded : false,
bIsMapWidgetLayer : true, //Setthis to false for overview map layers
bLayersReversed: true, //MS returns layers bottom-most layer first, we treat layer order in reverse sense
+ mapMetadataKeys: null,
+ layerMetadataKeys: null,
//the map file
sMapFile: null,
@@ -90,6 +92,9 @@
this.sMapFile = extension.MapFile ? extension.MapFile[0] : '';
+ this.mapMetadataKeys = extension.MapMetadata ? extension.MapMetadata[0] : null;
+ this.layerMetadataKeys = extension.LayerMetadata ? extension.LayerMetadata[0] : null;
+
this.bSingleTile = mapTag.singleTile;// this is set by the AppDef.Map object
this.keepAliveInterval = parseInt(extension.KeepAliveInterval ? extension.KeepAliveInterval[0] : 300);
@@ -191,7 +196,15 @@
var sessionid = this.getSessionID();
- var params = 'mapfile='+mapfile+"&session="+sessionid;
+ var metadata = '';
+ if (this.mapMetadataKeys) {
+ metadata += '&map_metadata='+this.mapMetadataKeys;
+ }
+ if (this.layerMetadataKeys) {
+ metadata += '&layer_metadata='+this.layerMetadataKeys;
+ }
+
+ var params = 'mapfile='+mapfile+"&session="+sessionid+metadata;
var options = {onSuccess: this.mapLoaded.bind(this),
parameters: params};
Fusion.ajaxRequest(loadmapScript, options);
@@ -208,6 +221,7 @@
this._fMetersperunit = o.metersPerUnit;
this.mapWidget._fMetersperunit = this._fMetersperunit;
this._sImageType = o.imagetype;
+ this.metadata = o.metadata;
this._oMaxExtent = OpenLayers.Bounds.fromArray(o.extent);
@@ -316,8 +330,15 @@
var loadmapScript = this.arch + '/' + sl + '/LoadMap.' + sl;
var sessionid = this.getSessionID();
+ var metadata = '';
+ if (this.mapMetadataKeys) {
+ metadata += '&map_metadata='+this.mapMetadataKeys;
+ }
+ if (this.layerMetadataKeys) {
+ metadata += '&layer_metadata='+this.layerMetadataKeys;
+ }
- var params = 'mapname='+this._sMapname+"&session="+sessionid;
+ var params = 'mapname='+this._sMapname+"&session="+sessionid+metadata;
var options = {onSuccess: this.mapReloaded.bind(this),
parameters: params};
Fusion.ajaxRequest(loadmapScript, options);
@@ -327,6 +348,10 @@
if (json) {
var o;
eval('o='+r.responseText);
+
+ //can metadata change?
+ //this.metadata = o.metadata;
+
this.parseMapLayersAndGroups(o);
this.aVisibleLayers = [];
for (var i=0; i<this.aLayers.length; i++) {
@@ -695,6 +720,14 @@
getLayerInfoUrl: function(layerName) {
return null;
+ },
+
+ getMetadata: function(key) {
+ if (typeof this.metadata[key] != 'undefined') {
+ return this.metadata[key];
+ } else {
+ return '';
+ }
}
};
@@ -781,6 +814,7 @@
this.actuallyVisible = o.actuallyVisible;
this.editable = o.editable;
this.parentGroup = o.parentGroup;
+ this.metadata = o.metadata;
this.scaleRanges = [];
this.minScale = 1.0e10;
this.maxScale = 0;
@@ -829,6 +863,14 @@
isVisible: function() {
var bParentVisible = this.parentGroup ? this.parentGroup.isVisible() : true;
return this.visible && bParentVisible;
+ },
+
+ getMetadata: function(key) {
+ if (typeof this.metadata[key] != 'undefined') {
+ return this.metadata[key];
+ } else {
+ return '';
+ }
}
};
Modified: trunk/MapServer/php/LoadMap.php
===================================================================
--- trunk/MapServer/php/LoadMap.php 2008-03-25 19:47:19 UTC (rev 1339)
+++ trunk/MapServer/php/LoadMap.php 2008-03-26 15:12:59 UTC (rev 1340)
@@ -41,16 +41,16 @@
/* 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'])) {
$oMap = ms_newMapObj($_REQUEST['mapfile']);
-
+
/* optionally move the mapfile to the session */
if ($moveToSession) {
//path to map file in the session is used by the client
@@ -70,7 +70,7 @@
$oMap->setFontSet(realpath($fontSet));
}
/* need to modify all image symbols reference in the map file
- eg STYLE
+ eg STYLE
SYMBOL "../etc/markers/target-7.gif" : this is relative to the map file
*/
for ($i=0; $i<$oMap->numlayers; $i++)
@@ -115,6 +115,14 @@
$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->metersPerUnit = GetMetersPerUnit($oMap->units);
$mapObj->dpi = $oMap->resolution;
@@ -126,7 +134,7 @@
if (!isset($_SESSION['maps'][$mapObj->mapName])) {
$_SESSION['maps'][$mapObj->mapName] = $mapId;
}
- $mapObj->extent = array( $oMap->extent->minx, $oMap->extent->miny,
+ $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;
@@ -138,6 +146,15 @@
{
$layer=$oMap->GetLayer($i);
$layerObj = NULL;
+
+ $layerObj->metadata = NULL;
+ if (isset($_REQUEST['layer_metadata'])) {
+ $layerMetadataKeys = explode(',',$_REQUEST['layer_metadata']);
+ foreach($layerMetadataKeys as $key) {
+ $layerObj->metadata->$key = $layer->getMetadata($key);
+ }
+ }
+
$layerObj->propertyMappings = '';
$layerObj->uniqueId = $i;
$layerObj->layerName = $layer->name;
@@ -159,42 +176,42 @@
$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
+
+ /* 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;
-
- //find all the unique scale breaks in this layer
+
+ //find all the unique scale breaks in this layer
$aScaleBreaks = array($layerMin, $layerMax);
for ($j=0; $j<$layer->numclasses; $j++) {
$oClass = $layer->getClass($j);
@@ -209,7 +226,7 @@
}
//sort them
sort($aScaleBreaks);
-
+
//create scale ranges for each pair of breaks
for ($j=0; $j<count($aScaleBreaks)-1; $j++) {
$scaleRange = NULL;
@@ -218,7 +235,7 @@
$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);
@@ -239,7 +256,7 @@
}
$layerObj->scaleRanges = $aScaleRanges;
array_push($mapObj->layers, $layerObj);
- }
+ }
$mapObj->groups = array();
$aGroups = $oMap->getAllGroupNames();
foreach($aGroups as $groupName) {
@@ -268,7 +285,7 @@
$b = $layer->getMetaData('groupVisible');
$group->visible = ($b == 'false') ? false : true;
$group->actuallyVisible = $layer->isVisible();
-
+
return $group;
}
More information about the fusion-commits
mailing list