AnsweredAssumed Answered

widget opened twice at first click

Question asked by Alfonso_CLUS on Dec 24, 2017
Latest reply on Dec 27, 2017 by Alfonso_CLUS

Hi all and Merry Christmas,

 

I created a very simple widget that clears the map's graphics layer. It only opens a jimu/dijits/Message which ask if you want to clear the features and two buttons, OK and CANCEL. The message dijit is created in the onOpen method and it is closed either when you click OK or CANCEL.

The weird thing is that when you start the app and click the widget button the first time, it opens two messages popups. This is because the onOpen method is called twice. The sequence is as follows:

postCreate - startup - onOpen - onClose - onOpen

 

However that double onOpen is not repeated for the next times you click the widget's button. I'd like to avoid that repetition.

 

In this widget, the only method developed is onOpen

 

    onOpen: function(){
      console.log('ClearGraphics::onOpen');
      var msg = new Message({
          type: "question",
          titleLabel: "Clear Map",
          message: "Want to remove features?",
          buttons:[{
              label: "YES",
             onClick: lang.hitch(this, lang.hitch(this, function(){
                    if (this.map.graphics.graphics.length > 0){
                        this.map.graphics.clear();
                    }
                    msg.close();
                    WidgetManager.getInstance().closeWidget(this.id);
             }))
          },{
               label: "CANCEL",
               onClick: lang.hitch(this, function(){
                  msg.close();
                  WidgetManager.getInstance().closeWidget(this.id);
            })
          }]
      });
    }

 

 

and the widgets properties in the manifest are:

"properties": {
    "inPanel": false,
    "hasLocale": true,
    "hasStyle": false,
    "hasConfig": true,
    "hasUIFile": false,
    "hasSettingPage": false,
    "hasSettingUIFile": false,
    "hasSettingLocale": false,
    "hasSettingStyle": false,
    "IsController": false
  }

 

Another question. Is it normal that the map's graphics layer starts with one graphic by default?

 

Happy Holidays and Thanks,

Alfonso

Outcomes