[OpenLayers-Users] wfs feature geometry based on one attribute value

Alexandre Dube adube at mapgears.com
Wed Dec 10 19:10:41 EST 2008


Hey Mika,

Do you mean a feature that is currently shown on the map or any feature 
from your data source, including the ones currently on screen and the 
ones not generated yet ?

Because if it's one on screen you could easily accomplish that by 
looping through your layer.features, searching in your wanted 
attributes['yourattribute'] value... If you're seeking a feature not yet 
created, you obviously can't proceed like that.

What type of data do you use ? Shapefiles ? PostGIS ? I suppose it could 
be possible to use an SQL query to PostGIS to retrieve what you need. ( 
Really, really not sure... )

But if you use shapefiles and you don't have that many features, you 
could write a small php script using phpmapscript to echo all your 
wanted attribute, followed by the bounding box ( or geometry, but bbox 
is smaller so your script would suffer less from long delay ), put the 
result of the script in an array and when your user search for an ID, 
loop through that array. Or you could do a hash with the attribute the 
user has to input as the key and directly access your array that way.

I did something similar : dev4.mapgears.com/bdga/WFS-T.html look at the 
list on the upper right. It's a dynamically generated list of cities 
that changes the map position on change to the selected city.

In firebug, in Console, look at the 3rd query response. You could have 
something similar.

Best of luck,

Alexandre,

Lehtonen, Mika wrote:
> Hi,
>
> what is the easiest and the less performance consuming method to 
> retrieve a geometry (actually the bounds would be enough) if I know an 
> attribute value on that particular feature and I also know that there is 
> only one feature having that particular attribute value? Layer is WFS 
> and is already loaded.
>
> So what I want is that when the user fills in the attribute field and 
> submits the form, he/she gets the geometry zoomed to fit. (Actually 
> that's not so simple, but with that I do my testing.)
>
> - mika -
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>   


-- 
Alexandre Dubé
Mapgears
www.mapgears.com




More information about the Users mailing list