svn commit: r357 - trunk/mapbender/http/javascripts/wfs.js

christoph at osgeo.org christoph at osgeo.org
Mon May 29 10:23:12 EDT 2006


Author: christoph
Date: 2006-05-29 14:23:11+0000
New Revision: 357

Modified:
   trunk/mapbender/http/javascripts/wfs.js

Log:
new, see wiki for details

Modified: trunk/mapbender/http/javascripts/wfs.js
Url: https://mapbender.osgeo.org/source/browse/mapbender/trunk/mapbender/http/javascripts/wfs.js?view=diff&rev=357&p1=trunk/mapbender/http/javascripts/wfs.js&p2=trunk/mapbender/http/javascripts/wfs.js&r1=356&r2=357
==============================================================================
--- trunk/mapbender/http/javascripts/wfs.js	(original)
+++ trunk/mapbender/http/javascripts/wfs.js	2006-05-29 14:23:11+0000
@@ -1,24 +1,10 @@
-// $Id$
-// http://www.mapbender.org/index.php/wfs.js
-// Copyright (C) 2002 CCGIS 
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2, or (at your option)
-// any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
+<?php 
+require_once("mod_geometryArray.js");
+?>
 var digiFrame = "digitize";
 var mb_wfs_fetched = new Array();
-var	mb_wfs_fetch = new Array();
+
+var	mb_wfs_fetch = new GeometryArray();
 var mb_wfsreq = 0;
 var mb_wfs_tolerance = 8;
 var mb_wfs_target = "mapframe1";
@@ -29,7 +15,7 @@
 var mb_wfs_objwin_height = 200;
 var mb_wfs_targets = new Array("mapframe1","overview");
 var mb_wfs_minPix = 8;
-var mb_wfs_maxBasePoints = 100;
+var mb_wfs_maxBasePoints = 200;
 var mb_wfs_lineColor = "#ff0000";
 var mb_wfs_fillColor = "#ff0000";
 var mb_wfs_diameter = 8;
@@ -40,35 +26,43 @@
 var canvasHasDrawing = new Array();
 var useCheckboxForHighlighting = true;
 var useUsemap = false;
+var wfsResultToDigitizeModule = false;
+
+if (isSetWfsResultToDigitize()) {
+	wfsResultToDigitizeModule = true;
+}
 
