I have added a feature map to my OpenLayers 2 map, by using the following code. When I click a spot on the map, it correctly retrieves the feature name for that place according to the feature layer.
Code:
featureControl = new OpenLayers.Control.WMSGetFeatureInfo({
url: featureLayer.url,
title: '',
layers: [ featureLayer ],
infoFormat: 'text/xml',
queryVisible: true
});
featureControl.events.register('getfeatureinfo', this, function(event) {
var xml = new window.DOMParser().parseFromString(event.text, 'application/xml'),
path = featureLayer.$featureInfoXPath,
featureName;
try {
featureName = xml.evaluate(path, xml, null, XPathResult.ANY_TYPE, null).iterateNext().value;
console.log('got the feature:', featureName)
} catch ( error ) {
console.log('error', error);
}
});
map.addControl(featureControl);
featureControl.activate();
However, I would like to trigger this retrieval of the feature name on other events as well, such as when I type in an address in an input field and I select an address in an auto complete. So I am looking for a mechanism to trigger the GetFeatureInfo event by something other than "click".
Is this possible, and if so, how?