[OpenLayers-Users] searching a feature with open layers

Tim Schaub tschaub at openplans.org
Tue Nov 20 12:31:42 EST 2007


Hey-

goeserver developer wrote:
> the following code doesn't work. If I remove the filter WFS displays the
> first feature. I am working on geoserver. Even filter in the layer
> initialisation doesn't work.
> 
> var	Filter
> ="<Filter><PropertyIsEqualTo><PropertyName>STATE_NAME</PropertyName><LiteralTexas</Literal></PropertyIsEqualTo></Filter>";
> layerWFS = new OpenLayers.Layer.WFS( "WFS States",
> "http://localhost:8080/geoserver/wfs?",
>          					{typename: "states",maxfeatures: 1}, {
>       						 extractAttributes: true});
>      						 
> 									 layerWFS.mergeNewParams({'filter' : Filter }); 
>                    layerWFS.style.strokeColor = "#ff0000"; 
> 									 map.addLayer(layerWFS);
> 

It's a bit tough to follow/reproduce what you're doing here, but that 
open "<LiteralTexas" tag looks pretty suspicious.

You might want to step back from OpenLayers and confirm for yourself 
that you get the responses you're looking for from your WFS.

Firefox is essential for web development.  The RestTest extension is a 
*very* handy way to mock up requests.  OpenLayers makes XMLHttpRequests 
(XHR) asynchronously to do things like get features from a WFS.  Though 
you'll raise the hackles of many if you call it RESTful, you can use the 
RestTest extension for Firefox to make XHR requests and examine the 
responses.

So, get Firefox and RestTest [1].  Open up the RestTest dialog and enter 
in your request.  Look at the response and tweak until you get it right.

Tim

[1] http://xucia.com/#RestTest


> Any help is appreciated.
> Thanks
> 
> 
> 
> Arnd Wippermann wrote:
>> You can apply a filter to the WFS layer. 
>> WFSlayer.mergeNewParams({'filter' : yourFilter }); 
>>
>> But this works only, if the filtered feature is visible in the current
>> extent of the map. If you know the centerpoint of the features, you can
>> set
>> a new center for the map after applying the filter.
>>
>> Example:http://gis.ibbeck.de/ginfo/apps/OLExamples/SphericalMercator/wfs_fil
>> ter.html
>>
>> Mit freundlichen Grüssen
>>
>> Arnd Wippermann
>> http://gis.ibbeck.de/ginfo/
>>
>>
>>
>>
>> -----Ursprüngliche Nachricht-----
>> Von: bjoice at firstam.com [mailto:bjoice at firstam.com] 
>> Gesendet: Freitag, 16. November 2007 08:55
>> An: arnd.wippermann at web.de
>> Betreff: RE: [OpenLayers-Users] searching a feature with open layers
>>
>> Hi,
>>
>> Thanks,
>> I would like to know , can I pass the value of an attribute (eg : In
>> top:states , can pass STATE_name ="texas')  instead of maxfeatures with
>> OpenLayers.Layer.WFS.
>> Thanks, . 
>>
>> -----Original Message-----
>> From: arnd.wippermann at web.de [mailto:arnd.wippermann at web.de]
>> Sent: Thursday, November 15, 2007 10:40 PM
>> To: Joice, Binny
>> Cc: users at openlayers.org
>> Subject: AW: [OpenLayers-Users] searching a feature with open layers
>>
>> Hi,
>>
>> You can load your WFS with OpenLayers with option 'extractAttributes':
>> true.
>>
>>
>>     //OpenLayers.ProxyHost for WFS needed!!!
>>     layerWFS = new OpenLayers.Layer.WFS( "WFS Titel", WFS_Url,
>>         {typename: "POLYGONS", maxfeatures: 500}, { typename: "POLYGONS",
>> extractAttributes: true});
>>  
>> Now you have access to the features geometry and the features attributes.
>>
>> Mit freundlichen Grüssen
>>
>> Arnd Wippermann
>> http://gis.ibbeck.de/ginfo/apps/OLExamples/SphericalMercator/OL_900913_frame
>> s.html
>>
>>
>>
>> -----Ursprüngliche Nachricht-----
>> Von: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org] Im
>> Auftrag von goeserver developer
>> Gesendet: Donnerstag, 15. November 2007 07:31
>> An: users at openlayers.org
>> Betreff: Re: [OpenLayers-Users] searching a feature with open layers
>>
>>
>> Hi,
>>
>> Thanks,
>> Suppose I have a layer like states , I need to spatially locate , a
>> particular feature (like : name =texas)it on the map . With javascipt and
>> WFS I am able to do it . But with openlayers ,how could it be done. 
>>
>>
>> Eric Lemoine-3 wrote:
>>> On Nov 13, 2007 1:19 PM, goeserver developer <bjoice at firstam.com> wrote:
>>>> Hi,
>>>>
>>>> How can I include a search ? I am displaying the topp:states layer 
>>>> along with google map with openlayers. I also want to include a 
>>>> textbox where I can key in the state name to search. How will 
>>>> geoserver
>> do the WFS part?
>>>> Can it be done with Geojson.
>>> I'm not sure I fully understand your need, but you may be interested 
>>> in this example:
>>> <http://www.openlayers.org/dev/examples/getfeatureinfo.html>. WMS 
>>> GetFeatureInfo is used on each click in this example.
>>>
>>> --
>>> Eric
>>> _______________________________________________
>>> Users mailing list
>>> Users at openlayers.org
>>> http://openlayers.org/mailman/listinfo/users
>>>
>>>
>> --
>> View this message in context:
>> http://www.nabble.com/searching-a-feature-with-open-layers-tf4797435.html#a1
>> 3761443
>> Sent from the OpenLayers Users mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> Users mailing list
>> Users at openlayers.org
>> http://openlayers.org/mailman/listinfo/users
>>
>> **********************************************************************
>> This message contains confidential information intended only for the use
>> of
>> the addressee(s) named above and may contain information that is legally
>> privileged.  If you are not the addressee, or the person responsible for
>> delivering it to the addressee, you are hereby notified that reading,
>> disseminating, distributing or copying this message is strictly
>> prohibited.
>> If you have received this message by mistake, please immediately notify us
>> by replying to the message and delete the original message immediately
>> thereafter.
>>
>> Thank you.
>>                                     FADLD Tag
>> **********************************************************************
>>
>> _______________________________________________
>> Users mailing list
>> Users at openlayers.org
>> http://openlayers.org/mailman/listinfo/users
>>
>>
> 




More information about the Users mailing list