[OpenLayers-Users] Is there any way to avoid loading spatial data
when using OpenLayers.Control.GetFeature?
Michael O'Cleirigh
michael.ocleirigh at rivulet.ca
Tue Aug 11 12:01:37 EDT 2009
Hello,
I have a WMS layer containing various polygons that are used to
subdivide a map. The boundaries run along the street center line and
rivers, etc. It is a transparent layer sitting on top of google maps.
When the user clicks on the map I want to use WFS to get the zone number
of the polygon that contains the clicked point.
But the problem is that I don't need the geographic detail of the zone.
I add the zone number into the WMS layer logical filter which toggles
the polygon visibility.
Because the performance is slow I want to avoid fetching the spatial
data as part of the WFS request.
In the browser I can add a 'propertyName' parameter and this will
constrain the attributes returned to only include the zone number (i.e.
to exclude the spatial column). But I can't figure out how to do this
to a OpenLayers.Protocol.WFS object.
Does anyone have an example of how I can do this? or do I need to craft
a custom OpenLayers.Request call?
Thanks for your help,
Mike
References:
The control is registered as:
control = new OpenLayers.Control.GetFeature( {
protocol : OpenLayers.Protocol.WFS.fromWMSLayer(wmsLayer),
box : false,
hover : false,
multiple : false,
click : true,
clickout : false,
toggle : false,
clickTolerance : 0,
maxFeatures : 5
});
My click hander is:
control.events.register("featureselected", this, function(e) {
// get the zone number from the feature attributes returned
through WFS
var selectedZone = e.feature.attributes[this.zoneFilterName];
if (this.containsZone(selectedZone) == 1) {
// this is a remove
this.removeZoneFromFilter(selectedZone);
} else {
// this is an add
this.addZoneToFilter(selectedZone);
}
// update the filters on this.wmsLayer
this.update();
});
In Browser WFS request:
If I run the WFS GET query in the browser I can add a propertyName
parameter that will cause only that named value to be returned
http://10.0.16.100:8081/geoserver/wfs?request=GetFeature&service=WFS&version=1.1.0&typeName=zone_boundary&srs=urn:x-ogc:def:crs:EPSG:900913&maxfeatures=1&propertyName=zoneNumber
Response:
<wfs:FeatureCollection numberOfFeatures="1"
timeStamp="2009-08-11T11:56:30.764-04:00"
xsi:schemaLocation="http://10.0.16.100:8081/geoserver/wfs?service=WFS&version=1.1.0&request=DescribeFeatureType&typeName=zone_boundary
http://www.opengis.net/wfs
http://10.0.16.100:8081/geoserver/schemas/wfs/1.1.0/wfs.xsd">
<gml:featureMembers>
<GEO:zone_boundary gml:id="zone_boundary.nfm--7e5195b1_1230a1029de_-76c4">
<GEO:zoneNumber>1</GEO:zoneNumber>
</GEO:zone_boundary>
</gml:featureMembers>
</wfs:FeatureCollection>
More information about the Users
mailing list