Hi All, I suggest the following changes to gazetteer listing format and operation: - Table format with header instead of plain divs - Remove built-in leading and trailing * (joker) characters from search string as it provides misleading operation, too many hits. User could include jokers where really needed. - Limit hit list to for example 100 records. For me, 700 caused unrecoverable blocking in browser (reload helped).
file in question: http/javascripts/mod_wfs_gazetteer_client.php best regards: Balázs Bámer
<?php # $Id: mod_wfs_gazetteer_client.php 2320 2008-04-01 12:44:25Z christoph $ # maintained by http://www.mapbender.org/index.php/User:Verena Diewald # http://www.mapbender.org/index.php/WFS_gazetteer # 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. require_once(dirname(__FILE__)."/../php/mb_validatePermission.php"); $gui_id = $_SESSION["mb_user_gui"]; $target = $_REQUEST["e_target"]; $isLoaded = $_REQUEST["isLoaded"]; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset='<?php echo CHARSET;?>'"> <title>mod_wfs_gazetteer</title> <?php include '../include/dyn_css.php'; ?> <script type="text/javascript"> <?php include '../include/dyn_js.php'; include '../include/dyn_php.php'; echo "var targetString = '" . $target . "';"; echo "var wfsConfIdString = '" . $wfsConfIdString . "';"; echo "var e_id_css = '" . $e_id_css . "';"; ?> // Element var maxHighlightedPoints try{ if (maxHighlightedPoints){ maxHighlightedPoints = Number(maxHighlightedPoints); if (isNaN(maxHighlightedPoints)) { // var e = new parent.Mb_warning("mod_wfs_gazetteer_client.php: Element var maxHighlightedPoints must be a number."); } } } catch(e){ maxHighlightedPoints = 0; // var e = new parent.Mb_warning("mod_wfs_gazetteer_client.php: Element var maxHighlightedPoints is not set, see 'edit element vars'."); } var targetArray = targetString.split(","); var global_wfsConfObj; var global_selectedWfsConfId; var point_px = 10; var resultGeom = null; var cw_fillcolor = "#cc33cc"; parent.mb_registerInitFunctions("window.frames['"+this.name+"'].initModWfsGazetteer()"); function openwindow(Adresse) { Fenster1 = window.open(Adresse, "Informationen", "width=500,height=500,left=100,top=100,scrollbars=yes,resizable=no"); Fenster1.focus(); } //---------------------------------------------------------------------------------- function appendWfsConf(newWfsConfIdString) { // merge with existing wfs conf ids if (wfsConfIdString !== "") { if (newWfsConfIdString !== "") { wfsConfIdString += "," + newWfsConfIdString; // rebuild form initModWfsGazetteer(); } } else { wfsConfIdString = newWfsConfIdString; // rebuild form initModWfsGazetteer(); } } function removeChildNodes(node) { while (node.childNodes.length > 0) { var childNode = node.firstChild; node.removeChild(childNode); } } /** * removes whitespaces and endlines before and after a string * */ function trimString (str) { return str.replace(/^\s+|\s+|\n+$/g, ''); } function appendStyles() { var styleObj; var rule = global_wfsConfObj[global_selectedWfsConfId].g_style + global_wfsConfObj[global_selectedWfsConfId].g_res_style; if (parent.ie) { var styleSheetObj=document.createStyleSheet(); styleObj=styleSheetObj.owningElement || styleSheetObj.ownerNode; styleObj.setAttribute("type","text/css"); ruleArray = rule.split("}"); for (var i=0; i < ruleArray.length - 1; i++) { var currentRule = trimString(ruleArray[i]); var nameValueArray = currentRule.split("{"); var name = nameValueArray[0]; var value = nameValueArray[1]; styleSheetObj.addRule(name,value); } } else { styleObj=document.createElement("style"); styleObj.setAttribute("type","text/css"); document.getElementsByTagName("head")[0].appendChild(styleObj); styleObj.appendChild(document.createTextNode(rule+"\n")); } } //---------------------------------------------------------------------------------- function initModWfsGazetteer() { // empty nodes var nodesToEmpty = ["selectWfsConfForm", "wfsForm", "res", "wfsInfo"]; while (nodesToEmpty.length > 0) { var currentId = nodesToEmpty.pop(); var currentNode = document.getElementById(currentId); removeChildNodes(currentNode); } document.getElementById("wfsGeomType").style.visibility = "hidden"; document.getElementById("wfsRemove").style.visibility = "hidden"; parent.mb_ajax_json("../php/mod_wfs_gazetteer_server.php", {command:"getWfsConf",wfsConfIdString:wfsConfIdString}, function(json, status) { global_wfsConfObj = json; var wfsCount = 0; for (var wfsConfId in global_wfsConfObj) { global_selectedWfsConfId = wfsConfId; if (typeof(global_wfsConfObj[wfsConfId] != 'function')) { wfsCount++; } } if (wfsCount === 0) { var e = new parent.Mb_exception("no wfs conf id available."); } else if (wfsCount === 1) { appendStyles(); appendWfsForm(); setWfsInfo(); } else { appendWfsConfSelectBox(); setWfsInfo(); } parent.mb_setWmcExtensionData({"wfsConfIdString":wfsConfIdString}); }); } function setWfsInfo() { var bulbNode = document.getElementById("wfsInfo"); // append bulb image removeChildNodes(bulbNode); var imgNode = document.createElement("img"); imgNode.id = "wfsInfoImg"; //imgNode.src = "../img/button_digitize/geomInfo.png"; imgNode.src = "../img/tree_new/info.png"; imgNode.border = 0; bulbNode.appendChild(imgNode); bulbNode.href = "javascript:openwindow('../php/mod_featuretypeMetadata.php?wfs_conf_id=" + global_selectedWfsConfId.toString() + "');"; bulbNode.style.visibility = "visible"; // set wfsGeomType image var wfsGeomTypeNode = document.getElementById("wfsGeomType"); var wfsGeomType = ""; for (var i=0; i < global_wfsConfObj[global_selectedWfsConfId].element.length; i++) { if (parseInt(global_wfsConfObj[global_selectedWfsConfId].element[i].f_geom)) { wfsGeomType = global_wfsConfObj[global_selectedWfsConfId].element[i].element_type; } } if (wfsGeomType.match(/Point/)) { wfsGeomTypeNode.src = "../img/button_digitize/point.png"; wfsGeomTypeNode.style.visibility = 'visible'; } else if (wfsGeomType.match(/Line/)) { wfsGeomTypeNode.src = "../img/button_digitize/line.png"; wfsGeomTypeNode.style.visibility = 'visible'; } else if (wfsGeomType.match(/Polygon/)) { wfsGeomTypeNode.src = "../img/button_digitize/polygon.png"; wfsGeomTypeNode.style.visibility = 'visible'; } else { var e = new parent.Mb_exception("WFS gazetteer: geometry type unknown."); } // set image: remove this WFS var wfsRemoveNode = document.getElementById("wfsRemove"); //wfsRemoveNode.src = "../img/button_digitize/geomRemove.png"; wfsRemoveNode.src = "../img/tree_new/delete_wms.png"; wfsRemoveNode.style.visibility = 'visible'; // Internet explorer if (parent.ie) { wfsRemoveNode.onclick = function() { var x = new Function ("", "delete global_wfsConfObj[global_selectedWfsConfId];setWfsConfIdString();initModWfsGazetteer();parent.mb_setWmcExtensionData({'wfsConfIdString':wfsConfIdString});"); x(); }; } // Firefox else { wfsRemoveNode.onclick = function () { delete global_wfsConfObj[global_selectedWfsConfId]; setWfsConfIdString(); initModWfsGazetteer(); parent.mb_setWmcExtensionData({"wfsConfIdString":wfsConfIdString}); } } } function setWfsConfIdString() { var str = []; for (var wfsConfId in global_wfsConfObj) { global_selectedWfsConfId = wfsConfId; if (typeof(global_wfsConfObj[wfsConfId] != 'function')) { str.push(wfsConfId); } } wfsConfIdString = str.join(","); } function appendWfsConfSelectBox() { var selectNode = document.createElement("select"); selectNode.name = "wfs_conf_sel"; var wfsFormNode = document.getElementById("selectWfsConfForm"); selectNode.onchange = function() { global_selectedWfsConfId = this.value; setWfsInfo(); appendStyles(); appendWfsForm(); }; var isSelected = false; for (var wfsConfId in global_wfsConfObj) { var optionNode = document.createElement("option"); optionNode.value = wfsConfId; optionNode.innerHTML = global_wfsConfObj[wfsConfId].g_label; if (!isSelected) { optionNode.selected = true; isSelected = true; global_selectedWfsConfId = wfsConfId; } selectNode.appendChild(optionNode); } var form = document.getElementById('selectWfsConfForm'); form.appendChild(selectNode); appendStyles(); appendWfsForm(); } function appendWfsForm() { var form = document.getElementById("wfsForm"); removeChildNodes(form); var resultDiv = document.getElementById("res"); removeChildNodes(resultDiv); var divContainer = document.createElement("div"); divContainer.className = global_wfsConfObj[global_selectedWfsConfId].g_label_id; divContainer.innerHTML = global_wfsConfObj[global_selectedWfsConfId].g_label; form.appendChild(divContainer); var wfsConfElementArray = global_wfsConfObj[global_selectedWfsConfId].element; for (var i = 0; i < wfsConfElementArray.length; i++){ if (parseInt(wfsConfElementArray[i].f_search)) { var spanNode = document.createElement("span"); spanNode.setAttribute("id", "ttttt"); spanNode.className = wfsConfElementArray[i].f_label_id; spanNode.innerHTML = wfsConfElementArray[i].f_label; var inputNode = document.createElement("input"); inputNode.type = "text"; inputNode.className = wfsConfElementArray[i].f_style_id; inputNode.id = wfsConfElementArray[i].element_name; form.appendChild(spanNode); form.appendChild(inputNode); form.appendChild(document.createElement("br")); } } var submitButton = document.createElement("input"); submitButton.type = "submit"; submitButton.className = global_wfsConfObj[global_selectedWfsConfId].g_button_id; submitButton.value = global_wfsConfObj[global_selectedWfsConfId].g_button; form.appendChild(submitButton); } function validate(){ global_resultHighlight = new parent.Highlight(targetArray, "wfs_gazetteer_highlight", {"position":"absolute", "top":"0px", "left":"0px", "z-index":100}, 2); var filterParameterCount = getNumberOfFilterParameters(); if(filterParameterCount == 0){ return false; } else{ var andConditions = ""; var el = global_wfsConfObj[global_selectedWfsConfId].element; for (var i = 0; i < el.length; i++) { if (el[i]['f_search'] == 1 && document.getElementById(el[i]['element_name']).value != '') { var a = new Array(); a = document.getElementById(el[i]['element_name']).value.split(","); var orConditions = ""; for (var j=0; j < a.length; j++) { orConditions += "<ogc:PropertyIsLike wildCard='*' singleChar='.' escape='!'>"; orConditions += "<ogc:PropertyName>" + el[i]['element_name'] + "</ogc:PropertyName>"; orConditions += "<ogc:Literal>"; if(el[i]['f_toupper'] == 1){ orConditions += a[j].toUpperCase(); } else{ orConditions += a[j]; } orConditions += "</ogc:Literal>"; orConditions += "</ogc:PropertyIsLike>"; } if(a.length > 1){ andConditions += "<Or>" + orConditions + "</Or>"; } else { andConditions += orConditions; } } } var u = global_wfsConfObj[global_selectedWfsConfId].wfs_getfeature + parent.mb_getConjunctionCharacter(global_wfsConfObj[global_selectedWfsConfId].wfs_getfeature); u += "REQUEST=getFeature&Typename="+global_wfsConfObj[global_selectedWfsConfId].featuretype_name+"&Version=1.0.0&service=WFS"; u += "&filter="; if (filterParameterCount > 1) { andConditions = "<And>" + andConditions + "</And>"; } var filter = "<ogc:Filter xmlns:ogc='http://ogc.org' xmlns:gml='http://www.opengis.net/gml'>"+andConditions+"</ogc:Filter>"; document.getElementById("res").innerHTML = "<table><tr><td><img src='../img/indicator_wheel.gif'></td><td>Searching...</td></tr></table>"; var parameters = {command:"getSearchResults", "wfs_conf_id":global_selectedWfsConfId, "frame":this.name, "url":u, "filter":filter, "backlink":""}; parent.mb_ajax_get("../php/mod_wfs_gazetteer_server.php", parameters, function (jsCode, status) { document.getElementById("res").innerHTML = "<table><tr><td>Arranging search results...</td></tr></table>"; eval(jsCode); for (var i=0; i < parent.wms.length; i++) { for (var j=0; j < parent.wms[i].objLayer.length; j++) { var currentLayer = parent.wms[i].objLayer[j]; var wms_id = parent.wms[i].wms_id; if (currentLayer.gui_layer_wfs_featuretype == global_selectedWfsConfId) { var layer_name = currentLayer.layer_name; parent.handleSelectedLayer_array(targetArray[0],[wms_id],[layer_name],'querylayer',1); parent.handleSelectedLayer_array(targetArray[0],[wms_id],[layer_name],'visible',1); } } } var body = ""; if (typeof(geom) == 'object') { body+="<table cellpadding=1><tr>"; var sorted=new Array(el.length); for (var i = 0; i < el.length; i++){ sorted[i]=el[i].f_respos+"~"+el[i].f_label; } sorted.sort( function (a,b){ var aa=a.substring(0,a.indexOf("~")); var bb=b.substring(0,b.indexOf("~")); return aa-bb; } ); for(var i=0; i<sorted.length; i++) { var label=sorted[i].substring(sorted[i].indexOf("~")+1); if(label.length>0) { body+="<td>"; body+=label; body+="</td>"; } } body+="</tr>"; resultGeom = geom; // set the global variable for (var i=0; i < geom.count(); i++) { body += "<tr id='geom"+i+"'style='cursor:pointer;' "; if ((i % 2) === 0) { body += "class='even'"; } else { body += "class='uneven'"; } body += " onmouseover=\"setResult('over', this.id)\" "; body += " onmouseout=\"setResult('out', this.id)\" "; body += " onclick=\"setResult('click', this.id)\">"; for (var j=0; j < geom.get(i).e.count(); j++) { body +="<td>"; body += geom.get(i).e.getValue(j) + " "; body +="</td>"; } body += "</tr>"; } body += "</table>"; } else { body = "Kein Ergebnis."; } document.getElementById('res').innerHTML = body; }); } return false; } function getNumberOfFilterParameters(){ var cnt = 0; var el = global_wfsConfObj[global_selectedWfsConfId].element; for (var i = 0; i < el.length; i++){ if( el[i]['f_search'] == 1){ if (document.getElementById(el[i]['element_name']).value != '') { cnt++; } } } return cnt; } /* * event -> {over || out || click} * geom -> commaseparated coordinates x1,y1,x2,y2 ... */ function setResult(event, id){ var index = parseInt(id.slice(4)); var currentGeom = resultGeom.get(index); if (maxHighlightedPoints > 0 && currentGeom.getTotalPointCount() > maxHighlightedPoints) { currentGeom = currentGeom.getBBox4(); } if (event == "over") { global_resultHighlight.add(currentGeom, cw_fillcolor); global_resultHighlight.paint(); } else if (event == "out"){ global_resultHighlight.del(currentGeom, cw_fillcolor); global_resultHighlight.paint(); } else if (event == "click"){ global_resultHighlight.del(currentGeom, cw_fillcolor); var bbox = currentGeom.getBBox(); var bufferFloat = parseFloat(global_wfsConfObj[global_selectedWfsConfId].g_buffer); var buffer = new parent.Point(bufferFloat,bufferFloat); bbox[0] = bbox[0].minus(buffer); bbox[1] = bbox[1].plus(buffer); parent.mb_calculateExtent(targetArray[0], bbox[0].x, bbox[0].y, bbox[1].x, bbox[1].y); parent.zoom(targetArray[0], 'true', 1.0); global_resultHighlight.add(currentGeom, cw_fillcolor); global_resultHighlight.paint(); } return true; } </script> </head> <body leftmargin='0' topmargin='10' bgcolor='#ffffff'> <form name='selectWfsConfForm' id='selectWfsConfForm'></form> <img src = "" name='wfsGeomType' id='wfsGeomType'> <img src = "" name='wfsRemove' id='wfsRemove'> <a name='wfsInfo' id='wfsInfo'></a> <form name='wfsForm' id='wfsForm' onsubmit='return validate()'></form> <div name='res' id='res' style='width:180px'></div> </body> </html>
_______________________________________________ Mapbender_dev mailing list [email protected] http://lists.osgeo.org/mailman/listinfo/mapbender_dev
