[Mapbender-commits] r1096 - trunk/mapbender/http/javascripts
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Thu Feb 8 09:51:24 EST 2007
Author: christoph
Date: 2007-02-08 09:51:19 -0500 (Thu, 08 Feb 2007)
New Revision: 1096
Modified:
trunk/mapbender/http/javascripts/geometry.js
Log:
* added measuring
* added class DivTag
* replaced "new Array()" by "[]"
Modified: trunk/mapbender/http/javascripts/geometry.js
===================================================================
--- trunk/mapbender/http/javascripts/geometry.js 2007-02-08 14:48:33 UTC (rev 1095)
+++ trunk/mapbender/http/javascripts/geometry.js 2007-02-08 14:51:19 UTC (rev 1096)
@@ -14,6 +14,17 @@
var nameMultiGeometry = "MultiGeometry";
var nameGeometry = "Geometry";
+var geomType = (
+ function () {
+ function constructorFunction(){
+ this.polygon = "polygon";
+ this.line = "line";
+ this.point = "point";
+ }
+ return new constructorFunction();
+ }
+) ();
+
// ----------------------------------------------------------------------------------------------------
// GeometryArray
// ----------------------------------------------------------------------------------------------------
@@ -43,7 +54,7 @@
}
this.addMember = function(geomtype){ // public
- this.m[this.m.length] = new MultiGeometry(geomtype, -1);
+ this.m[this.m.length] = new MultiGeometry(geomtype);
}
this.appendMember = function(aMember){ // public
@@ -59,7 +70,7 @@
}
this.findMultiGeometry = function(m) { // public
- var a = new Array();
+ var a = [];
for (var i=0; i < this.count(); i++) {
if (this.get(i).equals(m)) a.push(i);
}
@@ -137,7 +148,7 @@
this.geomTypeLine = "line";
this.geomTypePoint = "point";
this.name = nameGeometryArray;
- this.m = new Array();
+ this.m = [];
}
// ----------------------------------------------------------------------------------------------------
@@ -195,7 +206,7 @@
}
this.emptyMember = function(){ // public
- this.g = new Array();
+ this.g = [];
}
this.updateAllPointsLike = function(oldP, newP){ // public
@@ -245,7 +256,7 @@
}
}
- this.g = new Array();
+ this.g = [];
this.e = new Wfs_element();
this.geomtype = geomtype;
this.name = nameMultiGeometry;
@@ -295,12 +306,12 @@
this.addPointByCoordinates = function(x,y){ // public
this.v[this.v.length] = new Point(x,y);
-// this.updateDist();
+ this.updateDist();
}
this.addPoint = function(aPoint){ // public
this.v[this.v.length] = new Point(aPoint.x, aPoint.y);
-// this.updateDist();
+ this.updateDist();
}
this.addPointAtIndex = function(p,i){ // public
@@ -310,7 +321,7 @@
this.v[z] = this.v[z-1];
}
this.v[i] = new Point(p.x, p.y);
-// this.updateDist();
+ this.updateDist();
}
}
@@ -329,7 +340,7 @@
else if (i == 0) {this.v[tmpLength-1] = this.v[0];}
if (this.v.length == 1){return false;}
}
-// this.updateDist();
+ this.updateDist();
if(this.v.length == 0) {return false;}
return true;
}
@@ -343,7 +354,7 @@
this.v[this.count()-1] = p;
}
else {this.v[i] = p;}
-// this.updateDist();
+ this.updateDist();
}
this.updateAllPointsLike = function(oldP, newP){ // public
@@ -397,12 +408,25 @@
this.totaldist[i] = this.totaldist[i-1] + this.dist[i];
}
}
+ this.getCurrentDist = function(numberOfDigits) { //public
+ if (typeof(numberOfDigits) == "number") {
+ return roundToDigits(this.dist[this.count()-1], numberOfDigits);
+ }
+ return this.dist[this.count()-1];
+
+ }
+ this.getTotalDist = function(numberOfDigits) { //public
+ if (typeof(numberOfDigits) == "number") {
+ return roundToDigits(this.totaldist[this.count()-1], numberOfDigits);
+ }
+ return this.totaldist[this.count()-1];
+ }
this.geomtype = aGeomtype;
this.complete = false;
- this.v = new Array();
- this.dist = new Array();
- this.totaldist = new Array();
+ this.v = [];
+ this.dist = [];
+ this.totaldist = [];
this.name = nameGeometry;
}
@@ -454,16 +478,73 @@
return false;
}
- this.name = new Array();
- this.value = new Array();
+ this.name = [];
+ this.value = [];
}
+
// ----------------------------------------------------------------------------------------------------
+// DivTag
+// ----------------------------------------------------------------------------------------------------
+
+function DivTag (tagName, frameName, style) {
+ this.write = function (someText) {
+ if (this.exists()) {
+ this.rootNode.getElementById(this.tagName).innerHTML = someText;
+ }
+ }
+ this.clean = function () {
+ if (this.exists()) {
+ this.rootNode.getElementById(this.tagName).innerHTML = "";
+ }
+ }
+ this.exists = function () {
+ return (this.rootNode.getElementById(this.tagName))?true:false;
+ }
+ this.create = function () {
+ if (!this.exists()) {
+ var divTag = this.rootNode.createElement("div");
+ var divTagAppended = this.rootNode.getElementsByTagName("body")[0].appendChild(divTag);
+ divTagAppended.setAttribute("id",this.tagName);
+ divTagAppended.setAttribute("style",this.style);
+ }
+ else {
+ this.clean();
+ }
+ }
+ this.checkFrame = function () {
+ if (this.frameName != "") {
+ return (typeof(window.frames[this.frameName]) != 'undefined')
+ }
+ return true;
+ }
+
+ this.tagName = tagName;
+ this.frameName = frameName;
+ this.style = style;
+ this.rootNode = document;
+
+
+ if (this.frameName != "") {
+ if (this.checkFrame()) {
+ this.rootNode = window.frames[this.frameName].document;
+ }
+ else {
+ // throw exception
+ alert("frame "+this.frameName+" doesn't exist.");
+ }
+ }
+
+ this.create();
+}
+
+
+// ----------------------------------------------------------------------------------------------------
// Canvas
// ----------------------------------------------------------------------------------------------------
-function Canvas(mapframe, tagname) {
+function Canvas(mapframe, tagname, style, lineWidth) {
this.paint = function(gA) { // public
if (this.checkTag()) {
@@ -488,6 +569,9 @@
}
this.canvas.paint();
}
+ else {
+ alert('div tag doesnt exist');
+ }
}
this.drawGeometry = function(t,g,col){ // private
@@ -552,7 +636,6 @@
this.canvas.setColor(color);
this.canvas.drawPolygon(x_array, y_array);
}
-
this.checkTag = function () { // private
if (typeof(window.frames[this.mapframe]) != 'undefined') {
var isTag = (window.frames[this.mapframe].document.getElementById(this.tagname))?1:0;
@@ -560,7 +643,8 @@
var draw = window.frames[this.mapframe].document.createElement("div");
var tmp = window.frames[this.mapframe].document.getElementsByTagName("body")[0].appendChild(draw);
tmp.setAttribute("id",this.tagname);
- tmp.setAttribute("style","position:absolute;top:0px;left:0px;width:0px;height:0px;z-index:100");
+// tmp.setAttribute("style",this.style);
+ tmp.style.cssText = this.style;
}
else this.clean();
return true;
@@ -570,22 +654,26 @@
}
return false;
}
+ this.diameter = 8;
+ this.minWidth = 8;
+ this.lineWidth = lineWidth;
this.mapframe = mapframe;
this.tagname = tagname;
+ this.style = style;
+// this.canvasDivTag = new DivTag(this.tagname, this.mapframe, this.style);
if (this.checkTag()) {
this.canvas = new jsGraphics(this.tagname, window.frames[this.mapframe]);
- this.canvas.setStroke(3);
+ this.canvas.setStroke(this.lineWidth);
mb_registerPanSubElement(this.tagname);
}
- this.diameter = 8;
- this.minWidth = 8;
}
// ----------------------------------------------------------------------------------------------------
// Highlight
// ----------------------------------------------------------------------------------------------------
-function Highlight(target_array, tagname) {
+function Highlight(target_array, tagname, style, lineWidth) {
+
this.del = function(m, color) { // public
var a = this.gA.findMultiGeometry(m);
var del = false;
@@ -605,25 +693,29 @@
}
this.clean = function() { // public
- this.gA = new GeometryArray();
- this.paint();
+ if (this.gA.count() > 0) {
+ this.gA = new GeometryArray();
+ this.paint();
+ }
}
this.paint = function() { // public
- for (q in this.canvas) {
- if (typeof(this.canvas[q]) == "object") this.canvas[q].clean();
+ for (i=0; i < this.canvas.length; i++) {
+ if (typeof(this.canvas[i]) == "object") this.canvas[i].clean();
}
for(var i=0; i<this.targets.length; i++){
if (typeof(this.canvas[this.targets[i]]) == 'undefined') {
- this.canvas[this.targets[i]] = new Canvas(this.targets[i], this.tagname);
+ this.canvas[this.targets[i]] = new Canvas(this.targets[i], this.tagname, this.style, this.lineWidth);
}
this.canvas[this.targets[i]].paint(this.gA);
}
}
+ this.lineWidth = lineWidth;
this.tagname = 'mod_gaz_draw'+tagname; // private
+ this.style = style;
this.targets = target_array; // private
- this.canvas = new Array(); // private
+ this.canvas = []; // private
this.gA = new GeometryArray(); // private
this.lineColor = "#ff0000";
@@ -634,7 +726,7 @@
// Snapping
// ----------------------------------------------------------------------------------------------------
-function Snapping(aTarget, tolerance, color){
+function Snapping(aTarget, tolerance, color, zIndex){
this.check = function(currPoint){ // public
var minDist = false;
@@ -651,7 +743,7 @@
}
this.store = function(geom, point){ // public
- this.coord = new Array();
+ this.coord = [];
this.min_i = -1;
for (var i = 0 ; i < geom.count(); i++){
@@ -697,7 +789,7 @@
this.add = function(geom, k, j, i){ // private
var cnt = this.coord.length;
- this.coord[cnt] = new Array();
+ this.coord[cnt] = [];
if (typeof(j) != 'undefined'){
if (typeof(i) != 'undefined') this.coord[cnt]['coord'] = geom.getPoint(i,j,k);
@@ -722,10 +814,12 @@
}
this.tolerance = (typeof(tolerance) == 'undefined') ? 10 : tolerance;
+ this.lineWidth = 2;
this.target = aTarget;
- this.coord = new Array(); // private
+ this.style = "position:absolute; top:0px; left:0px; z-index:"+zIndex;
+ this.coord = []; // private
this.min_i = -1; //private
- this.highlight = new Highlight(new Array(this.target), "snapping"+Math.round(Math.random()*Math.pow(10,10)));
+ this.highlight = new Highlight(new Array(this.target), "snapping"+Math.round(Math.random()*Math.pow(10,10)), this.style, this.lineWidth);
}
// ----------------------------------------------------------------------------------------------------
@@ -801,7 +895,7 @@
}
function cloneObject(a){
- var z = new Array();
+ var z = [];
for (attr in a) {
var b = a[attr];
More information about the Mapbender_commits
mailing list