[Mapbender-commits] r8814 - in trunk/mapbender: http/classes http/javascripts http/php lib
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Wed May 7 00:39:59 PDT 2014
Author: hwbllmnn
Date: 2014-05-07 00:39:59 -0700 (Wed, 07 May 2014)
New Revision: 8814
Added:
trunk/mapbender/http/php/getOriginalKml.php
trunk/mapbender/http/php/kml2transformedgeojson.php
Modified:
trunk/mapbender/http/classes/class_map.php
trunk/mapbender/http/classes/class_wmc.php
trunk/mapbender/http/classes/class_wmcToXml.php
trunk/mapbender/http/javascripts/mod_changeEPSG.php
trunk/mapbender/http/javascripts/mod_savewmc.js
trunk/mapbender/lib/mb.ui.displayKmlFeatures.js
Log:
added kml transformation on epsg change
Modified: trunk/mapbender/http/classes/class_map.php
===================================================================
--- trunk/mapbender/http/classes/class_map.php 2014-05-07 07:34:42 UTC (rev 8813)
+++ trunk/mapbender/http/classes/class_map.php 2014-05-07 07:39:59 UTC (rev 8814)
@@ -16,6 +16,7 @@
private $isOverview = false;
private $wmsArray = array();
private $kmls;
+ private $originalKmls;
/**
* @destructor
@@ -222,6 +223,14 @@
$this->kmls = $kmls;
}
+ public function getOriginalKmls() {
+ return $this->originalKmls;
+ }
+
+ public function setOriginalKmls($originalKmls) {
+ $this->originalKmls = $originalKmls;
+ }
+
/**
*
* @return
@@ -500,6 +509,9 @@
if(property_exists($jsMapObject, 'kmls')) {
$this->kmls = $jsMapObject->kmls;
}
+ if(property_exists($jsMapObject, 'originalKmls')) {
+ $this->originalKmls = $jsMapObject->originalKmls;
+ }
if (isset($jsMapObject->isOverview) && $jsMapObject->isOverview == "1") {
$this->isOverview = true;
Modified: trunk/mapbender/http/classes/class_wmc.php
===================================================================
--- trunk/mapbender/http/classes/class_wmc.php 2014-05-07 07:34:42 UTC (rev 8813)
+++ trunk/mapbender/http/classes/class_wmc.php 2014-05-07 07:39:59 UTC (rev 8814)
@@ -211,7 +211,6 @@
if (count($mapObject) > 2) {
$e = new mb_exception("Save WMC only works for two concurrent map frames (overview plus main) at the moment.");
}
-
// set extension data
$this->generalExtensionArray = $extensionData;
@@ -1157,6 +1156,9 @@
// set general extension data
if (count($this->generalExtensionArray) > 0) {
+ if(array_key_exists('ORIGINALKMLS', $this->generalExtensionArray)) {
+ $this->generalExtensionArray['ORIGINALKMLS'] = unserialize(base64_decode($this->generalExtensionArray['ORIGINALKMLS']));
+ }
$json = new Mapbender_JSON();
array_push($wmcJsArray, "restoredWmcExtensionData = " . $json->encode($this->generalExtensionArray) . ";");
}
Modified: trunk/mapbender/http/classes/class_wmcToXml.php
===================================================================
--- trunk/mapbender/http/classes/class_wmcToXml.php 2014-05-07 07:34:42 UTC (rev 8813)
+++ trunk/mapbender/http/classes/class_wmcToXml.php 2014-05-07 07:39:59 UTC (rev 8814)
@@ -146,6 +146,9 @@
if($this->wmc->mainMap->getKmls()) {
$extensionData['kmls'] = json_encode($this->wmc->mainMap->getKmls());
}
+ if($this->wmc->mainMap->getOriginalKmls()) {
+ $extensionData['originalKmls'] = base64_encode(serialize($this->wmc->mainMap->getOriginalKmls()));
+ }
// store epsg and bbox of root layer of 0th WMS
$firstWms = $this->wmc->mainMap->getWms(0);
Modified: trunk/mapbender/http/javascripts/mod_changeEPSG.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_changeEPSG.php 2014-05-07 07:34:42 UTC (rev 8813)
+++ trunk/mapbender/http/javascripts/mod_changeEPSG.php 2014-05-07 07:39:59 UTC (rev 8814)
@@ -2,25 +2,25 @@
* Package: changeEPSG
*
* Description:
- * Select a spatial reference system EPSG code. All maps are transformed to
+ * Select a spatial reference system EPSG code. All maps are transformed to
* that system.
- *
+ *
* Files:
* - http/javascripts/mod_changeEPSG.php
* - http/php/mod_changeEPSG_server.php
*
* SQL:
- * > INSERT INTO gui_element (fkey_gui_id, e_id, e_pos, e_public, e_comment,
- * > 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,
+ * > INSERT INTO gui_element (fkey_gui_id, e_id, e_pos, e_public, e_comment,
+ * > 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) VALUES ('<gui_id>','changeEPSG',
* > 2,1,'change EPSG, Postgres required, overview is targed for full extent',
* > 'Change Projection','select','','',432,25,107,24,1,'',
* > '','select',
* > 'mod_changeEPSG.php','','overview','','');
* >
- * > INSERT INTO gui_element_vars (fkey_gui_id, fkey_e_id, var_name,
- * > var_value, context, var_type) VALUES('<app_id>', 'changeEPSG',
+ * > INSERT INTO gui_element_vars (fkey_gui_id, fkey_e_id, var_name,
+ * > var_value, context, var_type) VALUES('<app_id>', 'changeEPSG',
* > 'projections',
* > 'EPSG:4326;Geographic Coordinates,
* > EPSG:31466;Gauss-Krueger 2,EPSG:31467;Gaus-Krueger 3', '' ,
@@ -31,11 +31,11 @@
*
* Maintainer:
* http://www.mapbender.org/User:Christoph_Baudson
- *
+ *
* License:
* Copyright (c) 2009, Open Source Geospatial Foundation
- * This program is dual licensed under the GNU General Public License
- * and Simplified BSD license.
+ * This program is dual licensed under the GNU General Public License
+ * and Simplified BSD license.
* http://svn.osgeo.org/mapbender/trunk/mapbender/license/license.txt
*/
<?php
@@ -63,12 +63,12 @@
if (this.tagName.toUpperCase() !== "SELECT") {
return;
}
-
+
var $this = $(this);
-
+
if (args.length >= 1 && $.isFunction(args[0])) {
var f = args[0];
-
+
var options = {};
if (args.length >= 2 && typeof args[1] === "object") {
options = args[1];
@@ -124,7 +124,6 @@
var $changeEpsg = $(this);
$changeEpsg.ajaxChange(function () {
-
var srsValue = this.value;
if (srsValue === "") {
$(this).ajaxChange("abort");
@@ -136,7 +135,7 @@
});
var ChangeEpsg = function () {
-
+
var compileSrsArray = function () {
var srsArray = [];
@@ -187,7 +186,7 @@
return;
}
$changeEpsg.ajaxChange("done");
-
+
var newExtent = obj;
var mapObjNames = [];
var myTarget = options.target[0];
@@ -207,30 +206,30 @@
// this loop can be removed once the
// wms object has been removed.
// redundant.
-
+
for (j = 0; j < wms.length; j++) {
if (wms[j].wms_id == newExtent[i].wms) {
wms[j].setBoundingBoxBySrs(
- newExtent[i].newSrs,
+ newExtent[i].newSrs,
new Extent(
- parseFloat(newExtent[i].minx),
- parseFloat(newExtent[i].miny),
- parseFloat(newExtent[i].maxx),
+ parseFloat(newExtent[i].minx),
+ parseFloat(newExtent[i].miny),
+ parseFloat(newExtent[i].maxx),
parseFloat(newExtent[i].maxy)
)
);
}
}
-
+
$(mapObjNames.join(",")).mapbender(function(){
for (j = 0; j < this.wms.length; j++) {
if (this.wms[j].wms_id == newExtent[i].wms) {
this.wms[j].setBoundingBoxBySrs(
- newExtent[i].newSrs,
+ newExtent[i].newSrs,
new Extent(
- parseFloat(newExtent[i].minx),
- parseFloat(newExtent[i].miny),
- parseFloat(newExtent[i].maxx),
+ parseFloat(newExtent[i].minx),
+ parseFloat(newExtent[i].miny),
+ parseFloat(newExtent[i].maxx),
parseFloat(newExtent[i].maxy)
)
);
@@ -238,13 +237,13 @@
break;
}
});
- }
+ }
//
// Overview map
//
if (newExtent[i].frameName === myTarget){
var map = $("#" + myTarget).mapbender();
-
+
for (var ii = 0; ii < map.mb_MapHistoryObj.length; ii++) {
if (map.mb_MapHistoryObj[ii].epsg == newExtent[i].newSrs) {
exists = ii;
@@ -296,6 +295,10 @@
});
});
}
+ var kml = $('#mapframe1').data('kml');
+ if(kml) {
+ kml.reload();
+ }
}
setTimeout(function () {
$(":maps").mapbender(function () {
@@ -337,9 +340,9 @@
}
});
});
-
+
});
- });
+ });
};
Modified: trunk/mapbender/http/javascripts/mod_savewmc.js
===================================================================
--- trunk/mapbender/http/javascripts/mod_savewmc.js 2014-05-07 07:34:42 UTC (rev 8813)
+++ trunk/mapbender/http/javascripts/mod_savewmc.js 2014-05-07 07:39:59 UTC (rev 8814)
@@ -169,6 +169,7 @@
var kml = $('#mapframe1').data('kml');
if(kml) {
mb_mapObj[0].kmls = kml._kmls;
+ mb_mapObj[0].originalKmls = kml.originalKmls;
}
var mapObjectToSend = $.toJSON(mb_mapObj);
Added: trunk/mapbender/http/php/getOriginalKml.php
===================================================================
--- trunk/mapbender/http/php/getOriginalKml.php (rev 0)
+++ trunk/mapbender/http/php/getOriginalKml.php 2014-05-07 07:39:59 UTC (rev 8814)
@@ -0,0 +1,40 @@
+<?php
+# http://www.mapbender.org/index.php/Administration
+# 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__)."/../php/mb_validateSession.php");
+require_once(dirname(__FILE__) . "/../classes/class_connector.php");
+
+header("Content-Type: application/xml");
+
+if(isset($_REQUEST["url"])){
+ $url = $_REQUEST["url"];
+}else{
+ echo("{}");
+ exit;
+}
+
+$con = new connector();
+$kmlString = $con->load($url);
+try {
+ echo $kmlString;
+} catch (Exception $e) {
+ echo($e);
+ die;
+}
+
+?>
Added: trunk/mapbender/http/php/kml2transformedgeojson.php
===================================================================
--- trunk/mapbender/http/php/kml2transformedgeojson.php (rev 0)
+++ trunk/mapbender/http/php/kml2transformedgeojson.php 2014-05-07 07:39:59 UTC (rev 8814)
@@ -0,0 +1,42 @@
+<?php
+# http://www.mapbender.org/index.php/Administration
+# 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__)."/../php/mb_validateSession.php");
+require_once(dirname(__FILE__) . "/../classes/class_kml_ows.php");
+
+header("Content-Type: application/json");
+
+$kml = new KML();
+$kmlString = file_get_contents("php://input");
+try {
+
+ if($kml->parseKml($kmlString)){
+ $kml->transform($_REQUEST["targetEPSG"]);
+ $geojson = $kml->toGeoJSON();
+ echo $geojson;
+ }else{
+ echo("{}");
+ }
+
+
+} catch (Exception $e) {
+ echo($e);
+ die;
+}
+
+?>
Modified: trunk/mapbender/lib/mb.ui.displayKmlFeatures.js
===================================================================
--- trunk/mapbender/lib/mb.ui.displayKmlFeatures.js 2014-05-07 07:34:42 UTC (rev 8813)
+++ trunk/mapbender/lib/mb.ui.displayKmlFeatures.js 2014-05-07 07:39:59 UTC (rev 8814)
@@ -40,7 +40,7 @@
var self = this, o = this.options;
this.element.bind('click', function(e){
var map = self.element.mapbender();
- var pos = map.getMousePosition(e);
+ var pos = map.getMousePosition(e);
var clickPoint = map.convertPixelToReal(new Point(pos.x,pos.y));
var feed = null;
var requestGeometries = [];
@@ -48,7 +48,7 @@
// - Points are represented as icons, so we check if the click is on an icon
// - Polygons don't have a dom Element when not using Rapheljs, so we go ask postgis
// after that's finished the results are merged and displayed in a box
- var pointGeometries = {};
+ var pointGeometries = {};
var g,h,nodes = null;
$("*",self._popup).remove();
var $tabs = $("<ul></ul>");
@@ -59,12 +59,12 @@
for(var j = 0; j < feed.geomArray.count(); j++){
g = feed.geomArray.get(j);
- h = feed.highlightArray[j];
+ h = feed.highlightArray[j];
nodes = h.getNodes();
if(g.geomType == geomType.point){
// we only add one point per highlight so we can assume there's only one node
if(!nodes[0]){ continue;}
- var rect = nodes[0].getBoundingClientRect();
+ var rect = nodes[0].getBoundingClientRect();
if(e.clientX >= rect.left && e.clientX <= rect.right &&
e.clientY >= rect.top && e.clientY <= rect.bottom){
// we just need the keys to exist
@@ -72,7 +72,7 @@
// server
pointGeometries[j] = true;
}
-
+
}else{
requestGeometries.push(g.toText());
}
@@ -95,7 +95,7 @@
return;
}
-
+
// this iterates over an object where the keys are _not_ the incremential
// basically a sparse array. therefore It cannot be used to count the entries in the object
// this is why j is used
@@ -118,17 +118,17 @@
description = g.e.getElementValueByName("description");
$tabs.append('<li><a href="#rsspopup_'+ i +'">'+ title + '</a></li>');
self._popup.append('<div id="rsspopup_'+ i +'"><h1>'+ title +'</h1><p>'+ description +'</p></h1>');
-
+
if($tabs.children().size() > 1){
}
self._popup.dialog('open');
}
-
- if($tabs.children().size() > 1){
+
+ if($tabs.children().size() > 1){
var $tabcontainer = $("<div><div>");
$tabcontainer.append($tabs);
- $tabcontainer.append($('div',self._popup));
+ $tabcontainer.append($('div',self._popup));
$tabs.css("display","none");
self._popup.append($tabcontainer);
$tabcontainer.tabs();
@@ -170,11 +170,11 @@
if(o.autoOpen){
self._display(obj);
}
- });
+ });
self.element.bind('kml:error',function(event,message){
alert(message);
});
-
+
},
_init: function(){
var self = this, o = this.options;
@@ -192,6 +192,18 @@
//not adding feed twice
return;
}
+ $.ajax({url: '../php/getOriginalKml.php',
+ data: {url: o.url},
+ type: 'POST',
+ dataType: 'text/plain',
+ success: function(data) {
+ if(!self.originalKmls) {
+ self.originalKmls = {};
+ }
+ self.originalKmls[o.url] = data;
+ }
+ });
+
$.ajax({ url: self._endpointURL,
data: {url: o.url, targetEPSG: epsg},
type: 'POST',
@@ -220,9 +232,41 @@
self.element.trigger('kml:loaded',kmls[k]);
}
}
-
+ kmls = mb_getWmcExtensionData('ORIGINALKMLS');
+ if(kmls) {
+ this.originalKmls = kmls;
+ }
},
+ reload: function() {
+ var self = this, o = this.options;
+ var epsg = $(self.element).mapbender().epsg;
+ epsg = epsg.split(":")[1];
+
+ $.each(self._kmls, function(url, o) {
+ $('li[title="' + url + '"] > button[name="remove"]').click();
+ $.ajax({ url: self._endpointURL,
+ data: {url: o.url, targetEPSG: epsg},
+ type: 'POST',
+ dataType: "json",
+ success : function(data,textStatus,xhr){
+ if(!data){
+ self.element.trigger('kml:error',"request returned no data");
+ }
+ else if(data.errorMessage){
+ self.element.trigger('kml:error',data.errorMessage);
+ }else{
+ self._kmls[o.url] = {type:"geojson",data:data,url:o.url,display: o.display, loadedOnStartup: true};
+ self.element.trigger('kml:loaded',{type:"geojson",data:data,url:o.url,display: o.display});
+ }
+ },
+ error: function(XMLHttpRequest, textStatus, errorThrown){
+ self.element.trigger('kml:error',"Problem talking to server: " + errorThrown);
+ }
+ });
+ });
+ },
+
show : function(url){
this._kmls[url].display = true;
var $map = $(this.element).mapbender();
@@ -239,7 +283,7 @@
$map.calculateExtent(extent);
$map.setMapRequest();
},
-
+
remove: function(url){
// nrgh there are still references to the highlightobjects somewhere!
for(var i in this._kmls[url].highlightArray){
@@ -264,11 +308,11 @@
if(geojson.features){
// we always transform _from_ 4326 KML use this as their default
- //var projSrc = new Proj4js.Proj('EPSG:4326');
- //var projDest = new Proj4js.Proj($map.epsg);
+ // var projSrc = new Proj4js.Proj('EPSG:4326');
+ // var projDest = new Proj4js.Proj($map.epsg);
var markeroptions = {width: "19px", height: "34px"};
var g = null;
-
+
mapitem.geomArray = new GeometryArray();
mapitem.highlightArray = [];
mapitem.geomArray.importGeoJSON(geojson);
@@ -289,10 +333,10 @@
icon = g.e.getElementValueByName("Mapbender:icon");
//title = g.e.getElementValueByName("title");
name = g.e.getElementValueByName("name");
-
+
if(name != "false" && name !== false){
title = name; // use for tooltip
- }
+ }
if(icon == "false" || icon === false){
g.e.setElement("Mapbender:iconOffsetX", -10);
g.e.setElement("Mapbender:iconOffsetY", -34);
@@ -314,7 +358,7 @@
}
}
self.element.mapbender().events.afterMapRequest.register(function () {
- if(mapitem.display){
+ if(mapitem.display){
for(var i in mapitem.highlightArray){
mapitem.highlightArray[i].paint();
}
More information about the Mapbender_commits
mailing list