[Mapbender-commits] r2863 - branches/nimix_dev/http/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Mon Aug 18 10:48:26 EDT 2008
Author: nimix
Date: 2008-08-18 10:48:26 -0400 (Mon, 18 Aug 2008)
New Revision: 2863
Modified:
branches/nimix_dev/http/classes/class_wms.php
Log:
merge
Modified: branches/nimix_dev/http/classes/class_wms.php
===================================================================
--- branches/nimix_dev/http/classes/class_wms.php 2008-08-18 14:47:14 UTC (rev 2862)
+++ branches/nimix_dev/http/classes/class_wms.php 2008-08-18 14:48:26 UTC (rev 2863)
@@ -19,12 +19,12 @@
include_once(dirname(__FILE__)."/../../conf/mapbender.conf");
require_once(dirname(__FILE__)."/class_connector.php");
+require_once(dirname(__FILE__)."/class_user.php");
require_once(dirname(__FILE__)."/class_mb_exception.php");
require_once(dirname(__FILE__)."/class_administration.php");
$con = db_connect(DBSERVER,OWNER,PW);
db_select_db(DB,$con);
-
class wms {
var $lastURL;
@@ -77,7 +77,147 @@
function wms() {
}
-
+
+ function createOlObjFromWMS($base){
+ if(!$this->wms_title || $this->wms_title == ""){
+ echo "alert('Error: no valid capabilities-document !!');";
+ die; exit;
+ }
+ // wms_title and abstract have previously been urlencoded
+ // this solution may not yet be the ultimate one
+
+ $add_wms_string = "var wms_".$this->wms_id." = new OpenLayers.Layer.WMS.Untiled(" .
+ "'" . addslashes($this->wms_title) . "'," .
+ "'" . $this->wms_getmap ."'," ."{layers:'";
+ for($i=1;$i<count($this->objLayer);$i++){
+ $add_wms_string .= addslashes($this->objLayer[$i]->layer_name);
+ if($i!=count($this->objLayer)-1)
+ $add_wms_string .= ",";
+ }
+ $add_wms_string .= "', transparent: 'true'";
+ $add_wms_string .= ",format: '".$this->gui_wms_mapformat."'});\n";
+ if($base)
+ $add_wms_string .= "wms_".$this->wms_id.".isBaseLayer=true;\n";
+ $add_wms_string .= "wms_".$this->wms_id.".setVisibility(".($this->gui_wms_visible=="1"?"true":"false").");\n";
+ $add_wms_string .= "ol_map.addLayer(wms_".$this->wms_id.");\n";
+ echo $add_wms_string;
+ }
+
+ /**
+ * Compares this WMS to another WMS.
+ *
+ * @return boolean false, if
+ * - the capabilities URLs don't match
+ * - the layer count is different
+ * - the layer names are different
+ *
+ * @param $anotherWms wms this is just another WMS object
+ */
+ public function equals ($anotherWms) {
+ // If the getMap URLs are not equal, the WMS are not equal.
+ if ($this->wms_getmap != $anotherWms->wms_getmap) {
+// $e = new mb_notice($this . " != " . $anotherWms . " (getMap URL)");
+ return false;
+ }
+
+ // If the layer count is different, the WMS are not equal.
+ if (count($this->objLayer) != count($anotherWms->objLayer)) {
+// $e = new mb_notice($this . " != " . $anotherWms . " (layer count: " . count($this->objLayer) . ":" . count($anotherWms->objLayer). ")");
+ return false;
+ }
+
+ // If the layer names are different, the WMS are not equal.
+ for ($i = 0; $i < count($this->objLayer); $i++) {
+ $name1 = $this->objLayer[$i]->layer_name;
+ $name2 = $anotherWms->objLayer[$i]->layer_name;
+
+ if ($name1 != $name2) {
+// $e = new mb_notice($this . " != " . $anotherWms . " (layer names, " . $name1 . " vs. " . $name2 . ")");
+ return false;
+ }
+ }
+// $e = new mb_notice($this . " == " . $anotherWms);
+ return true;
+ }
+
+ /**
+ * The other WMS must be the same as this WMS, but with different
+ * application settings. These application settings are copied,
+ * the local settings are overwritten.
+ *
+ * @return boolean true if the settings could be copied; false
+ * when an error occured.
+ * @param $anotherWms wms The same WMS with possibly other settings
+ */
+/*
+ public function copyConfiguration ($anotherWms) {
+ if (!$this->equals($anotherWms)) {
+ $e = new mb_exception("class_wms.php: copyConfiguration(): parameters cannot be copied, it's a different WMS.");
+ return false;
+ }
+ for ($i = 0; $i < count($this->objLayer); $i++) {
+ $myCurrentLayer = $this->objLayer[$i];
+ $theirCurrentLayer = $anotherWms->objLayer[$i];
+
+ $myCurrentLayer->gui_layer_selectable = $theirCurrentLayer->gui_layer_selectable;
+ $myCurrentLayer->gui_layer_visible = $theirCurrentLayer->gui_layer_visible;
+ $myCurrentLayer->gui_layer_queryable = $theirCurrentLayer->gui_layer_queryable;
+ $myCurrentLayer->gui_layer_querylayer = $theirCurrentLayer->gui_layer_querylayer;
+ $myCurrentLayer->gui_layer_style = $theirCurrentLayer->gui_layer_style;
+ }
+ }
+*/
+
+ /**
+ * Removes duplicate WMS from an array of WMS. To find duplicates,
+ * two WMS are compared via equals().
+ *
+ * @return wms[]
+ * @param $wmsArray wms[]
+ */
+ public static function merge ($wmsArray) {
+ $e = new mb_notice("before: " . implode(", ", $wmsArray));
+ if (!is_array($wmsArray)) {
+ $e = new mb_exception("class_wms.php: merge(): parameter is NOT an array.");
+ return array();
+ }
+ if (count($wmsArray) == 0) {
+ $e = new mb_exception("class_wms.php: merge(): parameter is an EMPTY array.");
+ return array();
+ }
+
+ $newWmsArray = array();
+
+ while (count($wmsArray) > 0) {
+ $currentWms = array_pop($wmsArray);
+
+ $isNewWms = true;
+
+ if (get_class($currentWms) != "wms") {
+ $e = new mb_exception("class_wms.php: merge(): current WMS is not a WMS object, but a " . get_class($currentWms));
+ }
+ else {
+ for ($i = 0; $i < count($newWmsArray) && $isNewWms; $i++) {
+ if ($currentWms->equals($newWmsArray[$i])) {
+ $isNewWms = false;
+ }
+ }
+ if ($isNewWms) {
+// $e = new mb_notice("adding WMS " . $currentWms);
+ array_push($newWmsArray, $currentWms);
+ }
+ }
+ }
+ // reversal of the array, because the elements were popped
+ // from another array before.
+// $e = new mb_notice("after: " . implode(", ", array_reverse($newWmsArray)));
+ return array_reverse($newWmsArray);
+ }
+
+ public function __toString () {
+ return $this->wms_title;
+ }
+
function createObjFromXML($url, $cert = "", $pass = ""){
$x = new connector();
@@ -691,13 +831,80 @@
function stripEndlineAndCarriageReturn($string) {
return preg_replace("/\n/", "", preg_replace("/\r/", " ", $string));
}
- function createJsObjFromWMS($parent=0){
+ function createJsObjFromWMS($parent=0){
+ echo $this->createJsObjFromWMS_($parent);
+ }
+
+
+ function newLayer ($currentLayer, $currentExtent) {
+ $pos = $currentLayer["extension"]["LAYER_POS"];
+ $parent = $currentLayer["extension"]["LAYER_PARENT"];
+ $this->addLayer($pos, $parent);
+
+ // set layer data
+ $layerIndex = count($this->objLayer) - 1;
+ $newLayer = $this->objLayer[$layerIndex];
+ $newLayer->layer_uid = $currentLayer["extension"]["LAYER_ID"];
+ $newLayer->layer_name = $currentLayer["name"];
+ $newLayer->layer_title = $currentLayer["title"];
+ $newLayer->layer_dataurl_href = $currentLayer["dataurl"];
+ $newLayer->layer_pos = $currentLayer["extension"]["LAYER_POS"];
+ $newLayer->layer_queryable = $currentLayer["queryable"];
+ $newLayer->layer_minscale = $currentLayer["extension"]["MINSCALE"];
+ $newLayer->layer_maxscale = $currentLayer["extension"]["MAXSCALE"];
+ $newLayer->layer_metadataurl = $currentLayer["metadataurl"];
+ $newLayer->gui_layer_wms_id = $currentLayer["extension"]["WMS_LAYER_ID"];
+ $newLayer->gui_layer_status = $currentLayer["extension"]["GUI_STATUS"];
+ $newLayer->gui_layer_style = ""; // TODO: Add correct data
+ $newLayer->gui_layer_selectable = $currentLayer["extension"]["GUI_SELECTABLE"];
+ $newLayer->gui_layer_visible = $currentLayer["visible"];
+ $newLayer->gui_layer_queryable = $currentLayer["extension"]["GUI_QUERYABLE"];
+ $newLayer->gui_layer_querylayer = $currentLayer["extension"]["QUERYLAYER"];
+ $newLayer->gui_layer_minscale = $currentLayer["extension"]["GUI_MINSCALE"];
+ $newLayer->gui_layer_maxscale = $currentLayer["extension"]["GUI_MAXSCALE"];
+ if (isset($currentLayer["extension"]["WFSFEATURETYPE"])) {
+ $newLayer->gui_layer_wfs_featuretype = $currentLayer["extension"]["WFSFEATURETYPE"];
+ }
+ $newLayer->layer_abstract = $currentLayer["abstract"];
+
+
+ //
+ // set layer epsg
+ //
+ $newLayer->layer_epsg = array();
+ if ($currentExtent !== null) {
+ $currentLayerEpsg = array();
+ $currentLayerEpsg["epsg"] = $currentExtent->epsg;
+ $currentLayerEpsg["minx"] = $currentExtent->min->x;
+ $currentLayerEpsg["miny"] = $currentExtent->min->y;
+ $currentLayerEpsg["maxx"] = $currentExtent->max->x;
+ $currentLayerEpsg["maxy"] = $currentExtent->max->y;
+ array_push($newLayer->layer_epsg, $currentLayerEpsg);
+ }
+
+
+ //
+ // set layer style
+ //
+ for ($i = 0; $i < count($currentLayer["format"]); $i++) {
+ $layerStyleIndex = count($newLayer->gui_layer_style) - 1;
+ $newLayer->layer_style[$layerStyleIndex] = array();
+ $currentStyle = $newLayer->layer_style[$layerStyleIndex];
+ $currentStyle["name"] = $currentLayer["style"][$i]["name"];
+ $currentStyle["title"] = $currentLayer["style"][$i]["title"];
+ $currentStyle["legendurl"] = $currentLayer["style"][$i]["legendurl"];
+ $currentStyle["legendurl_format"] = $currentLayer["style"][$i]["legendurl_type"];
+ }
+ }
+
+ function createJsObjFromWMS_($parent=0){
+ $str = "";
if(!$this->wms_title || $this->wms_title == ""){
- echo "alert('Error: no valid capabilities-document !!');";
+ $str .= "alert('Error: no valid capabilities-document !!');";
die; exit;
}
if($parent){
- echo "parent.";
+ $str .= "parent.";
}
// wms_title and abstract have previously been urlencoded
// this solution may not yet be the ultimate one
@@ -719,19 +926,19 @@
"'" . $this->gui_wms_opacity ."'," .
"'" . $this->gui_wms_sldurl ."" .
"');";
- echo $add_wms_string;
+ $str .= $add_wms_string;
for($i=0;$i<count($this->data_format);$i++){
if($parent){
- echo "parent.";
+ $str .= "parent.";
}
- echo "wms_add_data_type_format('". $this->data_type[$i] ."','". $this->data_format[$i] ."');\n";
+ $str .= "wms_add_data_type_format('". $this->data_type[$i] ."','". $this->data_format[$i] ."');\n";
}
for($i=0; $i<count($this->objLayer); $i++){
if($parent){
- echo "parent.";
+ $str .= "parent.";
}
- print ("wms_add_layer('".
+ $str .= "wms_add_layer('".
$this->objLayer[$i]->layer_parent ."','".
$this->objLayer[$i]->layer_uid ."','".
addslashes($this->objLayer[$i]->layer_name) . "','".
@@ -751,37 +958,43 @@
$this->objLayer[$i]->gui_layer_querylayer ."','".
$this->objLayer[$i]->gui_layer_minscale ."','".
$this->objLayer[$i]->gui_layer_maxscale ."','".
- $this->objLayer[$i]->gui_layer_wfs_featuretype ."');\n");
+ $this->objLayer[$i]->gui_layer_wfs_featuretype ."');\n";
for($j=0; $j<count($this->objLayer[$i]->layer_epsg);$j++){
if($i==0){
if($parent){
- echo "parent.";
+ $str .= "parent.";
}
- print("wms_addSRS('".
+ $str .= "wms_addSRS('".
$this->objLayer[$i]->layer_epsg[$j]["epsg"] ."','".
$this->objLayer[$i]->layer_epsg[$j]["minx"] ."','".
$this->objLayer[$i]->layer_epsg[$j]["miny"] ."','".
$this->objLayer[$i]->layer_epsg[$j]["maxx"] ."','".
- $this->objLayer[$i]->layer_epsg[$j]["maxy"] ."');\n");
+ $this->objLayer[$i]->layer_epsg[$j]["maxy"] ."');\n";
}
if($parent){
- echo "parent.";
+ $str .= "parent.";
}
- print("layer_addEpsg('".
+ $str .= "layer_addEpsg('".
$this->objLayer[$i]->layer_epsg[$j]["epsg"] ."','".
$this->objLayer[$i]->layer_epsg[$j]["minx"] ."','".
$this->objLayer[$i]->layer_epsg[$j]["miny"] ."','".
$this->objLayer[$i]->layer_epsg[$j]["maxx"] ."','".
- $this->objLayer[$i]->layer_epsg[$j]["maxy"] ."');\n");
+ $this->objLayer[$i]->layer_epsg[$j]["maxy"] ."');\n";
}
for($j=0; $j<count($this->objLayer[$i]->layer_style);$j++){
if($parent){
- echo "parent.";
+ $str .= "parent.";
}
- print("wms_addLayerStyle('".$this->objLayer[$i]->layer_style[$j]["name"]."', '".$this->objLayer[$i]->layer_style[$j]["title"]."', ".$j.",".$i.",'".$this->objLayer[$i]->layer_style[$j]["legendurl"]."', '".$this->objLayer[$i]->layer_style[$j]["legendformat"]."');\n");
+ $str .= "wms_addLayerStyle('".$this->objLayer[$i]->layer_style[$j]["name"].
+ "', '".$this->objLayer[$i]->layer_style[$j]["title"].
+ "', ".$j.
+ ",".$i.
+ ",'".$this->objLayer[$i]->layer_style[$j]["legendurl"].
+ "', '".$this->objLayer[$i]->layer_style[$j]["legendformat"]."');\n";
}
}
+ return $str;
}
function createJsLayerObjFromWMS($parent=0, $layer_name){
@@ -1720,6 +1933,141 @@
/** end createObjfromDB **/
/**
+ * creatObjfromDBNoGui
+ *
+ */
+ function createObjFromDBNoGui($wms_id){
+
+ $sql = "Select * from wms where wms_id = $1 ";
+ $v = array($wms_id);
+ $t = array('i');
+ $res_wms = db_prep_query($sql,$v,$t);
+ $count_wms=0;
+ while($row2 = db_fetch_array($res_wms)){
+ $this->wms_id = $row2["wms_id"];
+ $this->wms_version = $row2["wms_version"];
+ $this->wms_title = $this->stripEndlineAndCarriageReturn($row2["wms_title"]);
+ $this->wms_abstract = $this->stripEndlineAndCarriageReturn($row2["wms_abstract"]);
+ $wmsowsproxy = $row2["wms_owsproxy"];
+ #$wmsowsproxy = "test";
+ if($wmsowsproxy != ""){
+ $owsproxyurl = OWSPROXY."/".session_id()."/".$wmsowsproxy."?";
+ $this->wms_getmap = $owsproxyurl;
+ $this->wms_getcapabilities = $owsproxyurl;
+ $this->wms_getfeatureinfo = $owsproxyurl;
+ $this->wms_getlegendurl = $owsproxyurl;
+ }
+ else{
+ $this->wms_getmap = $row2["wms_getmap"];
+ $this->wms_getcapabilities = $row2["wms_getcapabilities"];
+ $this->wms_getfeatureinfo = $row2["wms_getfeatureinfo"];
+ $this->wms_getlegendurl = $row2["wms_getlegendurl"];
+ }
+ $this->wms_getcapabilities_doc = $row2["wms_getcapabilities_doc"];
+ $this->wms_filter = $row2["wms_filter"];
+ $this->wms_supportsld = $row2["wms_supportsld"];
+ $this->wms_userlayer = $row2["wms_userlayer"];
+ $this->wms_userstyle = $row2["wms_userstyle"];
+ $this->wms_remotewfs = $row2["wms_remotewfs"];
+
+ #some default
+ $this->gui_wms_visible = 1;
+ $this->gui_wms_opacity = 100;
+ $this->gui_wms_epsg=$row["gui_wms_epsg"];
+ $this->gui_wms_sldurl = $row["gui_wms_sldurl"];
+
+ $count_wms++;
+ }
+
+ ### formats
+ $sql = "SELECT * FROM wms_format WHERE fkey_wms_id = $1 ";
+ $v = array($wms_id);
+ $t = array('i');
+ $res_wms = db_prep_query($sql,$v,$t);
+ $count_format=0;
+ while($row3 = db_fetch_array($res_wms)){
+ $this->data_type[$count_format] = $row3["data_type"];
+ $this->data_format[$count_format] = $row3["data_format"];
+ $count_format++;
+ }
+
+
+ $sql = "Select * from layer where fkey_wms_id = $1";
+ $v = array($wms_id);
+ $t = array('i');
+ $res_layer = db_prep_query($sql,$v,$t);
+ $count_layer=0;
+ while($row2 = db_fetch_array($res_layer)){
+ $this->addLayer($row2["layer_pos"],$row2["layer_parent"]);
+ $layer_cnt=count($this->objLayer)-1;
+ $this->objLayer[$layer_cnt]->layer_uid = $row2["layer_id"];
+ $this->objLayer[$layer_cnt]->layer_name =$row2["layer_name"];
+ $this->objLayer[$layer_cnt]->layer_title =$row2["layer_title"];
+ $this->objLayer[$layer_cnt]->layer_dataurl_href =$row2["layer_dataurl"];
+ $this->objLayer[$layer_cnt]->layer_metadataurl =$row2["layer_metadataurl"];
+ $this->objLayer[$layer_cnt]->layer_pos =$row2["layer_pos"];
+ $this->objLayer[$layer_cnt]->layer_queryable =$row2["layer_pos"];
+ $this->objLayer[$layer_cnt]->layer_queryable =$row2["layer_queryable"];
+ $this->objLayer[$layer_cnt]->layer_minscale =$row2["layer_minscale"];
+ $this->objLayer[$layer_cnt]->layer_maxscale = $row2["layer_maxscale"];
+
+ if($this->objLayer[$layer_cnt]->layer_minscale == ""){
+ $this->objLayer[$layer_cnt]->layer_minscale = 0;
+ }
+ if($this->objLayer[$layer_cnt]->layer_maxscale == ""){
+ $this->objLayer[$layer_cnt]->layer_maxscale = 0;
+ }
+ $this->objLayer[$layer_cnt]->gui_layer_minscale = $this->objLayer[$layer_cnt]->layer_minscale;
+ $this->objLayer[$layer_cnt]->gui_layer_maxscale = $this->objLayer[$layer_cnt]->layer_maxscale;
+
+ $sql = "Select * from layer_epsg where fkey_layer_id = $1 ORDER BY fkey_layer_id";
+ $v = array($this->objLayer[$layer_cnt]->layer_uid);
+ $t = array('i');
+ $res_layer_epsg = db_prep_query($sql,$v,$t);
+
+ $count_layer_epsg=0;
+ while($row2 = db_fetch_array($res_layer_epsg)){
+ $this->objLayer[$layer_cnt]->layer_epsg[$count_layer_epsg]["epsg"]=$row2["epsg"];
+ $this->objLayer[$layer_cnt]->layer_epsg[$count_layer_epsg]["minx"]=$row2["minx"];
+ $this->objLayer[$layer_cnt]->layer_epsg[$count_layer_epsg]["miny"]=$row2["miny"];
+ $this->objLayer[$layer_cnt]->layer_epsg[$count_layer_epsg]["maxx"]=$row2["maxx"];
+ $this->objLayer[$layer_cnt]->layer_epsg[$count_layer_epsg]["maxy"]=$row2["maxy"];
+ $count_layer_epsg++;
+ }
+
+ ### handle styles
+ $sql = "SELECT * FROM layer_style WHERE fkey_layer_id = $1 ";
+ $v = array($this->objLayer[$layer_cnt]->layer_uid);
+ $t = array('i');
+ $res_style = db_prep_query($sql,$v,$t);
+ $count_layer_style = 0;
+ while($row2 = db_fetch_array($res_style)){
+ $this->objLayer[$layer_cnt]->layer_style[$count_layer_style]["name"]=$row2["name"];
+ $this->objLayer[$layer_cnt]->layer_style[$count_layer_style]["title"]=$row2["title"];
+ if($wmsowsproxy != ""){
+ if($row2["legendurl"]!=''){
+ $this->objLayer[$layer_cnt]->layer_style[$count_layer_style]["legendurl"]=$owsproxyurl.
+ "REQUEST=getlegendgraphic&VERSION=".$this->wms_version."&LAYER=".$this->objLayer[$layer_cnt]->layer_name."&FORMAT=".$row2["legendurlformat"].
+ "&STYLE=".$row2["name"];
+ }
+ }
+ else{
+ if($row2["legendurl"]!=''){
+ $this->objLayer[$layer_cnt]->layer_style[$count_layer_style]["legendurl"]=$row2["legendurl"];
+ #$e = new mb_exception("legendurl = ".$this->objLayer[$layer_cnt]->layer_style[$count_layer_style]["legendurl"]);
+ }
+ }
+ $this->objLayer[$layer_cnt]->layer_style[$count_layer_style]["legendurlformat"]=$row2["legendurlformat"];
+ $count_layer_style++;
+ }
+
+ $count_layer++;
+ }
+
+ }
+ /** end createObjfromDBNoGui **/
+
+ /**
* function checkObjExistsInDB()
*
* this function checks wether the onlineresource already exists in the database.
@@ -1786,10 +2134,45 @@
if($this->wms_getcapabilities == '' || $this->wms_getmap == '' ){
echo "<br>Missing parameters: <br>";
$this->displayWMS();
- echo "<br> Data not commited<br>";
+ print_r($this);
+ echo "<br> Data not committed<br>";
die();
}
}
+
+ /**
+ * Selects all WMS of the current user from the database.
+ * Then it creates the corresponding WMS object and returns
+ * these objects as an array.
+ *
+ * @return wms[]
+ * @param $appId String
+ */
+ public static function selectMyWmsByApplication ($appId) {
+ // check if user is permitted to access the application
+ $currentUser = new User($_SESSION["mb_user_id"]);
+ $appArray = $currentUser->getApplicationsByPermission(false);
+ if (!in_array($appId, $appArray)) {
+ $e = new mb_warning("class_wms.php: selectMyWmsByApplication(): User '" . $currentUser . "' is not allowed to acces application '" . $appId . "'.");
+ return array();
+ }
+
+ // get WMS of this application
+ $sql = "SELECT fkey_wms_id FROM gui_wms WHERE " .
+ "fkey_gui_id = $1 ORDER BY gui_wms_position";
+ $v = array($appId);
+ $t = array('s');
+ $res = db_prep_query($sql,$v,$t);
+
+ // instantiate PHP objects and store in array
+ $wmsArray = array();
+ while ($row = db_fetch_array($res)) {
+ $currentWms = new wms();
+ $currentWms->createObjFromDB($appId, $row["fkey_wms_id"]);
+ array_push($wmsArray, $currentWms);
+ }
+ return $wmsArray;
+ }
}
class layer extends wms {
var $layer_id;
@@ -1820,5 +2203,11 @@
$this->layer_parent = $parent;
//var_dump($this);
}
+
+ public function __toString () {
+ $e = new mb_exception("TITLE: " . $this->layer_title);
+ return $this->layer_title;
+ }
+
}
?>
\ No newline at end of file
More information about the Mapbender_commits
mailing list