[OpenLayers-Users] search feature to attribute

Maren Kiehl maren.kiehl at gmx.de
Sun Aug 30 05:43:13 EDT 2009


Eric Lemoine schrieb:
> 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
>>
>>     
>
>   
Sorry, but that doenst work. When I implement this an exception is 
thrown which says "layer is undefined".
But I found another solution: Instead of the attribute-value "name" I 
took the value "the_geom" and transformed it into x and y coordinates. 
Now everything is fine.

Thanks for your help!
Maren





More information about the Users mailing list