Adding Context Menu for each layer to nliu's TOC widget

3912
3
01-14-2014 03:18 PM
EokNgo
by
New Contributor III
I'm attempting to add a context menu to the TOC widget provided by nliu here: http://gmaps-utility-gis.googlecode.com/svn/tags/agsjs/2.09/src/agsjs/dijit/TOC.js

I can get the context menu to appear however, it cannot see the data associated with the node.

// (Within the PostCreate function)
var pMenu;
pMenu = new Menu({});
pMenu.addChild(new MenuItem({
    label: "Turn On",
    onClick: this._manualTurnOn
}));
pMenu.startup();
pMenu.bindDomNode(this.rowNode);

// (Reference - Code above was added before this section shown below)
if (this.containerNode) {
    domStyle.set(this.containerNode, 'display', showChildren ? 'block' : 'none');
}


I add a _manualTurnOn function and was hoping to interact with the serviceLayer using this context menu (as well as some other functions later). However, when the function is triggered, there doesn't appear to be any context of the TOCNode object that was used to create the node this Menu is associates. It's clear I'm misunderstanding how this widget is structured (possibly even how widgets actually work).

Any clue how I might retrieve/interact with the underlying data associated with the node?
0 Kudos
3 Replies
AdrianMarsden
Occasional Contributor III
🙂 marked as helpful as you've got further than I did late last year - I had the same idea, but failed totally to get as far as you did.

What's your idea for options?  Mine is things like labels on/of

This would make a very good TOC, great.
0 Kudos
EokNgo
by
New Contributor III
Yeah, that was the idea. I have a duplicate of each layer and planned on using the context menu to turn it on/off to simulate the function in ArcMap.
0 Kudos
JoshBoulware2
New Contributor

Not sure if you were able to find a solution on your own, but I was able to modify nliu's TOC.JS (built on 2015-01-15 13:51:27.12) to create a context menu for each node and embed a parameter for each, that was passed to a function with onClick. In my case, I was using Feature Layers and using the context menu to open the corresponding FeatureTable by right-clicking the TOC node. The context menu was created for each TOC node and the Feature Layer url was added as a function parameter.

I couldn't find a way to create a single menu and bind it to each node, and still assign the appropriate url parameter, so I decided just to create a menu for each node. Not ideal, but it seems to work fine. No ill effects so far.

For Feature Layers, my context menu code was inserted after nliu's code - "this.rootLayer.on("load", j.hitch(this, this._createRootLayerTOC))"

My Code:

//console.debug(this.rootLayer);

//create variable to hold feature layer url

var layertopass = this.rootLayer.url;

//create context menu and child elements

var pMenu2 = new dijit.Menu({

targetNodeIds: [this.domNode]

});

pMenu2.addChild(new dijit.MenuItem({

label:"Attributes",

onClick: function(){

showFT(layertopass);

}

}));

pMenu2.startup();

The Feature Layer url string is passed to the showFT function, which uses it to create a new esri FeatureLayer, that is then used to create the corresponding new esri FeatureTable.

I'm not sure exactly how to handle dynamic layers for purposes of labeling, but I suspect you'll probably need to insert similar context menu in the "_createServiceLayerNode" section of nliu's code. Maybe try to grab the layer id and pass that to a labeling function. Just a guess, though.

Anyway... this worked for me. Hope it helps.

0 Kudos