call popup behavior from a button

649
3
08-16-2017 03:46 AM
AhmetKaraburun1
New Contributor

Is it possible to start view popup behavior from a specific button in arcgis js api 4? I mean is it possible to stop default click-for-popup behavior at the beginning and to start it by clicking on a specific button if needed?

0 Kudos
3 Replies
KenBuja
MVP Esteemed Contributor

If you look at the IdentifyTask sample, the popup isn't shown until the task has been completed.

identifyTask.execute(params).then(function(response) {

// code

}).then(showPopup); // Send the array of features to showPopup()

// Shows the results of the Identify in a popup once the promise is resolved
function showPopup(response) {
  if (response.length > 0) {
    view.popup.open({
      features: response,
      location: event.mapPoint
    });
  }
  dom.byId("viewDiv").style.cursor = "auto";
}

The showPopup function could instead be called from a button click, although you would have to keep track of the response and event.mapPoint.

ThomasSolow
Occasional Contributor III

In order to disable popups, you could disabled them on each layer individually.  But probably the easiest way to do is to add your own click event like:

// this will stop click events from propagating further
let eventCatcher = view.on('click', e => e.stopPropagation());

// this will resume click events
eventCatcher.remove();
AhmetKaraburun1
New Contributor

Thanks Thomas Solow, this is the solution I'm looking for.

0 Kudos