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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Mon Nov 26 08:32:38 EST 2007


Author: verenadiewald
Date: 2007-11-26 08:32:38 -0500 (Mon, 26 Nov 2007)
New Revision: 1854

Modified:
   trunk/mapbender/http/javascripts/mod_wfs_SpatialRequest.php
Log:
new functions for displaying spatialrequest results in popup divs

Modified: trunk/mapbender/http/javascripts/mod_wfs_SpatialRequest.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_wfs_SpatialRequest.php	2007-11-26 13:29:55 UTC (rev 1853)
+++ trunk/mapbender/http/javascripts/mod_wfs_SpatialRequest.php	2007-11-26 13:32:38 UTC (rev 1854)
@@ -79,6 +79,12 @@
 var buttonWfs_x = [];
 var buttonWfs_y = [];
 
+var numberOfAjaxCalls = 0;
+var numberOfFinishedAjaxCalls = 0;
+var resultGeometryPopup;
+var _geomArray = new GeometryArray();
+try {if(mod_digitize_elName){}}catch(e) {mod_digitize_elName = "digitize";}
+
 function addButtonWfs(id, isOn, src, title, x, y) {
 	buttonWfs_id.push(id);
 	buttonWfs_on.push(isOn);
@@ -384,7 +390,6 @@
 	el.onmousedown = mod_wfs_spatialRequest_start;
 }
 
-
 function isSetWfsResultToDigitize() {
 	if (parseInt(buttonWfs_toDigitize_on)==1) return true;
 	return false;
@@ -397,16 +402,15 @@
 		
 		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('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.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>");
@@ -415,10 +419,6 @@
 		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();
 	}
@@ -428,10 +428,19 @@
 }
 
 function mb_setwfsrequest(target,queryGeom){
+	if (typeof(wfsPopup) != "undefined") {
+		wfsPopup.hide();
+	}	
 	//mb_wfs_reset();
 	var ind = getMapObjIndexByName(target);
 	var w = [];
-	w_ = [];
+	js_wfs_conf_id = [];
+	_geomArray = new GeometryArray();
+	
+	if (typeof(resultGeometryPopup) != "undefined") {
+		resultGeometryPopup.hide();
+	}
+	
 	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++){
@@ -443,21 +452,23 @@
 	}
 	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(wfs_config[ii]['wfs_conf_id'] == w[i])  js_wfs_conf_id[js_wfs_conf_id.length] = ii;
 		}
 	}
 	
