AnsweredAssumed Answered

Disable Click Event

Question asked by bamcburney on May 2, 2016
Latest reply on May 3, 2016 by PrillLake

I'm writing a custom widget to select one or more parcels.  Using the code from Custom Widget for Selecting a Parcel, I am able to disable the popup and add a graphic for the selected parcel(s):

 

  startup: function() {
  //  this.inherited(arguments);
  //  this.mapIdNode.innerHTML = 'map id:' + this.map.id;
    console.log('startup');
    var map = this.map; 
    var parcelLayerId, parcelLayer, parcelList; 

 

    var highlightSymbol = new SimpleFillSymbol( 
      SimpleFillSymbol.STYLE_SOLID, 
      new SimpleLineSymbol( 
        SimpleLineSymbol.STYLE_SOLID, 
             new Color([255,0,0]), 3 
      ), 
      new Color([125,125,125,0.35]) 
    ); 

 

    LayerInfos.getInstance(map, map.itemInfo).then(lang.hitch(function(layerInfosObject) { 
      layerInfosObject.getLayerInfoArray().forEach(function(layerInfo) { 
        console.log(layerInfo.title);
        if (layerInfo.title == 'Search - Parcels') { 
             parcelLayerId = layerInfo.id; 
             parcelLayerInfo = layerInfosObject.getLayerInfoById(layerInfo.id) 
             parcelLayerInfo.disablePopup();
             console.log('parcel layer ID = ', parcelLayerId) 
       
      }); 
    })); 

 

    parcelLayer = map.getLayer(parcelLayerId); 
    parcelList = []; 

 

    this.own(on(parcelLayer, 'click', function(e) { 
      var parcelString = esriLang.substitute(e.graphic.attributes, "${PARCEL_NUMBER}"); 
      var highlightGraphic = new Graphic(e.graphic.geometry, highlightSymbol); 
      map.graphics.add(highlightGraphic); 
      parcelList.push(parcelString); 
      console.log('Selection = ' + parcelList); 
    }));
 

},

 

When the widget is closed, I am able to clear the graphics and re-enable the popup:

 

   onClose: function(){
     console.log('onClose');
     this.map.graphics.clear();
     parcelLayerInfo.enablePopup();
   },

 

The problem is the on click event is not removed and the graphic is still added.  Shouldn't this.own remove the click event automatically when the widget is closed?

Outcomes