Getting feature information from data source
We work on web mapping applications almost every day. We know how to create a map and add raster and vector layers. More than that, we know how to get vector data from different data sources: GeoJSON file, KML file, or from a WFS server.
At this point, and related to vector layers, one of the possible questions we could have is: how can we retrieve the feature's information? Fortunately, OpenLayers offers us some controls that can answer this question.
In this recipe, we are going to see in action the OpenLayers.Control.GetFeature
control class that has the ability to query the feature's data source.
We are going to create a map with a base layer and two vector layers. One from a WFS server, with the USA, and the other from a GML file with Europe's countries.
On top of the map, a button allows us to activate/deactivate the GetFeature
control and two radio buttons allow us to select between the USA or Europe layers to be queried.
How to do it...
Let...