[Mapbender-commits] r4543 - trunk/mapbender/http/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Fri Aug 28 08:33:38 EDT 2009
Author: christoph
Date: 2009-08-28 08:33:37 -0400 (Fri, 28 Aug 2009)
New Revision: 4543
Modified:
trunk/mapbender/http/classes/class_map.php
Log:
more sophisticated mergeWms (SRS recalculation)
bug fix (overview file name hard coded!)
Modified: trunk/mapbender/http/classes/class_map.php
===================================================================
--- trunk/mapbender/http/classes/class_map.php 2009-08-28 12:32:50 UTC (rev 4542)
+++ trunk/mapbender/http/classes/class_map.php 2009-08-28 12:33:37 UTC (rev 4543)
@@ -237,6 +237,118 @@
* @return
*/
public function mergeWmsArray ($wmsArray) {
+ if (func_num_args() > 1
+ && is_array($wmsArray)
+ && count($wmsArray) > 0) {
+
+ $options = func_get_arg(1);
+ if ($options["zoom"]) {
+ $ext = $this->getExtent();
+ $srs = $ext->epsg;
+ $currentWms = $wmsArray[0];
+
+ $bboxExists = false;
+ $wgs84Index = null;
+ // check if SRS of root layer matches WMC SRS
+ for ($i = 0; $i < count($currentWms->objLayer[0]->layer_epsg); $i++) {
+ $currentLayerEpsg = $currentWms->objLayer[0]->layer_epsg[$i];
+ if ($currentLayerEpsg["epsg"] !== $srs) {
+ if ($currentLayerEpsg["epsg"] = "EPSG:4326") {
+ $wgs84Index = $i;
+ }
+ continue;
+ }
+
+ // calculate WMC bbox from root layer bbox
+ $bboxExists = true;
+ $this->calculateExtent(new Mapbender_bbox(
+ $currentLayerEpsg["minx"],
+ $currentLayerEpsg["miny"],
+ $currentLayerEpsg["maxx"],
+ $currentLayerEpsg["maxy"],
+ $srs
+ ));
+ }
+
+ if (!$bboxExists && !is_null($wgs84Index)) {
+ $currentLayerEpsg = $currentWms->objLayer[0]->layer_epsg[$wgs84Index];
+ $extArray = array(
+ $currentLayerEpsg["minx"],
+ $currentLayerEpsg["miny"],
+ $currentLayerEpsg["maxx"],
+ $currentLayerEpsg["maxy"],
+ );
+ $oldEPSG = "4326";
+ $newEPSG = preg_replace("/EPSG:/","", $srs);
+
+ // calculate bbox via PostGIS
+ if(SYS_DBTYPE=='pgsql'){
+ $con = db_connect($DBSERVER,$OWNER,$PW);
+ $sqlMinx = "SELECT X(transform(GeometryFromText('POINT(".$extArray[0]." ".$extArray[1].")',".$oldEPSG."),".$newEPSG.")) as minx";
+ $resMinx = db_query($sqlMinx);
+ $minx = floatval(db_result($resMinx,0,"minx"));
+
+ $sqlMiny = "SELECT Y(transform(GeometryFromText('POINT(".$extArray[0]." ".$extArray[1].")',".$oldEPSG."),".$newEPSG.")) as miny";
+ $resMiny = db_query($sqlMiny);
+ $miny = floatval(db_result($resMiny,0,"miny"));
+
+ $sqlMaxx = "SELECT X(transform(GeometryFromText('POINT(".$extArray[2]." ".$extArray[3].")',".$oldEPSG."),".$newEPSG.")) as maxx";
+ $resMaxx = db_query($sqlMaxx);
+ $maxx = floatval(db_result($resMaxx,0,"maxx"));
+
+ $sqlMaxy = "SELECT Y(transform(GeometryFromText('POINT(".$extArray[2]." ".$extArray[3].")',".$oldEPSG."),".$newEPSG.")) as maxy";
+ $resMaxy = db_query($sqlMaxy);
+ $maxy = floatval(db_result($resMaxy,0,"maxy"));
+ }
+ else{
+ $con_string = "host=$GEOS_DBSERVER port=$GEOS_PORT dbname=$GEOS_DB user=$GEOS_OWNER password=$GEOS_PW";
+ $con = pg_connect($con_string) or die ("Error while connecting database");
+
+ $sqlMinx = "SELECT X(transform(GeometryFromText('POINT(".$extArray[0]." ".$extArray[1].")',".$oldEPSG."),".$newEPSG.")) as minx";
+ $resMinx = pg_query($con,$sqlMinx);
+ $minx = floatval(pg_fetch_result($resMinx,0,"minx"));
+
+ $sqlMiny = "SELECT Y(transform(GeometryFromText('POINT(".$extArray[0]." ".$extArray[1].")',".$oldEPSG."),".$newEPSG.")) as miny";
+ $resMiny = pg_query($con,$sqlMiny);
+ $miny = floatval(pg_fetch_result($resMiny,0,"miny"));
+
+ $sqlMaxx = "SELECT X(transform(GeometryFromText('POINT(".$extArray[2]." ".$extArray[3].")',".$oldEPSG."),".$newEPSG.")) as maxx";
+ $resMaxx = pg_query($con,$sqlMaxx);
+ $maxx = floatval(pg_fetch_result($resMaxx,0,"maxx"));
+
+ $sqlMaxy = "SELECT Y(transform(GeometryFromText('POINT(".$extArray[2]." ".$extArray[3].")',".$oldEPSG."),".$newEPSG.")) as maxy";
+ $resMaxy = pg_query($con,$sqlMaxy);
+ $maxy = floatval(pg_fetch_result($resMaxy,0,"maxy"));
+ }
+ $bboxExists = true;
+ $this->calculateExtent(new Mapbender_bbox(
+ $minx,
+ $miny,
+ $maxx,
+ $maxy,
+ $srs
+ ));
+ }
+ if (!$bboxExists) {
+ $e = new mb_exception(__FILE__ . ": mergeWmsArray: Could not determine bounding box of WMS in SRS " . $srs);
+ }
+ }
+ if ($options["show"] && is_numeric($options["show"])) {
+ // set all layers of WMS to visible
+ for ($i = 0; $i < count($wmsArray); $i++) {
+ $numLayers = count($wmsArray[$i]->objLayer);
+
+ // do not display if layer count is too big
+ if ($numLayers > intval($options["show"])) {
+ continue;
+ }
+
+ for ($j = 0; $j < $numLayers; $j++) {
+ $wmsArray[$i]->objLayer[$j]->gui_layer_visible = 1;
+ }
+ }
+ }
+ }
$this->wmsArray = wms::merge(array_merge($this->wmsArray, $wmsArray));
}
@@ -472,10 +584,20 @@
// reset the WMS array
// BEWARE, SUPER UGLY CODE AHEAD!!
// (BUT THERE IS NO OTHER WAY TO DO IT)
- if (strpos($row["e_src"], "mod_mapOV.php?wms") !== false) {
+ if (strpos($row["e_js_file"], "ovnf.php") !== false) {
// $e = new mb_exception("guess this is the OV");
- $pattern = "/[\.\/a-zA-Z_]*\?wms=([0-9]*)[^0-9]*/";
- $ovIndex = preg_replace($pattern, "\$1", $row["e_src"]);
+
+ $ov_sql = "SELECT var_value FROM gui_element_vars WHERE " .
+ "var_name = 'overview_wms' AND fkey_e_id = $1 AND " .
+ "fkey_gui_id = $2";
+ $ov_v = array($frameName, $appId);
+ $ov_t = array('s', 's');
+ $ov_res = db_prep_query($ov_sql, $ov_v, $ov_t);
+ $ov_row = db_fetch_array($ov_res);
+ if ($ov_row) {
+ $ov_index = intval($row["var_value"]);
+ }
+
// $e = new mb_exception("OV index: " . $ovIndex);
if (!$ovIndex) {
$ovIndex = 0;
More information about the Mapbender_commits
mailing list