[OpenLayers-Users] search feature to attribute

Christopher Schmidt crschmidt at metacarta.com
Sun Aug 30 11:22:44 EDT 2009


On Sat, Aug 29, 2009 at 09:34:44AM +0200, Maren Kiehl 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 (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?

var feat = null;
for (var i=0; i< layer.features.length; i++) {
    feat = layer.features[i];
    if (feat.attributes['name'] == value) {
        break;
    }
}
console.log(feat);

-- Chris
> Thanks for your support.
> Best regards,
> Maren
> 
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users

-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list