Select to view content in your preferred language

How do i remove an event listener from Identify Task

2300
4
Jump to solution
09-14-2020 11:54 PM
SteffiAntony
Emerging Contributor

Seems like this should be simple, but I'm stumped. i need the functionality to be done in such a a way that on button click the identify task should be run properly on every click function on map . and on the same time when i press the same button again it should stop the API calls, and the event should be removed and vice-versa. how do it can be possible?

var identifyButton = dom.byId("identify")
on(identifyButton"click"function (evt) {
    map.on("click"executeIdentifyTask);

    //create identify tasks and setup parameters
    identifyTask = new IdentifyTask(textbox.value);

    identifyParams = new IdentifyParameters();
    identifyParams.tolerance = 3;
    identifyParams.returnGeometry = true;
    identifyParams.layerIds = [02];
    identifyParams.layerOption = IdentifyParameters.LAYER_OPTION_ALL;
    identifyParams.width = map.width;
    identifyParams.height = map.height;
  })
  function executeIdentifyTask(event) {
    identifyParams.geometry = event.mapPoint;
    identifyParams.mapExtent = map.extent;

    var deferred = identifyTask
      .execute(identifyParams)
      .addCallback(function (response) {
        // response is an array of identify result objects
        // Let's return an array of features.
        return arrayUtils.map(responsefunction (result) {
          var feature = result.feature;
          var layerName = result.layerName;

          feature.attributes.layerName = layerName;
              var Templates = new InfoTemplate("");
              feature.setInfoTemplate(Templates);

              return feature;
        });
      });

    // InfoWindow expects an array of features from each deferred
    // object that you pass. If the response from the task execution
    // above is not an array of features, then you need to add a callback
    // like the one above to post-process the response and return an
    // array of features.
    map.infoWindow.setFeatures([deferred]);
    map.infoWindow.show(event.mapPoint);
  }
Tags (1)
0 Kudos
1 Solution

Accepted Solutions
ManishPatel
Esri Contributor

Hi Steffi Antony,

You can use the connect and disconnect to disable the events. And if I understand your requirement correctly, I have put together a sample for you. Have a look at it at Identify with Popup 

The source code you can find at https://codepen.io/mrpatel/pen/OJNwMeE 

Hope this helps.

Cheers!

Manish

Cheers,
Manish

View solution in original post

0 Kudos
4 Replies
ManishPatel
Esri Contributor

Hi Steffi Antony,

You can use the connect and disconnect to disable the events. And if I understand your requirement correctly, I have put together a sample for you. Have a look at it at Identify with Popup 

The source code you can find at https://codepen.io/mrpatel/pen/OJNwMeE 

Hope this helps.

Cheers!

Manish

Cheers,
Manish
0 Kudos
SteffiAntony
Emerging Contributor

Thank you. Manish Patel‌ meanwhile i added 2 line of code.

    identifyClickHandler = on(map'click'executeIdentifyTask);

  identifyClickHandler.remove();

is this ok??

  var identifyButton = dom.byId("identify")
  on(identifyButton"click"function (evt) {
    identifyClickHandler = on(map'click'executeIdentifyTask);
    identifyTask = new IdentifyTask(textbox.value);

    identifyParams = new IdentifyParameters();
    identifyParams.tolerance = 3;
    identifyParams.returnGeometry = true;
    identifyParams.layerIds = [02];
    identifyParams.layerOption = IdentifyParameters.LAYER_OPTION_ALL;
    identifyParams.width = map.width;
    identifyParams.height = map.height;
  })
  function executeIdentifyTask(event) {
    identifyParams.geometry = event.mapPoint;
    identifyParams.mapExtent = map.extent;

    var deferred = identifyTask
      .execute(identifyParams)
      .addCallback(function (response) {
        return arrayUtils.map(responsefunction (result) {
          var feature = result.feature;
          var layerName = result.layerName;

          feature.attributes.layerName = layerName;
          // console.log(feature.attributes);
          var Templates = new InfoTemplate("");
          feature.setInfoTemplate(Templates);

          return feature;
        });
      });
    map.infoWindow.setFeatures([deferred]);
    map.infoWindow.show(event.mapPoint);
    identifyClickHandler.remove();
  }
0 Kudos
ManishPatel
Esri Contributor

Yes that will work too.

Cheers,
Manish
ManishPatel
Esri Contributor

Steffi Antony‌ please dont forget to mark the question as answered if the code provided helped to answer your question. This will help others to check when they need to find any answer.

Cheers,

Manish

Cheers,
Manish
0 Kudos