[Mapbender-commits] r1143 - trunk/mapbender/http/javascripts
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Fri Feb 23 09:22:38 EST 2007
Author: christoph
Date: 2007-02-23 09:22:38 -0500 (Fri, 23 Feb 2007)
New Revision: 1143
Added:
trunk/mapbender/http/javascripts/geometry.js
Log:
geometry library
Added: trunk/mapbender/http/javascripts/geometry.js
===================================================================
--- trunk/mapbender/http/javascripts/geometry.js (rev 0)
+++ trunk/mapbender/http/javascripts/geometry.js 2007-02-23 14:22:38 UTC (rev 1143)
@@ -0,0 +1,790 @@
+/*
+* $Id$
+* COPYRIGHT: (C) 2001 by ccgis. This program is free software under the GNU General Public
+* License (>=v2). Read the file gpl.txt that comes with Mapbender for details.
+*/
+// http://www.mapbender.org/index.php/GeometryArray.js
+
+
+var nameGeometryArray = "GeometryArray";
+var nameMultiGeometry = "MultiGeometry";
+var nameGeometry = "Geometry";
+
+var geomType = (
+ function () {
+ function ConstructorFunction(){
+ this.polygon = "polygon";
+ this.line = "line";
+ this.point = "point";
+ }
+ return new ConstructorFunction();
+ }
+) ();
+
+
+// ----------------------------------------------------------------------------------------------------
+// List: a template for geometry data structures
+// ----------------------------------------------------------------------------------------------------
+
+var List = function() {
+ this.count = function() {
+ return this.list.length;
+ };
+ this.del = function(i){
+ i = this.getIndex(i);
+ for(var z = i; z < this.count() - 1; z++){
+ this.list[z] = this.list[z+1];
+ }
+ this.list.length -= 1;
+ };
+ this.get = function(i) {
+ i = this.getIndex(i);
+ if (i !== null) {return this.list[i];}
+ return false;
+ };
+ this.add = function(item) {
+ this.list.push(item);
+ };
+ this.addCopy = function(item) {
+ this.list.push(cloneObject(item));
+ };
+ this.union = function(aList) {
+ for (var i=0; i < aList.count(); i++) {this.addCopy(aList.get(i));}
+ };
+ this.getIndex = function(i){
+ if ((i >= 0 && i < this.list.length) || (i*(-1)>0 && i*(-1) <= this.list.length)){
+ if (i >= 0) {return i;} else {return this.list.length+i;}
+ }
+ else {
+ alert("exception: member index " + i + " is not valid");
+ return null;
+ }
+ };
+ this.toString = function(){
+ var str = "";
+ for (var i =0 ; i < this.count() ; i++){
+ str += this.get(i).toString();
+ }
+ return str;
+ };
+
+ this.list = null;
+};
+
+// ----------------------------------------------------------------------------------------------------
+// GeometryArray
+// ----------------------------------------------------------------------------------------------------
+
+function GeometryArray(){
+
+ this.del = function(i){
+ i = this.getIndex(i);
+ for(var z = i; z < this.count() - 1; z++){
+ this.list[z] = this.list[z+1];
+ }
+ this.list.length -= 1;
+ };
+
+ this.addMember = function(geomType){
+ this.add(new MultiGeometry(geomType));
+ };
+
+ this.name = nameGeometryArray;
+ this.list = [];
+
+}
+
+GeometryArray.prototype = new List();
+
+GeometryArray.prototype.getGeometry = function(i,j){
+ return this.get(i).get(j);
+};
+
+GeometryArray.prototype.getPoint = function(i,j,k){
+ return this.get(i).get(j).get(k);
+};
+
+GeometryArray.prototype.findMultiGeometry = function(geom) {
+ var a = [];
+ for (var i=0; i < this.count(); i++) {
+ if (this.get(i).equals(geom)) {a.push(i);}
+ }
+ return a;
+};
+
+GeometryArray.prototype.delGeometry = function(i,j){
+ if (this.get(i).del(j) === false) {this.del(i);}
+};
+
+GeometryArray.prototype.delPoint = function (i,j,k){
+ var res = this.get(i).delPoint(j,k);
+ if (res === false) {this.del(i);}
+};
+
+GeometryArray.prototype.close = function(){
+ if (!this.get(-1).get(-1).close()) {
+ this.delGeometry(-1, -1);
+ }
+ else {
+ if (this.get(-1).get(-1).count() === 0) {this.get(-1).del(-1);}
+ if (this.get(-1).count() === 0) {this.del(-1);}
+ }
+};
+
+GeometryArray.prototype.delAllPointsLike = function(point){
+ var finished = false;
+ while (finished === false){
+ finished = true;
+ for (var i = 0 ; finished === true && i < this.count() ; i++){
+ for (var j = 0 ; finished === true && j < this.get(i).count() ; j++){
+ for (var k = 0 ; finished === true && k < this.get(i).get(j).count() ; k++){
+ if (this.getPoint(i,j,k).equals(point)){
+ this.delPoint(i,j,k);
+ finished = false;
+ }
+ }
+ }
+ }
+ }
+};
+
+GeometryArray.prototype.updateAllPointsLike = function(oldP, newP){
+ for (var i = 0; i < this.count(); i++){
+ this.get(i).updateAllPointsLike(oldP, newP);
+ }
+};
+
+
+
+// ----------------------------------------------------------------------------------------------------
+// MultiGeometry
+// ----------------------------------------------------------------------------------------------------
+
+function MultiGeometry(geomType){
+
+ this.addGeometry = function(){
+ this.add(new Geometry(this.geomType));
+ };
+
+ this.del = function(i){
+ i = this.getIndex(i);
+ if (i !== null){
+ var tmpLength = this.count() - 1;
+ for (var z = i; z < tmpLength ; z ++){
+ this.list[z] = this.list[z+1];
+ e[z] = e[z+1];
+ }
+ this.list.length -= 1;
+ if (this.list.length === 0) {return false;}
+ }
+ return true;
+ };
+
+ this.list = [];
+ this.e = new Wfs_element();
+ this.geomType = geomType;
+ this.name = nameMultiGeometry;
+}
+
+MultiGeometry.prototype = new List();
+
+MultiGeometry.prototype.updateAllPointsLike = function(oldP, newP){
+ for (var i = 0; i < this.count(); i++) {this.get(i).updateAllPointsLike(oldP, newP);}
+};
+
+MultiGeometry.prototype.getBBox = function(){
+ var q = this.get(0).get(0);
+ var min = cloneObject(q);
+ var max = cloneObject(q);
+ for(var i=0; i<this.count();i++){
+ var pos = this.get(i).getBBox();
+ if (pos[0].x < min.x) {min.x = pos[0].x;}
+ if (pos[1].x > max.x) {max.x = pos[1].x;}
+ if (pos[1].y > max.y) {max.y = pos[1].y;}
+ if (pos[0].y < min.y) {min.y = pos[0].y;}
+ }
+ return [min, max];
+};
+
+MultiGeometry.prototype.getCenter = function(){
+ var tmp = this.getBBox();
+ var x = parseFloat(tmp[0].x) + parseFloat((tmp[1].x - tmp[0].x)/2);
+ var y = parseFloat(tmp[0].y) + parseFloat((tmp[1].y - tmp[0].y)/2);
+ return new Point(x,y);
+};
+
+MultiGeometry.prototype.getTotalPointCount = function(){
+ var c = 0;
+ for (var i = 0 ; i < this.count(); i++) {c += this.get(i).count();}
+ return c;
+};
+
+MultiGeometry.prototype.getPoint = function(j,k){
+ return this.get(j).get(k);
+};
+
+MultiGeometry.prototype.equals = function(multigeom) {
+ if (this.geomType != multigeom.geomType) {return false;}
+ if (this.count() != multigeom.count()) {return false;}
+ if (this.getTotalPointCount() != multigeom.getTotalPointCount()) {return false;}
+ for (var i=0; i<this.count(); i++) {
+ if (!this.get(i).equals(multigeom.get(i))) {return false;}
+ }
+ return true;
+};
+
+MultiGeometry.prototype.delPoint = function(i,j){ // public
+ var res = this.get(i).del(j);
+ if (res === false) {return this.del(i);}
+ return true;
+};
+
+
+// ----------------------------------------------------------------------------------------------------
+// Geometry
+// ----------------------------------------------------------------------------------------------------
+
+function Geometry(aGeomtype){
+
+ this.del = function(i){
+ i = this.getIndex(i);
+ if (i !== null) {
+ var tmpLength = this.count()-1;
+
+ for (var z = i; z < tmpLength ; z ++){
+ this.list[z] = this.list[z+1];
+ }
+ this.list.length -= 1;
+
+ if (this.geomType == geomType.polygon){
+ if (i == tmpLength) {this.list[0] = this.list[tmpLength-1];}
+ else if (i === 0) {this.list[tmpLength-1] = this.list[0];}
+ if (this.list.length == 1){return false;}
+ }
+ updateDist();
+ if(this.list.length === 0) {return false;}
+ return true;
+ }
+ return false;
+ };
+
+ this.addPointByCoordinates = function(x,y){
+ this.add(new Point(x,y));
+ updateDist();
+ };
+
+ this.addPoint = function(aPoint){
+ this.add(new Point(aPoint.x, aPoint.y));
+ updateDist();
+ };
+
+ this.addPointAtIndex = function(p,i){
+ i = this.getIndex(i);
+ if (i !== null){
+ for(var z = this.count(); z > i; z--){
+ this.list[z] = this.list[z-1];
+ }
+ this.list[i] = new Point(p.x, p.y);
+ updateDist();
+ }
+ };
+
+ this.updateGeometry = function(p, i){
+ i = this.getIndex(i);
+ if ((i === 0 || i == this.count()-1) && this.geomType == geomType.polygon){
+ this.list[0] = p;
+ this.list[this.count()-1] = p;
+ }
+ else {this.list[i] = p;}
+ updateDist();
+ };
+
+ var updateDist = function(){
+ dist[0] = 0;
+ totaldist[0] = 0;
+ for (var i = 1 ; i < that.count(); i++){
+ dist[i] = that.get(i-1).dist(that.get(i));
+ totaldist[i] = totaldist[i-1] + dist[i];
+ }
+ };
+ this.getCurrentDist = function(numberOfDigits) {
+ if (typeof(numberOfDigits) == "number") {
+ return roundToDigits(dist[this.count()-1], numberOfDigits);
+ }
+ return dist[this.count()-1];
+
+ };
+ this.getTotalDist = function(numberOfDigits) {
+ if (typeof(numberOfDigits) == "number") {
+ return roundToDigits(totaldist[this.count()-1], numberOfDigits);
+ }
+ return totaldist[this.count()-1];
+ };
+ this.close = function(){
+ complete = true;
+ if (this.geomType == geomType.polygon){
+ if (this.count() > 2){
+ if (!this.get(0).equals(this.get(-1))) {
+ this.addPoint(this.get(0));
+ }
+ }
+ else {return false;}
+ }
+ if (this.geomType == geomType.line){
+ if (this.count() < 2){return false;}
+ }
+ return true;
+ };
+ this.isComplete = function() {
+ return complete;
+ };
+
+ this.list = [];
+ var dist = [];
+ var totaldist = [];
+ var complete = false;
+
+ var that = this;
+
+ this.geomType = aGeomtype;
+ this.name = nameGeometry;
+}
+
+Geometry.prototype = new List();
+
+Geometry.prototype.getBBox = function(){
+ var q = this.get(0);
+ var min = cloneObject(q);
+ var max = cloneObject(q);
+
+ for (var j=0; j<this.count(); j++){
+ var pos = this.get(j);
+ if (pos.x < min.x) {min.x = pos.x;}
+ else if (pos.x > max.x) {max.x = pos.x;}
+ if (pos.y < min.y) {min.y = pos.y;}
+ else if (pos.y > max.y) {max.y = pos.y;}
+ }
+ return [min, max];
+};
+
+Geometry.prototype.updateAllPointsLike = function(oldP, newP){
+ var len = this.count();
+ for (var i = 0; i < len ; i++){
+ if (oldP.equals(this.get(i))){
+ if (i>0 && newP.equals(this.get(i-1))){
+ this.del(i);
+ len--;
+ i--;
+ }
+ else {this.updateGeometry(newP, i);}
+ }
+ }
+};
+
+Geometry.prototype.equals = function(geom) {
+ if (this.geomType != geom.geomType) {return false;}
+ if (this.count() != geom.count()) {return false;}
+ for (var i=0; i < this.count(); i++) {
+ if (!this.get(i).equals(geom.get(i))) {return false;}
+ }
+ return true;
+};
+
+
+
+
+
+// ----------------------------------------------------------------------------------------------------
+// Wfs_element (FIXME)
+// ----------------------------------------------------------------------------------------------------
+
+function Wfs_element(){
+
+ this.count = function(){return name.length;};
+
+ this.getName = function(i){
+ if (isValidElementIndex(i)) {return name[i];}
+ return false;
+ };
+
+ this.getValue = function(i){
+ if (isValidElementIndex(i)) {return value[i];}
+ return false;
+ };
+
+ this.setElement = function(aName, aValue){
+ var i = this.getElementIndexByName(aName);
+ if (i === false) {i = this.count();}
+ name[i] = aName;
+ value[i] = aValue;
+ return true;
+ };
+
+ var isValidElementIndex = function(i){
+ if (i>=0 && i<name.length) {return true;}
+ alert("exception: illegal element index");
+ return false;
+ };
+
+ var name = [];
+ var value = [];
+}
+
+Wfs_element.prototype.getElementIndexByName = function(elementName){
+ for (var j = 0 ; j < this.count() ; j++){
+ if (this.getName(j) == elementName) {return j;}
+ }
+ return false;
+};
+
+Wfs_element.prototype.getElementValueByName = function(elementName){
+ var i = this.getElementIndexByName(elementName);
+ if (i === false) {return false;}
+ return this.getValue(i);
+};
+
+
+
+// ----------------------------------------------------------------------------------------------------
+// Canvas
+// ----------------------------------------------------------------------------------------------------
+
+
+function Canvas(aMapframe, aTagName, aStyle, aLineWidth) {
+
+ this.drawGeometry = function(t,g,col){
+ var mapObjInd = getMapObjIndexByName(mapframe);
+ width = mb_mapObj[mapObjInd].width;
+ height = mb_mapObj[mapObjInd].height;
+ for(var i=0; i < g.count(); i++){
+ if(t==geomType.point) {
+ var p = realToMap(mapframe,g.get(i).get(0));
+ if (p.x + diameter < mb_mapObj[mapObjInd].width && p.x - diameter > 0 &&
+ p.y + diameter < mb_mapObj[mapObjInd].height && p.y - diameter > 0) {
+ drawCircle(p.x-1, p.y-1, diameter,col);
+ }
+ }
+ else if(t==geomType.line || t==geomType.polygon) {
+ for (var j=0; j<g.get(i).count()-1; j++) {
+ var pq = calculateVisibleDash(realToMap(mapframe,g.get(i).get(j)), realToMap(mapframe,g.get(i).get(j+1)), width, height);
+ if (pq) {
+ drawLine([pq[0].x-1, pq[1].x-1], [pq[0].y-1, pq[1].y-1], col);
+ }
+ }
+ }
+ else {
+ alert('unknown geomType ' + t);
+ }
+ }
+ };
+
+ this.isTooSmall = function(g){
+ var tmp = g.getBBox();
+ var min = realToMap(mapframe,tmp[0]);
+ var max = realToMap(mapframe,tmp[1]);
+ if((Math.abs(max.x - min.x) < minWidth) && (Math.abs(max.y - min.y) < minWidth)) {
+ return true;
+ }
+ return false;
+ };
+
+ var drawCircle = function(x, y, diameter, color) {
+ canvas.setColor(color);
+ canvas.drawEllipse(x-diameter/2,y-diameter/2,diameter,diameter);
+ };
+
+ var drawLine = function(x_array, y_array, color) {
+ canvas.setColor(color);
+ canvas.drawPolyline(x_array, y_array);
+ };
+
+ this.getCanvas = function(){return canvas;};
+
+ var diameter = 8;
+ var minWidth = 8;
+ var lineWidth = aLineWidth;
+ var mapframe = aMapframe;
+ var style = aStyle;
+
+ var that = this;
+ this.canvasDivTag = new DivTag(aTagName, mapframe, style);
+ var canvas = new jsGraphics(aTagName, window.frames[mapframe]);
+ canvas.setStroke(lineWidth);
+ mb_registerPanSubElement(aTagName);
+}
+
+Canvas.prototype.clean = function () {
+ this.canvasDivTag.clean();
+};
+
+Canvas.prototype.paint = function(gA) {
+ for (var q = 0; q < gA.count(); q++) {
+ var m = gA.get(q);
+ var t = m.geomType;
+ var col = m.color;
+ if (t == geomType.point) {this.drawGeometry(t,m,col);}
+ else {
+ if (this.isTooSmall(m)){
+ var newMember = new MultiGeometry(geomType.point);
+ newMember.addGeometry();
+ newMember.get(-1).addPoint(m.getCenter());
+ this.drawGeometry(geomType.point,newMember,col);
+ }
+ else{
+ if(t == geomType.line) {this.drawGeometry(t,m, col);}
+ else if(t == geomType.polygon) {this.drawGeometry(t,m,col);}
+ else {alert("unknown geomType");}
+ }
+ }
+ }
+ this.getCanvas().paint();
+};
+
+// ----------------------------------------------------------------------------------------------------
+// Highlight
+// ----------------------------------------------------------------------------------------------------
+
+function Highlight(aTargetArray, aTagName, aStyle, aLineWidth) {
+ this.del = function(m, color) {
+ var a = gA.findMultiGeometry(m);
+ var del = false;
+ for (var i=0; i<a.length && del === false; i++) {
+ if (gA.get(a[i]).color == color) {
+ gA.del(a[i]);
+ del = true;
+ }
+ }
+ this.paint();
+ };
+
+ this.add = function(m, color) {
+ gA.addCopy(m);
+ if (typeof(color) != 'undefined') {gA.get(-1).color = color;}
+ else {gA.get(-1).color = lineColor;}
+ this.paint();
+ };
+
+ this.clean = function() {
+ if (gA.count() > 0) {
+ gA = new GeometryArray();
+ this.paint();
+ }
+ };
+
+ this.paint = function() {
+ for (var i=0; i < canvas.length; i++) {
+ if (typeof(canvas[i]) == "object") {canvas[i].clean();}
+ }
+ for (var i=0; i<targets.length; i++){
+ if (typeof(canvas[i]) == 'undefined') {
+ canvas[i] = new Canvas(targets[i], tagname, style, lineWidth);
+ }
+ canvas[i].paint(gA);
+ }
+ };
+
+ var lineWidth = aLineWidth;
+ var tagname = 'mod_gaz_draw'+aTagName;
+ var style = aStyle;
+ var targets = aTargetArray;
+ var canvas = [];
+ var gA = new GeometryArray();
+ var lineColor = "#ff0000";
+}
+
+// ----------------------------------------------------------------------------------------------------
+// Snapping
+// ----------------------------------------------------------------------------------------------------
+
+function Snapping(aTarget, aTolerance, aColor, aZIndex){
+
+ this.draw = function(center,radius){
+ mG = new MultiGeometry(geomType.point);
+ mG.addGeometry();
+ mG.get(-1).addPoint(center);
+ highlight.add(mG);
+ };
+ this.getTolerance = function() {return tolerance;};
+ this.getTarget = function() {return target;};
+ this.cleanHighlight = function() {return highlight.clean();};
+ this.addPoint = function(aPoint) {coord.push(aPoint);};
+ this.getPointCount = function() {return coord.length;};
+ this.getPoint = function(i) {return coord[i];};
+ this.resetPoints = function() {coord = [];};
+ this.getNearestNeighbour = function(){
+ if (min_i != -1) {return this.getPoint(min_i);}
+ return false;
+ };
+ this.setIndexOfNearestNeighbour = function(i){min_i = i;};
+ this.resetIndexOfNearestNeighbour = function(){min_i = -1;};
+
+ var tolerance = (typeof(aTolerance) == 'undefined') ? 10 : aTolerance;
+ var coord = [];
+ var min_i = -1;
+ var target = aTarget;
+ var lineWidth = 2;
+ var style = {"position":"absolute", "top":"0px", "left":"0px", "z-index":aZIndex};
+ var highlight = new Highlight([target], "snapping"+Math.round(Math.random()*Math.pow(10,10)), style, lineWidth);
+}
+
+Snapping.prototype.check = function(currPoint){
+ var minDist = false;
+
+ for (var i = 0 ; i < this.getPointCount() ; i++) {
+
+ var currDist = currPoint.dist(realToMap(this.getTarget(), this.getPoint(i)));
+ if (minDist === false || currDist < minDist) {
+ minDist = currDist;
+ if (minDist < this.getTolerance()) {this.setIndexOfNearestNeighbour(i);}
+ }
+ }
+ if (this.getPointCount() > 0 && minDist > this.getTolerance()) {
+ this.resetIndexOfNearestNeighbour();
+ }
+ this.cleanHighlight();
+ if (this.isSnapped()) {
+ this.draw(this.getNearestNeighbour(), this.getTolerance());
+ }
+};
+
+Snapping.prototype.store = function(geom, point){
+ this.resetPoints();
+ this.resetIndexOfNearestNeighbour();
+
+ for (var i = 0 ; i < geom.count(); i++){
+ if (geom.name == nameGeometryArray || geom.name == nameMultiGeometry){
+ for (var j = 0 ; j < geom.get(i).count() ; j++){
+ if (geom.get(i).name == nameMultiGeometry){
+ for (var k = 0 ; k < geom.get(i).get(j).count() ; k++){
+ if ((geom.get(i).get(j).isComplete() === true && typeof(point) == 'undefined') || (typeof(point) != 'undefined' && !geom.get(i).get(j).get(k).equals(point))){
+ this.add(geom.getPoint(i, j, k));
+ }
+ }
+ }
+ else {
+ if ((geom.get(i).isComplete() === true && typeof(point) == 'undefined') || (typeof(point) != 'undefined' && !geom.get(i).get(j).get(k).equals(point))){
+ this.add(geom.getPoint(i, j));
+ }
+ }
+ }
+ }
+ else {
+ if (typeof(point) != 'undefined' && !geom.get(i).get(j).get(k).equals(point)){
+ this.add(geom.get(i));
+ }
+ }
+ }
+};
+
+Snapping.prototype.isSnapped = function(){
+ if (this.getNearestNeighbour() !== false) {return true;}
+ return false;
+};
+
+Snapping.prototype.getSnappedPoint = function(geom){
+ return this.getNearestNeighbour();
+};
+
+Snapping.prototype.add = function(aPoint){
+ this.addPoint(aPoint);
+};
+
+Snapping.prototype.clean = function(){
+ this.cleanHighlight();
+};
+
+
+
+// ----------------------------------------------------------------------------------------------------
+// misc. functions
+// ----------------------------------------------------------------------------------------------------
+
+function calculateVisibleDash (p0, p1, width, height) {
+ if (p0.x > p1.x) {var p_temp = p0; p0 = p1; p1 = p_temp; p_temp = null;}
+ var p = p0; var q = p1; var m; var ix; var iy;
+ if (p1.x != p0.x) {
+ m = -(p1.y-p0.y)/(p1.x-p0.x);
+ if (p0.x < width && p1.x > 0 && !(p0.y < 0 && p1.y < 0) && !(p0.y > height && p1.y > height) ) {
+ if (p0.x < 0) {
+ iy = p0.y - m*(0-p0.x);
+ if (iy > 0 && iy < height) {p = new Point(0, iy);}
+ else if (iy > height) {
+ ix = p0.x+((p0.y - height)/m);
+ if (ix > 0 && ix < width) {p = new Point(ix, height);} else {return false;}
+ }
+ else if (iy < 0) {
+ ix = p0.x+(p0.y/m);
+ if (ix > 0 && ix < width) {p = new Point(ix, 0);} else {return false;}
+ }
+ else {return false;}
+ }
+ else if (p0.y >= 0 && p0.y <= height) {p = p0;}
+ else if (p0.y < 0) {
+ ix = p0.x+(p0.y/m);
+ if (ix > 0 && ix < width) {p = new Point(ix, 0);} else {return false;}
+ }
+ else if (p0.y > height && m > 0) {
+ ix = p0.x+((p0.y - height)/m);
+ if (ix > 0 && ix < width) {p = new Point(ix, height);} else {return false;}
+ }
+ else {return false;}
+ if (p1.x > width) {
+ iy = p1.y - m*(width-p1.x);
+ if (iy > 0 && iy < height) {q = new Point(width, iy);}
+ else if (iy < 0) {
+ ix = p0.x+(p0.y/m);
+ if (ix > 0 && ix < width) {q = new Point(ix, 0);} else {return false;}
+ }
+ else if (iy > height) {
+ ix = p0.x+((p0.y - height)/m);
+ if (ix > 0 && ix < width) {q = new Point(ix, height);} else {return false;}
+ }
+ else {return false;}
+ }
+ else if (p1.y >= 0 && p1.y <= height) {q = p1;}
+ else if (p1.y < 0) {
+ ix = p1.x+(p1.y/m);
+ if (ix > 0 && ix < width) {q = new Point(ix, 0);} else {return false;}
+ }
+ else if (p1.y > height) {
+ ix = p1.x+((p1.y- height)/m);
+ if (ix > 0 && ix < width) {q = new Point(ix, height);} else {return false;}
+ }
+ }
+ else {return false;}
+ }
+ else {
+ if (!(p0.y < 0 && p1.y < 0) && !(p0.y > height && p1.y > height)) {
+ if (p0.y < 0) {p = new Point(p0.x, 0);}
+ else if (p0.y > height) {p = new Point(p0.x, height);}
+ else {p = p0;}
+ if (p1.y < 0) {q = new Point(p0.x, 0);}
+ else if (p1.y > height) {q = new Point(p0.x, height);}
+ else {q = p1;}
+ }
+ else {return false;}
+ }
+ return [new Point(Math.round(q.x), Math.round(q.y)), new Point(Math.round(p.x), Math.round(p.y))];
+}
+
+function objString (a){
+ var z = "";
+
+ for (attr in a) {
+ var b = a[attr];
+ if (typeof(b) == "object") {z += objString(b);}
+ else {z += attr + " " + b + "\n";alert(attr + " " + b);}
+ }
+ return z;
+}
+
+function cloneObject(a){
+ var z = [];
+
+ for (attr in a) {
+ var b = a[attr];
+ if (typeof(b) == "object") {z[attr] = cloneObject(b);}
+ else {z[attr] = b;}
+ }
+ return z;
+}
\ No newline at end of file
Property changes on: trunk/mapbender/http/javascripts/geometry.js
___________________________________________________________________
Name: svn:keywords
+ HeadURL Id LastChangedBy LastChangedDate LastChangedRevision
More information about the Mapbender_commits
mailing list