svn commit: r354 - trunk/mapbender/http/javascripts

christoph at osgeo.org christoph at osgeo.org
Mon May 29 06:42:49 EDT 2006


Author: christoph
Date: 2006-05-29 10:42:49+0000
New Revision: 354

Added:
   trunk/mapbender/http/javascripts/mod_geometryArray.js
   trunk/mapbender/http/javascripts/point.js
   trunk/mapbender/http/javascripts/wfs_usemap.js

Log:
new geometry classes

Added: trunk/mapbender/http/javascripts/mod_geometryArray.js
Url: https://mapbender.osgeo.org/source/browse/mapbender/trunk/mapbender/http/javascripts/mod_geometryArray.js?view=auto&rev=354
==============================================================================
--- (empty file)
+++ trunk/mapbender/http/javascripts/mod_geometryArray.js	2006-05-29 10:42:49+0000
@@ -0,0 +1,537 @@
+// 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";
+
+// ----------------------------------------------------
+// ----------- class: geometry array ------------------
+function GeometryArray(){
+
+	this.count = function(){
+		return this.m.length;
+	}
+
+	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.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.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 > min.y) {min.y = pos[1].y;}
+			if (pos[0].y < max.y) {max.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.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!");}
+}
+

Added: trunk/mapbender/http/javascripts/point.js
Url: https://mapbender.osgeo.org/source/browse/mapbender/trunk/mapbender/http/javascripts/point.js?view=auto&rev=354
==============================================================================
--- (empty file)
+++ trunk/mapbender/http/javascripts/point.js	2006-05-29 10:42:49+0000
@@ -0,0 +1,87 @@
+//http://www.mapbender.org/index.php/point.js
+
+function Point(x, y){
+	this.dist = function(p){
+		return Math.sqrt(Math.pow(this.y-p.y,2) + Math.pow(this.x-p.x,2)) ;
+	}
+	
+	this.equals = function(p){
+		if (this.x == p.x && this.y == p.y) {return true;}
+		return false;
+	}
+	
+	this.minus = function(p){
+		return new Point(this.x-p.x, this.y-p.y);
+	}
+
+	this.plus = function(p){
+		return new Point(this.x+p.x, this.y+p.y);
+	}
+
+	this.dividedBy = function(c){
+		if (c != 0) {return new Point(this.x/c, this.y/c);}
+		alert("Exception: Division by zero");
+		return false;
+	}
+	
+	this.times = function(c){
+		return new Point(this.x*c, this.y*c);
+	}
+	
+	this.round = function(numOfDigits){
+		var tmpX = Math.round(this.x*Math.pow(10, parseInt(numOfDigits)))/Math.pow(10, parseInt(numOfDigits));
+		var tmpY = Math.round(this.y*Math.pow(10, parseInt(numOfDigits)))/Math.pow(10, parseInt(numOfDigits));
+		return new Point(tmpX, tmpY);
+	}
+
+	this.toString = function(){
+		return "(" + this.x + ", " + this.y + ")";
+	}
+
+	this.x = x;
+	this.y = y;
+}
+
+//------------------------------------------------------------------------
+// possible improvement: point has flag: map OR real. additional functions: toReal, toMap
+
+function mapToReal(frameName, aPoint) {
+	var v = makeClickPos2RealWorldPos(frameName, aPoint.x, aPoint.y);
+	return new Point(v[0], v[1]);
+}
+
+function realToMap(frameName, aPoint) {
+	var v = makeRealWorld2mapPos(frameName, aPoint.x, aPoint.y);
+	return new Point(Math.round(v[0]), Math.round(v[1]));
+}
+
+function mb_calcExtent(frameName, min, max) {
+	var ind = getMapObjIndexByName(frameName);
+	var extent = max.minus(min);
+	var center = extent.dividedBy(2).plus(min);
+	
+	var relation_px_x = mb_mapObj[ind].width / mb_mapObj[ind].height;
+	var relation_px_y = mb_mapObj[ind].height / mb_mapObj[ind].width;
+	var relation_bbox_x = extent.x / extent.y;     
+	
+	if(relation_bbox_x <= relation_px_x){                
+		min = new Point(center.x - relation_px_x * extent.y / 2, min.y);
+		max = new Point(center.x + relation_px_x * extent.y / 2, max.y);
+	}
+	else if(relation_bbox_x > relation_px_x){                
+		min = new Point(min.x, center.y - relation_px_y * extent.x / 2);
+		max = new Point(max.x, center.y + relation_px_y * extent.x / 2);
+	}
+	mb_mapObj[ind].extent = min.x +","+ min.y +","+ max.x  +","+ max.y;
+}
+
+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;
+}
\ No newline at end of file

