1

I am trying to see if there is a way to add a link in the InfoWindow that fires a function in JavaScript. I'm working with a map that shows rail lines in the US and the idea is to store selected lines in an array to collect information.

I know that you can override the 'Zoom To' link with dojo.disconnect(map.infoWindow._eventConnections[4]) to replace the zoom action with your own, but I do not want to sacrifice this function. I would use .setContent() and add the link to the function using HTML, but because I'm using .setFeatures(), this would remove information about the feature currently selected.

1

I guess you are using the ArcGIS-JS-API 3.X. You have check the Popup class, and add a new action using the addActions(actions) Method.

For example:

  var customActions;

  map.infoWindow.on("selection-change", function() {
    var selectedFeature = map.infoWindow.getSelectedFeature();

    if (selectedFeature && selectedFeature.attributes.TYPE === "crime") {
      var crimeAction = {
        title: "Crime Report",
        className: "crime-report-action",
        callback: function() {
          console.log("Get Full Crime Report");
        }
      };
      customActions = map.infoWindow.addActions([ crimeAction ]);
    }
    else {
      map.infoWindow.removeActions(customActions);
    }
});
  • Yes, I am using 3.2. I keep on forgetting that there's 4.X because it's 3D only at the moment. This seemed to do the trick! – Pyro Mar 8 at 15:09
  • Check out the new 4.X... it isn't only 3D! – Katah Mar 10 at 18:38

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.