<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Adding Context Menu for each layer to nliu's TOC widget in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/adding-context-menu-for-each-layer-to-nliu-s-toc/m-p/333544#M30785</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For Feature Layers, my context menu code was inserted after nliu's code - "this.rootLayer.on("load", j.hitch(this, this._createRootLayerTOC))"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My Code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//console.debug(this.rootLayer);&lt;/P&gt;&lt;P&gt;//create variable to hold feature layer url&lt;/P&gt;&lt;P&gt;var layertopass = this.rootLayer.url;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//create context menu and child elements&lt;/P&gt;&lt;P&gt;var pMenu2 = new dijit.Menu({&lt;/P&gt;&lt;P&gt;targetNodeIds: [this.domNode]&lt;/P&gt;&lt;P&gt;});&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;pMenu2.addChild(new dijit.MenuItem({&lt;/P&gt;&lt;P&gt;label:"Attributes",&lt;/P&gt;&lt;P&gt;onClick: function(){&lt;/P&gt;&lt;P&gt;showFT(layertopass);&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;pMenu2.startup();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyway... this worked for me. Hope it helps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 25 Feb 2015 17:08:26 GMT</pubDate>
    <dc:creator>JoshBoulware2</dc:creator>
    <dc:date>2015-02-25T17:08:26Z</dc:date>
    <item>
      <title>Adding Context Menu for each layer to nliu's TOC widget</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/adding-context-menu-for-each-layer-to-nliu-s-toc/m-p/333541#M30782</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm attempting to add a context menu to the TOC widget provided by nliu here: &lt;/SPAN&gt;&lt;A href="http://gmaps-utility-gis.googlecode.com/svn/tags/agsjs/2.09/src/agsjs/dijit/TOC.js" rel="nofollow noopener noreferrer" target="_blank"&gt;http://gmaps-utility-gis.googlecode.com/svn/tags/agsjs/2.09/src/agsjs/dijit/TOC.js&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I can get the context menu to appear however, it cannot see the data associated with the node.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
// (Within the PostCreate function)
var pMenu;
pMenu = new Menu({});
pMenu.addChild(new MenuItem({
&amp;nbsp;&amp;nbsp;&amp;nbsp; label: "Turn On",
&amp;nbsp;&amp;nbsp;&amp;nbsp; onClick: this._manualTurnOn
}));
pMenu.startup();
pMenu.bindDomNode(this.rowNode);

// (Reference - Code above was added before this section shown below)
if (this.containerNode) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; domStyle.set(this.containerNode, 'display', showChildren ? 'block' : 'none');
}
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any clue how I might retrieve/interact with the underlying data associated with the node?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:47:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/adding-context-menu-for-each-layer-to-nliu-s-toc/m-p/333541#M30782</guid>
      <dc:creator>EokNgo</dc:creator>
      <dc:date>2021-12-11T15:47:25Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Context Menu for each layer to nliu's TOC widget</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/adding-context-menu-for-each-layer-to-nliu-s-toc/m-p/333542#M30783</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; 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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What's your idea for options?&amp;nbsp; Mine is things like labels on/of&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This would make a very good TOC, great.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jan 2014 08:31:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/adding-context-menu-for-each-layer-to-nliu-s-toc/m-p/333542#M30783</guid>
      <dc:creator>AdrianMarsden</dc:creator>
      <dc:date>2014-01-15T08:31:11Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Context Menu for each layer to nliu's TOC widget</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/adding-context-menu-for-each-layer-to-nliu-s-toc/m-p/333543#M30784</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jan 2014 15:27:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/adding-context-menu-for-each-layer-to-nliu-s-toc/m-p/333543#M30784</guid>
      <dc:creator>EokNgo</dc:creator>
      <dc:date>2014-01-15T15:27:54Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Context Menu for each layer to nliu's TOC widget</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/adding-context-menu-for-each-layer-to-nliu-s-toc/m-p/333544#M30785</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For Feature Layers, my context menu code was inserted after nliu's code - "this.rootLayer.on("load", j.hitch(this, this._createRootLayerTOC))"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My Code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//console.debug(this.rootLayer);&lt;/P&gt;&lt;P&gt;//create variable to hold feature layer url&lt;/P&gt;&lt;P&gt;var layertopass = this.rootLayer.url;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//create context menu and child elements&lt;/P&gt;&lt;P&gt;var pMenu2 = new dijit.Menu({&lt;/P&gt;&lt;P&gt;targetNodeIds: [this.domNode]&lt;/P&gt;&lt;P&gt;});&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;pMenu2.addChild(new dijit.MenuItem({&lt;/P&gt;&lt;P&gt;label:"Attributes",&lt;/P&gt;&lt;P&gt;onClick: function(){&lt;/P&gt;&lt;P&gt;showFT(layertopass);&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;pMenu2.startup();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyway... this worked for me. Hope it helps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Feb 2015 17:08:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/adding-context-menu-for-each-layer-to-nliu-s-toc/m-p/333544#M30785</guid>
      <dc:creator>JoshBoulware2</dc:creator>
      <dc:date>2015-02-25T17:08:26Z</dc:date>
    </item>
  </channel>
</rss>

