[OpenLayers-Users] WFS with script protocol and filters

gismgr gismgr at sec.state.ma.us
Thu May 3 11:18:17 EDT 2012


Hello all, 

I'm trying to set up a request from geoserver to grab a single point based on a user-input search string.  I'm using OpenLayers 2.12 and geoserver 2.1.3.

>From what I understand, this should work: 
						
						found_layer = new OpenLayers.Layer.Vector(
							' Points',
							{
								strategies: strategy,
								displayInLayerSwitcher: false,
								protocol: new OpenLayers.Protocol.Script({
									url:'http://gismgr:8080/geoserver/wfs',
									callbackKey: 'format_options',
									callbackPrefix: 'callback:',
									params: {
										service: 'WFS',
										version: '1.1.0',
										srsName: 'EPSG:3857',
										request: 'GetFeature',
										typeName: 'MHC:Inventory_Points',
										outputFormat: 'json',
										//CQL_FILTER: filter
										CQL_FILTER: "MHCN='"+search_string+"'",
									}
								}),
							}
						)

I've tried just about every trick I've been able to find on the internet - multiple different strategies including the filter strategy, setting a rule based on the CQL format, etc.  All I ever get back is an empty layer.


I can get it to work with no filter, using the BBOX strategy and filterToParams.  Then if I'm already zoomed in near the point (i.e., the bbox strategy has already loaded it) I can use getFeaturesByAttribute to zoom to and query the point of interest.  But the data layer is far too large for this to be a good solution - I really need to be able to request just a single feature from geoserver.

This code works, but doesn't filter to a single point: 
			inv_points = new OpenLayers.Layer.Vector(
				' Points', {
					strategies: [new OpenLayers.Strategy.BBOX()],
					//visibility: false,
					minScale: 55000,
					protocol: new OpenLayers.Protocol.Script({
						url:'http://gismgr:8080/geoserver/wfs',
						callbackKey: 'format_options',
						callbackPrefix: 'callback:',
						params: {
							service: 'WFS',
							version: '1.1.0',
							srsName: 'EPSG:3857',
							request: 'GetFeature',
							typeName: 'MHC:Inventory_Points',
							outputFormat: 'json'
						},
						filterToParams: function(filter, params) {
							// example to demonstrate BBOX serialization
							//Not sure what this does but the vector layers don't work unless they have it
							if (filter.type === OpenLayers.Filter.Spatial.BBOX) {
								params.bbox = filter.value.toArray();
								if (filter.projection) {
									params.bbox.push(filter.projection.getCode());
								}
							}
							return params;
						}
					})
				}
			);


Is there some way that I can alter the filterToParams function to filter to a single feature?  I found this post, but parsing it for just the bits I would need is a little beyond my skills just yet: http://lists.osgeo.org/pipermail/openlayers-users/2011-June/020981.html

 Any suggestions would be vastly appreciated ... 

Kat


More information about the Users mailing list