+	numberOfAjaxCalls =  js_wfs_conf_id.length;
+	
 	if(queryGeom.geomType==geomType.polygon){
-		for(var i=0; i<w_.length; i++){
-			var url = wfs_config[w_[i]]['wfs_getfeature'];
+		for(var i=0; i<js_wfs_conf_id.length; i++){
+			var url = wfs_config[js_wfs_conf_id[i]]['wfs_getfeature'];
 			url += "service=wfs&request=getFeature&version=1.0.0";
-			url += "&typename="+ wfs_config[w_[i]]['featuretype_name'];
+			url += "&typename="+ wfs_config[js_wfs_conf_id[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'];
+			for(var j=0; j<wfs_config[js_wfs_conf_id[i]]['element'].length; j++){
+				if(wfs_config[js_wfs_conf_id[i]]['element'][j]['f_geom'] == 1){
+					filter += wfs_config[js_wfs_conf_id[i]]['element'][j]['element_name'];
 				}
 			}
 			filter += "</ogc:PropertyName><gml:Polygon srsName=\"EPSG:4326\">";
@@ -468,7 +479,7 @@
 			}
 			filter += '</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs>';
 			filter += '</gml:Polygon></Within></ogc:Filter>';
-			mb_get_geom(url, filter, i, wfs_config[w_[i]]['featuretype_name'], w_[i], w[i]);
+			mb_get_geom(url, filter, i, wfs_config[js_wfs_conf_id[i]]['featuretype_name'], js_wfs_conf_id[i], w[i]);
 		}
 	}
 	else if(queryGeom.geomType==geomType.line){
@@ -476,34 +487,34 @@
 		if(queryGeom.geomType == geomType.line){
 			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=";
+		for(var i=0; i<js_wfs_conf_id.length; i++){
+			var url = wfs_config[js_wfs_conf_id[i]]['wfs_getfeature'];
+			param = "service=wfs&request=getFeature&version=1.0.0&typename="+ wfs_config[js_wfs_conf_id[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'];
+			for(var j=0; j<wfs_config[js_wfs_conf_id[i]]['element'].length; j++){
+				if(wfs_config[js_wfs_conf_id[i]]['element'][j]['f_geom'] == 1){
+					filter += wfs_config[js_wfs_conf_id[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, wfs_config[w_[i]]['featuretype_name'], w_[i], w[i]);
+			mb_get_geom(url, filter, i, wfs_config[js_wfs_conf_id[i]]['featuretype_name'], js_wfs_conf_id[i], w[i]);
 		}
 	}
 	else if(queryGeom.geomType == geomType.point){
 		var tmp = queryGeom.get(0);
 		var buffer = mb_wfs_tolerance/2;
-		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=";
+		for(var i=0; i<js_wfs_conf_id.length; i++){
+			var url = wfs_config[js_wfs_conf_id[i]]['wfs_getfeature'];
+			param = "service=wfs&request=getFeature&version=1.0.0&typename="+ wfs_config[js_wfs_conf_id[i]]['featuretype_name']+"&filter=";
 			var filter = "<ogc:Filter xmlns:ogc='http://ogc.org' xmlns:gml='http://www.opengis.net/gml'>";
 			filter += "<Intersects><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'];
+			for(var j=0; j<wfs_config[js_wfs_conf_id[i]]['element'].length; j++){
+				if(wfs_config[js_wfs_conf_id[i]]['element'][j]['f_geom'] == 1){
+					filter += wfs_config[js_wfs_conf_id[i]]['element'][j]['element_name'];
 				}
 			}
 			filter += "</ogc:PropertyName><gml:Polygon srsName='4326'><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>";	
@@ -511,7 +522,7 @@
 			filter += (tmp.x + buffer) + "," + (tmp.y + buffer) + " " + (tmp.x - buffer) + "," + (tmp.y + buffer) + " " + (tmp.x - buffer) + "," + (tmp.y - buffer); 
 			filter += "</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></Intersects></ogc:Filter>";
 			url += param;
-			mb_get_geom(url, filter, i, wfs_config[w_[i]]['featuretype_name'], w_[i], w[i]);
+			mb_get_geom(url, filter, i, wfs_config[js_wfs_conf_id[i]]['featuretype_name'], js_wfs_conf_id[i], w[i]);
 		}
 	}
 //	highlight = new Highlight(mb_wfs_targets, highlight_tag_id, {"position":"absolute", "top":"0px", "left":"0px", "z-index":generalHighlightZIndex}, generalHighlightLineWidth);
@@ -522,14 +533,170 @@
 	
 	mb_ajax_post("../" + wfsResultModulePath + wfsResultModuleFilename,{'url':url,'filter':filter,'typename':typename,'js_wfs_conf_id':js_wfs_conf_id, 'db_wfs_conf_id':db_wfs_conf_id},function(js_code,status){
 //		alert(js_code);
-		eval(js_code);
-		if (typeof(geom) == 'object') mb_execWfsReadSubFunctions(geom);
+		if (js_code) {
+			eval(js_code);
+		}
+		if (typeof(geom) == "undefined") {
+			var geom = new GeometryArray();
+		}
+		checkIfAllAjaxCallsFinished(geom);
 //		prompt('', js_code);
 	});
 }
 
+function checkIfAllAjaxCallsFinished (geom) {
+	numberOfFinishedAjaxCalls++;
+	if (typeof(geom) == 'object'){
+		_geomArray.union(geom);
+	}
+	if (numberOfFinishedAjaxCalls == numberOfAjaxCalls) {
+		mb_execWfsReadSubFunctions(_geomArray);
+		numberOfFinishedAjaxCalls = 0;
+	}
+}
+
 function useExtentIsSet () {
 	return mod_wfs_spatialRequest_useExtent;
 }
 
+function isValidWfsConfIndex (wfsConf, wfsConfIndex) {
+	return (typeof(wfsConfIndex) == "number" && wfsConfIndex >=0 && wfsConfIndex < wfsConf.length);
+}
 
+function Numsort (a, b) {
+  return a - b;
+}
+
+function getListTitle (geom) {
+	wfsConfId = geom.wfs_conf;
+	wfsConf = get_complete_wfs_conf();
+	if (isValidWfsConfIndex(wfsConf, wfsConfId)) {
+		var resultArray = [];
+		var resultName = "";
+		for (var i = 0 ; i < wfsConf[wfsConfId]['element'].length ; i++) {
+			if (wfsConf[wfsConfId]['element'][i]['f_show'] == 1 && geom.e.getElementValueByName(wfsConf[wfsConfId]['element'][i]['element_name']) !=false) {
+				var pos = wfsConf[wfsConfId]['element'][i]['f_respos'];
+				if (typeof(resultArray[pos]) != "undefined") {
+					resultArray[pos] += " " + geom.e.getElementValueByName(wfsConf[wfsConfId]['element'][i]['element_name']);
+				}
+				else {
+					resultArray[pos] = geom.e.getElementValueByName(wfsConf[wfsConfId]['element'][i]['element_name']);
+				} 
+				resultName += geom.e.getElementValueByName(wfsConf[wfsConfId]['element'][i]['element_name']) + " ";
+			}
+		}
+		resultArray.sort(Numsort);
+		var resultName = resultArray.join(" ");
+		if (resultName == "") {
+			resultName = wfsConf[wfsConfId]['g_label'];
+		}
+		return resultName;
+	}
+	else {
+		return msgObj.digitizeDefaultGeometryName;
+	}
+}
+
+function appendGeometryArrayToDigitize(geom){
+	parent.window.frames[mod_digitize_elName].appendGeometryArray(geom);
+}
+
+function appendGeometryToDigitize(i){
+	var digitizeArray = new GeometryArray();
+	digitizeArray.addCopy(_geomArray.get(i));
+	parent.window.frames[mod_digitize_elName].appendGeometryArray(digitizeArray);
+}
+
+function createListOfGeometries(){
+	var listOfGeom = "<table style='background-color:#EEEEEE;'>\n";
+	if (_geomArray.count() > 0) {
+		if(buttonWfs_toDigitize_on==1){
+			listOfGeom += "<tr><td style='color:black;font-size:12px;'>edit all</td>\n";
+			listOfGeom += "<td><img title='edit all' src='"+buttonWfs_toDigitize_src+"'  style='cursor:pointer' onclick='appendGeometryArrayToDigitize(_geomArray);'></img>";
+			listOfGeom += "</td>\n</tr>\n";
+			listOfGeom += "<tr>\n<td>&nbsp;</td>\n</tr>\n"; 
+		}
+		for (var i = 0 ; i < _geomArray.count(); i ++) {
+			if (_geomArray.get(i).get(-1).isComplete()) {
+				listOfGeom += "\t<tr>\n\t\t<td style = 'color:blue;font-size:12px;cursor:pointer;'\n";
+				listOfGeom += "\t\t\t onmouseover='mb_wfs_perform(\"over\",_geomArray.get("+i+"));' ";
+				listOfGeom += " onmouseout='mb_wfs_perform(\"out\",_geomArray.get("+i+"))' ";
+				listOfGeom += " onclick='mb_wfs_perform(\"click\",_geomArray.get("+i+")); showWfs("+i+");' ";
+				var geomName = getListTitle(_geomArray.get(i)); 
+				//if (_geomArray.get(i).geomType == geomType.polygon) {geomName += "(polygon)";}
+				//else if (_geomArray.get(i).geomType == geomType.line) {geomName += "(line)";}
+				//else if (_geomArray.get(i).geomType == geomType.point) {geomName += "(point)";}
+				listOfGeom += ">" + geomName +"</td>";
+				if(buttonWfs_toDigitize_on==1){
+					listOfGeom += "<td><img title='edit geometry object' src='"+buttonWfs_toDigitize_src+"'  style='cursor:pointer' onclick='appendGeometryToDigitize("+i+");'></img></td>";
+				}
+				listOfGeom += "\t\t</tr>\n"; 
+			}
+		}
+	}
+	listOfGeom += "</table>\n";
+	return listOfGeom; 
+}
+
+function displayPopup(geom){
+	_geomArray = geom;
+	if (typeof(resultGeometryPopup) == "undefined") {
+		resultGeometryPopup = new mb_popup(searchPopupTitle,createListOfGeometries(),searchPopupWidth,searchPopupHeight,searchPopupX,searchPopupY);
+	}
+	else {
+		resultGeometryPopup.setWidth(searchPopupWidth);
+		resultGeometryPopup.setHtml(createListOfGeometries());
+	}
+	resultGeometryPopup.show();
+}
+
+function showWfs(geometryIndex) {
+	var wfsConfIndex = _geomArray.get(geometryIndex).wfs_conf;
+	var currentWfsConf = wfsConf[wfsConfIndex];
+	
+	var resultHtml = "";
+	resultHtml += "<table style='background-color:#EEEEEE;'>\n";
+	for (var i = 0 ; i <currentWfsConf.element.length; i ++) {
+	    if(currentWfsConf.element[i].f_show_detail==1){
+	    	if( _geomArray.get(geometryIndex).e.getElementValueByName(currentWfsConf.element[i].element_name)!=false){
+				//console.log(currentWfsConf.element[i].element_name+"---"+currentWfsConf.element[i].f_respos);
+				resultHtml +="<tr><td>\n"; 
+				resultHtml += currentWfsConf.element[i].f_label;
+				resultHtml +="</td>\n"; 
+				resultHtml += "<td>\n";
+				var elementVal = _geomArray.get(geometryIndex).e.getElementValueByName(currentWfsConf.element[i].element_name); 
+				if(currentWfsConf.element[i].f_form_element_html.indexOf("href")!=-1){
+					var setUrl = currentWfsConf.element[i].f_form_element_html.replace(/href\s*=\s*['|"]\s*['|"]/, "href='"+elementVal+"' target='_blank'");
+					if(setUrl.match(/><\/a>/)){
+						var newLink	=	setUrl.replace(/><\/a>/, ">"+elementVal+"</a>");			
+					}
+					else{
+						var newLink = setUrl;
+					}
+					resultHtml +=  newLink;
+				}
+				else{
+					resultHtml += elementVal;
+				}
+				resultHtml += "</td></tr>\n";		
+			}
+		}
+	}
+	resultHtml += "</table>\n";
+	
+	var getCenter =  _geomArray.get(geometryIndex).getCenter();
+	// getMapPos for positioning of new PopupDiv near object in mapframe1
+	//var getMapPos = makeRealWorld2mapPos("mapframe1",getCenter.x, getCenter.y);
+	if (typeof(wfsPopup) == "undefined") {
+		wfsPopup = new mb_popup(detailPopupTitle,resultHtml,detailPopupWidth,detailPopupHeight,detailPopupX,detailPopupY);
+	}
+	else {
+		wfsPopup.hide();
+		wfsPopup = new mb_popup(detailPopupTitle,resultHtml,detailPopupWidth,detailPopupHeight,detailPopupX,detailPopupY);
+	}
+	wfsPopup.show();
+}
+
+if(wfsResultToPopupDiv==1){
+	mb_registerWfsReadSubFunctions(function(geom){displayPopup(geom);});
+}



More information about the Mapbender_commits mailing list