[Mapbender-commits] r9024 - trunk/mapbender/http/plugins
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Tue Aug 5 06:02:39 PDT 2014
Author: armin11
Date: 2014-08-05 06:02:39 -0700 (Tue, 05 Aug 2014)
New Revision: 9024
Modified:
trunk/mapbender/http/plugins/mb_metadata_addon.php
trunk/mapbender/http/plugins/mb_metadata_server.php
Log:
New div to show extent in dataset metadata editor on a map. Also a given polygon should be visualized
Modified: trunk/mapbender/http/plugins/mb_metadata_addon.php
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_addon.php 2014-08-05 09:53:14 UTC (rev 9023)
+++ trunk/mapbender/http/plugins/mb_metadata_addon.php 2014-08-05 13:02:39 UTC (rev 9024)
@@ -1,12 +1,11 @@
<?php
require_once dirname(__FILE__) . "/../../core/globalSettings.php";
require_once(dirname(__FILE__) . "/../../conf/mimetype.conf");
-
+
function displayCategories ($sql) {
if (Mapbender::session()->get("mb_lang") === "de") {
$sql = str_replace("category_code_en", "category_code_de", $sql);
}
-
$str = "";
$res = db_query($sql);
while ($row = db_fetch_assoc($res)) {
@@ -233,6 +232,10 @@
<legend><?php echo _mb("User defined region");?><img class="help-dialog" title="<?php echo _mb("Help");?>" help="{text:'<?php echo _mb("You can define your own bounding box or region if you upload an gml geometry object. Only bbox and polygons are accepted at the moment!");?>'}" src="../img/questionmark.png" alt="" /></legend>
<table id='geometryuploadtable' name='geometryuploadtable'><tr><td><img id="uploadgmlimage" name= "uploadgmlimage" onclick='initUploadGmlForm();' src='../img/button_blue_red/up.png' id='uploadImage' title='upload' /></td><td><?php echo _mb("Upload a surronding geometry for this dataset");?><img class="help-dialog" title="<?php echo _mb("Help");?>" help="{text:'<?php echo _mb("Help for geometry upload possibility");?>'}" src="../img/questionmark.png" alt="" /></td></tr></table>
</fieldset>
+ <fieldset>
+ <legend><?php echo _mb("Extent on map");?><img class="help-dialog" title="<?php echo _mb("Help");?>" help="{text:'<?php echo _mb("Here you can see the extent and a possibly given surrounding polygon on an overview map.");?>'}" src="../img/questionmark.png" alt="" /></legend>
+ <img id="extent_preview" src="" title="<?php echo _mb("Preview for Extent - if available");?>" alt="<?php echo _mb("Preview for Extent - if available");?>"/>
+ </fieldset>
</div>
<div id="tabs-6">
<fieldset>
Modified: trunk/mapbender/http/plugins/mb_metadata_server.php
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_server.php 2014-08-05 09:53:14 UTC (rev 9023)
+++ trunk/mapbender/http/plugins/mb_metadata_server.php 2014-08-05 13:02:39 UTC (rev 9024)
@@ -3,6 +3,7 @@
require_once dirname(__FILE__) . "/../classes/class_user.php";
require_once dirname(__FILE__) . "/../classes/class_wms.php";//already includes iso19139!
require_once dirname(__FILE__) . "/../classes/class_Uuid.php";
+require_once dirname(__FILE__) . "/../../tools/wms_extent/extent_service.conf";
$ajaxResponse = new AjaxResponse($_POST);
@@ -12,8 +13,19 @@
$ajaxResponse->setMessage($message);
$ajaxResponse->send();
die();
-};
+}
+function DOMNodeListObjectValuesToArray($domNodeList) {
+ $iterator = 0;
+ $array = array();
+ foreach ($domNodeList as $item) {
+ $array[$iterator] = $item->nodeValue; // this is a DOMNode instance
+ // you might want to have the textContent of them like this
+ $iterator++;
+ }
+ return $array;
+}
+
function getWms ($wmsId = null) {
$user = new User(Mapbender::session()->get("mb_user_id"));
$wmsIdArray = $user->getOwnedWms();
@@ -39,14 +51,17 @@
function gml2wkt($gml) {
//function to create wkt from given gml multipolygon
+ //DOM
+ $gmlObject = new DOMDocument();
libxml_use_internal_errors(true);
try {
- $gmlObject = simplexml_load_string($gml);
+ //$feedXML = simplexml_load_string($feedFile);
+ $gmlObject->loadXML($gml);
if ($gmlObject === false) {
foreach(libxml_get_errors() as $error) {
$err = new mb_exception("mb_metadata_server.php:".$error->message);
}
- throw new Exception("mb_metadata_server.php:".'Cannot parse Metadata GML!');
+ throw new Exception("mb_metadata_server.php:".'Cannot parse GML!');
return false;
}
}
@@ -54,25 +69,62 @@
$err = new mb_exception("mb_metadata_server.php:".$e->getMessage());
return false;
}
+
//if parsing was successful
if ($gmlObject !== false) {
//ST_GeomFromText('MULTIPOLYGON(((235670.354215375 894016.780856,235668.324215375 894025.050856,235681.154215375 894028.210856,235683.184215375 894019.940856,235670.354215375 894016.780856)))', 2805) )
//read crs from gml
- $crs = $gmlObject->xpath('/gml:Polygon/@srsName');
- $crsId = end(explode(":",$crs[0]));
+ $xpath = new DOMXPath($gmlObject);
+ $xpath->registerNamespace('gml','http://www.opengis.net/gml');
+ $crs = $xpath->query('/gml:Polygon/@srsName');
+ $crsArray = DOMNodeListObjectValuesToArray($crs);
+ $crsId = end(explode(":",$crsArray[0]));
+ if (!isset($crsId) || $crsId =="" || $crsId == NULL) {
+ //set default to lonlat wgs84
+ $crsId = "4326";
+ }
$wkt = "SRID=".$crsId.";POLYGON(";
- //$e = new mb_exception("mb_metadata_server.php: crs:".$crs[0]);
- //for each found polygon
- $outerPolygons = $gmlObject->xpath('/gml:Polygon/gml:outerBoundaryIs/gml:LinearRing/gml:coordinates');
- //$e = new mb_exception("mb_metadata_server.php:".gettype($outerPolygons).$outerPolygons);
- $wkt .= "(".str_replace(";",",",str_replace(","," ",str_replace(" ",";",$outerPolygons[0])))."))";
- //$wkt .= ")";
- //$e = new mb_exception("mb_metadata_server.php: wkt: ".$wkt);
+ $outerPolygons = $xpath->query('/gml:Polygon/gml:outerBoundaryIs/gml:LinearRing/gml:coordinates');
+ $outerPolygonsArray = DOMNodeListObjectValuesToArray($outerPolygons);
+ //$e = new mb_exception("mb_metadata_server.php: ".$outerPolygonsArray[0]);
+ $wkt .= "(".str_replace(";",",",str_replace(","," ",str_replace(" ",";",$outerPolygonsArray[0])))."))";
return $wkt;
}
}
+function getExtentGraphic($layer_4326_box) {
+ $area_4326_box = explode(',',EXTENTSERVICEBBOX);
+ if ($layer_4326_box[0] <= $area_4326_box[0] || $layer_4326_box[2] >= $area_4326_box[2] || $layer_4326_box[1] <= $area_4326_box[1] || $layer_4326_box[3] >= $area_4326_box[3]) {
+ if ($layer_4326_box[0] < $area_4326_box[0]) {
+ $area_4326_box[0] = $layer_4326_box[0];
+ }
+ if ($layer_4326_box[2] > $area_4326_box[2]) {
+ $area_4326_box[2] = $layer_4326_box[2];
+ }
+ if ($layer_4326_box[1] < $area_4326_box[1]) {
+ $area_4326_box[1] = $layer_4326_box[1];
+ }
+ if ($layer_4326_box[3] > $area_4326_box[3]) {
+ $area_4326_box[3] = $layer_4326_box[3];
+ }
+ $d_x = $area_4326_box[2] - $area_4326_box[0];
+ $d_y = $area_4326_box[3] - $area_4326_box[1];
+
+ $new_minx = $area_4326_box[0] - 0.05*($d_x);
+ $new_maxx = $area_4326_box[2] + 0.05*($d_x);
+ $new_miny = $area_4326_box[1] - 0.05*($d_y);
+ $new_maxy = $area_4326_box[3] + 0.05*($d_y);
+
+ if ($new_minx < -180) $area_4326_box[0] = -180; else $area_4326_box[0] = $new_minx;
+ if ($new_maxx > 180) $area_4326_box[2] = 180; else $area_4326_box[2] = $new_maxx;
+ if ($new_miny < -90) $area_4326_box[1] = -90; else $area_4326_box[1] = $new_miny;
+ if ($new_maxy > 90) $area_4326_box[3] = 90; else $area_4326_box[3] = $new_maxy;
+ }
+ $getMapUrl = EXTENTSERVICEURL."VERSION=1.1.1&REQUEST=GetMap&SERVICE=WMS&LAYERS=".EXTENTSERVICELAYER."&STYLES=&SRS=EPSG:4326&BBOX=".$area_4326_box[0].",".$area_4326_box[1].",".$area_4326_box[2].",".$area_4326_box[3]."&WIDTH=120&HEIGHT=120&FORMAT=image/png&BGCOLOR=0xffffff&TRANSPARENT=TRUE&EXCEPTIONS=application/vnd.ogc.se_inimage&minx=".$layer_4326_box[0]."&miny=".$layer_4326_box[1]."&maxx=".$layer_4326_box[2]."&maxy=".$layer_4326_box[3];
+ return $getMapUrl;
+}
+
switch ($ajaxResponse->getMethod()) {
case "getWms" :
$wmsIdArray = getWms();
@@ -1126,22 +1178,41 @@
$sql = <<<SQL
UPDATE mb_metadata SET bounding_geom = $2 WHERE metadata_id = $1
SQL;
- $v = array($metadataId, $wktPolygon);
- $e = new mb_exception($metadataId);
- $t = array('i','POLYGON');
- $res = db_prep_query($sql,$v,$t);
- if (!$res) {
- abort(_mb("Problem while storing geometry into database!"));
+ $v = array($metadataId, $wktPolygon);
+ $e = new mb_exception($metadataId);
+ $t = array('i','POLYGON');
+ $res = db_prep_query($sql,$v,$t);
+ if (!$res) {
+ abort(_mb("Problem while storing geometry into database!"));
+ } else {
+ //build new preview url if possible and give it back in ajax response
+
+ $ajaxResponse->setMessage("Stored successfully geometry into database!");
+ $ajaxResponse->setSuccess(true);
+ }
} else {
- abort(_mb("Stored successfully geometry into database!"));
- }
- } else {
abort(_mb("Converting GML to WKT failed!"));
}
//parse gml and extract multipolygon to wkt representation
//push multipolygon into database
break;
+ case "deleteSurroundingGeom" :
+ $metadataId = $ajaxResponse->getParameter("metadataId");
+ $sql = <<<SQL
+UPDATE mb_metadata SET bounding_geom = NULL WHERE metadata_id = $1
+SQL;
+ $v = array($metadataId);
+ //$e = new mb_exception($metadataId);
+ $t = array('i','POLYGON');
+ $res = db_prep_query($sql,$v,$t);
+ if (!$res) {
+ abort(_mb("Problem while deleting geometry from database!"));
+ } else {
+ $ajaxResponse->setMessage("Deleted surrounding geometry from metadata record!");
+ $ajaxResponse->setSuccess(true);
+ }
+ break;
case "importXmlAddon" :
//this case is similar to insert the metadata from external link, but came from internal file from tmp folder which has been uploaded before
$resourceId = $ajaxResponse->getParameter("resourceId");
More information about the Mapbender_commits
mailing list