[Mapbender-commits] r9001 - trunk/mapbender/http/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Fri Jul 25 04:30:41 PDT 2014
Author: armin11
Date: 2014-07-25 04:30:41 -0700 (Fri, 25 Jul 2014)
New Revision: 9001
Modified:
trunk/mapbender/http/classes/class_wmc.php
Log:
Exchange legend urls for mimetype image/png in stored wmc with newer urls from mapbender registry
Modified: trunk/mapbender/http/classes/class_wmc.php
===================================================================
--- trunk/mapbender/http/classes/class_wmc.php 2014-07-23 09:43:29 UTC (rev 9000)
+++ trunk/mapbender/http/classes/class_wmc.php 2014-07-25 11:30:41 UTC (rev 9001)
@@ -526,6 +526,18 @@
$startTime = microtime();
//declare xpath to pull all layer with given ids from stored wmc docs
$query_mbLayerId = "/wmc:ViewContext/wmc:LayerList/wmc:Layer/wmc:Extension/mapbender:layer_id";
+ //$query_mbLayerLegend = "/wmc:ViewContext/wmc:LayerList/wmc:Layer/wmc:StyleList/";
+ /*
+ <StyleList>
+ <Style current="1">
+ <Name>default</Name>
+ <Title>1</Title>
+ <LegendURL width="" height="" format="">
+ <OnlineResource xlink:type="simple" xlink:href="https://gislksim.service24.rlp.de/ArcGIS/services/erneuerbare_energien/BuergerGIS_Erneuerbare_Energien/MapServer/WMSServer?request=GetLegendGraphic%26version=1.1.1%26format=image/png%26layer=1"/>
+ </LegendURL>
+ </Style>
+ </StyleList>
+ */
//parse xml with php simple xml and handle errors
libxml_use_internal_errors(true);
try {
@@ -548,6 +560,8 @@
$WMCDoc->registerXPathNamespace("xlink","http://www.w3.org/1999/xlink");
//pull out List of layer objects
$layerIdList = $WMCDoc->xpath($query_mbLayerId);
+ //for styles / legend
+ //$layerLegendUrlList = $WMCDoc->xpath($query_mbLayerLegend);
$e = new mb_notice(count($layerIdList));
//Select current layer and wms information with one SQL select query!
$v = array();
@@ -555,20 +569,35 @@
$layerIds = array();
$sql = "SELECT layer_id, layer_name, fkey_wms_id, wms_timestamp, wms_getmap, wms_getlegendurl, wms_owsproxy FROM layer, wms WHERE layer.fkey_wms_id = wms.wms_id and layer_id in (";
$i = 0;
+ //generate csv list of layer_ids
+ $layerList = "";
foreach($layerIdList as $layerIdObject) {
//use only integer layer ids
if (is_int((integer)$layerIdObject) && $layerIdObject != null && $layerIdObject != "") {
- if($i > 0){$sql .= ",";}
- $sql .= "$".($i + 1);
+ if($i > 0){$layerList .= ",";}
+ $layerList .= "$".($i + 1);
array_push($v,$layerIdObject);
array_push($t,'i');
}
$i++;
}
$i = 0;
+ $sql = $sql.$layerList;
$sql .= ")";
$res = db_prep_query($sql,$v,$t);
$e = new mb_notice("class_wmc: sql to pull current wms and layer information from database: ".$sql);
+ //pull all styles of layer with ids from mapbender registry
+ $sql = "SELECT * from layer_style WHERE fkey_layer_id IN (";
+ $sql .= $layerList;
+ $sql .= ")";
+ $resStyle = db_prep_query($sql,$v,$t);
+ //get result as array
+ $style = array();
+ while($row = db_fetch_array($resStyle)) {
+ $style[$row["fkey_layer_id"]][$row["name"]] [$row["legendurlformat"]] = $row["legendurl"];
+ //$e = new mb_notice($row["fkey_layer_id"] . " : " . $row["name"]. " - legendurl: ".$row["legendurl"]." - format: ".$row["legendurlformat"]);
+ }
+ //$e = new mb_exception("after style");
//for each found layer
while($row = db_fetch_array($res)){
$wmsId = $row["fkey_wms_id"];
@@ -589,7 +618,7 @@
$wmsGetMapUrl = $row["wms_getmap"];
$wmsGetLegendUrl = $row["wms_getlegendurl"];
//Exchange the given styles for each layer
- //TODO: Exchange the style urls on a right way!
+ //TODO: Exchange the style urls on a right way! Use the layer_style table for this!
}
//Loop over found layerObject - normally only one single layer is there. Alter the information in the simple xml object
foreach($WMCDoc->xpath($queryPath) as $layer ) {
@@ -606,6 +635,20 @@
$url = $wmsGetLegendUrl . $query;
$layer->StyleList->Style->LegendURL->OnlineResource->attributes('xlink', true)->href = $url;
}
+ } else {
+ $layerDoc = simplexml_load_string($layer->saveXML());
+ foreach($layerDoc->xpath('/Layer/StyleList/Style[@current="1"]') as $styleObject) {
+ //only one current style is possible!
+ //if old legendurl was given, exchange it with new from database
+ if($styleObject->LegendURL->OnlineResource){
+ if (isset($style[(integer)$layerId][(string)$styleObject->Name]['image/png']) && $style[(integer)$layerId][(string)$styleObject->Name]['image/png'] != '') {
+ //set
+ $e = new mb_notice("class_wmc: exchange old legendurl url : ".$layer->StyleList->Style->LegendURL->OnlineResource->attributes('xlink', true)->href." with new legendurl: ".$style[(integer)$layerId][(string)$styleObject->Name]['image/png']);
+ $layer->StyleList->Style->LegendURL->OnlineResource->attributes('xlink', true)->href = $style[(integer)$layerId][(string)$styleObject->Name]['image/png'];
+ }
+
+ }
+ }
}
}
}
More information about the Mapbender_commits
mailing list