[Mapbender-commits] r8873 - in trunk/mapbender: http/javascripts lib
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Fri May 16 01:36:59 PDT 2014
Author: hwbllmnn
Date: 2014-05-16 01:36:58 -0700 (Fri, 16 May 2014)
New Revision: 8873
Modified:
trunk/mapbender/http/javascripts/mod_changeEPSG.php
trunk/mapbender/lib/mb.ui.displayKmlFeatures.js
Log:
use client side transformation, always from WGS84 (needs proj4js)
Modified: trunk/mapbender/http/javascripts/mod_changeEPSG.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_changeEPSG.php 2014-05-16 07:42:29 UTC (rev 8872)
+++ trunk/mapbender/http/javascripts/mod_changeEPSG.php 2014-05-16 08:36:58 UTC (rev 8873)
@@ -297,7 +297,7 @@
}
var kml = $('#mapframe1').data('kml');
if(kml) {
- kml.reload();
+ kml.render();
}
}
setTimeout(function () {
Modified: trunk/mapbender/lib/mb.ui.displayKmlFeatures.js
===================================================================
--- trunk/mapbender/lib/mb.ui.displayKmlFeatures.js 2014-05-16 07:42:29 UTC (rev 8872)
+++ trunk/mapbender/lib/mb.ui.displayKmlFeatures.js 2014-05-16 08:36:58 UTC (rev 8873)
@@ -27,6 +27,12 @@
var translatedI18nObject = Mapbender.cloneObject(originalI18nObject);
//var translatedI18nObject = originalI18nObject;
+Proj4js.defs["EPSG:25832"] = "+proj=utm +zone=32 +ellps=GRS80 +units=m +no_defs";
+Proj4js.defs["EPSG:31466"] = "+proj=tmerc +lat_0=0 +lon_0=6 +k=1 +x_0=2500000 +y_0=0 +ellps=bessel +datum=potsdam +units=m +no_defs";
+Proj4js.defs["EPSG:31467"] = "+proj=tmerc +lat_0=0 +lon_0=9 +k=1 +x_0=3500000 +y_0=0 +ellps=bessel +datum=potsdam +units=m +no_defs";
+Proj4js.defs["EPSG:31468"] = "+proj=tmerc +lat_0=0 +lon_0=12 +k=1 +x_0=4500000 +y_0=0 +ellps=bessel +datum=potsdam +units=m +no_defs";
+Proj4js.defs["EPSG:31469"] = "+proj=tmerc +lat_0=0 +lon_0=15 +k=1 +x_0=5500000 +y_0=0 +ellps=bessel +datum=potsdam +units=m +no_defs";
+
var displayFeatures = {
options: {
url: "",
@@ -34,6 +40,8 @@
autoOpen: true,
autoDisplay: true
},
+ wgs84: new Proj4js.Proj('EPSG:4326'),
+ targetProj: new Proj4js.Proj('EPSG:25832'),
_kmls: {},
kmlOrder: [],
_popup : null,
@@ -122,8 +130,11 @@
var bbox = this.getBbox(item.data.features[idx]);
+ var min = Proj4js.transform(this.wgs84, this.targetProj, {x: bbox[0], y: bbox[1]});
+ var max = Proj4js.transform(this.wgs84, this.targetProj, {x: bbox[2], y: bbox[3]});
+
map.calculateExtent(
- new Mapbender.Extent(bbox[0], bbox[1], bbox[2], bbox[3])
+ new Mapbender.Extent(min.x, min.y, max.x, max.y)
);
map.setMapRequest();
},
@@ -132,7 +143,10 @@
var bbox = this.getLayerBbox(url);
var map = $('#mapframe1').mapbender();
- map.calculateExtent(new Mapbender.Extent(bbox[0], bbox[1], bbox[2], bbox[3]));
+ var min = Proj4js.transform(this.wgs84, this.targetProj, {x: bbox[0], y: bbox[1]});
+ var max = Proj4js.transform(this.wgs84, this.targetProj, {x: bbox[2], y: bbox[3]});
+
+ map.calculateExtent(new Mapbender.Extent(min.x, min.y, max.x, max.y));
map.setMapRequest();
},
@@ -228,7 +242,7 @@
});
$.ajax({ url: '../php/kmlToGeoJSON.php',
- data: {url: o.url, targetEPSG: epsg},
+ data: {url: o.url, targetEPSG: 'EPSG:4326'},
type: 'POST',
dataType: "json",
success : function(data,textStatus,xhr){
@@ -250,35 +264,36 @@
},
reload: function() {
- var self = this, o = this.options;
- var epsg = $(self.element).mapbender().epsg;
- epsg = epsg.split(":")[1];
+ // probably nothing needs to be done when transforming on the fly on the client
+ // var self = this, o = this.options;
+ // var epsg = $(self.element).mapbender().epsg;
+ // epsg = epsg.split(":")[1];
- $.each(self.kmlOrder, function(k, url) {
- var o = self._kmls[url];
- if(!o) return;
- // TODO prevent map reload at this point
- $('li[title="' + url + '"] > button[name="remove"]').click();
- $.ajax({ url: self._endpointURL + '?targetEPSG= ' + epsg,
- data: self.originalKmls[url],
- 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);
- }
- });
- });
+ // $.each(self.kmlOrder, function(k, url) {
+ // var o = self._kmls[url];
+ // if(!o) return;
+ // // TODO prevent map reload at this point
+ // $('li[title="' + url + '"] > button[name="remove"]').click();
+ // $.ajax({ url: self._endpointURL + '?targetEPSG= ' + epsg,
+ // data: self.originalKmls[url],
+ // 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);
+ // }
+ // });
+ // });
},
setOrder: function(order) {
@@ -344,10 +359,9 @@
switch(feature.geometry.type.toLowerCase()) {
case 'point':
var map = $(this.element).mapbender();
- var res = 10;
- var minx = feature.geometry.coordinates[0] - 20 * res;
- var miny = feature.geometry.coordinates[1] - 20 * res;
- return [minx, miny, minx + 40 * res, miny + 40 * res];
+ var minx = feature.geometry.coordinates[0] - 0.001;
+ var miny = feature.geometry.coordinates[1] - 0.001;
+ return [minx, miny, minx + 0.002, miny + 0.002];
case 'linestring':
var coords = feature.geometry.coordinates;
@@ -384,10 +398,11 @@
var pt = {x: feature.geometry.coordinates[0],
y: feature.geometry.coordinates[1]};
if(isNaN(pt.x) || isNaN(pt.y)) return;
- pt = $('#mapframe1').mapbender().convertRealToPixel(pt);
- if(feature.preview) {
- pt = {x: feature.geometry.coordinates[0], y: feature.geometry.coordinates[1]};
+ if(!feature.preview) {
+ pt = Proj4js.transform(this.wgs84, this.targetProj, pt);
+ pt = $('#mapframe1').mapbender().convertRealToPixel(pt);
}
+ if(isNaN(pt.x) || isNaN(pt.y)) return;
if(feature.properties['Mapbender:icon']) {
var size = 32;
if(feature.preview) {
@@ -407,9 +422,10 @@
var self = this;
var path;
$.each(feature.geometry.coordinates, function(_, v) {
- var pt = map.convertRealToPixel({x: v[0], y: v[1]});
- if(feature.preview) {
- pt = {x: v[0], y: v[1]};
+ var pt = {x: v[0], y: v[1]};
+ if(!feature.preview) {
+ pt = Proj4js.transform(self.wgs84, self.targetProj, pt);
+ pt = map.convertRealToPixel(pt);
}
if(isNaN(pt.x) || isNaN(pt.y)) return;
if(!path) {
@@ -427,9 +443,10 @@
var self = this;
var path;
$.each(feature.geometry.coordinates[0], function(_, v) {
- var pt = map.convertRealToPixel({x: v[0], y: v[1]});
- if(feature.preview) {
- pt = {x: v[0], y: v[1]};
+ var pt = {x: v[0], y: v[1]};
+ if(!feature.preview) {
+ pt = Proj4js.transform(self.wgs84, self.targetProj, pt);
+ pt = map.convertRealToPixel(pt);
}
if(isNaN(pt.x) || isNaN(pt.y)) return;
if(!path) {
@@ -498,6 +515,7 @@
render: function() {
var target = $('#kml-rendering-pane');
var map = $('#mapframe1').mapbender();
+ this.targetProj = new Proj4js.Proj(map.getSrs());
var self = this;
if(target.length == 0) {
$('#mapframe1').append('<div id="kml-rendering-pane" style="position: absolute; top: 0px; left: 0px; z-index: 80;"></div>');
More information about the Mapbender_commits
mailing list