Clicking On A Location To List Features

THL Toolbox > Developers' Zone > Gis Development > Clicking On A Location To List Features

Clicking on a Location to List Features

Contributor(s): Tom Benner

The THL Interactive Map's Implementation

When the "i" button control is enabled and the user clicks on a point on the map, the following is done:

Request to GeoServer

A BBOX value is calculated based on the click's pixel location, using a tolerance value set in the code that allows the user to click within, say, 2 pixels of a feature to still see it in the results. This tolerance is especially useful for point features, which may be displayed with icons/circles that are larger than the single pixel that the feature actually occupies.

A CQL_FILTER value is constructed that is a union of all the CQL_FILTERs of the currently visible layers on the map (e.g. "object_type=45+OR+object_type=46"). This is joined using a logical "AND" to the BBOX from above, and a WFS GetFeature request is made using the resulting CQL_FILTER value.

Feature List Popup

When the GetFeature request is returned, a popup is created. For each FID, a request is made to the Place Dictionary API (e.g. external link: http://places.thlib.org/feature/200.js) to get information on that feature. Those results are used to set the name, feature type, and caption of the feature in the feature list. (NB: This could be simplified and sped up by including these fields in GeoServer, so that the PD API calls aren't necessary.)

Using WMS GetFeatureInfo instead of WFS GetFeature

The most common way of adding this type of functionality is to use a WMS GetFeatureInfo request instead of WFS GetFeature. The reasons that GetFeature was chosen over GetFeatureInfo are:

  • GetFeatureInfo has a two pixel tolerance hard-coded into it, so that any adjustment of this tolerance is impossible. Having the flexibility of editing this tolerance was necessary for the range of feature types in the THL interactive map.
  • GetFeatureInfo seemed to not support a CQL_FILTER parameter, which is absolutely needed on the interactive map

However, if GetFeatureInfo the two issues listed above aren't relevant, GetFeatureInfo is a very useful tool. Example code of its use with a OpenLayers map is available external link: here.

Provided for unrestricted use by the external link: Tibetan and Himalayan Library