-if (useCheckboxForHighlighting){ 
+if (useCheckboxForHighlighting) { 
 	mb_registerSubFunctions('highlightGeometry()');
 }
-if (useUsemap){
+
+if (useUsemap) {
 	mb_registerSubFunctions('mod_usemap("")');
 }
+/*
 if (useExtentIsSet()) {
 	mb_registerSubFunctions("mb_setwfsrequest_extent()");
 }
+function mb_setwfsrequest_extent() {
 
-function mb_setwfsrequest_extent(){
-	if (useExtentIsSet()){
+	if (useExtentIsSet()) {
 		var ind = getMapObjIndexByName(mb_wfs_targets[0]);
 		var pos_a = makeClickPos2RealWorldPos(mb_wfs_targets[0],0,0);
 		var pos_b = makeClickPos2RealWorldPos(mb_wfs_targets[0],mb_mapObj[ind].width,mb_mapObj[ind].height);
-
+	
 		var x = new Array();
 		var y = new Array();
 		x[0] = pos_a[0];
 		x[1] = pos_b[0];
 		y[0] = pos_a[1];
 		y[1] = pos_b[1];
-
+		
 		mb_setwfsrequest(mb_wfs_targets[0],'rectangle',x,y);
 	}
 }
+*/
  
-function mb_setwfsrequest(target,type,x,y){
+function mb_setwfsrequest(target,geom){
 	mb_wfs_reset();
 	var ind = getMapObjIndexByName(target);
 	var w = new Array();
@@ -89,17 +83,8 @@
 			}
 		}
 	}
-	if(type=='point'){
-		type = 'rectangle';
-		var tmp = makeRealWorld2mapPos(mb_wfs_target,x[0], y[0]);
-		var n1 = makeClickPos2RealWorldPos(mb_wfs_target, (tmp[0] + mb_wfs_tolerance/2), (tmp[1] + mb_wfs_tolerance/2));
-		x[0] = n1[0];
-		y[0] = n1[1];
-		var n2 = makeClickPos2RealWorldPos(mb_wfs_target, (tmp[0] - mb_wfs_tolerance/2), (tmp[1] - mb_wfs_tolerance/2));
-		x[1] = n2[0];
-		y[1] = n2[1];
-	}
-	if(type=='polygon'){
+	
+	if(geom.geomtype==geomTypePolygon){
 		for(var i=0; i<w_.length; i++){
 			var path = "../php/mod_wfs_result.php?url=";
 			var url = wfs_conf[w_[i]]['wfs_getfeature'];
@@ -110,27 +95,27 @@
 			path += "&filter=";
 			var filter = '<ogc:Filter xmlns:ogc="http://ogc.org" xmlns:gml="http://www.opengis.net/gml">';
 			filter += "<Within>";
-			filter += '<ogc:PropertyName>';
-			for(var j=0; j<wfs_conf[w_[i]]['element'].length; j++){
-				if(wfs_conf[w_[i]]['element'][j]['f_geom'] == 1){
-					filter += wfs_conf[w_[i]]['element'][j]['element_name'];
-				}
-			}
-			filter += "</ogc:PropertyName>";
-			filter += '<gml:Polygon srsName="EPSG:4326">';
-			filter += '<gml:outerBoundaryIs>';
-			filter += '<gml:LinearRing>';
-			filter += '<gml:coordinates>';
-			for(var k=0; k<x.length; k++){
-				if(k>0){
-					filter += " ";
-				}
-				filter += x[k]+","+y[k];								 
-			}
-			filter += '</gml:coordinates>';
-			filter += '</gml:LinearRing>';
-			filter += '</gml:outerBoundaryIs>';
-			filter += '</gml:Polygon>';
+				filter += '<ogc:PropertyName>';
+					for(var j=0; j<wfs_conf[w_[i]]['element'].length; j++){
+						if(wfs_conf[w_[i]]['element'][j]['f_geom'] == 1){
+							filter += wfs_conf[w_[i]]['element'][j]['element_name'];
+						}
+					}
+				filter += "</ogc:PropertyName>";
+				filter += '<gml:Polygon srsName="EPSG:4326">';
+					filter += '<gml:outerBoundaryIs>';
+						filter += '<gml:LinearRing>';
+							filter += '<gml:coordinates>';
+								for(var k=0; k<geom.count(); k++){
+									if(k>0){
+										filter += " ";
+									}
+									filter += geom.get(k).x+","+geom.get(k).y;								 
+								}
+							filter += '</gml:coordinates>';
+						filter += '</gml:LinearRing>';
+					filter += '</gml:outerBoundaryIs>';
+				filter += '</gml:Polygon>';
 			filter += '</Within>';
 			filter += '</ogc:Filter>';
 			path += filter;
@@ -138,7 +123,17 @@
 			mb_wfsreq++;
 		}
 	}
-	if(type=='rectangle'){
+	else if(geom.geomtype==geomTypeLine || geom.geomtype == geomTypePoint){
+		var rectangle = new Array();
+		if(geom.geomtype == geomTypePoint){
+			var tmp = realToMap(mb_wfs_target,geom.get(0));
+			var buffer = new Point(mb_wfs_tolerance/2, mb_wfs_tolerance/2);
+			rectangle[0] = mapToReal(mb_wfs_target, tmp.plus(buffer));
+			rectangle[1] = mapToReal(mb_wfs_target, tmp.minus(buffer));
+		}
+		if(geom.geomtype == geomTypeLine){
+			var rectangle = geom.getBBox();
+		}
 		for(var i=0; i<w_.length; i++){
 			var path = "../php/mod_wfs_result.php?url=";
 			var url = wfs_conf[w_[i]]['wfs_getfeature'];
@@ -157,9 +152,9 @@
 			}
 			filter += "</ogc:PropertyName>";
 			filter += '<gml:Box srsName="4326"><gml:coordinates>';	
-			filter += x[0]+","+y[0];
+			filter += rectangle[0].x+","+rectangle[0].y;
 			filter += " ";
-			filter += x[1]+","+y[1]; 
+			filter += rectangle[1].x+","+rectangle[1].y; 
 			filter += '</gml:coordinates></gml:Box></ogc:BBOX>';
 			filter += '</ogc:Filter>';
 			path += filter;
@@ -167,185 +162,7 @@
 			mb_wfsreq++;
 		}
 	}
-}
-
-// ---------------------------------------------------------------------------------------------------------------
-// --- 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'] == "Polygon"){
-				usemap += mod_usemap_polygon(i);
-			}
-			else if (mb_wfs_fetch[i]['geomtype'] == "Point"){
-				usemap += mod_usemap_circle(i);
-			}
-			else if (mb_wfs_fetch[i]['geomtype'] == "Line") {
-				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) ----------------------------------------------------------------------------------------------
-// ---------------------------------------------------------------------------------------------------------------
-
-
-function mb_repaint(){
-	for (var i = 0 ; i < mb_wfs_targets.length ; i ++){
-		mf = mb_wfs_targets[i];
-		if (canvas[mf]){
-			canvas[mf].paint();
-		}
-	}
+	return true;
 }
 
 function mb_wfs_createwin(ind,url){
@@ -358,12 +175,12 @@
 	tmp.style.visibility = 'hidden';
 }
 