Added: trunk/mapbender/http/javascripts/wfs_usemap.js
Url: https://mapbender.osgeo.org/source/browse/mapbender/trunk/mapbender/http/javascripts/wfs_usemap.js?view=auto&rev=354
==============================================================================
--- (empty file)
+++ trunk/mapbender/http/javascripts/wfs_usemap.js	2006-05-29 10:42:49+0000
@@ -0,0 +1,179 @@
+
+// ---------------------------------------------------------------------------------------------------------------
+// --- usemap (begin) --------------------------------------------------------------------------------------------
+
+function mod_usemap (wfs_name) {
+	if (wfs_name == "") {
+		usemap = "";
+	}
+	var ind = getMapObjIndexByName(mb_wfs_targets[0]);
+	var myImg = window.frames[mb_wfs_targets[0]].document.getElementById("um_img").style; 
+	myImg.width = mb_mapObj[ind].width;
+	myImg.height = mb_mapObj[ind].height;
+
+	for (var i = 0 ; i < mb_wfs_fetch.length ; i ++) {
+	
+		if (mb_wfs_fetch[i]['wfs_conf'] == wfs_name || wfs_name == "") {
+		
+			if (mb_wfs_fetch[i]['geomtype'] == geomTypePolygon) {
+				usemap += mod_usemap_polygon(i);
+			}
+			else if (mb_wfs_fetch[i]['geomtype'] == geomTypePoint) {
+				usemap += mod_usemap_circle(i);
+			}
+			else if (mb_wfs_fetch[i]['geomtype'] == geomTypeLine) {
+				usemap += mod_usemap_line(i);
+			}
+		}
+	}
+	writeUsemap(usemap);
+}
+
+function mod_usemap_circle(ind){
+	var str = "";
+	var coord = "";
+	
+	for (var i = 0 ; i < mb_wfs_fetch[ind]['geometry'].length ; i ++) {
+		var xArray = mb_wfs_fetch[ind]['geometry'][i]['x'];
+		var yArray = mb_wfs_fetch[ind]['geometry'][i]['y'];
+		var title = getElementValueByName(mb_wfs_fetch, ind, "name") + " (Pt)";
+		var pos = makeRealWorld2mapPos(mb_wfs_targets[0],xArray[0],yArray[0]);
+		coord += pos[0] + ", " + pos[1];
+		
+		str += "<AREA  onmouseover='parent.mb_wfs_perform(\"over\",parent.mb_wfs_fetch["+ind+"])' ";
+		str += "onmouseout='parent.mb_wfs_perform(\"out\",parent.mb_wfs_fetch["+ind+"])' shape='circle'  coords='";
+		str += coord + ", " + mod_usemap_radius + "' href='#'>";
+	}
+	
+	return str;
+}
+
+function mod_usemap_line_calculate (xArray, yArray, j, orientation, cnt) {
+	var coord = "";
+
+	var p1 = makeRealWorld2mapPos(mb_wfs_targets[0],xArray[j],yArray[j]);
+	var p2 = makeRealWorld2mapPos(mb_wfs_targets[0],xArray[j+orientation],yArray[j+orientation]);
+
+	var vec = new Array();
+	vec[0] = p2[0] - p1[0];
+	vec[1] = p2[1] - p1[1];
+	
+	if (vec[0] != 0 || vec[1] != 0) {
+		n_vec = new Array();
+		if (vec[0] != 0) {
+			if (vec[0] > 0) {
+				n_vec[0] = (-vec[1])/vec[0];
+				n_vec[1] = -1;
+			}
+			else {
+				n_vec[0] = (vec[1])/vec[0];
+				n_vec[1] = 1;
+			}
+		}
+		else {
+			if (vec[1] > 0) {
+				n_vec[0] = 1;
+				n_vec[1] = 0;
+			}
+			else {
+				n_vec[0] = -1;
+				n_vec[1] = 0;
+			}
+		}
+
+		n_vec_length = Math.sqrt(Math.pow(n_vec[0], 2) + Math.pow(n_vec[1], 2));
+		n_vec[0] = (n_vec[0]*mod_usemap_line_tolerance)/n_vec_length;
+		n_vec[1] = (n_vec[1]*mod_usemap_line_tolerance)/n_vec_length;
+
+		lp = new Array();
+		lp[0] = p1[0] + n_vec[0];
+		lp[1] = p1[1] - n_vec[1];
+
+		if (cnt > 0) {
+			coord += ", ";
+		}
+		coord += parseInt(lp[0]) + ", " + parseInt(lp[1]);
+		coord += ", " + parseInt(lp[0]+vec[0]) + ", " + parseInt(lp[1]+vec[1]);
+		
+	}
+	return coord;
+}
+
+function mod_usemap_line(ind){
+	var str = "";
+	for (var i = 0 ; i < mb_wfs_fetch[ind]['geometry'].length ; i ++) {
+		var coord = "";
+		var cnt = 0;
+
+		xArray = new Array();
+		xArray = mb_wfs_fetch[ind]['geometry'][i]['x'];
+		yArray = new Array();
+		yArray = mb_wfs_fetch[ind]['geometry'][i]['y'];
+		
+	
+		for (var j = 0 ; j < xArray.length - 1  ; j ++) {
+			var result = mod_usemap_line_calculate(xArray, yArray, j, 1, cnt);
+			if (result != "") {
+				coord += result;
+				cnt++;
+			}
+		}
+		
+		for (var j = (xArray.length - 1) ; j > 0 ; j--) {
+			var result = mod_usemap_line_calculate(xArray, yArray, j, -1, cnt);
+			if (result != "") {
+				coord += result;
+				cnt++;
+			}
+		}
+		
+		if (coord != "") {
+			str += "<AREA ";
+			str += "onmouseover='parent.mb_wfs_perform(\"over\",parent.mb_wfs_fetch["+ind+"])' ";
+			str += "onmouseout='parent.mb_wfs_perform(\"out\",parent.mb_wfs_fetch["+ind+"])' ";
+			str += "shape='poly'  coords='";
+			str += coord + "' href='#'>";
+		}
+		else {
+			//display circle
+			var pos = makeRealWorld2mapPos(mb_wfs_targets[0],xArray[0],yArray[0]);
+			coord += pos[0] + ", " + pos[1];
+			
+			str += "<AREA  onmouseover='parent.mb_wfs_perform(\"over\",parent.mb_wfs_fetch["+ind+"])' ";
+			str += "onmouseout='parent.mb_wfs_perform(\"out\",parent.mb_wfs_fetch["+ind+"])' shape='circle'  coords='";
+			str += coord + ", " + mod_usemap_radius + "' href='#'>";
+		}
+	}
+	
+	return str;
+}
+
+function mod_usemap_polygon(ind){
+	var str = "";
+	var coord = "";
+	
+	for (var i = 0 ; i < mb_wfs_fetch[ind]['geometry'].length ; i ++) {
+		var xArray = mb_wfs_fetch[ind]['geometry'][i]['x'];
+		var yArray = mb_wfs_fetch[ind]['geometry'][i]['y'];
+		var title = getElementValueByName(mb_wfs_fetch, ind, "name") + " (Py)";
+		var pos = makeRealWorld2mapPos(mb_wfs_targets[0],xArray[0],yArray[0]);
+		coord += pos[0] + ", " + pos[1];
+		
+		for (var j = 1 ; j < xArray.length ; j ++) {
+			pos = makeRealWorld2mapPos(mb_wfs_targets[0],xArray[j],yArray[j]);
+			coord += ", " + pos[0] + ", " + pos[1];
+		}
+		
+		str += "<AREA  onmouseover='parent.mb_wfs_perform(\"over\",parent.mb_wfs_fetch["+ind+"])' ";
+		str += "onmouseout='parent.mb_wfs_perform(\"out\",parent.mb_wfs_fetch["+ind+"])' shape='poly'  coords='";
+		str += coord + "' href='#'>";
+	}
+	
+	return str;
+}
+
+function writeUsemap(str) {
+	writeTag(mb_wfs_targets[0], 'um', str);
+}
+// --- usemap (end) ----------------------------------------------------------------------------------------------
+// ---------------------------------------------------------------------------------------------------------------




More information about the Mapbender_commits mailing list