[Mapbender-commits] r2861 - branches/nimix_dev/http/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Mon Aug 18 10:45:42 EDT 2008
Author: nimix
Date: 2008-08-18 10:45:42 -0400 (Mon, 18 Aug 2008)
New Revision: 2861
Added:
branches/nimix_dev/http/classes/class_element.php
branches/nimix_dev/http/classes/class_map.php
Modified:
branches/nimix_dev/http/classes/class_administration.php
branches/nimix_dev/http/classes/class_bbox.php
branches/nimix_dev/http/classes/class_gml2.php
branches/nimix_dev/http/classes/class_gui.php
branches/nimix_dev/http/classes/class_locale.php
Log:
merge
Modified: branches/nimix_dev/http/classes/class_administration.php
===================================================================
--- branches/nimix_dev/http/classes/class_administration.php 2008-08-18 14:44:53 UTC (rev 2860)
+++ branches/nimix_dev/http/classes/class_administration.php 2008-08-18 14:45:42 UTC (rev 2861)
@@ -18,6 +18,7 @@
require_once(dirname(__FILE__)."/../../conf/mapbender.conf");
require_once(dirname(__FILE__)."/class_mb_exception.php");
+
$con = db_connect(DBSERVER,OWNER,PW);
db_select_db(DB,$con);
@@ -27,8 +28,8 @@
* class to wrap administration methods
*
* @uses phpmailer
- */
-class administration{
+ */
+class administration {
/**
* authentificates a user
* @param string name of the user
@@ -150,6 +151,54 @@
}
}
+ /**
+ * Removes the namespace from a tag name
+ * @return String like "gml"
+ * @param $s String like "ogc:gml"
+ */
+ public static function sepNameSpace($s) {
+ $c = strpos($s,":");
+ if ($c > 0) {
+ return substr($s,$c+1);
+ }
+ return $s;
+ }
+
+ /**
+ * Parses an XML with PHP XML parser, see
+ * http://de2.php.net/manual/de/book.xml.php
+ *
+ * @return Array an associative array of tags, values, attributes and types
+ * @param $someXml String The actual XML as string.
+ */
+ public static function parseXml ($someXml) {
+ $values = null;
+ $tags = null;
+
+ $parser = xml_parser_create(CHARSET);
+
+ // set parsing options
+ xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
+ xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
+ xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, CHARSET);
+
+ // this is the actual parsing process
+ xml_parse_into_struct($parser, $someXml, $values, $tags);
+
+ // check if an error occured
+ $code = xml_get_error_code ($parser);
+ if ($code) {
+ // report error
+ $line = xml_get_current_line_number($parser);
+ $errorMessage = xml_error_string($code) . " in line " . $line;
+ $mb_exception = new mb_exception($errorMessage);
+ return false;
+ }
+ xml_parser_free($parser);
+
+ return $values;
+ }
+
/**
* returns a random password with numbers and chars both lowercase and uppercase (0-9a-zA-Z)
*
@@ -387,19 +436,13 @@
* @param string the wmc_id
* @return boolean Did the query run succesfull? This does not necessarily mean that
* an entry was deleted.
+ * @deprecated
*/
function deleteWmc($wmc_id, $user_id){
- $sql = "DELETE FROM mb_user_wmc ";
- $sql .= "WHERE fkey_user_id = $1 AND wmc_id = $2";
- $v = array($user_id,$wmc_id);
- $t = array('i','s');
- $res = db_prep_query($sql,$v,$t);
- if ($res) {
- return true;
- }
- else {
- return false;
- }
+ $e = new mb_notice("administration->deleteWmc is deprecated, use wmc->delete instead!");
+
+ $wmc = new wmc();
+ return $wmc->delete($wmc_id, $user_id);
}
/**
@@ -558,19 +601,13 @@
*
* @param integer the wms id
* @return string|boolean either the wmc as string or false when none exists
+ * @deprecated
*/
function getWmcById($id){
- $sql = "SELECT wmc FROM mb_user_wmc WHERE wmc_id = $1 ";
- $v = array($id);
- $t = array('s');
- $res = db_prep_query($sql,$v,$t);
- $row = db_fetch_array($res);
- if ($row) {
- return $row["wmc"];
- }
- else {
- return false;
- }
+ $e = new mb_notice("administration->getWmcById is deprecated, use wmc->getDocument instead!");
+
+ $wmc = new wmc();
+ return $wmc->getDocument($id);
}
/**
@@ -659,19 +696,14 @@
return $arrayGuis;
}
+ /**
+ * @deprecated
+ */
function getWmcByOwner($user_id){
- $sql_wmc = "SELECT wmc_id FROM mb_user_wmc ";
- $sql_wmc .= "WHERE fkey_user_id = $1 GROUP BY wmc_id";
- $v = array($user_id);
- $t = array('i');
- $res_wmc = db_prep_query($sql_wmc,$v,$t);
- $count_g = 0;
- $arrayWmc = array();
- while($row = db_fetch_array($res_wmc)){
- $arrayWmc[$count_g] = $row["wmc_id"];
- $count_g++;
- }
- return $arrayWmc;
+ $e = new mb_notice("administration->getWmcByOwner is deprecated, use user->getWmcByOwner instead!");
+
+ $user = new User($user_id);
+ return $user->getWmcByOwner();
}
function getGuisByPermission($mb_user_id,$ignoreublic){
Modified: branches/nimix_dev/http/classes/class_bbox.php
===================================================================
--- branches/nimix_dev/http/classes/class_bbox.php 2008-08-18 14:44:53 UTC (rev 2860)
+++ branches/nimix_dev/http/classes/class_bbox.php 2008-08-18 14:45:42 UTC (rev 2861)
@@ -19,6 +19,7 @@
require_once(dirname(__FILE__)."/../../conf/mapbender.conf");
require_once(dirname(__FILE__)."/../classes/class_mb_exception.php");
+require_once(dirname(__FILE__)."/../classes/class_point.php");
$con = db_connect(DBSERVER,OWNER,PW);
db_select_db(DB,$con);
@@ -146,6 +147,10 @@
return false;
}
+ function toHtml () {
+ return (string) $this->min->toHtml() . " | " . $this->max->toHtml();
+ }
+
function __toString() {
return (string) "[" . $this->min . $this->max . " " . $this->epsg . "]";
}
Copied: branches/nimix_dev/http/classes/class_element.php (from rev 2653, trunk/mapbender/http/classes/class_element.php)
===================================================================
--- branches/nimix_dev/http/classes/class_element.php (rev 0)
+++ branches/nimix_dev/http/classes/class_element.php 2008-08-18 14:45:42 UTC (rev 2861)
@@ -0,0 +1,240 @@
+<?php
+# $Id: class_bbox.php 1965 2008-01-15 08:24:29Z christoph $
+# http://www.mapbender.org/index.php/
+# Copyright (C) 2002 CCGIS
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+
+define("ELEMENT_PATTERN", "/sessionID/");
+
+class Element {
+
+ var $guiId;
+ var $id;
+ var $pos;
+ var $isPublic;
+ var $comment;
+ var $title;
+ var $element;
+ var $src;
+ var $attributes;
+ var $left;
+ var $top;
+ var $width;
+ var $height;
+ var $zIndex;
+ var $moreStyles;
+ var $content;
+ var $closeTag;
+ var $jsFile;
+ var $mbMod;
+ var $target;
+ var $requires;
+ var $helpUrl;
+
+ public function __contruct() {
+
+ }
+
+ public function select ($id, $applicationId) {
+ $sql = "SELECT fkey_gui_id, e_id, e_pos, e_public, e_comment, e_public, ".
+ "gettext($1, e_title) as e_title, e_element, e_src, e_attributes, " .
+ "e_left, e_top, e_width, e_height, e_z_index, e_more_styles, " .
+ "e_content, e_closetag, e_js_file, e_mb_mod, e_target, " .
+ "e_requires, e_url FROM gui_element WHERE e_id = $2 AND " .
+ "fkey_gui_id = $3 LIMIT 1";
+ $v = array ($_SESSION["mb_lang"], $id, $applicationId);
+ $t = array ("s", "s", "s");
+ $res = db_prep_query($sql, $v, $t);
+ $row = db_fetch_array($res);
+ if ($row) {
+ $this->guiId = $applicationId;
+ $this->id = $row["e_id"];
+ $this->pos = $row["e_pos"];
+ $this->isPublic = $row["e_public"];
+ $this->comment = $row["e_comment"];
+ $this->title = $row["e_title"];
+ $this->element = $row["e_element"];
+ $this->src = $row["e_src"];
+ $this->attributes = $row["e_attributes"];
+ $this->left = $row["e_left"];
+ $this->top = $row["e_top"];
+ $this->width = $row["e_width"];
+ $this->height = $row["e_height"];
+ $this->zIndex = $row["e_z_index"];
+ $this->moreStyles = $row["e_more_styles"];
+ $this->content = $row["e_content"];
+ $this->closeTag = $row["e_closetag"];
+ $this->jsFile = $row["e_js_file"];
+ $this->mbMod = $row["e_mb_mod"];
+ $this->target = $row["e_target"];
+ $this->requires = $row["e_requires"];
+ $this->helpUrl = $row["e_url"];
+ return true;
+ }
+ return false;
+ }
+
+ public function __toString () {
+ return $this->toHtml();
+ }
+
+ public function getJavaScriptModules () {
+ $jsArray = array();
+ if ($this->mbMod != "") {
+ $moduleArray = explode(",", $this->mbMod);
+ for ($i = 0; $i < count($moduleArray); $i++) {
+ $currentFile = dirname(__FILE__) . "/../javascripts/" . trim($moduleArray[$i]);
+ if (file_exists($currentFile)) {
+ array_push($jsArray, $currentFile);
+ }
+ else {
+ $e = new mb_exception("Javascript module not found: " . $currentFile);
+ }
+ }
+ }
+ return $jsArray;
+ }
+
+ public function toHtmlArray () {
+ if ($this->isPublic) {
+ return array($this->getHtmlOpenTag(), $this->getHtmlContent(), $this->getHtmlCloseTag());
+ }
+ return array("", "", "");
+ }
+
+ public function toHtml () {
+ if ($this->isPublic) {
+ return implode("", $this->toHtmlArray());
+ }
+ return "";
+ }
+
+ private function getHtmlOpenTag () {
+ $openTag = "";
+
+ if ($this->id) {
+ // tag name
+ $openTag .= "<" . $this->element . " ";
+
+ // id and name
+ $openTag .= "id='" . $this->id . "' name='" . $this->id . "' ";
+
+ // attributes
+ if ($this->attributes) {
+ $openTag .= stripslashes($this->replaceSessionStringByUrlParameters($this->attributes)) . " ";
+ }
+
+ // title
+ if ($this->title) {
+ $openTag .= "title='" . $this->title . "' ";
+ }
+
+ // src
+ if ($this->src) {
+ $openTag .= "src = '" . $this->replaceSessionStringByUrlParameters($this->src);
+
+ // for iframes which are not "loadData",
+ // add additional parameters
+ if ($this->closeTag == "iframe" && $this->id != "loadData") {
+ if(mb_strpos($this->src, "?")) {
+ $openTag .= "&";
+ }
+ else {
+ $openTag .= "?";
+ }
+ $openTag .= "e_id_css=" . $this->id . "&" .
+ "e_id= " . $this->id . "&" .
+ "e_target=" . $this->target . "&" .
+ $this->getUrlParameters();
+ }
+ $openTag .= "' ";
+ }
+
+ // style
+ $openTag .= " style = '";
+ if ($this->top != "" && $this->left != "") {
+ $openTag .= "position:absolute;" .
+ "left:" . $this->left . ";" .
+ "top:" . $this->top . ";";
+ }
+ if ($this->width != "" && $this->height != "") {
+ $openTag .= "width:" . $this->width . ";" .
+ "height:" . $this->height . ";";
+ }
+ if ($this->zIndex) {
+ $openTag .= "z-index:" . $this->zIndex . ";";
+ }
+ if ($this->moreStyles) {
+ $openTag .= $this->moreStyles;
+ }
+ $openTag .= "'>";
+
+ if ($this->element == "body" && USE_LOAD_MESSAGE) {
+ $htmlWhileLoading = "<img src='../img/indicator_wheel.gif'> " .
+ "<b>Ma<font color='#0000CE'>p</font><font color='#C00000'>b</font>ender " .
+ MB_VERSION_NUMBER . " " . strtolower(MB_VERSION_APPENDIX) . "</b>..." .
+ "loading application '" . $this->guiId . "'";
+
+ $openTag .= "<div id='loading_mapbender' " .
+ "style='position:absolute;top:100;left:100'>" .
+ $htmlWhileLoading . "</div>" .
+ "<div id='complete_mapbender' " .
+ "style='display:none'>";
+ }
+ }
+ return $openTag;
+ }
+
+ private function getHtmlContent () {
+ $htmlContent = "";
+ if ($this->content != "") {
+ $htmlContent .= stripslashes($this->content);
+ }
+ return $htmlContent;
+ }
+
+ private function getHtmlCloseTag () {
+ if ($this->element == "body" && USE_LOAD_MESSAGE) {
+ return "</div></body>";
+ }
+ if ($this->closeTag != "") {
+ return "</" . $this->closeTag . ">";
+ }
+ return "";
+ }
+
+ private function getUrlParameters () {
+ $urlParameters = SID;
+ if (isset($this->guiId)) {
+ $urlParameters .= "&guiID=" . $this->guiId;
+ }
+ if (isset($this->id)) {
+ $urlParameters .= "&elementID=" . $this->id;
+ }
+ return $urlParameters;
+ }
+
+ private function replaceSessionStringByUrlParameters ($string) {
+ $urlParameters = $this->getUrlParameters();
+ return preg_replace(ELEMENT_PATTERN, $urlParameters, $string);
+ }
+
+}
+
+
+?>
\ No newline at end of file
Modified: branches/nimix_dev/http/classes/class_gml2.php
===================================================================
--- branches/nimix_dev/http/classes/class_gml2.php 2008-08-18 14:44:53 UTC (rev 2860)
+++ branches/nimix_dev/http/classes/class_gml2.php 2008-08-18 14:45:42 UTC (rev 2861)
@@ -16,10 +16,10 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-require_once("class_mb_exception.php");
-require_once("class_connector.php");
-require_once("../extensions/JSON.php");
-require_once("../../conf/mapbender.conf");
+require_once(dirname(__FILE__)."/../classes/class_mb_exception.php");
+require_once(dirname(__FILE__)."/../classes/class_connector.php");
+require_once(dirname(__FILE__)."/../classes/class_json.php");
+require_once(dirname(__FILE__)."/../../conf/mapbender.conf");
class gml2 {
var $geomtype_point = 'Point';
var $geomtype_polygon = 'Polygon';
@@ -196,7 +196,7 @@
xml_parser_free($parser);
foreach ($values as $element) {
- $e = new mb_exception($element[tag]);
+ #$e = new mb_exception($element[tag]);
if(strtoupper($this->sepNameSpace($element[tag])) == strtoupper("boundedBy") && $element[type] == "open"){
$boundedBy = true;
}
@@ -427,6 +427,49 @@
return $nodeName;
}
+ /**
+ * Parses the feature segment of a GML and stores the geometry in the
+ * $geometry variable of the class.
+ *
+ * Example of a feature segment of a GML.
+ * <gml:featureMember>
+ * <ms:ROUTE fid="ROUTE.228168">
+ * <gml:boundedBy>
+ * <gml:Box srsName="EPSG:31466">
+ * <gml:coordinates>2557381.0,5562371.1 2557653.7,5562526.0</gml:coordinates>
+ * </gml:Box>
+ * </gml:boundedBy>
+ * <ms:geometry>
+ * <gml:LineString>
+ * <gml:coordinates>
+ * 2557380.97,5562526 2557390.96,
+ * 5562523.22 2557404.03,5562518.2 2557422.31,
+ * 5562512 2557437.16,5562508.37 2557441.79,
+ * 5562507.49 2557454.31,5562505.1 2557464.27,
+ * 5562503.97 2557473.24,5562502.97 2557491.67,
+ * 5562502.12 2557505.65,5562502.43 2557513.78,
+ * 5562501.12 2557520.89,5562498.79 2557528.5,
+ * 5562495.07 2557538.9,5562488.91 2557549.5,
+ * 5562483.83 2557558.55,5562476.61 2557569.07,
+ * 5562469.82 2557576.61,5562462.72 2557582.75,
+ * 5562457.92 2557588.57,5562452.56 2557590.38,
+ * 5562449.69 2557593.57,5562445.07 2557596.17,
+ * 5562441.31 2557601.71,5562433.93 2557612.97,
+ * 5562421.03 2557626,5562405.33 2557639.66,
+ * 5562389.75 2557653.69,5562371.12
+ * </gml:coordinates>
+ * </gml:LineString>
+ * </ms:geometry>
+ * <code>354</code>
+ * <Verkehr>0</Verkehr>
+ * <rlp>t</rlp>
+ * </ms:ROUTE>
+ * </gml:featureMember>
+ *
+ * @return void
+ * @param $domNode DOMNodeObject the feature tag of the GML
+ * (<gml:featureMember> in the above example)
+ */
public function parse($domNode) {
$currentSibling = $domNode->firstChild;
@@ -443,10 +486,14 @@
$ns = $namespace['ns'];
$columnName = $namespace['value'];
- if ($name==$ns.":the_geom"){
+ // check if this node is a geometry node.
+ // however, even if it is a property node,
+ // it has a child node, the text node!
+ // So we might need to do something more
+ // sophisticated here...
+ if ($currentSibling->hasChildNodes()){
$geomNode = $currentSibling->firstChild;
$geomType = $geomNode->nodeName;
-// echo "geomtype: " . $geomType . "<br>";
switch ($geomType) {
case "gml:Polygon" :
$this->geometry = new GMLPolygon();
@@ -459,20 +506,21 @@
case "gml:Point" :
$this->geometry = new GMLPoint();
$this->geometry->parsePoint($geomNode);
-# $this->properties["Mapbender:icon"] = "../img/sy_star.png";
break;
case "gml:MultiLineString" :
$this->geometry = new GMLMultiLine();
$this->geometry->parseMultiLine($geomNode);
-// $this->properties["Mapbender:icon"] = "../img/sy_star.png";
break;
case "gml:MultiPolygon" :
$this->geometry = new GMLMultiPolygon();
$this->geometry->parseMultiPolygon($geomNode);
-// $this->properties["Mapbender:icon"] = "../img/sy_star.png";
break;
+ default:
+ $this->properties[$columnName] = $value;
+ break;
}
- } else {
+ }
+ else {
$this->properties[$columnName] = $value;
}
@@ -500,7 +548,7 @@
$cnt ++;
}
- $json = new Services_JSON();
+ $json = new Mapbender_JSON();
$str .= $json->encode($prop);
$str .= "}";
Modified: branches/nimix_dev/http/classes/class_gui.php
===================================================================
--- branches/nimix_dev/http/classes/class_gui.php 2008-08-18 14:44:53 UTC (rev 2860)
+++ branches/nimix_dev/http/classes/class_gui.php 2008-08-18 14:45:42 UTC (rev 2861)
@@ -18,6 +18,7 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
require_once(dirname(__FILE__)."/../../conf/mapbender.conf");
+require_once(dirname(__FILE__)."/../classes/class_element.php");
$con = db_connect($DBSERVER,$OWNER,$PW);
db_select_db(DB,$con);
@@ -27,9 +28,51 @@
*/
class gui {
- public function __construct () {
+ var $id;
+ var $elementArray = array();
+
+ public function __construct ($id) {
+ if ($id) {
+ $this->id = $id;
+ $this->elementArray = $this->selectElements();
+ }
}
+ public function selectElements () {
+ $sql = "SELECT e_id FROM gui_element WHERE fkey_gui_id = $1 " .
+ "ORDER BY e_pos";
+ $v = array($this->id);
+ $t = array('s');
+ $res = db_prep_query($sql,$v,$t);
+ $elementArray = array();
+ while ($row = db_fetch_array($res)) {
+ array_push($elementArray, $row[0]);
+ }
+
+ $this->elementArray = array();
+ for ($i = 0; $i < count($elementArray); $i++) {
+ $currentElement = new Element();
+ $currentElement->select($elementArray[$i], $this->id);
+ array_push($this->elementArray, $currentElement);
+ }
+ return $this->elementArray;
+ }
+
+ public function toHtml () {
+ $htmlString = "";
+ $htmlString .= $this->elementsToHtml();
+ return $htmlString;
+ }
+
+ public function getJavaScriptModules () {
+ $jsArray = array();
+ for ($i = 0; $i < count($this->elementArray); $i++) {
+ $currentElement = $this->elementArray[$i];
+ array_merge($jsArray, $currentElement->getJavaScriptModules());
+ }
+ return $jsArray;
+ }
+
/**
* Checks if a GUI with a given ID exists in the database
*
@@ -221,5 +264,33 @@
return false;
}
}
+
+ private function elementsToHtml () {
+ $bodyStringArray = array();
+ $elementString = "";
+ for ($i = 0; $i < count($this->elementArray); $i++) {
+ $currentElement = $this->elementArray[$i];
+ if ($currentElement->id != "body") {
+ $elementString .= $currentElement->toHtml();
+ }
+ else {
+ $bodyStringArray = $currentElement->toHtmlArray();
+ }
+ }
+ $elementString .= "<form id='sendData' name='sendData' action='' " .
+ "method='POST' target='loadData' " .
+ "style='position:absolute;left:800px'>" .
+ "<input type='hidden' name='data'></form>";
+
+ if (count($bodyStringArray) == 3) {
+ $elementString = $bodyStringArray[0] .
+ $bodyStringArray[1] .
+ $elementString .
+ $bodyStringArray[2];
+
+ }
+ return $elementString;
+ }
+
}
?>
\ No newline at end of file
Modified: branches/nimix_dev/http/classes/class_locale.php
===================================================================
--- branches/nimix_dev/http/classes/class_locale.php 2008-08-18 14:44:53 UTC (rev 2860)
+++ branches/nimix_dev/http/classes/class_locale.php 2008-08-18 14:45:42 UTC (rev 2861)
@@ -93,19 +93,19 @@
}
$locale = $this->systemLocales[$this->knownLanguages[$languageId]][$this->os];
- bindtextdomain(LOCALE_DOMAIN, LOCALE_DIR);
- textdomain(LOCALE_DOMAIN);
if (setlocale(LC_ALL, $locale)) {
$this->name = $locale;
$_SESSION["mb_lang"] = $languageId;
$_SESSION["mb_locale"] = $this->name;
$e = new Mb_notice("locale " . $this->name . " ok on " . $this->os);
+ // from http://de3.php.net/manual/de/function.gettext.php
+ bindtextdomain("Mapbender", dirname(__FILE__)."/../../resources/locale/");
+ textdomain("Mapbender");
return true;
}
- $e = new Mb_notice("locale " . $locale . " not found.");
-
}
}
+ $e = new Mb_notice("locale " . $locale . " not found.");
return false;
}
Copied: branches/nimix_dev/http/classes/class_map.php (from rev 2653, trunk/mapbender/http/classes/class_map.php)
===================================================================
--- branches/nimix_dev/http/classes/class_map.php (rev 0)
+++ branches/nimix_dev/http/classes/class_map.php 2008-08-18 14:45:42 UTC (rev 2861)
@@ -0,0 +1,435 @@
+<?php
+require_once(dirname(__FILE__)."/../classes/class_bbox.php");
+/**
+ * Representing a map object, identical to the JS object in javascripts/map.js
+ * @class
+ */
+class Map {
+
+ private $width;
+ private $height;
+ private $frameName;
+ private $elementName = "maps";
+ private $extent;
+ private $isOverview = false;
+ private $wmsArray = array();
+
+ /**
+ * @destructor
+ * @param
+ */
+ function __destruct() {
+ }
+
+ /**
+ * @constructor
+ * @param
+ */
+ function __construct() {
+ }
+
+ //-------------------------------------------------------------------------
+ // getter and setter
+ //-------------------------------------------------------------------------
+ /**
+ * @param $value Integer
+ */
+ public function setWidth ($value) {
+ $this->width = $value;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public function getWidth () {
+ return $this->width;
+ }
+
+ /**
+ * @param $value Integer
+ */
+ public function setHeight ($value) {
+ $this->height = $value;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public function getHeight () {
+ return $this->height;
+ }
+
+ /**
+ * @param $value String
+ */
+ public function setFrameName ($value) {
+ $this->frameName = $value;
+ }
+
+ /**
+ *
+ * @return String
+ */
+ public function getFrameName () {
+ return $this->frameName;
+ }
+
+ /**
+ * @param $value String
+ */
+ public function setExtent ($aMapbenderBbox) {
+ $this->extent = $aMapbenderBbox;
+ }
+
+ /**
+ *
+ * @return Mapbender_bbox
+ */
+ public function getExtent () {
+ return $this->extent;
+ }
+
+ /**
+ *
+ * @return String EPSG code of the map.
+ */
+ public function getEpsg () {
+ return $this->extent->epsg;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public function getWmsArray () {
+ return $this->wmsArray;
+ }
+
+ /**
+ *
+ * @return
+ * @param $wmsArray Object
+ */
+ public function setWmsArray ($wmsArray) {
+ $this->wmsArray = $wmsArray;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public function isOverview () {
+ return $this->isOverview;
+ }
+
+ public function setIsOverview ($bool) {
+ $this->isOverview = $bool;
+ }
+
+ /**
+ * @param $value Object
+ */
+ public function addWms ($value) {
+ array_push($this->wms, $value);
+ }
+
+
+ // ------------------------------------------------------------------------
+ // map manipulation
+ // ------------------------------------------------------------------------
+
+ /**
+ * Appends the WMS of another map to this map.
+ *
+ * @param $anotherMap Map
+ */
+ public function append ($anotherMap) {
+ $this->wmsArray = array_merge($anotherMap->getWmsArray(), $this->wmsArray);
+ }
+
+ /**
+ * Merges this map with another map: Copies the map settings from the
+ * other map and merges the WMS (keeping the settings of the other
+ * map if there are duplicates)
+ *
+ * @param $anotherMap Map
+ */
+ public function merge ($anotherMap) {
+ $this->width = $anotherMap->width;
+ $this->height = $anotherMap->height;
+ $this->frameName = $anotherMap->frameName;
+ $this->elementName = $anotherMap->elementName;
+ $this->extent = $anotherMap->extent;
+ $this->isOverview = $anotherMap->isOverview;
+ $this->wmsArray = wms::merge(array_merge($anotherMap->getWmsArray(), $this->wmsArray));
+ }
+
+ /**
+ * Adds WMS to this map
+ *
+ * @return
+ */
+ public function appendWmsArray ($wmsArray) {
+ $this->wmsArray = array_merge($this->wmsArray, $wmsArray);
+ }
+
+ /**
+ * Merge WMS into this map
+ *
+ * @return
+ */
+ public function mergeWmsArray ($wmsArray) {
+ $this->wmsArray = wms::merge(array_merge($this->wmsArray, $wmsArray));
+ }
+
+
+ // ------------------------------------------------------------------------
+ // Instantiation
+ // ------------------------------------------------------------------------
+ /**
+ *
+ * @return
+ * @param $jsMapObject Object
+ */
+ public function createFromJs ($jsMapObject) {
+ $arrayBBox = explode(",", $jsMapObject->extent);
+ $minx = floatval($arrayBBox[0]);
+ $miny = floatval($arrayBBox[1]);
+ $maxx = floatval($arrayBBox[2]);
+ $maxy = floatval($arrayBBox[3]);
+ $srs = $jsMapObject->epsg;
+ $bbox = new Mapbender_bbox($minx, $miny, $maxx, $maxy, $srs);
+
+ $this->width = $jsMapObject->width;
+ $this->height = $jsMapObject->height;
+ $this->frameName = $jsMapObject->frameName;
+ $this->extent = $bbox;
+
+ if (isset($jsMapObject->isOverview) && $jsMapObject->isOverview == "1") {
+ $this->isOverview = true;
+ }
+
+ for ($i=0; $i < count($jsMapObject->wms); $i++){
+
+ $currentWms = $jsMapObject->wms[$i];
+ $wms = new wms();
+
+ //
+ // set WMS data
+ //
+ $wms->wms_id = $currentWms->wms_id;
+ $wms->wms_version = $currentWms->wms_version;
+ $wms->wms_title = $currentWms->wms_title;
+ $wms->wms_abstract = $currentWms->wms_abstract;
+ $wms->wms_getmap = $currentWms->wms_getmap;
+ $wms->wms_getfeatureinfo = $currentWms->wms_getfeatureinfo;
+ $wms->wms_getlegendurl = $currentWms->wms_getlegendurl;
+ $wms->wms_filter = $currentWms->wms_filter;
+ $wms->gui_epsg = $currentWms->gui_epsg;
+ $wms->gui_minx = $currentWms->gui_minx;
+ $wms->gui_miny = $currentWms->gui_miny;
+ $wms->gui_maxx = $currentWms->gui_maxx;
+ $wms->gui_maxy = $currentWms->gui_maxy;
+ $wms->gui_wms_mapformat = $currentWms->gui_wms_mapformat;
+ $wms->gui_wms_featureinfoformat = $currentWms->gui_wms_featureinfoformat;
+ $wms->gui_wms_exceptionformat = $currentWms->gui_wms_exceptionformat;
+ $wms->gui_wms_opacity = $currentWms->wms_opacity;
+ $wms->gui_wms_sldurl = $currentWms->gui_wms_sldurl;
+ $wms->gui_wms_visible = $currentWms->gui_wms_visible;
+ $wms->gui_wms_epsg = $currentWms->gui_wms_epsg;
+ $wms->data_type = $currentWms->data_type;
+ $wms->data_format = $currentWms->data_format;
+
+ for ($k = 0; $k < count($currentWms->objLayer); $k++){
+ // the current layer of the JSON map object
+ $currentLayer = $currentWms->objLayer[$k];
+
+ // add new layer to WMS
+ $pos = $currentLayer->layer_pos;
+ $parent = $currentLayer->layer_parent;
+ $wms->addLayer($pos, $parent);
+
+ $newLayerIndex = count($wms->objLayer) - 1;
+ // $newLayer is a short cut to the layer we just added
+ $newLayer = $wms->objLayer[$newLayerIndex];
+
+ // set layer data
+ $newLayer->layer_uid = $currentLayer->layer_uid;
+ $newLayer->layer_name = $currentLayer->layer_name;
+ $newLayer->layer_title = $currentLayer->layer_title;
+ $newLayer->layer_dataurl_href = $currentLayer->layer_dataurl_href;
+ $newLayer->layer_pos = $currentLayer->layer_pos;
+ $newLayer->layer_queryable = $currentLayer->layer_queryable;
+ $newLayer->layer_minscale = $currentLayer->layer_minscale;
+ $newLayer->layer_maxscale = $currentLayer->layer_maxscale;
+ $newLayer->layer_metadataurl = $currentLayer->metadataurl;
+ $newLayer->gui_layer_wms_id = $wms->objLayer[0]->layer_uid;
+ $newLayer->gui_layer_status = $currentLayer->gui_layer_status;
+ $newLayer->gui_layer_style = $currentLayer->gui_layer_style;
+ $newLayer->gui_layer_selectable = $currentLayer->gui_layer_selectable;
+ $newLayer->gui_layer_visible = $currentLayer->gui_layer_visible;
+ $newLayer->gui_layer_queryable = $currentLayer->gui_layer_queryable;
+ $newLayer->gui_layer_querylayer = $currentLayer->gui_layer_querylayer;
+ $newLayer->gui_layer_minscale = $currentLayer->gui_layer_minscale;
+ $newLayer->gui_layer_maxscale = $currentLayer->gui_layer_maxscale;
+ $newLayer->gui_layer_wfs_featuretype = $currentLayer->gui_layer_wfs_featuretype;
+
+ // BEWARE THIS IS SUPER UGLY CODE
+ $newLayer->layer_epsg = array();
+ for ($z = 0; $z < count($currentLayer->layer_epsg); $z++) {
+ $newLayer->layer_epsg[$z] = array();
+ $newLayer->layer_epsg[$z]["epsg"] = $currentLayer->layer_epsg[$z]->epsg;
+ $newLayer->layer_epsg[$z]["minx"] = $currentLayer->layer_epsg[$z]->minx;
+ $newLayer->layer_epsg[$z]["miny"] = $currentLayer->layer_epsg[$z]->miny;
+ $newLayer->layer_epsg[$z]["maxx"] = $currentLayer->layer_epsg[$z]->maxx;
+ $newLayer->layer_epsg[$z]["maxy"] = $currentLayer->layer_epsg[$z]->maxy;
+ }
+
+ // BEWARE THIS IS SUPER UGLY CODE
+ $newLayer->layer_style = array();
+ for ($z = 0; $z < count($currentLayer->layer_style); $z++) {
+ $newLayer->layer_style[$z] = array();
+ $newLayer->layer_style[$z]["name"] = $currentLayer->layer_style[$z]->name;
+ $newLayer->layer_style[$z]["title"] = $currentLayer->layer_style[$z]->title;
+ $newLayer->layer_style[$z]["legendurl"] = $currentLayer->layer_style[$z]->legendurl;
+ $newLayer->layer_style[$z]["legendurlformat"] = $currentLayer->layer_style[$z]->legendurlformat;
+ }
+
+ }
+ array_push($this->wmsArray, $wms);
+ }
+ return true;
+ }
+
+
+ // ------------------------------------------------------------------------
+ // database functions
+ // ------------------------------------------------------------------------
+ public static function selectMainMapByApplication ($appId) {
+ return map::selectByApplication($appId, "mapframe1");
+ }
+
+ public static function selectOverviewMapByApplication ($appId) {
+ $currentMap = map::selectByApplication($appId, "overview");
+ if ($currentMap !== null) {
+ $currentMap->setIsOverview(true);
+ }
+ return $currentMap;
+ }
+
+
+ // ------------------------------------------------------------------------
+ // Output
+ // ------------------------------------------------------------------------
+ /**
+ * Returns an array of string, which are JS statements.
+ * @return String[]
+ */
+ public function toJavaScript ($wmsIndex) {
+ $jsCodeArray = array();
+
+ // initialise map object
+ if ($wmsIndex === null) {
+ $wmsIndex = "null";
+ }
+ $registerMapString = "mb_registerMapObj('" .
+ $this->frameName . "', " .
+ "'maps', " .
+ $wmsIndex . ", " .
+ $this->width . ", " .
+ $this->height . ");";
+ array_push($jsCodeArray, $registerMapString);
+
+// $e = new mb_notice("Map to JS: ov? " . $this->isOverview);
+
+ // if map is overview...
+ if ($this->isOverview) {
+ // ...set overview flag
+ $setOverviewFlagString = "mb_mapObj[mb_mapObj.length-1].isOverview = true;";
+ array_push($jsCodeArray, $setOverviewFlagString);
+ }
+
+ // set width
+ $setMapframeWidth = "document.getElementById('" . $this->frameName . "')." .
+ "style.width = " . $this->width . ";";
+ array_push($jsCodeArray, $setMapframeWidth);
+
+ // set height
+ $setMapframeHeight = "document.getElementById('" . $this->frameName . "')." .
+ "style.height = " . $this->height . ";";
+ array_push($jsCodeArray, $setMapframeHeight);
+
+ // calculate extent
+ $calcExtentString = "mb_calculateExtent('" .
+ $this->frameName . "', " .
+ $this->extent->min->x . ", " .
+ $this->extent->min->y . ", " .
+ $this->extent->max->x . ", " .
+ $this->extent->max->y . ");";
+ array_push($jsCodeArray, $calcExtentString);
+ return $jsCodeArray;
+ }
+
+
+ // ------------------------------------------------------------------------
+ // PRIVATE FUNCTIONS
+ // ------------------------------------------------------------------------
+
+ private static function selectByApplication ($appId, $frameName) {
+ // find the mapframe in the application elements...
+ $sql = "SELECT * FROM gui_element WHERE fkey_gui_id = $1 AND " .
+ "e_id = $2 LIMIT 1";
+ $v = array($appId, $frameName);
+ $t = array('s', 's');
+ $res = db_prep_query($sql,$v,$t);
+ $row = db_fetch_array($res);
+
+ // if found...
+ if ($row) {
+ $currentMap = new Map();
+
+ // use settings from database
+ $currentMap->setWidth($row["e_width"]);
+ $currentMap->setHeight($row["e_height"]);
+ $currentMap->setFrameName($row["e_id"]);
+
+ // get the WMS
+ $wmsArray = wms::selectMyWmsByApplication($appId);
+
+// $e = new mb_notice("WMS in this map: " . implode(",", $wmsArray));
+
+ // if this is the overview, find the WMS index and
+ // 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) {
+// $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"]);
+ $e = new mb_exception("OV index: " . $ovIndex);
+ if (!$ovIndex) {
+ $ovIndex = 0;
+ }
+ $wmsArray = array($wmsArray[$ovIndex]);
+// $e = new mb_notice("WMS in this map (corrected): " . implode(",", $wmsArray));
+ }
+ else {
+// $e = new mb_exception("guess this is NOT the OV");
+ }
+
+ $currentMap->wmsArray = $wmsArray;
+
+ // TO DO: EXTENT!
+
+ return $currentMap;
+ }
+ else {
+ return null;
+ }
+ }
+
+
+}
+?>
\ No newline at end of file
More information about the Mapbender_commits
mailing list