Skip to main content
corrected spelling
Source Link
nmtoken
  • 13.6k
  • 5
  • 38
  • 89

Triggering the retrieval of a feature on a feature layer by something other than click using Open LayersOpenLayers 2

I have added a feature map to my Open LayersOpenLayers 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 autocompleteauto complete. So I am looking for a mechanism to trigger the getfeatureinfoGetFeatureInfo event by something other than "click". 

Is this possible? And, and if so, how?

Triggering the retrieval of a feature on a feature layer by something other than click using Open Layers 2

I have added a feature map to my Open Layers 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 autocomplete. So I am looking for a mechanism to trigger the getfeatureinfo event by something other than "click". Is this possible? And if so, how?

Triggering the retrieval of a feature on a feature layer by something other than click using OpenLayers 2

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?

Notice removed Draw attention by CommunityBot
Bounty Ended with Owen J Lamb's answer chosen by CommunityBot
Tweeted twitter.com/StackGIS/status/803250281207066624
Notice added Draw attention by Squrler
Bounty Started worth 100 reputation by Squrler
deleted 10 characters in body; edited tags
Source Link

I have added a feature map to my Open Layers 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 autocomplete. So I am looking for a mechanism to trigger the getfeatureinfo event by something other than "click". Is this possible? And if so, how?

I have added a feature map to my Open Layers 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 autocomplete. So I am looking for a mechanism to trigger the getfeatureinfo event by something other than "click". Is this possible? And if so, how?

I have added a feature map to my Open Layers 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 autocomplete. So I am looking for a mechanism to trigger the getfeatureinfo event by something other than "click". Is this possible? And if so, how?

Source Link

Triggering the retrieval of a feature on a feature layer by something other than click using Open Layers 2

I have added a feature map to my Open Layers 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 autocomplete. So I am looking for a mechanism to trigger the getfeatureinfo event by something other than "click". Is this possible? And if so, how?