[OpenLayers-Users] search feature to attribute
Eric Lemoine
eric.lemoine at camptocamp.com
Sat Aug 29 17:34:05 EDT 2009
On Saturday, August 29, 2009, Maren Kiehl <maren.kiehl at gmx.de> wrote:
> Hi at all.
>
> I'm searching for a function which can identify a feature by searching
> an attribute-value.
> I have the name of a feature-attribute (http://feature.attributes.name) and
> wanna search the apposite feature. After that I wanna zoom to the center
> of this feature(map.setCenter(feature.geometry.getBounds().getCenterLonLat(), zoom);).
> The problem ist: I dont know how to identify the feature by knowing the attribute. I get the
> attribute-value from a php-value in another page. By clicking a link on
> this page a window opens and shows a little map with the feature-point
> in the center of it. Everything (little map opens in a popup and shows the extent of all points)
> works except for the last step.
> Does somebody know how to get the feature? Does a function for this problem exist?
Would something like the following work for you?
(NAME is the attribute name, and VALUE the attribute value)
function getFeatureByValue(layer) {
var features = layer.features;
for(var i=0; i<features.length; i++) {
var feature = features[i];
if(feature.attributes[NAME] == VALUE) {
return feature;
}
}
}
>
> Thanks for your support.
> Best regards,
> Maren
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>
--
Eric Lemoine
Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex
Tel : 00 33 4 79 44 44 96
Mail : eric.lemoine at camptocamp.com
http://www.camptocamp.com
More information about the Users
mailing list