[Mapbender-commits] r1107 - trunk/mapbender/http/javascripts
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Thu Feb 8 10:34:08 EST 2007
Author: christoph
Date: 2007-02-08 10:33:57 -0500 (Thu, 08 Feb 2007)
New Revision: 1107
Removed:
trunk/mapbender/http/javascripts/mod_geometryArray.js
Log:
now part of geometry.js
Deleted: trunk/mapbender/http/javascripts/mod_geometryArray.js
===================================================================
--- trunk/mapbender/http/javascripts/mod_geometryArray.js 2007-02-08 15:33:21 UTC (rev 1106)
+++ trunk/mapbender/http/javascripts/mod_geometryArray.js 2007-02-08 15:33:57 UTC (rev 1107)
@@ -1,595 +0,0 @@
-/*
-* $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
-
-<?php
- require_once("point.js");
-?>
-var geomTypePolygon = "polygon";
-var geomTypeLine = "line";
-var geomTypePoint = "point";
-
-var nameGeometryArray = "GeometryArray";
-var nameMultiGeometry = "MultiGeometry";
-var nameGeometry = "Geometry";
-
-function cloneObject(a){
- var z = new Array();
-
- for (attr in a) {
- var b = a[attr];
- if (typeof(b) == "object") {z[attr] = cloneObject(b);}
- else z[attr] = b;
- }
- return z;
-}
-
-function addslashes(str) {
- str=str.replace(/\'/g,'\\\'');
- str=str.replace(/\"/g,'\\"');
- str=str.replace(/\\/g,'\\\\');
- str=str.replace(/\0/g,'\\0');
- return str;
-}
-function stripslashes(str) {
- str=str.replace(/\\'/g,'\'');
- str=str.replace(/\\"/g,'"');
- str=str.replace(/\\\\/g,'\\');
- str=str.replace(/\\0/g,'\0');
- return str;
-}
-
-
-// ----------------------------------------------------
-// ----------- class: geometry array ------------------
-function GeometryArray(){
-
- this.count = function(){
- return this.m.length;
- }
-
- this.union = function(geomArray){
- for (var i=0; i < geomArray.count(); i++) this.appendMember(geomArray.get(i));
- }
-
- this.get = function(i){
- i = this.getIndex(i);
- if (i != null) return this.m[i];
- return false;
- }
-
- this.getGeometry = function(i,j){
- return this.get(i).get(j);
- }
-
- this.getPoint = function(i,j,k){
- return this.get(i).get(j).get(k);
- }
-
- this.addMember = function(geomtype){
- this.m[this.m.length] = new MultiGeometry(geomtype, -1);
- }
-
- this.appendMember = function(aMember){
- this.m[this.m.length] = cloneObject(aMember);
- }
-
- this.del = function(i){
- i = this.getIndex(i);
- for(var z = i; z < this.m.length - 1; z++){
- this.m[z] = this.m[z+1];
- }
- this.m.length -= 1;
- }
-
- this.findMultiGeometry = function(m) {
- for (var i=0; i < this.count(); i++) {
- if (this.get(i).equals(m)) return i;
- }
- return null;
- }
-
- this.removeMultiGeometry = function(m) {
- var i = true;
- i = this.findMultiGeometry(m);
- if (i != null) this.del(i);
- }
-
- this.delGeometry = function(i,j){
- var res = this.get(i).del(j);
- if (res == false) this.del(i);
- }
-
- this.delPoint = function (i,j,k){
- var res = this.get(i).delPoint(j,k);
- if (res == false) this.del(i);
- }
-
- this.close = function(){
- this.get(-1).get(-1).close();
- if (this.get(-1).get(-1).count() == 0) {this.get(-1).del(-1);}
- if (this.get(-1).count() == 0) {this.del(-1);}
- }
-
- this.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;
- }
- }
- }
- }
- }
- }
-
- this.updateAllPointsLike = function(oldP, newP){
- for (var i = 0; i < this.count(); i++){
- this.get(i).updateAllPointsLike(oldP, newP);
- }
- }
-
- this.toString = function(){
- var str = "";
- for (var i =0 ; i < this.count() ; i++){
- str += this.get(i).toString();
- }
- return str;
- }
-
- this.getIndex = function(i){ //private
- if ((i >= 0 && i < this.m.length) || (i*(-1)>0 && i*(-1) <=this.m.length)){
- if (i >= 0) return i; else return this.m.length+i;
- }
- else {
- alert("exception: member index " + i + " is not valid");
- return null;
- }
- }
-
- this.name = nameGeometryArray;
- this.m = new Array();
-}
-
-// ----------------------------------------------------
-// ----------- class: multigeometry -----------
-function MultiGeometry(geomtype, wfs_conf){
-
- this.count = function(){
- return this.g.length;
- }
-
- this.get = function(i){
- i = this.getIndex(i);
- if (i != null) return this.g[i];
- return false;
- }
-
- this.getPoint = function(j,k){
- return this.get(j).get(k);
- }
-
- this.addGeometry = function(){
- this.g[this.g.length] = new Geometry(this.geomtype);
- }
-
- this.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;
- }
-
- this.del = function(i){
- i = this.getIndex(i);
- if (i != null){
- var tmpLength = this.count() - 1;
- for (var z = i; z < tmpLength ; z ++){
- this.g[z] = this.g[z+1];
- this.e[z] = this.e[z+1];
- }
- this.g.length -= 1;
-
- if (this.g.length == 0) return false;
- }
- return true;
- }
-
- this.delPoint = function(i,j){
- var res = this.get(i).del(j);
- if (res == false) {return this.del(i);}
- return true;
- }
-
- this.emptyMember = function(){
- this.g = new Array();
- }
-
- this.updateAllPointsLike = function(oldP, newP){
- for (var i = 0; i < this.count(); i++){
- this.get(i).updateAllPointsLike(oldP, newP);
- }
- }
-
- this.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 new Array(min, max);
- }
-
- this.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);
- }
-
- this.getTotalPointCount = function(){
- var c = 0;
- for (var i = 0 ; i < this.count(); i++){
- c += this.get(i).count();
- }
- return c;
- }
-
- this.toString = function(){
- var str = "";
- for (var i = 0 ; i < this.count(); i++){
- str += this.get(i).toString();
- }
- return str;
- }
-
- this.getIndex = function(i){ //private
- if ((i >= 0 && i < this.g.length) || (i*(-1)>0 && i*(-1) <=this.g.length)){
- if (i >= 0) {return i;} else {return this.g.length+i;}
- }
- else {
- alert("exception: geometry index is not valid");
- return null;
- }
- }
-
- this.g = new Array();
- this.e = new Wfs_element();
- this.geomtype = geomtype;
- this.name = nameMultiGeometry;
- this.wfs_conf = wfs_conf;
-}
-
-// ----------------------------------------------------
-// ----------- class: geometry ------------------------
-function Geometry(aGeomtype){
-
- this.count = function(){
- return this.v.length;
- }
-
- this.get = function(i){
- i = this.getIndex(i);
- if (i != null){return this.v[i];}
- return false;
- }
-
- this.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 new Array(min, max);
- }
-
- this.close = function(){
- this.complete = true;
- if (this.geomtype == geomTypePolygon){
- if (this.count() > 0){this.addPoint(this.get(0));}
- }
- }
-
- this.addPointByCoordinates = function(x,y){
- this.v[this.v.length] = new Point(x,y);
-// this.updateDist();
- }
-
- this.addPoint = function(aPoint){
- this.v[this.v.length] = new Point(aPoint.x, aPoint.y);
-// this.updateDist();
- }
-
- this.addPointAtIndex = function(p,i){
- i = this.getIndex(i);
- if (i != null){
- for(var z = this.v.length; z > i; z--){
- this.v[z] = this.v[z-1];
- }
- this.v[i] = new Point(p.x, p.y);
-// this.updateDist();
- }
- }
-
- this.del = function(i){
- i = this.getIndex(i);
- if (i != null) {
- var tmpLength = this.count()-1;
-
- for (var z = i; z < tmpLength ; z ++){
- this.v[z] = this.v[z+1];
- }
- this.v.length -= 1;
-
- if (this.geomtype == geomTypePolygon){
- if (i == tmpLength) {this.v[0] = this.v[tmpLength-1];}
- else if (i == 0) {this.v[tmpLength-1] = this.v[0];}
- if (this.v.length == 1){return false;}
- }
-// this.updateDist();
- if(this.v.length == 0) {return false;}
- return true;
- }
- return false;
- }
-
- this.updateGeometry = function(p, i){
- i = this.getIndex(i);
- if ((i == 0 || i == this.count()-1) && this.geomtype == geomTypePolygon){
- this.v[0] = p;
- this.v[this.count()-1] = p;
- }
- else {this.v[i] = p;}
-// this.updateDist();
- }
-
- this.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);
- }
- }
- }
-
- this.isComplete = function() {
- return this.complete;
- }
-
- this.toString = function(){
- var str = "";
- for (var i = 0 ; i < this.count(); i++){
- str += this.get(i).toString();
- }
- return str;
- }
-
- this.equals = function(geom) {
- if (this.geomtype != geom.geomtype) return false;
- if (this.count() != geom.count()) return false;
- for (var i in this.v) {
- if (!this.get(i).equals(geom.get(i))) return false;
- }
- return true;
- }
-
- this.getIndex = function(i){ //private
- if ((i >= 0 && i < this.v.length) || (i*(-1)>0 && i*(-1) <=this.v.length)){
- if (i >= 0) {return i;} else {return this.v.length+i;}
- }
- else {
- alert("exception: point index is not valid");
- return null;
- }
- }
-
- this.updateDist = function(){ //private
- this.dist[0] = 0;
- this.totaldist[0] = 0;
- for (var i = 1 ; i < this.count(); i++){
- this.dist[i] = this.get(i-1).dist(this.get(i));
- this.totaldist[i] = this.totaldist[i-1] + this.dist[i];
- }
- }
-
- this.geomtype = aGeomtype;
- this.complete = false;
- this.v = new Array();
- this.dist = new Array();
- this.totaldist = new Array();
- this.name = nameGeometry;
-}
-
-// ----------------------------------------------------
-// ----------- class: Wfs_element ---------------------
-function Wfs_element(){
-
- this.count = function(){
- return this.name.length;
- }
-
- this.getElementValueByName = function(elementName){
- var i = this.getElementIndexByName(elementName);
- if (i == -1) {return false;}
- return this.value[i];
- }
-
- this.getName = function(i){
- if (this.isValidElementIndex(i)) {return this.name[i];}
- return false;
- }
-
- this.getValue = function(i){
- if (this.isValidElementIndex(i)) {return this.value[i];}
- return false;
- }
-
- this.setElement = function(aName, aValue){
- var i = this.getElementIndexByName(aName);
- if (i == -1) i = this.name.length;
- this.name[i] = aName;
- this.value[i] = aValue;
- return true;
- }
-
- this.getElementIndexByName = function(elementName){ // private
- var arrayLength = this.name.length;
- for (var j = 0 ; j < arrayLength ; j++){
- if (this.name[j] == elementName) {return j;}
- }
- return -1;
- }
-
- this.isValidElementIndex = function(i){ //private
- if (i>=0 && i<this.name.length) {return true;}
- alert("exception: illegal element index");
- return false;
- }
-
- this.name = new Array();
- this.value = new Array();
-}
-
-// ------------------------------------------------------
-// ----------- class: Snapping --------------------------
-function Snapping(aTarget, tolerance, color, isInFrame){
-
- this.isSnapped = function(){
- if (this.min_i != -1) {return true;}
- return false;
- }
-
- this.getSnappedPoint = function(geom){
- var point;
- var i = this.coord[this.min_i]['member'];
- var j = this.coord[this.min_i]['geometry'];
- var k = this.coord[this.min_i]['point'];
- if (geom.name == nameGeometryArray) {point = geom.getPoint(i,j,k);}
- else if (geom.name == nameMultiGeometry) {point = geom.getPoint(j,k);}
- else if (geom.name == nameGeometry) {point = geom.get(k);}
- return point;
- }
-
- this.check = function(currPoint){
- var minDist = false;
- for (var i = 0 ; i < this.coord.length ; i++) {
- var aDist = currPoint.dist(this.coord[i]['coord']);
- if (minDist == false || aDist < minDist) {
- minDist = aDist;
- if (minDist < this.tolerance) {this.min_i = i;}
- }
- }
- if (this.coord.length>0 && minDist > this.tolerance) {this.min_i = -1;}
- this.clean();
- if (this.min_i != -1) this.draw(this.coord[this.min_i]['coord'], this.tolerance, 3);
- }
-
- this.add = function(geom, k, j, i){
- var cnt = this.coord.length;
- this.coord[cnt] = new Array();
-
- if (typeof(j) != 'undefined'){
- if (typeof(i) != 'undefined'){
- this.coord[cnt]['coord'] = parent.realToMap(this.target, geom.getPoint(i,j,k));
- }
- else this.coord[cnt]['coord'] = parent.realToMap(this.target, geom.getPoint(j,k));
- }
- else this.coord[cnt]['coord'] = parent.realToMap(this.target, geom.get(k));
-
- this.coord[cnt]['member'] = i;
- this.coord[cnt]['geometry'] = j;
- this.coord[cnt]['point'] = k;
- }
-
- this.store = function(geom, event, point){
- this.coord = new Array();
- this.min_i = -1;
-
- 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 ((event != button_move && geom.get(i).get(j).isComplete() == true) || (typeof(point) != 'undefined' && !geom.get(i).get(j).get(k).equals(point))){
- this.add(geom, k, j, i);
- }
- }
- }
- else {
- if ((event != button_move && geom.get(i).get(j).isComplete() == true) || (typeof(point) != 'undefined' && !geom.get(i).get(j).get(k).equals(point))){
- this.add(geom, j, i);
- }
- }
- }
- }
- else {
- if ((event != button_move && geom.get(i).get(j).isComplete() == true) || (typeof(point) != 'undefined' && !geom.get(i).get(j).get(k).equals(point))){
- this.add(geom, i);
- }
- }
- }
- }
-
- this.draw = function(center,radius,size){ //private
- this.canvas.setColor(this.color);
- this.canvas.drawEllipse(-2+center.x-(size/2)*radius,-2+center.y-(size/2)*radius,size*radius,size*radius);
- this.canvas.paint();
- }
-
- this.clean = function(){ // private
- var el = parent.window.frames[this.target].document.getElementById(this.divtag);
- if (el) el.innerHTML = "";
- }
-
- this.tolerance = (typeof(tolerance) == 'undefined') ? 10 : tolerance;
- this.color = (typeof(color) == 'undefined') ? "#ff0000" : color;
- this.target = aTarget;
-
- this.coord = new Array(); // private
- this.canvas; // private
- this.divtag = "snapping"+Math.random()*Math.pow(10,10); //private
- this.min_i = -1; //private
-
- var attributes = new Array();
- attributes[0] = new Array();
- attributes[0][0] = "style";
- attributes[0][1] = "position:absolute;top:0px;left:0px;width:0px;height:0px;z-index:500";
- if (isInFrame == true){
- node = parent.mb_checkTag(this.target, "div", this.divtag, "body", attributes);
- this.canvas = new parent.jsGraphics(this.divtag, parent.window.frames[this.target]);
- }
- else{
- node = mb_checkTag(this.target, "div", this.divtag, "body", attributes);
- this.canvas = new jsGraphics(this.divtag, window.frames[this.target]);
- }
- this.canvas.setStroke(3);
- if (node == false) {alert("Fatal error: Element id is already taken!");}
-}
\ No newline at end of file
More information about the Mapbender_commits
mailing list