[Mapbender-commits] r1027 - trunk/mapbender/http/javascripts

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Jan 24 08:08:40 EST 2007


Author: christoph
Date: 2007-01-24 08:08:39 -0500 (Wed, 24 Jan 2007)
New Revision: 1027

Modified:
   trunk/mapbender/http/javascripts/mod_wfs_SpatialRequest.php
Log:
add ajax style wfs requests

Modified: trunk/mapbender/http/javascripts/mod_wfs_SpatialRequest.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_wfs_SpatialRequest.php	2007-01-24 13:08:13 UTC (rev 1026)
+++ trunk/mapbender/http/javascripts/mod_wfs_SpatialRequest.php	2007-01-24 13:08:39 UTC (rev 1027)
@@ -1,371 +1,454 @@
- <?php
-#$Id: mod_wfs_spatialRequest.php,v 1.4 2006/03/08 15:26:26 c_baudson Exp $
-#$Header: /cvsroot/mapbender/mapbender/http/javascripts/mod_wfs_spatialRequest.php,v 1.4 2006/03/08 15:26:26 c_baudson Exp $
-# 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.
-
-session_start();
-import_request_variables("PG");
-require_once(dirname(__FILE__)."/../php/mb_validateSession.php");
-require_once(dirname(__FILE__)."/../../conf/mapbender.conf");
-$con = db_connect(DBSERVER,OWNER,PW);
-db_select_db(DB,$con);
-?>
-var useCheckboxForHighlighting = 0;
-<?php
-
-
-$gui_id = $_REQUEST["gui_id"];
-$e_id_css = "setSpatialRequest";
-include '../include/dyn_js.php';
-$sql = "SELECT e_src, e_target FROM gui_element WHERE e_id = 'setSpatialRequest' AND fkey_gui_id = '".$gui_id."'";
-$res = db_query($sql);
-$cnt = 0;
-while($row = db_fetch_array($res)){ 
-   $e_src = $row["e_src"];
-   $e_target = $row["e_target"];
-   $cnt++;
-}
-if($cnt > 1){ echo "alert('setExtRequest: ID not unique!');\n";}
-echo "var mod_wfs_spatialRequest_target = '".$e_target."';\n";
-?>
-var wfsAreaType_point = "point";
-var wfsAreaType_polygon = "polygon";
-var wfsAreaType_rectangle = "rectangle";
-var wfsAreaType_extent = "extent";
-var wfsAreaType_current = "";
-
-var activeButton = null;
-var mod_wfs_spatialRequest_geometry = null;
-
-var mod_wfs_spatialRequest_frameName = "";
-var mod_wfs_spatialRequest_epsg;
-var mod_wfs_spatialRequest_width;
-var mod_wfs_spatialRequest_height;
-
-var mod_wfs_spatialRequestSubFunctions = new Array();
-var mod_wfs_spatialRequest_bg = "";
-var mod_wfs_spatialRequest_pgsql = true;
-var mod_wfs_spatialRequest_win = null;
-var mod_wfs_spatialRequest_thema = false;
-
-var button_point = "point";
-var button_polygon = "polygon";
-var button_rectangle = "rectangle";
-var button_extent = "extent";
-var button_dialogue = "dialogue";
-
-// ------------------------------------------------------------------------------------------
-// ------------ button handling -------------------------------------------------------------
-
-function displayButtons() {
-	for (var i = 0 ; i < buttonWfs_id.length ; i ++) {
-		if (parseInt(buttonWfs_on[i])==1) {
-			document.write("<div id='div_"+buttonWfs_id[i]+"' style='position:absolute; top:"+buttonWfs_y[i]+"; left:"+buttonWfs_x[i]+"'><img name=\""+buttonWfs_id[i]+"\" onmouseover=\"mb_regButton_frame('initWfsButton', null, "+i+");\" id=\""+buttonWfs_id[i]+"\" title=\""+buttonWfs_title_off[i]+"\" src=\""+buttonWfs_imgdir+buttonWfs_src[i]+"\"></div>");
-		}
-	}
-}
-
-function initWfsButton(ind, pos) {
-	mb_button[ind] = document.getElementById(buttonWfs_id[pos]);
-	mb_button[ind].img_over = buttonWfs_imgdir + buttonWfs_src[pos].replace(/_off/,"_over");
-	mb_button[ind].img_on = buttonWfs_imgdir + buttonWfs_src[pos].replace(/_off/,"_on");
-	mb_button[ind].img_off = buttonWfs_imgdir + buttonWfs_src[pos];
-	mb_button[ind].status = 0;
-	mb_button[ind].elName = buttonWfs_id[pos];
-	mb_button[ind].fName = "";
-	mb_button[ind].go = new Function ("wfsEnable(mb_button["+ind+"], " + pos + ")");
-	mb_button[ind].stop = new Function ("wfsDisable(mb_button["+ind+"], " + pos + ")");
-	var ind = getMapObjIndexByName(mod_wfs_spatialRequest_target);
-	mod_wfs_spatialRequest_width = mb_mapObj[ind].width;
-	mod_wfs_spatialRequest_height = mb_mapObj[ind].height;
-	mod_wfs_spatialRequest_epsg = mb_mapObj[ind].epsg;
-	mb_registerSubFunctions("drawDashedLineExt()");
-	mb_registerPanSubElement("measuring");
-}	
-
-function wfsEnable(obj) {
-	if (obj.id == button_point) {
-		if (activeButton == null) {
-			activeButton = obj;
-		}
-		mod_wfs_spatialRequest_geometry = new Geometry(geomTypePoint);
-		wfsAreaType_current = wfsAreaType_point;
-		mod_wfs_spatialRequest_digitize_go(geomTypePoint);		
-	}
-	if (obj.id == button_polygon) {
-		if (activeButton == null) {
-			activeButton = obj;
-		}
-		mod_wfs_spatialRequest_geometry = new Geometry(geomTypePolygon);
-		wfsAreaType_current = wfsAreaType_polygon;
-		mod_wfs_spatialRequest_digitize_go(geomTypePolygon);		
-		var measureSub = "";
-		for(var i=0; i<mod_wfs_spatialRequestSubFunctions.length; i++){
-			measureSub += eval(mod_wfs_spatialRequestSubFunctions[i]);
-		}   
-		writeTag(mod_wfs_spatialRequest_target,"measure_sub",measureSub);
-	}
-	else if (obj.id == button_rectangle){
-		if (activeButton == null) {
-			activeButton = obj;
-		}
-		mod_wfs_spatialRequest_geometry = new Geometry(geomTypeLine);
-		wfsAreaType_current = wfsAreaType_rectangle;
-		mod_selAreaExt_click();	
-	}
-	else if (obj.id == button_extent){
-		if (activeButton == null) {
-			activeButton = obj;
-		}
-		mod_wfs_spatialRequest_geometry = new Geometry(geomTypeLine);
-		wfsAreaType_current = wfsAreaType_extent;
-		var ind = getMapObjIndexByName(mod_wfs_spatialRequest_target);
-		var p0 = mapToReal(mod_wfs_spatialRequest_target, new Point(0,0));
-		var p1 = mapToReal(mod_wfs_spatialRequest_target, new Point(mb_mapObj[ind].width,mb_mapObj[ind].height)); 
-		mod_wfs_spatialRequest_geometry.addPoint(p0);
-		mod_wfs_spatialRequest_geometry.addPoint(p1);
-		mod_getAreaExt_send();
-	}
-	else if (obj.id == button_dialogue) {
-		activeButton = obj;
-		mod_wfs_SpatialRequest_dialog();
-	}
-}
-
-function wfsDisable(obj) {
-	var el = window.frames[mod_wfs_spatialRequest_target].document; 
-	el.onmousedown = null;
-	el.ondblclick = null;
-	el.onmousemove = null;
-	writeTag(mod_wfs_spatialRequest_target,"measure_display","");
-	writeTag(mod_wfs_spatialRequest_target,"measure_sub","");
-	activeButton = null;
-}
-
-// ------------------------------------------------------------------------------------------
-
-// ----------------------------------------------------------------------------------------------
-// -------------------- rectangle -----------------------------------------------------------------
-
-function mod_selAreaExt_click(){
-   var el = window.frames[mod_wfs_spatialRequest_target].document;
-   el.onmouseover = mod_selAreaExt_init;
-   el.onmousedown = mod_box_start;
-   el.onmouseup = mod_selAreaExt_get;
-   el.onmousemove = mod_box_run;
-}
-function mod_selAreaExt_init(e){
-   mb_isBF = mod_wfs_spatialRequest_target;
-   mb_zF = mod_wfs_spatialRequest_target;
-}
-function mod_selAreaExt_get(e){
-	mod_selAreaExt_setValidClipping(mod_box_stop(e));
-	mb_isBF = mod_wfs_spatialRequest_target;
-	mb_zF = mod_wfs_spatialRequest_target;
-}
-function mod_selAreaExt_setValidClipping(coords){
-	if (mod_wfs_spatialRequest_geometry != null) {
-		mod_wfs_spatialRequest_geometry.addPoint(new Point(coords[0],coords[1]));
-		mod_wfs_spatialRequest_geometry.addPoint(new Point(coords[2],coords[3]));
-		
-		if(mod_wfs_spatialRequest_geometry.count() == 2){
-			mod_getAreaExt_send();
-		}
-		else{
-			alert("Ausschnitt ungültig!")
-			mb_disableThisButton(activeButton.id);
-		}
-	}
-}
-// ----------------------------------------------------------------------------------------------
-
-
-// ----------------------------------------------------------------------------------------------
-// -------------------- polygon && point --------------------------------------------------------
-
-function mod_wfs_spatialRequest_digitize_go(geomtype){
-	if (geomtype == geomTypePolygon) {
-		mod_wfs_spatialRequest_geometry = new Geometry(geomTypePolygon);
-	}
-	s = new Snapping(mod_wfs_spatialRequest_target);
-
-	var el = window.frames[mod_wfs_spatialRequest_target].document;
-	el.onmousedown = mod_wfs_spatialRequest_start;
-	el.onmousemove = mod_wfs_spatialRequest_run;
-	var measureSub = "";
-	for(var i=0; i<mod_wfs_spatialRequestSubFunctions.length; i++){
-		measureSub += eval(mod_wfs_spatialRequestSubFunctions[i]);
-	}   
-	writeTag(mod_wfs_spatialRequest_target,"measure_sub",measureSub);
-}
-
-// ---------------------------------------------------------------------------------------------
-
-function mod_wfs_spatialRequest_run(e) {
-	if (mod_wfs_spatialRequest_geometry.count() >= 3) {
-		mb_getMousePos(e,mod_wfs_spatialRequest_target);
-		var pos = new Point(clickX,clickY).round(2);
-		s.check(pos);
-	}
-}
-
-function mod_wfs_spatialRequest_start(e){
-	var realWorldPos;
-	if (s.isSnapped() == true) {
-		realWorldPos = s.getSnappedPoint(mod_wfs_spatialRequest_geometry); 
-		s.clean();
-	}
-	else {
-		parent.mb_getMousePos(e,mod_wfs_spatialRequest_target);
-		realWorldPos = parent.mapToReal(mod_wfs_spatialRequest_target,new Point(parent.clickX,parent.clickY)).round(2);
-	}
-
-	mod_wfs_spatialRequest_geometry.addPoint(realWorldPos);
-
-	if (mod_wfs_spatialRequest_geometry.count() == 1) {
-		s.add(mod_wfs_spatialRequest_geometry, 0);
-	}
-	if (s.isSnapped() && mod_wfs_spatialRequest_geometry.count() >= 3 && mod_wfs_spatialRequest_geometry.get(-1).equals(mod_wfs_spatialRequest_geometry.get(0))) {
-		mod_wfs_spatialRequest_geometry.close();
-		mod_getAreaExt_send();
-		return;
-	}
-	
-	if(wfsAreaType_current == wfsAreaType_point){
-		mod_getAreaExt_send();
-		return;
-	}
-	drawDashedLineExt();
-}
-function drawDashedLineExt(){
-	var str_mPoints = "<div style='position:absolute;left:0px;top:0px' ><img src='"+mb_trans.src+"' width='"+mod_wfs_spatialRequest_width+"' height='0'></div>";
-	str_mPoints += "<div style='position:absolute;left:0px;top:0px' ><img src='"+mb_trans.src+"' width='0' height='"+mod_wfs_spatialRequest_height+"'></div>";
-	if (mod_wfs_spatialRequest_geometry != null) {
-		for(var i=0; i<mod_wfs_spatialRequest_geometry.count(); i++){
-			var pos = realToMap(mod_wfs_spatialRequest_target,mod_wfs_spatialRequest_geometry.get(i));
-			str_mPoints += "<div style='font-size:1px;position:absolute;top:"+(pos.y-2)+"px;left:"+(pos.x-2)+"px;width:3px;height:3px;background-color:#ff0000'></div>";
-		}
-		if(mod_wfs_spatialRequest_geometry.count()>1){
-			for(var k=1; k<mod_wfs_spatialRequest_geometry.count(); k++){
-				var pos0 = realToMap(mod_wfs_spatialRequest_target,mod_wfs_spatialRequest_geometry.get(k));
-				var pos1 = realToMap(mod_wfs_spatialRequest_target,mod_wfs_spatialRequest_geometry.get(k-1));
-				str_mPoints += evaluateDashesExt(pos1,pos0,k);
-			}
-		}
-	}
-	writeTag(mod_wfs_spatialRequest_target,"measuring",str_mPoints);
-}
-function evaluateDashesExt(p1,p0,count){
-	var str_dashedLine = "";
-	var d = p0.dist(p1);
-	var n = Math.round(d);
-	var s =  p0.minus(p1).dividedBy(n);
-	for(var i=1; i<n; i++){
-		var currPoint = p1.plus(s.times(i)).minus(new Point(2,2)).round(0); 
-		if(currPoint.x >= 0 && currPoint.x <= mod_wfs_spatialRequest_width && currPoint.y >= 0 && currPoint.y <= mod_wfs_spatialRequest_height){
-			str_dashedLine += "<div style='font-size:1px;position:absolute;top:"+currPoint.y+"px;left:"+currPoint.x+"px;width:3px;height:3px;background-color:#ff0000'></div>";
-		}
-	}
-	return str_dashedLine;
-}
-function mod_wfs_spatialRequest_close(){
-	if(mod_wfs_spatialRequest_geometry.count() < 3){
-		return;
-	}
-	mod_wfs_spatialRequest_geometry.closeGeometry();
-	drawDashedLineExt();
-	mod_getAreaExt_send();
-}
-
-function register_setExtRequestSubFunctions(stringFunction){
-	mod_wfs_spatialRequestSubFunctions[mod_wfs_spatialRequestSubFunctions.length] = stringFunction;
-}
-
-function mod_getAreaExt_send(){	
-	mb_setwfsrequest(mod_wfs_spatialRequest_target,mod_wfs_spatialRequest_geometry);
-	mod_wfs_spatialRequest_delete();
-	mb_disableThisButton(activeButton.id);
-	mod_wfs_spatialRequest_geometry = null;
-}
-
-function mod_wfs_spatialRequest_delete(){
-	writeTag(mod_wfs_spatialRequest_target,"measuring","");
-	writeTag(mod_wfs_spatialRequest_target,"measure_display","");
-}
-
-function mod_wfs_spatialRequest_timeout(){
-	var el = window.frames[mod_wfs_spatialRequest_target].document; 
-	el.onmousedown = null;
-	el.ondblclick = null;
-	el.onmousemove = null;
-}
-
-function mod_wfs_spatialRequest_disableTimeout(){
-	var el = window.frames[mod_wfs_spatialRequest_target].document;
-	el.onmousedown = mod_wfs_spatialRequest_start;
-}
-
-
-function isSetWfsResultToDigitize() {
-	if (parseInt(buttonWfs_toDigitize_on)==1) return true;
-	return false;
-}
-
-function mod_wfs_SpatialRequest_dialog(){	
-	if(!mod_wfs_spatialRequest_win || mod_wfs_spatialRequest_win == null || mod_wfs_spatialRequest_win.closed == true){
-		mod_wfs_spatialRequest_win = window.open("","mod_wfs_spatialRequest_win","width=200,height=150,resizable=yes");
-		mod_wfs_spatialRequest_win.document.open("text/html");
-		
-		mod_wfs_spatialRequest_win.document.writeln('<script language="JavaScript" type="text/javascript">');	
-		mod_wfs_spatialRequest_win.document.writeln('function set(obj){');
-			mod_wfs_spatialRequest_win.document.writeln('for(var i=0; i< document.getElementsByName("geom").length; i++){');
-				mod_wfs_spatialRequest_win.document.writeln('if(document.getElementsByName("geom")[i].checked){');
-					mod_wfs_spatialRequest_win.document.writeln('window.opener.mod_setExtRequest_geom = document.getElementsByName("geom")[i].value;'); 
-				mod_wfs_spatialRequest_win.document.writeln('}');
-			mod_wfs_spatialRequest_win.document.writeln('}');
-//			mod_wfs_spatialRequest_win.document.writeln('window.opener.mod_wfs_spatialRequest_geom = obj.value;');
-			mod_wfs_spatialRequest_win.document.writeln('window.opener.wfsEnable(obj);');
-			mod_wfs_spatialRequest_win.document.writeln('window.close();');
-			mod_wfs_spatialRequest_win.document.writeln('return false;	');
-		mod_wfs_spatialRequest_win.document.writeln('}');
-		mod_wfs_spatialRequest_win.document.writeln('</script>');
-		
-		mod_wfs_spatialRequest_win.document.writeln("<form>");
-		mod_wfs_spatialRequest_win.document.writeln("<input id='point' name='geom' type='radio' value='"+button_point+"' onclick='set(this)'> Punkt<br>");
-		mod_wfs_spatialRequest_win.document.writeln("<input id='rectangle' name='geom' type='radio' value='"+button_rectangle+"' onclick='set(this)'> Rechteck<br>");
-		mod_wfs_spatialRequest_win.document.writeln("<input id='polygon' name='geom' type='radio' value='"+button_polygon+"'onclick='set(this)'> Polygon<br>");
-		mod_wfs_spatialRequest_win.document.writeln("<input id='extent' name='geom' type='radio' value='"+button_extent+"'onclick='set(this)'> Extent<br>");
-		var checked = "";
-//		if (mod_wfs_spatialRequest_useExtent) {
-//			checked = " checked";
-//		}		
-		//mod_wfs_spatialRequest_win.document.writeln("<input id='extent' name='geom' type='radio' value='extent' onclick='set(this)' " + checked + "> Extent<br>");
-		mod_wfs_spatialRequest_win.document.writeln("</form>");
-		mod_wfs_spatialRequest_win.document.close();
-	}
-	else{
-		mod_wfs_spatialRequest_win.focus();
-	}	
-}
-//deprecated stuff
-function mod_wfs_spatialRequest_dialog(){	
-}
-function useExtentIsSet () {
-	return mod_wfs_spatialRequest_useExtent;
-}
-
-displayButtons();
+<?php
+#$Id: mod_wfs_spatialRequest.php,v 1.4 2006/03/08 15:26:26 c_baudson Exp $
+#$Header: /cvsroot/mapbender/mapbender/http/javascripts/mod_wfs_spatialRequest.php,v 1.4 2006/03/08 15:26:26 c_baudson Exp $
+# 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.
+
+session_start();
+import_request_variables("PG");
+require_once("../php/mb_validateSession.php");
+require_once("../../conf/mapbender.conf");
+$con = db_connect(DBSERVER,OWNER,PW);
+db_select_db(DB,$con);
+
+$gui_id = $_REQUEST["gui_id"];
+$e_id_css = "setSpatialRequest";
+include '../include/dyn_js.php';
+$sql = "SELECT e_src, e_target FROM gui_element WHERE e_id = 'setSpatialRequest' AND fkey_gui_id = '".$gui_id."'";
+$res = db_query($sql);
+$cnt = 0;
+while($row = db_fetch_array($res)){ 
+   $e_src = $row["e_src"];
+   $e_target = $row["e_target"];
+   $cnt++;
+}
+if($cnt > 1){ echo "alert('setExtRequest: ID not unique!');\n";}
+echo "var mod_wfs_spatialRequest_target = '".$e_target."';\n";
+?>
+
+var wfsAreaType_point = "point";
+var wfsAreaType_polygon = "polygon";
+var wfsAreaType_rectangle = "rectangle";
+var wfsAreaType_extent = "extent";
+var wfsAreaType_current = "";
+
+var activeButton = null;
+var mod_wfs_spatialRequest_geometry = null;
+
+var mod_wfs_spatialRequest_frameName = "";
+var mod_wfs_spatialRequest_epsg;
+var mod_wfs_spatialRequest_width;
+var mod_wfs_spatialRequest_height;
+
+var mod_wfs_spatialRequestSubFunctions = new Array();
+var mod_wfs_spatialRequest_bg = "";
+var mod_wfs_spatialRequest_pgsql = true;
+var mod_wfs_spatialRequest_win = null;
+var mod_wfs_spatialRequest_thema = false;
+
+var button_point = "point";
+var button_polygon = "polygon";
+var button_rectangle = "rectangle";
+var button_extent = "extent";
+var button_dialogue = "dialogue";
+var mb_wfs_tolerance = 8;
+
+// ------------------------------------------------------------------------------------------
+// ------------ button handling -------------------------------------------------------------
+
+function displayButtons() {
+	for (var i = 0 ; i < buttonWfs_id.length ; i ++) {
+		if (parseInt(buttonWfs_on[i])==1) {
+			document.write("<div id='div_"+buttonWfs_id[i]+"' style='position:absolute; top:"+buttonWfs_y[i]+"; left:"+buttonWfs_x[i]+"'><img name=\""+buttonWfs_id[i]+"\" onmouseover=\"mb_regButton_frame('initWfsButton', null, "+i+");\" id=\""+buttonWfs_id[i]+"\" title=\""+buttonWfs_title_off[i]+"\" src=\""+buttonWfs_imgdir+buttonWfs_src[i]+"\"></div>");
+		}
+	}
+}
+
+function initWfsButton(ind, pos) {
+	mb_button[ind] = document.getElementById(buttonWfs_id[pos]);
+	mb_button[ind].img_over = buttonWfs_imgdir + buttonWfs_src[pos].replace(/_off/,"_over");
+	mb_button[ind].img_on = buttonWfs_imgdir + buttonWfs_src[pos].replace(/_off/,"_on");
+	mb_button[ind].img_off = buttonWfs_imgdir + buttonWfs_src[pos];
+	mb_button[ind].status = 0;
+	mb_button[ind].elName = buttonWfs_id[pos];
+	mb_button[ind].fName = "";
+	mb_button[ind].go = new Function ("wfsEnable(mb_button["+ind+"], " + pos + ")");
+	mb_button[ind].stop = new Function ("wfsDisable(mb_button["+ind+"], " + pos + ")");
+	var ind = getMapObjIndexByName(mod_wfs_spatialRequest_target);
+	mod_wfs_spatialRequest_width = mb_mapObj[ind].width;
+	mod_wfs_spatialRequest_height = mb_mapObj[ind].height;
+	mod_wfs_spatialRequest_epsg = mb_mapObj[ind].epsg;
+	mb_registerSubFunctions("drawDashedLineExt()");
+	mb_registerPanSubElement("measuring");
+}	
+
+function wfsEnable(obj) {
+	if (obj.id == button_point) {
+		if (activeButton == null) {
+			activeButton = obj;
+		}
+		mod_wfs_spatialRequest_geometry = new Geometry(geomTypePoint);
+		wfsAreaType_current = wfsAreaType_point;
+		mod_wfs_spatialRequest_digitize_go(geomTypePoint);		
+	}
+	if (obj.id == button_polygon) {
+		if (activeButton == null) {
+			activeButton = obj;
+		}
+		mod_wfs_spatialRequest_geometry = new Geometry(geomTypePolygon);
+		wfsAreaType_current = wfsAreaType_polygon;
+		mod_wfs_spatialRequest_digitize_go(geomTypePolygon);		
+		var measureSub = "";
+		for(var i=0; i<mod_wfs_spatialRequestSubFunctions.length; i++){
+			measureSub += eval(mod_wfs_spatialRequestSubFunctions[i]);
+		}   
+		writeTag(mod_wfs_spatialRequest_target,"measure_sub",measureSub);
+	}
+	else if (obj.id == button_rectangle){
+		if (activeButton == null) {
+			activeButton = obj;
+		}
+		mod_wfs_spatialRequest_geometry = new Geometry(geomTypeLine);
+		wfsAreaType_current = wfsAreaType_rectangle;
+		mod_selAreaExt_click();	
+	}
+	else if (obj.id == button_extent){
+		if (activeButton == null) {
+			activeButton = obj;
+		}
+		mod_wfs_spatialRequest_geometry = new Geometry(geomTypeLine);
+		wfsAreaType_current = wfsAreaType_extent;
+		var ind = getMapObjIndexByName(mod_wfs_spatialRequest_target);
+		var p0 = mapToReal(mod_wfs_spatialRequest_target, new Point(0,0));
+		var p1 = mapToReal(mod_wfs_spatialRequest_target, new Point(mb_mapObj[ind].width,mb_mapObj[ind].height)); 
+		mod_wfs_spatialRequest_geometry.addPoint(p0);
+		mod_wfs_spatialRequest_geometry.addPoint(p1);
+		mod_getAreaExt_send();
+	}
+	else if (obj.id == button_dialogue) {
+		activeButton = obj;
+		mod_wfs_SpatialRequest_dialog();
+	}
+}
+
+function wfsDisable(obj) {
+	var el = window.frames[mod_wfs_spatialRequest_target].document; 
+	el.onmousedown = null;
+	el.ondblclick = null;
+	el.onmousemove = null;
+	writeTag(mod_wfs_spatialRequest_target,"measure_display","");
+	writeTag(mod_wfs_spatialRequest_target,"measure_sub","");
+	activeButton = null;
+}
+
+// ------------------------------------------------------------------------------------------
+
+// ----------------------------------------------------------------------------------------------
+// -------------------- rectangle -----------------------------------------------------------------
+
+function mod_selAreaExt_click(){
+   var el = window.frames[mod_wfs_spatialRequest_target].document;
+   el.onmouseover = mod_selAreaExt_init;
+   el.onmousedown = mod_box_start;
+   el.onmouseup = mod_selAreaExt_get;
+   el.onmousemove = mod_box_run;
+}
+function mod_selAreaExt_init(e){
+   mb_isBF = mod_wfs_spatialRequest_target;
+   mb_zF = mod_wfs_spatialRequest_target;
+}
+function mod_selAreaExt_get(e){
+	mod_selAreaExt_setValidClipping(mod_box_stop(e));
+	mb_isBF = mod_wfs_spatialRequest_target;
+	mb_zF = mod_wfs_spatialRequest_target;
+}
+function mod_selAreaExt_setValidClipping(coords){
+	if (mod_wfs_spatialRequest_geometry != null) {
+		mod_wfs_spatialRequest_geometry.addPoint(new Point(coords[0],coords[1]));
+		mod_wfs_spatialRequest_geometry.addPoint(new Point(coords[2],coords[3]));
+		
+		if(mod_wfs_spatialRequest_geometry.count() == 2){
+			mod_getAreaExt_send();
+		}
+		else{
+			alert("Ausschnitt ungültig!")
+			mb_disableThisButton(activeButton.id);
+		}
+	}
+}
+// ----------------------------------------------------------------------------------------------
+
+
+// ----------------------------------------------------------------------------------------------
+// -------------------- polygon && point --------------------------------------------------------
+
+function mod_wfs_spatialRequest_digitize_go(geomtype){
+	if (geomtype == geomTypePolygon) {
+		mod_wfs_spatialRequest_geometry = new Geometry(geomTypePolygon);
+	}
+	s = new Snapping(mod_wfs_spatialRequest_target);
+
+	var el = window.frames[mod_wfs_spatialRequest_target].document;
+	el.onmousedown = mod_wfs_spatialRequest_start;
+	el.onmousemove = mod_wfs_spatialRequest_run;
+	var measureSub = "";
+	for(var i=0; i<mod_wfs_spatialRequestSubFunctions.length; i++){
+		measureSub += eval(mod_wfs_spatialRequestSubFunctions[i]);
+	}   
+	writeTag(mod_wfs_spatialRequest_target,"measure_sub",measureSub);
+}
+
+// ---------------------------------------------------------------------------------------------
+
+function mod_wfs_spatialRequest_run(e) {
+	if (mod_wfs_spatialRequest_geometry.count() >= 3) {
+		mb_getMousePos(e,mod_wfs_spatialRequest_target);
+		var pos = new Point(clickX,clickY).round(2);
+		s.check(pos);
+	}
+}
+
+function mod_wfs_spatialRequest_start(e){
+	var realWorldPos;
+	if (s.isSnapped() == true) {
+		realWorldPos = s.getSnappedPoint(mod_wfs_spatialRequest_geometry); 
+		s.clean();
+	}
+	else {
+		mb_getMousePos(e,mod_wfs_spatialRequest_target);
+		realWorldPos = mapToReal(mod_wfs_spatialRequest_target,new Point(clickX,clickY)).round(2);
+	}
+
+	mod_wfs_spatialRequest_geometry.addPoint(realWorldPos);
+
+	if (mod_wfs_spatialRequest_geometry.count() == 1) {
+		s.add(mod_wfs_spatialRequest_geometry, 0);
+	}
+	if (s.isSnapped() && mod_wfs_spatialRequest_geometry.count() >= 3 && mod_wfs_spatialRequest_geometry.get(-1).equals(mod_wfs_spatialRequest_geometry.get(0))) {
+		mod_wfs_spatialRequest_geometry.close();
+		mod_getAreaExt_send();
+		return;
+	}
+	
+	if(wfsAreaType_current == wfsAreaType_point){
+		mod_getAreaExt_send();
+		return;
+	}
+	drawDashedLineExt();
+}
+function drawDashedLineExt(){
+	var str_mPoints = "<div style='position:absolute;left:0px;top:0px' ><img src='"+mb_trans.src+"' width='"+mod_wfs_spatialRequest_width+"' height='0'></div>";
+	str_mPoints += "<div style='position:absolute;left:0px;top:0px' ><img src='"+mb_trans.src+"' width='0' height='"+mod_wfs_spatialRequest_height+"'></div>";
+	if (mod_wfs_spatialRequest_geometry != null) {
+		for(var i=0; i<mod_wfs_spatialRequest_geometry.count(); i++){
+			var pos = realToMap(mod_wfs_spatialRequest_target,mod_wfs_spatialRequest_geometry.get(i));
+			str_mPoints += "<div style='font-size:1px;position:absolute;top:"+(pos.y-2)+"px;left:"+(pos.x-2)+"px;width:3px;height:3px;background-color:#ff0000'></div>";
+		}
+		if(mod_wfs_spatialRequest_geometry.count()>1){
+			for(var k=1; k<mod_wfs_spatialRequest_geometry.count(); k++){
+				var pos0 = realToMap(mod_wfs_spatialRequest_target,mod_wfs_spatialRequest_geometry.get(k));
+				var pos1 = realToMap(mod_wfs_spatialRequest_target,mod_wfs_spatialRequest_geometry.get(k-1));
+				str_mPoints += evaluateDashesExt(pos1,pos0,k);
+			}
+		}
+	}
+	writeTag(mod_wfs_spatialRequest_target,"measuring",str_mPoints);
+}
+function evaluateDashesExt(p1,p0,count){
+	var str_dashedLine = "";
+	var d = p0.dist(p1);
+	var n = Math.round(d);
+	var s =  p0.minus(p1).dividedBy(n);
+	for(var i=1; i<n; i++){
+		var currPoint = p1.plus(s.times(i)).minus(new Point(2,2)).round(0); 
+		if(currPoint.x >= 0 && currPoint.x <= mod_wfs_spatialRequest_width && currPoint.y >= 0 && currPoint.y <= mod_wfs_spatialRequest_height){
+			str_dashedLine += "<div style='font-size:1px;position:absolute;top:"+currPoint.y+"px;left:"+currPoint.x+"px;width:3px;height:3px;background-color:#ff0000'></div>";
+		}
+	}
+	return str_dashedLine;
+}
+function mod_wfs_spatialRequest_close(){
+	if(mod_wfs_spatialRequest_geometry.count() < 3){
+		return;
+	}
+	mod_wfs_spatialRequest_geometry.closeGeometry();
+	drawDashedLineExt();
+	mod_getAreaExt_send();
+}
+
+function register_setExtRequestSubFunctions(stringFunction){
+	mod_wfs_spatialRequestSubFunctions[mod_wfs_spatialRequestSubFunctions.length] = stringFunction;
+}
+
+function mod_getAreaExt_send(){	
+	mb_setwfsrequest(mod_wfs_spatialRequest_target,mod_wfs_spatialRequest_geometry);
+	mod_wfs_spatialRequest_delete();
+	mb_disableThisButton(activeButton.id);
+	mod_wfs_spatialRequest_geometry = null;
+}
+
+function mod_wfs_spatialRequest_delete(){
+	writeTag(mod_wfs_spatialRequest_target,"measuring","");
+	writeTag(mod_wfs_spatialRequest_target,"measure_display","");
+}
+
+function mod_wfs_spatialRequest_timeout(){
+	var el = window.frames[mod_wfs_spatialRequest_target].document; 
+	el.onmousedown = null;
+	el.ondblclick = null;
+	el.onmousemove = null;
+}
+
+function mod_wfs_spatialRequest_disableTimeout(){
+	var el = window.frames[mod_wfs_spatialRequest_target].document;
+	el.onmousedown = mod_wfs_spatialRequest_start;
+}
+
+
+function isSetWfsResultToDigitize() {
+	if (parseInt(buttonWfs_toDigitize_on)==1) return true;
+	return false;
+}
+
+function mod_wfs_SpatialRequest_dialog(){	
+	if(!mod_wfs_spatialRequest_win || mod_wfs_spatialRequest_win == null || mod_wfs_spatialRequest_win.closed == true){
+		mod_wfs_spatialRequest_win = window.open("","mod_wfs_spatialRequest_win","width=200,height=150,resizable=yes");
+		mod_wfs_spatialRequest_win.document.open("text/html");
+		
+		mod_wfs_spatialRequest_win.document.writeln('<script language="JavaScript" type="text/javascript">');	
+		mod_wfs_spatialRequest_win.document.writeln('function set(obj){');
+			mod_wfs_spatialRequest_win.document.writeln('for(var i=0; i< document.getElementsByName("geom").length; i++){');
+				mod_wfs_spatialRequest_win.document.writeln('if(document.getElementsByName("geom")[i].checked){');
+					mod_wfs_spatialRequest_win.document.writeln('window.opener.mod_setExtRequest_geom = document.getElementsByName("geom")[i].value;'); 
+				mod_wfs_spatialRequest_win.document.writeln('}');
+			mod_wfs_spatialRequest_win.document.writeln('}');
+//			mod_wfs_spatialRequest_win.document.writeln('window.opener.mod_wfs_spatialRequest_geom = obj.value;');
+			mod_wfs_spatialRequest_win.document.writeln('window.opener.wfsEnable(obj);');
+			mod_wfs_spatialRequest_win.document.writeln('window.close();');
+			mod_wfs_spatialRequest_win.document.writeln('return false;	');
+		mod_wfs_spatialRequest_win.document.writeln('}');
+		mod_wfs_spatialRequest_win.document.writeln('</script>');
+		
+		mod_wfs_spatialRequest_win.document.writeln("<form>");
+		mod_wfs_spatialRequest_win.document.writeln("<input id='point' name='geom' type='radio' value='"+button_point+"' onclick='set(this)'> Punkt<br>");
+		mod_wfs_spatialRequest_win.document.writeln("<input id='rectangle' name='geom' type='radio' value='"+button_rectangle+"' onclick='set(this)'> Rechteck<br>");
+		mod_wfs_spatialRequest_win.document.writeln("<input id='polygon' name='geom' type='radio' value='"+button_polygon+"'onclick='set(this)'> Polygon<br>");
+		mod_wfs_spatialRequest_win.document.writeln("<input id='extent' name='geom' type='radio' value='"+button_extent+"'onclick='set(this)'> Extent<br>");
+		var checked = "";
+//		if (mod_wfs_spatialRequest_useExtent) {
+//			checked = " checked";
+//		}		
+		//mod_wfs_spatialRequest_win.document.writeln("<input id='extent' name='geom' type='radio' value='extent' onclick='set(this)' " + checked + "> Extent<br>");
+		mod_wfs_spatialRequest_win.document.writeln("</form>");
+		mod_wfs_spatialRequest_win.document.close();
+	}
+	else{
+		mod_wfs_spatialRequest_win.focus();
+	}	
+}
+function mb_setwfsrequest(target,queryGeom){
+	//mb_wfs_reset();
+	var ind = getMapObjIndexByName(target);
+	var w = new Array();
+	w_ = new Array();
+	wfs_config = window.frames["wfs_conf"].get_wfs_conf();
+	for (var i=0; i<mb_mapObj[ind].wms.length; i++){
+		for(var ii=0; ii<mb_mapObj[ind].wms[i].objLayer.length; ii++){
+			var o = mb_mapObj[ind].wms[i].objLayer[ii];
+			if(o.gui_layer_wfs_featuretype != '' && o.gui_layer_querylayer == '1'){
+				w[w.length] = o.gui_layer_wfs_featuretype;
+			}	
+		}
+	}
+	for(var i=0; i<w.length; i++){
+		for(var ii=0; ii<wfs_config.length; ii++){			
+			if(wfs_config[ii]['wfs_conf_id'] == w[i]) w_[w_.length] = ii;
+		}
+	}
+	
+	if(queryGeom.geomtype==geomTypePolygon){
+		for(var i=0; i<w_.length; i++){
+			var url = wfs_config[w_[i]]['wfs_getfeature'];
+			url += "service=wfs&request=getFeature&version=1.0.0";
+			url += "&typename="+ wfs_config[w_[i]]['featuretype_name'];
+			url += "&filter=";
+			var filter = '<ogc:Filter xmlns:ogc="http://ogc.org" xmlns:gml="http://www.opengis.net/gml">';
+			filter += "<Within><ogc:PropertyName>";
+			for(var j=0; j<wfs_config[w_[i]]['element'].length; j++){
+				if(wfs_config[w_[i]]['element'][j]['f_geom'] == 1){
+					filter += wfs_config[w_[i]]['element'][j]['element_name'];
+				}
+			}
+			filter += "</ogc:PropertyName><gml:Polygon srsName=\"EPSG:4326\">";
+			filter += '<gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>';
+			for(var k=0; k<queryGeom.count(); k++){
+				if(k>0)	filter += " ";
+				filter += queryGeom.get(k).x+","+queryGeom.get(k).y;								 
+			}
+			filter += '</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs>';
+			filter += '</gml:Polygon></Within></ogc:Filter>';
+			mb_get_geom(url, filter, i, w_[i]);
+		}
+	}
+	else if(queryGeom.geomtype==geomTypeLine || queryGeom.geomtype == geomTypePoint){
+		var rectangle = new Array();
+		if(queryGeom.geomtype == geomTypePoint){
+			var tmp = realToMap(mb_wfs_target, queryGeom.get(0));
+			var buffer = new Point(mb_wfs_tolerance/2, -mb_wfs_tolerance/2);
+			rectangle[0] = mapToReal(mb_wfs_target, tmp.minus(buffer));
+			rectangle[1] = mapToReal(mb_wfs_target, tmp.plus(buffer));
+		}
+		if(queryGeom.geomtype == geomTypeLine){
+			var rectangle = queryGeom.getBBox();
+		}
+		for(var i=0; i<w_.length; i++){
+			var url = wfs_config[w_[i]]['wfs_getfeature'];
+			param = "service=wfs&request=getFeature&version=1.0.0&typename="+ wfs_config[w_[i]]['featuretype_name']+"&filter=";
+			var filter = "<ogc:Filter xmlns:ogc='http://ogc.org' xmlns:gml='http://www.opengis.net/gml'>";
+			filter += "<ogc:BBOX><ogc:PropertyName>";
+			for(var j=0; j<wfs_config[w_[i]]['element'].length; j++){
+				if(wfs_config[w_[i]]['element'][j]['f_geom'] == 1){
+					filter += wfs_config[w_[i]]['element'][j]['element_name'];
+				}
+			}
+			filter += "</ogc:PropertyName><gml:Box srsName='4326'><gml:coordinates>";	
+			filter += rectangle[0].x+","+rectangle[0].y+ " " + rectangle[1].x+","+rectangle[1].y; 
+			filter += "</gml:coordinates></gml:Box></ogc:BBOX></ogc:Filter>";
+			url += param;
+			mb_get_geom(url, filter, i, w_[i]);
+		}
+	}
+	highlight = new Highlight(mb_wfs_targets, highlight_tag_id);
+	return true;
+}
+
+function mb_get_geom(url, filter, index, wfs_conf_id) {
+	mb_ajax_post("../php/mod_wfs_result.php",{'url':url,'filter':filter,'typename':wfs_config[wfs_conf_id]['featuretype_name'],'wfs_conf_id':wfs_conf_id},function(js_code,status){
+//		alert(js_code);
+		eval(js_code);
+		if (typeof(geom) == 'object') mb_execWfsReadSubFunctions(geom);
+//		prompt('', js_code);
+	});
+}
+
+//deprecated stuff
+function mod_wfs_spatialRequest_dialog(){	
+}
+function useExtentIsSet () {
+	return mod_wfs_spatialRequest_useExtent;
+}
+
+displayButtons();



More information about the Mapbender_commits mailing list