[Mapbender-commits] r6463 - trunk/mapbender/lib
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Tue Jun 29 11:08:57 EDT 2010
Author: kmq
Date: 2010-06-29 15:08:57 +0000 (Tue, 29 Jun 2010)
New Revision: 6463
Modified:
trunk/mapbender/lib/mb.ui.wfsGazetteer.js
Log:
additional file to previous commit
Modified: trunk/mapbender/lib/mb.ui.wfsGazetteer.js
===================================================================
--- trunk/mapbender/lib/mb.ui.wfsGazetteer.js 2010-06-29 15:06:22 UTC (rev 6462)
+++ trunk/mapbender/lib/mb.ui.wfsGazetteer.js 2010-06-29 15:08:57 UTC (rev 6463)
@@ -4,7 +4,9 @@
options: {
},
+
_create: function () {
+ var that = this;
if (typeof this.options.wfsConf !== "object" &&
this.options.wfsConf !== null
) {
@@ -17,7 +19,7 @@
if (parseInt(el.f_search, 10) !== 1) {
continue;
}
- var id = this.element.id + "_" + el.element_name;
+ var id = $(this.element).attr('id') + "_" + el.element_name;
var $formElement;
if (el.f_form_element_html.match(/\<select/)) {
@@ -49,10 +51,165 @@
"for": id
}).text(el.f_label).append($formElement);
- $(".mb-wfsGazetteer-form", this.element).prepend($label);
+ $(".mb-ui-wfsGazetteer-form", this.element).prepend($label);
}
+ $(this.element).submit(function(e){
+ // we never want the form to actually be submitted
+ e.preventDefault();
+ // get filters from field, and search
+ that.search({});
+ return false;
+ });
+
+ $(this.element).bind('reset',function(){
+ // what if the spatial filter became a value in a hidden field?
+ $('.error',this.element).css('border','');
+ $('.error',this.element).removeClass('error');
+ that._status('');
+ return true;
+ });
},
+ /*
+ *
+ * @param filter an object where each key specifies one field to filter by using it's value
+ *
+ */
+ search : function(filter) {
+ $('.error',this.element).css('border','');
+ $('.error',this.element).removeClass('error');
+ this._status('');
+
+ if(!filter){ return; }
+ var OGCFilter = null;
+ for(var i = 0; i < filter.length; i++){
+ }
+
+ var element = null;
+ var value = null;
+ var srs = this.options.wfsConf.featuretype_srs;
+ var ft = this.options.wfsConf.featuretype_name;
+ var id = "";
+ var OGCFilterExpression = "";
+ var orConditions = [];
+ var andConditions = [];
+ for(var j = 0; i < this.options.wfsConf.element.length; i++){
+ el = this.options.wfsConf.element[i];
+ id = $(this.element).attr('id') + "_" + el.element_name;
+
+ var qname = el.element_name.split(':');
+ nsPrefix = qname.length == 2 ? qname[1]+":" : "";
+ elementQname = nsPrefix + el.element_name
+ value = $('#'+id).val() || "";
+
+ // check if field is mandatory
+ if(el.f_min_input > value.length){
+ $('#'+id).addClass('error');
+ $(".error",this.element).css('border','2px inset red');
+ this._status('Errors in search');
+ return;
+ }
+ if(value.length === 0){ continue;}
+
+ value = el.f_toupper == 1 ? value.toUpperCase() : value;
+
+ switch(el.f_operator){
+
+ case 'greater_than':
+ OGCFilterExpression = "<OGC:PropertyIsGreaterThan>";
+ OGCFilterExpression += "<OGC:propertyName>"+ elementQname +"</OGC:propertyName>";
+ OGCFilterExpression += "<OGC:Literal>"+value+"*</OGC:Literal>";
+ OGCFilterExpression += "</OGC:PropertyIsGreaterThan>";
+ break;
+
+ case 'greater_equal_than':
+ OGCFilterExpression = "<OGC:PropertyIsGreaterThanOrEqualTo>";
+ OGCFilterExpression += "<OGC:propertyName>"+ elementQname +"</OGC:propertyName>";
+ OGCFilterExpression += "<OGC:Literal>"+value+"*</OGC:Literal>";
+ OGCFilterExpression += "</OGC:PropertyIsGreaterThanOrEqualTo>";
+ break;
+
+ case 'less_than':
+ OGCFilterExpression = "<OGC:PropertyIsLessThan>";
+ OGCFilterExpression += "<OGC:propertyName>"+ elementQname +"</OGC:propertyName>";
+ OGCFilterExpression += "<OGC:Literal>"+value+"*</OGC:Literal>";
+ OGCFilterExpression += "</OGC:PropertyIsLessThan>";
+ break;
+
+ case 'less_equal_than':
+ OGCFilterExpression = "<OGC:PropertyIsLessThan>";
+ OGCFilterExpression += "<OGC:propertyName>"+ elementQname +"</OGC:propertyName>";
+ OGCFilterExpression += "<OGC:Literal>"+value+"*</OGC:Literal>";
+ OGCFilterExpression += "</OGC:PropertyIsLessThan>";
+ break;
+
+ case 'equal':
+ OGCFilterExpression = "<OGC:PropertyIsEqualTo>";
+ OGCFilterExpression += "<OGC:propertyName>"+ elementQname +"</OGC:propertyName>";
+ OGCFilterExpression += "<OGC:Literal>"+value+"*</OGC:Literal>";
+ OGCFilterExpression += "</OGC:PropertyIsEqualTo>";
+ break;
+
+ case 'leftside':
+ OGCFilterExpression = "<OGC:PropertyIsLike wildCard='*' singleChar='.' escape='!'>";
+ OGCFilterExpression += "<OGC:propertyName>"+ elementQname +"</OGC:propertyName>";
+ OGCFilterExpression += "<OGC:Literal>*"+value+"</OGC:Literal>";
+ OGCFilterExpression += "</OGC:PropertyIsLike>";
+ break;
+
+ case 'rightside':
+ OGCFilterExpression = "<OGC:PropertyIsLike wildCard='*' singleChar='.' escape='!'>";
+ OGCFilterExpression += "<OGC:propertyName>"+ elementQname +"</OGC:propertyName>";
+ OGCFilterExpression += "<OGC:Literal>"+value+"*</OGC:Literal>";
+ OGCFilterExpression += "</OGC:PropertyIsLike>";
+ break;
+
+ case 'bothside':
+ default:
+ OGCFilterExpression = "<OGC:PropertyIsLike wildCard='*' singleChar='.' escape='!'>";
+ OGCFilterExpression += "<OGC:propertyName>"+ elementQname +"</OGC:propertyName>";
+ OGCFilterExpression += "<OGC:Literal>*"+value+"*</OGC:Literal>";
+ OGCFilterExpression += "</OGC:PropertyIsLike>";
+ break;
+
+
+ }
+
+ orConditions.push(OGCFilterExpression);
+ }
+ var OGCORFilter = orConditions.length == 1 ? orConditions[0] : "<Or>"+ orConditions.join('') +"<Or>";
+ andConditions.push(OGCORFilter);
+
+ //TODO: spatial filter
+
+ var OGCANDFilter = andConditions.length == 1 ? andConditions[0] : "<And>"+ andConditions.join('') +"<and>";
+ OGCFilter = "<ogc:filter>" + OGCANDFilter +"</ogc:filter>";
+
+ var params = {
+ command : "getSearchResults",
+ wfs_conf_id : this.options.wfsConf.wfs_id, //?
+ typename : this.options.wfsConf.featuretype_name,
+ frame : "",
+ filter : OGCFilter,
+ backlink : ""
+ };
+ var that = this;
+ mb_ajax_get("../php/mod_wfs_gazetteer_server.php", params, function(json,status){
+ that._trigger('receivefeaturecollection',null,{
+ featureCollection:json,
+ wfsConf: that.options.wfsConf});
+ });
+
+
+ },
+ receivefeaturecollection: function(event,ui){
+ debugger;
+ },
+ _status: function(message){
+ $('.mb-ui-wfsGazetteer-status',$(this.element)).html(message);
+ },
+ clear: function(){
+ },
destroy: function () {
console.log("destroy");
}
More information about the Mapbender_commits
mailing list