context menus limitations?

3024
3
Jump to solution
11-18-2015 11:37 AM
LefterisKoumis
Occasional Contributor III

I noticed that inside the click function of a context menu I don't have access to the map object or call a new function outside the context menu.

Are these limitations for the context menus?

for the script below, I get these errors....

Cannot read property 'addLayer' of undefined

this.myfunction is not a function

---------

ctxMenuForGraphics = new Menu({});

  ctxMenuForGraphics.addChild(new MenuItem(

  {

  label: "something",

  onClick: function ()

  {  

   this.map.addLayer(xxx);

   this.myfunction();

  

  }

  }));

  ctxMenuForGraphics.startup();

--------

},

myfunction: function(){

----

},

-----------

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Lefteris,

  This works fine:

        var ctxMenuForGraphics = new Menu({});
        ctxMenuForGraphics.addChild(new MenuItem({
          label: "info",
          onClick: lang.hitch(this, function (){
            console.info(this.map);
          })
        }));

View solution in original post

0 Kudos
3 Replies
RobertScheitlin__GISP
MVP Emeritus

Lefteris,

  This works fine:

        var ctxMenuForGraphics = new Menu({});
        ctxMenuForGraphics.addChild(new MenuItem({
          label: "info",
          onClick: lang.hitch(this, function (){
            console.info(this.map);
          })
        }));
0 Kudos
LefterisKoumis
Occasional Contributor III

Thank you.

How do I access the labels assigned for the context menu of a graphic?

I tried ctxMenuForGraphics.MenuItem.label[0] but it doesn't work.

I notice that when you assigned a menu to a graphic A and then a bigger graphic B with its own menu covers graphic A, even if you remove the graphic B later, the menu A will be changed to the one that graphic B had. Strange and I am trying to keep the menu for graphics A unchanged.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Lefteris,

  For the first part of the question:

ctxMenuForGraphics.addChild(new MenuItem({
          label: "info",
          onClick: lang.hitch(this, function (evt){
            console.info(evt.target.innerHTML);
          })
        }));

For the second part, I don't have any experience there.

0 Kudos