1

I would like to be able to grab attribute data from a popupwindow when its associated feature is clicked. When there is only one feature in the window this is no problem by accessing the features by:

map.infowindow.features[0].attributes["desired attribute"].

If the info window contains more than one point, however, this cannot tell be which one is visible in the popup. My goal is to be able to detect when the window is scrolled through, identify what feature is shown, loop through the features attributes for the desired data, and then pass that data to another function.

I desire to do that so a graph can be synced with whatever is in the info window, but I do not want the graph in the info window itself.

Ive noticed that the infowindow object has a selectNext and Select Previous that I dont know if its useful or not.

EDIT**

        map.infoWindow.on("selection-change", function () {
            // get the selected feature/graphic in the popup window.
            var feature = map.infoWindow.getSelectedFeature();
            var featureMeter = feature.attributes["Meter"];
            if (feature) {
                console.log(featureMeter);
                // do stuff with the feature.
            }
        });

        meterLayer.on("click", function (evt) {
            map.infoWindow.setFeatures([evt.graphic]);

        });

The initial click on the map returns three values the last of which is the correct value. The "next" icon will only return one and the correct value.

1

After the "selection-change" event, you can call the infoWindow's getSelectedFeature() method to get the feature currently shown in the infoWindow. You might need to test if the feature exists before you do anything with it, because the selection change event fires when the previously selected feature is removed from the selection. Here is a code sample that can get you started.

map.infoWindow.on("selection-change", function () {
  // get the selected feature/graphic in the popup window.
  var feature = map.infoWindow.getSelectedFeature();

  if (feature) {
    console.log(feature.attributes["desired attribute"]);
    // do stuff with the feature.
  }
});
  • This appears to register the event three times. It displays the 2nd feature in the info window twice and then the first feature on the initial click. Then clicking the next and prev returns only one and the correct feature. Any thoughts as to how to handle the initial click? – LCaraway Jul 6 '16 at 15:58
  • Do you have an example that shows what you're seeing? Your response reads like there are things happening behind the scenes in your code. – raykendo Jul 6 '16 at 21:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.