svn commit: r739 - trunk/mapbender/http/classes/class_wmc.php
christoph at osgeo.org
christoph at osgeo.org
Thu Aug 3 08:48:01 EDT 2006
Author: christoph
Date: 2006-08-03 12:48:00+0000
New Revision: 739
Modified:
trunk/mapbender/http/classes/class_wmc.php
Log:
major rebuild of function createsJsObjFromWMC
- especially focussed on 'merge', which was quite buggy previously.
- now supports IE
Modified: trunk/mapbender/http/classes/class_wmc.php
Url: https://mapbender.osgeo.org/source/browse/mapbender/trunk/mapbender/http/classes/class_wmc.php?view=diff&rev=739&p1=trunk/mapbender/http/classes/class_wmc.php&p2=trunk/mapbender/http/classes/class_wmc.php&r1=738&r2=739
==============================================================================
--- trunk/mapbender/http/classes/class_wmc.php (original)
+++ trunk/mapbender/http/classes/class_wmc.php 2006-08-03 12:48:00+0000
@@ -536,7 +536,6 @@
}
function createJsObjFromWMC($target, $mapObj, $action){
- if ($action == "merge") $action = "append";
$wmc_string = "";
$validActions = array("load", "merge", "append");
if (!in_array($action, $validActions)) {
@@ -545,24 +544,24 @@
else {
$wmc_string .= "var index = " . $target . "getMapObjIndexByName('" . $mapObj . "');\n";
if ($action == "load") {
+ // delete all previous wms
$wmc_string .= "while(" . $target . "mb_mapObj[index].wms.length > 0){" . $target . "mb_mapObjremoveWMS(index,0);}";
$wmc_string .= $target . "deleteWmsObject();\n";
}
if ($action == "merge") {
- $wmc_string .= "var ind = " . $target . "getMapObjIndexByName('" . $mapObj . "');\n";
- $wmc_string .= "var wms_exists = false;\n";
- $wmc_string .= "var layer_exists = false;\n";
- $wmc_string .= "var current_wms_index = null;\n";
- $wmc_string .= "var current_layer_index = null;\n";
- $wmc_string .= "var changedWmsIds = new Array();\n";
- $wmc_string .= "var wmsAlreadyInArray = false;\n";
+ $wmc_string .= "var wms_exists = false;\n"; // true if this wms exists in the mapObj
+ $wmc_string .= "var current_wms_index = null;\n"; // if wms_exists: index of the wms in the map obj; else: null
+ $wmc_string .= "var layer_exists = false;\n"; // true if this layer exists in an existing wms of the mapObj
+ $wmc_string .= "var current_layer_index = null;\n"; // if layer_exists: index of the layer of the wms in the mapObj; else: null
}
$new_wms = "";
$cnt_wms = -1;
$added_wms = array();
+ // for all layers in wmc, find individual wms...
for ($i = 0; $i < count($this->wmc_layer_title); $i++) {
$current_wms = $this->wmc_wms_serviceURL[$i];
+ // ...this is something like 'for every wms'
if (!in_array($current_wms , $added_wms)) {
$layerlist = "";
$querylayerlist = "";
@@ -571,11 +570,10 @@
if ($action == "merge") {
$wmc_string .= "wms_exists = false;\n";
$wmc_string .= "current_wms_index = null;\n";
- $wmc_string .= "for (var m=0; m < " . $target . "mb_mapObj[ind].wms.length; m++) {\n";
- $wmc_string .= "\tif ('" . $this->wmc_wms_serviceURL[$i] . "' == " . $target . "mb_mapObj[ind].wms[m].wms_getmap) {\n";
+ $wmc_string .= "for (var m=0; m < " . $target . "mb_mapObj[index].wms.length; m++) {\n";
+ $wmc_string .= "\tif ('" . $this->wmc_wms_serviceURL[$i] . "' == " . $target . "mb_mapObj[index].wms[m].wms_getmap) {\n";
$wmc_string .= "\t\twms_exists = true;\n";
$wmc_string .= "\t\tcurrent_wms_index = m;\n";
- $wmc_string .= "\t\tchangedWmsIds[changedWmsIds.length] = wms[m].wms_id;\n";
$wmc_string .= "\t}\n";
$wmc_string .= "}\n";
$wmc_string .= "if (!wms_exists) {\n";
@@ -588,6 +586,7 @@
die; exit;
}
+ // add wms
$wmc_string .= "\t" . $target . "add_wms('','".
$this->wmc_wms_version[$i] ."','".
$this->wmc_wms_title[$i] ."','".
@@ -606,6 +605,7 @@
$wmc_string .= "}\n";
}
+ // add epsg
$wmc_string .= $target . "wms_addSRS('".
$this->wmc_bBox_SRS ."','".
$this->wmc_bBox_minx ."','".
@@ -614,17 +614,23 @@
$this->wmc_bBox_maxy ."','".
"');\n";
+ // for each layer...
for ($ii = 0; $ii < count($this->wmc_layer_title); $ii++) {
$layer_wms = $this->wmc_wms_serviceURL[$ii];
+ // ... of this wms
if ($current_wms == $layer_wms) {
+
+ // add format (FIXME: is this working?)
$z = count($this->wmc_layer_format[$ii]);
for($j=0;$j<$z;$j++){
$wmc_string .= $target . "wms_add_data_type_format('map','". $this->wmc_layer_format[$ii][$j] ."');\n";
}
+
if ($cnt_layers == 0) {
if ($action == "merge") {
$wmc_string .= "if (!wms_exists) {\n\t";
}
+ // add parent layer
$wmc_string .= $target . "wms_add_layer('','','". $this->wmc_wms_title[$i] ."','','0','0','0','0','','".$id."','1','1','1','0','0','0','0');\n";
if ($action == "merge") {
$wmc_string .= "}\n";
@@ -632,16 +638,35 @@
}
$cnt_layers++;
- if ($this->wmc_layer_queryable[$ii]) {
- $cnt_query_layers++;
- if (!in_array($this->wmc_layer_name[$ii], explode(",",$querylayerlist))) {
- if ($querylayerlist == "") {$querylayerlist = $this->wmc_layer_name[$ii];} else {$querylayerlist .= "," . $this->wmc_layer_name[$ii];}
- }
- }
if ($action == "merge") {
- $wmc_string .= "if (!wms_exists) {\n";
+ $wmc_string .= "if (wms_exists) {\n";
+
+ // check if this layer already exists in this wms
+ $wmc_string .= "\tlayer_exists = false;\n";
+ $wmc_string .= "\tcurrent_layer_index = null;\n";
+ $wmc_string .= "\tfor (var m=0; m < " . $target . "mb_mapObj[index].wms[current_wms_index].objLayer.length; m++) {\n";
+ $wmc_string .= "\t\tif ('" . $this->wmc_layer_name[$ii] . "' == " . $target . "mb_mapObj[index].wms[current_wms_index].objLayer[m].layer_name) {\n";
+ $wmc_string .= "\t\t\tlayer_exists = true;\n";
+ $wmc_string .= "\t\t\tcurrent_layer_index = m;\n";
+ $wmc_string .= "\t\t}\n";
+ $wmc_string .= "\t}\n";
+
+ $wmc_string .= "\tif (layer_exists) {\n";
+ // check if the visibility or the queryability are different to the existing layer
+ $wmc_string .= "\t\tif (" . $target . "mb_mapObj[index].wms[current_wms_index].objLayer[current_layer_index].gui_layer_visible != '" . intval(!$this->wmc_layer_hidden[$ii]) . "'";
+ $wmc_string .= " || " . $target . "mb_mapObj[index].wms[current_wms_index].objLayer[current_layer_index].gui_layer_querylayer != '" . $this->wmc_layer_queryable[$ii] . "') {\n";
+
+ // if yes, update the visibility and queryability
+ $wmc_string .= "\t\t\t" . $target . "mb_mapObj[index].wms[current_wms_index].objLayer[current_layer_index].gui_layer_visible = " . intval(!$this->wmc_layer_hidden[$ii]) . ";\n";
+ $wmc_string .= "\t\t\t" . $target . "mb_mapObj[index].wms[current_wms_index].objLayer[current_layer_index].gui_layer_querylayer = " . $this->wmc_layer_queryable[$ii] . ";\n";
+ $wmc_string .= "\t\t}\n";
+ $wmc_string .= "\t}\n";
+ $wmc_string .= "}\n";
+ $wmc_string .= "\telse {\n";
}
+
+ // add layer
$wmc_string .= "\t" . $target . "wms_add_layer('0','".
$this->wmc_layer_name[$ii] . "','".
$this->wmc_layer_title[$ii] ."','".
@@ -657,64 +682,27 @@
$this->wmc_layer_queryable[$ii] ."','0','0');\n";
if ($action == "merge") {
- $wmc_string .= "}\n";
- $wmc_string .= "else {\n";
-
- // check if this layer already exists in this wms
- $wmc_string .= "\tlayer_exists = false;\n";
- $wmc_string .= "\tcurrent_layer_index = null;\n";
- $wmc_string .= "\tfor (var m=0; m < " . $target . "mb_mapObj[ind].wms[current_wms_index].objLayer.length; m++) {\n";
- $wmc_string .= "\t\tif ('" . $this->wmc_layer_name[$ii] . "' == " . $target . "mb_mapObj[ind].wms[current_wms_index].objLayer[m].layer_name) {\n";
- $wmc_string .= "\t\t\tlayer_exists = true;\n";
- $wmc_string .= "\t\t\tcurrent_layer_index = m;\n";
- $wmc_string .= "\t\t}\n";
- $wmc_string .= "\t}\n";
-
- $wmc_string .= "\tif (!layer_exists) {\n";
- // do nothing (later: add this layer to current wms)
- $wmc_string .= "\t}\n";
- $wmc_string .= "\telse {\n";
-
- // check if the visibility or the queryability are different to the existing layer
- // FIXME: this 'if' may not work
- $wmc_string .= "\t\tif (" . $target . "mb_mapObj[ind].wms[current_wms_index].objLayer[current_layer_index].gui_layer_visible != '" . intval(!$this->wmc_layer_hidden[$ii]) . "'";
- $wmc_string .= " || " . $target . "mb_mapObj[ind].wms[current_wms_index].objLayer[current_layer_index].gui_layer_querylayer != '" . $this->wmc_layer_queryable[$ii] . "') {\n";
-
- // if yes, update the visibility and queryability..
- $wmc_string .= "\t\t\t" . $target . "mb_mapObj[ind].wms[current_wms_index].objLayer[current_layer_index].gui_layer_visible = " . intval(!$this->wmc_layer_hidden[$ii]) . ";\n";
- $wmc_string .= "\t\t\t" . $target . "mb_mapObj[ind].wms[current_wms_index].objLayer[current_layer_index].gui_layer_querylayer = " . $this->wmc_layer_queryable[$ii] . ";\n";
- // ... and check if current wms is in array of wmses that need restating...
- $wmc_string .= "\t\t\twmsAlreadyInArray = false;\n";
-/*
-
- $wmc_string .= "\t\t\tfor (var z=0; z<changedWmsIds.length; z++) {\n";
- // FIXME: this 'if' may not work
- $wmc_string .= "\t\t\t\tif (changedWmsIds[z] == " . $target . "mb_mapObj[ind].wms[current_wms_index].wms_id) {\n";
- $wmc_string .= "\t\t\t\t\twmsAlreadyInArray = true;\n";
- $wmc_string .= "\t\t\t\t}\n";
- $wmc_string .= "\t\t\t}\n";
-
- //...if the layers of the current wms need restating, add them to the array
- $wmc_string .= "\t\t\tif (wmsAlreadyInArray == false) {\n";
- $wmc_string .= "\t\t\t\tchangedWmsIds[changedWmsIds.length] = " . $target . "mb_mapObj[ind].wms[current_wms_index].wms_id;\n";
- $wmc_string .= "\t\t\t}\n";
-*/
- $wmc_string .= "\t\t}\n";
- $wmc_string .= "\t}\n";
- $wmc_string .= "}\n";
+ $wmc_string .= "\t}\n";
}
-
+ // if layer is queryable, add it to querylayerlist
+ if ($this->wmc_layer_queryable[$ii]) {
+ $cnt_query_layers++;
+ if (!in_array($this->wmc_layer_name[$ii], explode(",",$querylayerlist))) {
+ if ($querylayerlist == "") {$querylayerlist = $this->wmc_layer_name[$ii];} else {$querylayerlist .= "," . $this->wmc_layer_name[$ii];}
+ }
+ }
+ // if layer is visible, add it to layerlist
if (intval(!$this->wmc_layer_hidden[$ii]) && !in_array($this->wmc_layer_name[$ii], explode(",",$layerlist))) {
if ($layerlist == "") {$layerlist = $this->wmc_layer_name[$ii];} else {$layerlist .= "," . $this->wmc_layer_name[$ii];}
}
+ // add layer style (FIXME: is this working?)
for($j=0; $j<count($this->wmc_layer_style_name[$ii]);$j++){
$wmc_string .= $target . "wms_addLayerStyle('".$this->wmc_layer_style_name[$ii][$j] ."','".$this->wmc_layer_style_title[$ii][$j] ."','".$j."','".$cnt_layers."', '" . $this->wmc_layer_style_legendurl[$ii][$j] . "', '" . $this->wmc_layer_style_legendurl_format[$ii][$j] . "');\n";
}
}
}
-
// add wms to mapObj with all layers and querylayers
if ($action == "merge") {
$wmc_string .= "if (!wms_exists) {\n";
@@ -723,18 +711,17 @@
if ($action == "merge") {
$wmc_string .= "}\n";
$wmc_string .= "else {\n";
- $wmc_string .= $target. "mb_mapObj[ind].layers[current_wms_index] = \"" . $layerlist . "\";\n";
- $wmc_string .= $target. "mb_mapObj[ind].querylayers[current_wms_index] = \"" . $querylayerlist . "\";\n";
+ $wmc_string .= $target. "mb_mapObj[index].layers[current_wms_index] = \"" . $layerlist . "\";\n";
+ $wmc_string .= $target. "mb_mapObj[index].querylayers[current_wms_index] = \"" . $querylayerlist . "\";\n";
$wmc_string .= "}\n";
}
}
}
$wmc_string .= "var old_mapObj = ".$target."cloneObject(".$target."mb_mapObj);\n";
- $wmc_string .= $target . "mb_mapObj = new Array();\n";
+ $wmc_string .= $target . "deleteMapObj();\n";
$wmc_string .= "for (var i=0; i<old_mapObj.length; i++) {\n";
$wmc_string .= "\tif (old_mapObj[i].frameName != 'overview') {\n";
$wmc_string .= "\t\t" . $target . "mb_registerMapObj(old_mapObj[i].frameName, old_mapObj[i].elementName, null, " . $this->wmc_windowWidth . ", " . $this->wmc_windowHeight . ");\n";
-# $wmc_string .= "alert(".$target . "mb_mapObj[i].extent);";
$wmc_string .= "\t\t" . $target . "document.getElementById(old_mapObj[i].frameName).style.width = " . $this->wmc_windowWidth . ";\n";
$wmc_string .= "\t\t" . $target . "document.getElementById(old_mapObj[i].frameName).style.height = " . $this->wmc_windowHeight . ";\n";
$wmc_string .= "\t}\n";
@@ -742,15 +729,13 @@
$wmc_string .= "\t\t" . $target . "mb_registerMapObj('overview', old_mapObj[i].elementName, 0, old_mapObj[i].width, old_mapObj[i].width);\n";
$wmc_string .= "\t}\n";
$wmc_string .= "}\n";
- $wmc_string .= $target . "mb_execloadWmsSubFunctions();\n";
-// $wmc_string .= $target . "setMapRequest('" . $mapObj . "');\n";
$wmc_string .= "for (var i=0; i<old_mapObj.length; i++) {\n";
$wmc_string .= "\t".$target."mb_calculateExtent(old_mapObj[i].frameName, ";
$wmc_string .= $this->wmc_bBox_minx .",".$this->wmc_bBox_miny .",";
$wmc_string .= $this->wmc_bBox_maxx .",".$this->wmc_bBox_maxy.");\n";
$wmc_string .= "\t". $target . "setMapRequest(old_mapObj[i].frameName);\n";
$wmc_string .= "}\n";
-
+ $wmc_string .= $target . "mb_execloadWmsSubFunctions();\n";
}
return $wmc_string;
}
More information about the Mapbender_commits
mailing list