-function rearrangeXY (cnt){
-	for(var j=0; j<mb_wfs_fetch[cnt]['geometry'].length; j++){
-		var g = mb_wfs_sortXY(mb_wfs_fetch[cnt]['geometry'][j]);
-		mb_wfs_fetch[cnt]['geometry'][j] = new Array();
-		mb_wfs_fetch[cnt]['geometry'][j]['x'] = g[0];
-		mb_wfs_fetch[cnt]['geometry'][j]['y'] = g[1];
+function mb_repaint() {
+	for (var i = 0 ; i < mb_wfs_targets.length ; i ++) {
+		mf = mb_wfs_targets[i];
+		if (canvas[mf]) {
+			canvas[mf].paint();
+		}
 	}
 }
 
@@ -371,166 +188,46 @@
 	var tmp = n.split("_");
 	var current_wfs_name = tmp[3];
 	var wfs_conf = window.frames["wfs_conf"].get_wfs_conf();
-	//	alert("response from " + wfs_conf[tmp[3]]['wfs_conf_abstract']);	
-	if(a && a.length){
-		var str = n + ": \n";
-		for(var i=0; i<a.length; i++){
-			var cnt = mb_wfs_fetch.length;
-
+	//alert("response from " + wfs_conf[tmp[3]]['wfs_conf_abstract']);	
+	if(a != false && a.count()>0){
+		for(var i=0; i<a.count(); i++){
+			
 			var ind = getMapObjIndexByName(mb_wfs_targets[0]);
 			var wfs_tmp = wfs_conf[current_wfs_name]['featuretype_srs'] + " - " + mb_mapObj[ind].epsg;
 
-			if (wfs_conf[current_wfs_name]['featuretype_srs'] == mb_mapObj[ind].epsg){
-				mb_wfs_fetch[cnt] = a[i];
-				mb_wfs_fetch[cnt]['wfs_conf'] = current_wfs_name;
-				rearrangeXY(cnt);
-
-				var check = mb_wfs_cntBasePoint(mb_wfs_fetch[cnt]['geometry']);
-				if(check == false){
-
-					var newGeom = mb_wfs_getBBOX(mb_wfs_fetch[cnt]['geometry']);
-
-					mb_wfs_fetch[cnt]['geometry'] = new Array();
-					mb_wfs_fetch[cnt]['geometry'][0] = new Array();
-					mb_wfs_fetch[cnt]['geometry'][0]['x'] = new Array();
-					mb_wfs_fetch[cnt]['geometry'][0]['y'] = new Array();
-					mb_wfs_fetch[cnt]['geometry'][0]['x'][0] = parseFloat(newGeom[0]);
-					mb_wfs_fetch[cnt]['geometry'][0]['y'][0] = parseFloat(newGeom[1]);
-					mb_wfs_fetch[cnt]['geometry'][0]['x'][1] = parseFloat(newGeom[0]);
-					mb_wfs_fetch[cnt]['geometry'][0]['y'][1] = parseFloat(newGeom[3]);
-					mb_wfs_fetch[cnt]['geometry'][0]['x'][2] = parseFloat(newGeom[2]);
-					mb_wfs_fetch[cnt]['geometry'][0]['y'][2] = parseFloat(newGeom[3]);
-					mb_wfs_fetch[cnt]['geometry'][0]['x'][3] = parseFloat(newGeom[2]);
-					mb_wfs_fetch[cnt]['geometry'][0]['y'][3] = parseFloat(newGeom[1]);
-					mb_wfs_fetch[cnt]['geometry'][0]['x'][4] = parseFloat(newGeom[0]);
-					mb_wfs_fetch[cnt]['geometry'][0]['y'][4] = parseFloat(newGeom[1]);
+			if (wfs_conf[current_wfs_name]['featuretype_srs'] == mb_mapObj[ind].epsg) {
+				mb_wfs_fetch.appendMember(a.get(i));
+				mb_wfs_fetch.get(-1).wfs_conf = current_wfs_name;
+
+				if(tooManyBasepoints()){ //if a geometry has too many basepoints, its bbox will be displayed
+					var newGeom = mb_wfs_fetch.get(-1).getBBox();
+					mb_wfs_fetch.get(-1).emptyMember();
+					mb_wfs_fetch.get(-1).addGeometry();
+					mb_wfs_fetch.getGeometry(-1,-1).addPoint(newGeom[0]);
+					mb_wfs_fetch.getGeometry(-1,-1).addPoint(new Point(newGeom[0].x, newGeom[1].y));
+					mb_wfs_fetch.getGeometry(-1,-1).addPoint(newGeom[1]);
+					mb_wfs_fetch.getGeometry(-1,-1).addPoint(new Point(newGeom[1].x, newGeom[0].y));
+					mb_wfs_fetch.getGeometry(-1,-1).close();
 				}
 			}
-			else {
-				alert("EPSG mismatch. Invalid WFS result. Press OK to continue.");
-			}
-		}	
-		checkMbWfsFetch();
+			else alert("EPSG mismatch. Invalid WFS result. Press OK to continue.");
+		}		
 	}
-	mb_wfs_listMember(current_wfs_name);
-}
-
-function checkMbWfsFetch(){
-	var error = "";
-	for (var i = 0 ; i < mb_wfs_fetch.length ; i++){
-		error += checkWfsObj(i);
-	}
-	if (error){
-		var wfsWindow = open("about:blank", "wfsattributes", "width=300, height=300, resizable, dependent=yes, scrollbars=yes");
-		wfsWindow.document.open("text/html");			
-		wfsWindow.document.write("An error occured:<br><hr>" + error);
-		wfsWindow.document.close();
+	if (wfsResultToDigitizeModule == false) {
+		mb_wfs_listMember(current_wfs_name);
 	}
-}
-
-function checkWfsObj (index){
-	var obj = mb_wfs_fetch[index];
-	var geometry = false;
-	var element = false;
-	var geomtype = false;
-	var wfs_conf = false;
-	var error = "";
-
-	for (attr in obj){
-		if (attr == "geometry"){
-			geometry = true;
-			var objGeom = obj['geometry'];
-			var objGeomLength = objGeom.length;
-			if (objGeomLength == 0){
-				error += "object " + index + " doesn't contain any geometries.<br>";
-			}
-			else {
-				for (var i = 0 ; i < objGeomLength ; i ++){
-					var objGeomAtIndex = objGeom[i];
-					var x = false;
-					var y = false;
-					for (attrib in objGeomAtIndex){
-						if (attrib == "x"){
-							x = true;
-						}
-						else if (attrib == "y"){
-							y = true;
-						}
-						else {
-							error += "object " + index + ": unknown geometry attribute: " + attrib + ".<br>";
-						}
-					}					
-					if (x == true && y == true){
-						if (objGeomAtIndex['x'].length != objGeomAtIndex['y'].length || objGeomAtIndex['x'].length == 0){
-							error += "object " + index + " has an invalid geometry.<br>";
-						}
-					}
-					else {
-						error += "object " + index + " doesn't contain x- or y-values.<br>";
-					}
-				}
-			}
-		}
-		else if (attr == "element"){
-			elements = true;
-
-			var objElem = obj['element'];
-			var objElemLength = objElem.length;
-			for (var i = 0 ; i < objElemLength ; i ++){
-				var objElemAtIndex = objElem[i];
-				var elemName = false;
-				var elemVal = false;
-				for (attrib in objElemAtIndex){
-					if (attrib == "name"){
-						elemName = true;
-					}
-					else if (attrib == "val"){
-						elemVal = true;
-					}
-					else {
-						error += "object " + index + ": unknown element attributes: " + attrib + ".<br>";
-					}
-				}
-				if (elemName != true || elemVal != true){
-					error += "object " + index + ": missing object attributes.<br>";
-				}
-				else {
-					if (objElemAtIndex['name'] == "name"){
-						if (!objElemAtIndex['val']){
-							error += "object " + index + " doesn't have a name.<br>";
-						}
-					}
-				}
-			}
+	else {
+		if (mb_wfs_fetch.count()>0) {
+			tab_open(digiFrame);
 		}
-		else if (attr == "geomtype"){
-			geomtype = true;
-			if (obj['geomtype'] != "Point" && obj['geomtype'] != "Line" && obj['geomtype'] != "Polygon"){
-				error += "object " + index + ": wrong geometry type.<br>";
-			}
+		for (var i = 0 ; i < mb_wfs_fetch.count() ; i ++) {
+			parent.window.frames[digiFrame].appendGeometry(mb_wfs_fetch.get(i));
 		}
-		else if (attr == "wfs_conf"){
-			wfs_conf = true;
-			if (!obj['wfs_conf']){
-				error += "object " + index + ": no wfs conf.<br>";
-			}
-		}
-		else {
-			error += "object " + index + ": unknown attribute: " + attr + ".<br>";
-		}
-	}
-	if (geometry == false || geomtype == false || elements == false){
-		error += "object " + index + " is corrupted.<br>";
-	}
-	if (error){
-		error += displayObject(mb_wfs_fetch[index]);
-		error += "<hr>";
 	}
-	return error;
 }
 
 function mb_wfs_reset(){
-	mb_wfs_fetch = new Array();
+	mb_wfs_fetch = new GeometryArray();
 	usemap = "";
 	
 	if(mb_wfs_objwin == null){
@@ -554,94 +251,61 @@
 	return true;
 }
 
-function displayObject(someArray){
-	var a = someArray;
-	var str = "";
-	
-	for (attr in a){
-		b = a[attr];
-
-		if (typeof(b) == "object"){
-			str += "<br>[" + attr + "]<br>";
-			str += displayObject(b);
-		}
-		else {
-			str += "<br>[" + attr + "]: " + b + "<br>";
-		}
-	}	
-	return str;
-}
-
-function getElementValueByName(member, memberIndex, elementName){
-	var arrayLength = member[memberIndex]['element'].length;
-	for (var j = 0 ; j < arrayLength ; j++) {
-		if (member[memberIndex]['element'][j]['name'] == elementName){
-			return member[memberIndex]['element'][j]['val'];
-		}
-	}
-	return false;
-}
-
 function mb_wfs_listMember(wfs_name){
 	var wfs_conf = window.frames["wfs_conf"].get_wfs_conf();
 	var usemap = "";
 	var str = "<table>";
-	for(var i=0; i<mb_wfs_fetch.length; i++){
-		var t = wfs_conf[mb_wfs_fetch[i]['wfs_conf']];
-		// str += t['g_label']+ ": <br>";
+	for(var i=0; i<mb_wfs_fetch.count(); i++){
+		var t = wfs_conf[mb_wfs_fetch.get(i).wfs_conf];
 		for(var j=0; j<t['element'].length; j++){
 			if(t['element'][j]['f_show'] > 0){
-				for(var k=0; k<mb_wfs_fetch[i]['element'].length; k++){
-					if(t['element'][j]['element_name'] == mb_wfs_fetch[i]['element'][k]['name']){
-						//str += mb_wfs_fetch[i]['element'][k]['name'] + ": ";
-						str += "<tr><td><img src = '../img/wfs_digitize.png' onClick = 'tab_open(digiFrame);parent.window.frames[digiFrame].addMember(mb_wfs_fetch["+i+"])'></td>";
-						str += "<td>";
-						if (useCheckboxForHighlighting){
-							str += "<input type=checkbox id=highlightCheckbox" + i + " onClick='highlightGeometry()'></td><td>";
-						}
-						str += "<div";
-						if (!useCheckboxForHighlighting){
-							str += " onmouseover='mb_wfs_perform(\"over\",mb_wfs_fetch["+i+"])' ";
-							str += " onmouseout='mb_wfs_perform(\"out\",mb_wfs_fetch["+i+"])' ";
-						}
-						str += " onclick='mb_wfs_perform(\"click\",mb_wfs_fetch["+i+"])' ";
-						str += ">" + mb_wfs_fetch[i]['element'][k]['val']+"</div></td></tr>";
+				var k = mb_wfs_fetch.get(i).e.getElementIndexByName(t['element'][j]['element_name'])
+				if(k != -1){
+					str += "<tr><td><img src = '../img/wfs_digitize.png' onClick = 'tab_open(digiFrame);parent.window.frames[digiFrame].appendGeometry(mb_wfs_fetch.get("+i+"))'></td><td>";
+					if (useCheckboxForHighlighting) {
+						str += "<input type=checkbox id=highlightCheckbox" + i + " onClick='highlightGeometry()'></td><td>";
+					}
+					str += "<div";
+					if (!useCheckboxForHighlighting) {
+						str += " onmouseover='mb_wfs_perform(\"over\",mb_wfs_fetch.get("+i+"))' ";
+						str += " onmouseout='mb_wfs_perform(\"out\",mb_wfs_fetch.get("+i+"))' ";
 					}
+					str += " onclick='mb_wfs_perform(\"click\",mb_wfs_fetch.get("+i+"))' ";
+					str += ">" + mb_wfs_fetch.get(i).e.getValue(k)+ "</div></td></tr>";
 				}
 			}
 		}
 	}
 	str += "</table>";
 	mb_wfs_objwin.innerHTML = str;
-	if (useUsemap){
+	if (useUsemap) {
 		mod_usemap(wfs_name);
 	}
 }
 
-function highlightGeometry(){
-	var l = mb_wfs_fetch.length;
-	//	if (l > 0){
+function highlightGeometry() {
 	mb_wfs_wzClean();
 	mb_wfs_checkTag();
-	//	}
-	for (var i = 0; i < l ; i++){
+
+	var l = mb_wfs_fetch.count();
+	for (var i = 0; i < l ; i++) {
 		var id = "highlightCheckbox"+i;
 		var cb = document.getElementById(id);
-		if (cb){
-			if (cb.checked){
-				mb_wfs_draw(mb_wfs_fetch[i]);
+		if (cb) {
+			if (cb.checked) {
+				mb_wfs_draw(mb_wfs_fetch.get(i));
 			}
 		}
 	}
 	mb_repaint();
 }
 
-function get_wfs_conf(index){
+function get_wfs_conf(index) {
 	var wfs_conf = window.frames["wfs_conf"].get_wfs_conf();
 	return wfs_conf[index];
 }
 
-function get_complete_wfs_conf(){
+function get_complete_wfs_conf() {
 	var wfs_conf = window.frames["wfs_conf"].get_wfs_conf();
 	return wfs_conf;
 }
@@ -654,7 +318,7 @@
 		mb_repaint();
 	}
 	if(type=='out'){
-		if (useCheckboxForHighlighting){
+		if (useCheckboxForHighlighting) {
 			highlightGeometry();
 		}
 		else {
@@ -663,146 +327,98 @@
 	}
 	if(type=='click'){
 		mb_wfs_checkTag();
-		var tmp = mb_wfs_getBBOX(m['geometry']);
-		var b = parseFloat(wfs_conf[m['wfs_conf']]['g_buffer']);
-		mb_calculateExtent(mb_wfs_targets[0],parseFloat(tmp[0])-b,parseFloat(tmp[1])-b,parseFloat(tmp[2])+b,parseFloat(tmp[3])+b);
+		var tmp = m.getBBox();
+		var b = parseFloat(wfs_conf[m.wfs_conf]['g_buffer']);
+		var buffer = new Point(b,b)
+		mb_calcExtent(mb_wfs_targets[0],tmp[0].minus(buffer), tmp[1].plus(buffer));
 		zoom(mb_wfs_targets[0], 'true', 1.0);
-		if (!useCheckboxForHighlighting){
+		if (!useCheckboxForHighlighting) {
 			mb_wfs_draw(m);
 		}
 	}
 }
 
-function mb_wfs_cntBasePoint(g){
-	var c = 0;
-	for(var i=0; i<g.length;i++){
-		c += (Math.round(g[i]['x'].length)/2);
-	}
-	if(c <= mb_wfs_maxBasePoints){
+function tooManyBasepoints() {
+	if (mb_wfs_fetch.get(-1).getTotalPointCount() > mb_wfs_maxBasePoints) {
 		return true;
 	}
-	else{
-		return false;
-	}
-}
-
-function mb_wfs_getBBOX(g){
-	var tmp_x = new Array();
-	var tmp_y = new Array();
-
-	for(var i=0; i<g.length;i++){
-		tmp_x = tmp_x.concat(g[i]['x']);
-		tmp_y = tmp_y.concat(g[i]['y']);
-	}
-	var min_x = parseFloat(tmp_x[0]);
-	var min_y = parseFloat(tmp_y[0]);
-	var max_x = parseFloat(tmp_x[0]);
-	var max_y = parseFloat(tmp_y[0]);
-
-	var x,y;
-
-	for(var i=1; i<tmp_x.length; i++){
-		x = parseFloat(tmp_x[i]);
-		y = parseFloat(tmp_y[i]);
-		if (x < min_x){
-			min_x = x;
-		}
-		else if (x > max_x){
-			max_x = x;
-		}
-		if (y < min_y){
-			min_y = y;
-		}
-		else if (y > max_y){
-			max_y = y;
-		}
-	}
-	var r = new Array(min_x, min_y, max_x, max_y);
-	return r;
+	return false;
 }
 
 function mb_wfs_checkPix(frame,g){
-	var tmp = mb_wfs_getBBOX(g);
-	var minpix = makeRealWorld2mapPos(frame,tmp[0],tmp[3]);
-	var maxpix = makeRealWorld2mapPos(frame,tmp[2],tmp[1]);
-	if((maxpix[0] - minpix[0] < mb_wfs_minPix) && (maxpix[1] - minpix[1] < mb_wfs_minPix)){
+	var tmp = g.getBBox();
+	var minpix = realToMap(frame,tmp[0]);
+	var maxpix = realToMap(frame,tmp[1]);
+	if((maxpix.x - minpix.x < mb_wfs_minPix) && (maxpix.y - minpix.y < mb_wfs_minPix)){
 		return false;
 	}
-	else{
-		return true;
-	}
-}
-function mb_wfs_center(frame,g){
-	var tmp = mb_wfs_getBBOX(g);
-	var x = parseFloat(tmp[0]) + parseFloat((tmp[2] - tmp[0])/2);
-	var y = parseFloat(tmp[1]) + parseFloat((tmp[3] - tmp[1])/2);
-	var r = new Array();
-	r[0] = new Array();
-	r[0]['x'] = new Array();
-	r[0]['y'] = new Array();
-	r[0]['x'][0] = x;
-	r[0]['y'][0] = y;
-	return r;
+	return true;
 }
+
 function mb_wfs_draw(m){
-	var t = m['geomtype'];
-	if(t.indexOf("Point")>-1){
+	var t = m.geomtype;
+	if(t == geomTypePoint){
 		for(var i=0; i<mb_wfs_targets.length; i++){
-			mb_wfs_wz(mb_wfs_targets[i],'Point',m['geometry']);
+			mb_wfs_wz(mb_wfs_targets[i],geomTypePoint,m);
 		}
 	}
-	else if(t.indexOf("Line")>-1){
-		for(var i=0; i<mb_wfs_targets.length; i++){
-			var c = mb_wfs_checkPix(mb_wfs_targets[i],m['geometry']);
-			if(c == false){
-				var r = mb_wfs_center(mb_wfs_targets[i],m['geometry']);
-				mb_wfs_wz(mb_wfs_targets[i],'Point',r);
-			}
-			else{
-				mb_wfs_wz(mb_wfs_targets[i],'Line',m['geometry']);
+	else {
+		var r = m.getCenter();
+		var newMember = new MultiGeometry();
+		newMember.addGeometry();
+		newMember.get(-1).addPoint(r);
+		if(t == geomTypeLine){
+			for(var i=0; i<mb_wfs_targets.length; i++){
+				var c = mb_wfs_checkPix(mb_wfs_targets[i],m);
+				if(c == false){
+					mb_wfs_wz(mb_wfs_targets[i],geomTypePoint,newMember);
+				}
+				else{
+					mb_wfs_wz(mb_wfs_targets[i],geomTypeLine,m);
+				}
 			}
 		}
-	}
-	else if(t.indexOf("Polygon")>-1){
-		for(var i=0; i<mb_wfs_targets.length; i++){
-			var c = mb_wfs_checkPix(mb_wfs_targets[i],m['geometry']);
-			if(c == false){
-				var r = mb_wfs_center(mb_wfs_targets[i],m['geometry']);
-				mb_wfs_wz(mb_wfs_targets[i],'Point',r);
-			}
-			else{
-				mb_wfs_wz(mb_wfs_targets[i],'Polygon',m['geometry']);
+		else if(t == geomTypePolygon){
+			for(var i=0; i<mb_wfs_targets.length; i++){
+				var c = mb_wfs_checkPix(mb_wfs_targets[i],m);
+				if(c == false){
+					mb_wfs_wz(mb_wfs_targets[i],geomTypePoint,newMember);
+				}
+				else{
+					mb_wfs_wz(mb_wfs_targets[i],geomTypePolygon,m);
+				}
 			}
 		}
+		else{
+			alert("unknown geomtype");
+		}	
 	}
-	else{
-		alert("unknown geomtype");
-	}	
+
 }
 function mb_wfs_wz(mf,t,g){
-	if(t=='Point'){
-		for(var i=0; i<g.length; i++){
-			var apos = mb_wfs_toPix(mf,g[i]);
+	if(t==geomTypePoint){
+		for(var i=0; i<g.count(); i++){
+			var apos = mb_wfs_toPix(mf,g.get(i));
 			canvas[mf].setColor(mb_wfs_lineColor);
-			canvas[mf].drawEllipse((apos[0]-mb_wfs_diameter/2),(apos[1]-mb_wfs_diameter/2),mb_wfs_diameter,mb_wfs_diameter);
+			canvas[mf].drawEllipse((apos['x'][0]-mb_wfs_diameter/2),(apos['y'][0]-mb_wfs_diameter/2),mb_wfs_diameter,mb_wfs_diameter);
 		}
 	}
-	else if(t=='Line'){
-		for(var i=0; i<g.length; i++){
-			var apos = mb_wfs_toPix(mf,g[i]);	
+	else if(t==geomTypeLine){
+		for(var i=0; i<g.count(); i++){
+			var apos = mb_wfs_toPix(mf,g.get(i));	
 			canvas[mf].setColor(mb_wfs_lineColor);
-			canvas[mf].drawPolyline(apos[0],apos[1]);
-		}
+			canvas[mf].drawPolyline(apos['x'],apos['y']);
+		}	
 	}
-	else if(t=='Polygon'){
-		for(var i=0; i<g.length; i++){
-			var apos = mb_wfs_toPix(mf,g[i]);	
-			mb_wfs_toPix(mf,g[i]);	
+	else if(t==geomTypePolygon){
+		for(var i=0; i<g.count(); i++){
+			var apos = mb_wfs_toPix(mf,g.get(i));	
 			canvas[mf].setColor(mb_wfs_lineColor);
-			canvas[mf].drawPolygon(apos[0],apos[1]);
+			canvas[mf].drawPolygon(apos['x'],apos['y']);
 		}
 	}
 }
+
 function mb_wfs_wzClean(){
 	for(var i=0; i<mb_wfs_targets.length; i++){
 		var el = window.frames[mb_wfs_targets[i]].document.getElementById('mod_gaz_draw');
@@ -811,6 +427,7 @@
 	}
 	return true;
 }
+
 function mb_wfs_checkTag(){
 	for(var i=0; i<mb_wfs_targets.length; i++){
 		var isTag = (window.frames[mb_wfs_targets[i]].document.getElementById('mod_gaz_draw'))?1:0;
@@ -826,26 +443,15 @@
 	}
 	return true;
 }
-function mb_wfs_sortXY(g){
-	var r = new Array();
-	r[0] = new Array();
-	r[1] = new Array();
-	var cnt = 0;
-	for(var i=0; i<g.length -1 ; i+=2){
-		r[0][cnt] = g[i];
-		r[1][cnt] = g[i+1];
-		cnt++;
-	}
-	return r;
-}
+
 function mb_wfs_toPix(mf,g){
 	var r = new Array();
-	r[0] = new Array();
-	r[1] = new Array(); 
-	for(var i=0; i<g['x'].length; i++){
-		var pos = makeRealWorld2mapPos(mf,g['x'][i],g['y'][i]);
-		r[0][i] = pos[0];
-		r[1][i] = pos[1];
+	r['x'] = new Array();
+	r['y'] = new Array();
+	for(var i=0; i<g.count(); i++){
+		var currentV = realToMap(mf,g.get(i));
+		r['x'][i] = currentV.x;
+		r['y'][i] = currentV.y;
 	}
 	return r;
 }
\ No newline at end of file




More information about the Mapbender_commits mailing list