Using AGSJS TOC with ArcGIS Javascript 3.0

6499
13
Jump to solution
06-21-2012 10:39 AM
MeleKoneya
Occasional Contributor III
I have been using the Table of Contents widget from

https://code.google.com/p/gmaps-utility-gis/  with ArcGIS Javasript API 2.8 but wanted to update my API to 3.0 and have not had luck doing so.

I am not clear on how to migrate to 3.0 even after reading the documention.    I did update my dojoconfig to use the "packages" property.

dojoConfig = {
        parseOnLoad: true,
        packages: [{
          name: "agsjs",
          location: "http://gmaps-utility-gis.googlecode.com/svn/tags/agsjs/1.07/build/agsjs"
         
        
          }]

However, when using dojo.require("agsjs.dijit.TOC");  the table of contents does not load and the rest of my page does not load either.

Has anyone been able to use this Table of Contents widget with 3.0?    If so,  can you provide instructions on how you got it to work?

Thanks,

Mele
0 Kudos
1 Solution

Accepted Solutions
NianweiLiu
Occasional Contributor II
The key is add
dojo.require("dojo.fx") 
which is a module used inside the widget. Since dojo 1.7 many modules have to be explicitly loaded.
Also, you need to download the code to your server since 3.0. There are some issues with xdomain used in junction with dojo.require.

You can get the updated code and sample here:

http://www.arcgis.com/home/item.html?id=9b6280a6bfb0430f8d1ebc969276b109

View solution in original post

0 Kudos
13 Replies
JosephDaood
New Contributor
hej
I have the same problem here. :confused:
0 Kudos
NianweiLiu
Occasional Contributor II
The key is add
dojo.require("dojo.fx") 
which is a module used inside the widget. Since dojo 1.7 many modules have to be explicitly loaded.
Also, you need to download the code to your server since 3.0. There are some issues with xdomain used in junction with dojo.require.

You can get the updated code and sample here:

http://www.arcgis.com/home/item.html?id=9b6280a6bfb0430f8d1ebc969276b109
0 Kudos
MeleKoneya
Occasional Contributor III
Thanks for answering this forum post and providing instructions on how to use your dijit in the 3.0 api.   I have downloaded the latest JS from the link you provided and followed your instructions and things are working in 3.0

Mele
0 Kudos
AdrianMarsden
Occasional Contributor III
Hi

Seeing this thread made me have another go at this TOC - last time I was still learning about the JSAPI

I have a code base that I use for many pages that all share the same main dynamic map service - the main page calls the script and passes an array of default visible layers, this is then test for in my code and actioned -

function defaultvis(layer) {
    visible = [];
    var items = dojo.map(layer.layerInfos, function (info, index) {


        if (contains(defaultlayers, info.name)) {
            visible.push(info.id);
            console.debug(info.name + "ative")
        } else {

            console.debug(info.name)
        }


    });
  
    dynamicMapServiceLayer.setVisibleLayers(visible);
}


This works fine, but of course the TOC code doesn't pick up on the changed visibility and shows all layers unticked (the default state)  Any ideas how I should call a refresh or something of the TOC to get the boxes ticked?

Many thanks to the writer for a really nice TOC - it functions just as stated.

Cheers

ACM
0 Kudos
AdrianMarsden
Occasional Contributor III
In case anyone else ins interested I worked it out - I have an array that contains the names of my default sub-layers, called defaultlayers, it is a global variable  I then altered this part of the TOC.js


    _createRootLayerTOC: function () {
        var b = this.rootLayer;
        if (!b._tocInfos) {
            var c = {};
            dojo.forEach(b.layerInfos, function (d) {
                c["" + d.id] = d;
          console.debug(d)
    if (contains(defaultlayers,d.name)) {
      d.visible = true;
     }
    else {
     d.visible = false;
     }

.....


Cheers

ACM
0 Kudos
NianweiLiu
Occasional Contributor II
Hi

This works fine, but of course the TOC code doesn't pick up on the changed visibility and shows all layers unticked (the default state)  Any ideas how I should call a refresh or something of the TOC to get the boxes ticked?


The latest version (2.02) at http://www.arcgis.com/home/item.html?id=9b6280a6bfb0430f8d1ebc969276b109 will use the actual visibility of each layer if they are different than the settings in map service. You can also use the cross domain build without downloading it.
0 Kudos
MeleKoneya
Occasional Contributor III
I have noticed that I have to reload my page in order to get the TOC to display.    I can see that the agsjs.dijit.TOC is created on the initial load of the page, but the results do not show up in my 'tocDiv'.     I have also experienced this behavior on the internet example site http://gmaps-utility-gis.googlecode.com/svn/tags/agsjs/2.02/examples/toc.html    on the initial load the TOC does not show, but if I refresh in IE8, it does.    Just wondering if there is a work around to address this behavior.   Thanks,  Mele
0 Kudos
KhmelevskiyAndrey
New Contributor
I have noticed that I have to reload my page in order to get the TOC to display.    I can see that the agsjs.dijit.TOC is created on the initial load of the page, but the results do not show up in my 'tocDiv'.     I have also experienced this behavior on the internet example site http://gmaps-utility-gis.googlecode.com/svn/tags/agsjs/2.02/examples/toc.html    on the initial load the TOC does not show, but if I refresh in IE8, it does.    Just wondering if there is a work around to address this behavior.   Thanks,  Mele

I have exactly the same problem: when  you run my app in IE9 the fist time it works however after it rerun again TOC it is not displayed any more - same happen with http://gmaps-utility-gis.googlecode.com/svn-history/r354/trunk/agsjs/examples/toc.html. I have tried to destroy dom and widjet itself - but it did not help. Is there any solution for it?
0 Kudos
JosephDaood
New Contributor
I have exactly the same problem: when  you run my app in IE9 the fist time it works however after it rerun again TOC it is not displayed any more - same happen with http://gmaps-utility-gis.googlecode.com/svn-history/r354/trunk/agsjs/examples/toc.html. I have tried to destroy dom and widjet itself - but it did not help. Is there any solution for it?


me too, I posted a new forum about that http://forums.arcgis.com/threads/63619-how-can-I-save-map-and-layers-settings-in-a-cookie?p=220155#p...

It looks like a bug in toc. Is there any work around to this problem ?
0 Kudos