Trying to set layer visibility with dojo buttons, not working...

679
2
05-22-2014 06:29 PM
CharlesGant
New Contributor III
Hey guys,

Well I keep chugging along.  Next issue I have ran into is using dojo buttons.  I'm trying to activate layers when a particular button is fixed.  Was just gonna use the ole radio buttons but I found this http://maps.rosreestr.ru/arcgis_js_api/sdk/help/jssamples/map_agol.html online which uses the dojo buttons.

However, I can get the button to activate onClick.  I placed a console.log() command inside of the function to make sure that the two were taking to each other, and they aren't.  I have tried various combinations and I cant seem to figure out why this wont work.  Code is below.  Any thoughts from anyone?

JS
    function changeMap(layers) {
    console.log("Layers: " + layers);
    hideImageTiledLayers(layers);
    for (var i=0; i<layers.length; i++) {
      layers.show();
    }
     }

     function hideImageTiledLayers(layers) {
    for (var j=0, jl=map.layerIds.length; j<jl; j++) {
      var layer = map.getLayer(map.layerIds);
      if (dojo.indexOf(layers, layer) == -1) {
     layer.hide();
      }
    }
     } 


HTML
       <div id="FFGButton">
       <h3>Observation</br> Interval</h3>
       <button dojoType="dijit/form/Button" onclick="changeMap([csv30min]);"> 30 Min</button>
       <button dojoType="dijit/form/Button" onClick="changeMap([csv60min]);"> 1 Hour</button>
       <button dojoType="dijit/form/Button" onClick="changeMap([csv120min]);"> 2 Hour</button>
       <button dojoType="dijit/form/Button" onClick="changeMap([csv180min]);"> 3 Hour</button>
       <button dojoType="dijit/form/Button" onClick="changeMap([csv360min]);"> 6 Hour</button>
       </div>
0 Kudos
2 Replies
ManishkumarPatel
Occasional Contributor II
Hey guys,

Well I keep chugging along.  Next issue I have ran into is using dojo buttons.  I'm trying to activate layers when a particular button is fixed.  Was just gonna use the ole radio buttons but I found this http://maps.rosreestr.ru/arcgis_js_api/sdk/help/jssamples/map_agol.html online which uses the dojo buttons.

However, I can get the button to activate onClick.  I placed a console.log() command inside of the function to make sure that the two were taking to each other, and they aren't.  I have tried various combinations and I cant seem to figure out why this wont work.  Code is below.  Any thoughts from anyone?

JS
                function changeMap(layers) {
                console.log("Layers: " + layers);
                hideImageTiledLayers(layers);
                for (var i=0; i<layers.length; i++) {
                  layers.show();
                }
              }

              function hideImageTiledLayers(layers) {
                for (var j=0, jl=map.layerIds.length; j<jl; j++) {
                  var layer = map.getLayer(map.layerIds);
                  if (dojo.indexOf(layers, layer) == -1) {
                    layer.hide();
                  }
                }
              }    


HTML
                            <div id="FFGButton">
                            <h3>Observation</br> Interval</h3>
                            <button dojoType="dijit/form/Button" onclick="changeMap([csv30min]);"> 30 Min</button>
                            <button dojoType="dijit/form/Button" onClick="changeMap([csv60min]);"> 1 Hour</button>
                            <button dojoType="dijit/form/Button" onClick="changeMap([csv120min]);"> 2 Hour</button>
                            <button dojoType="dijit/form/Button" onClick="changeMap([csv180min]);"> 3 Hour</button>
                            <button dojoType="dijit/form/Button" onClick="changeMap([csv360min]);"> 6 Hour</button>
                            </div>



Hi Charles,

The code snippet seems to be ok. Although unless you can put up your complete code in a jsfiddle it would be just a guessing game.

My guess would be that check the values that you are passing as the parameter in changeMap([csv30min]).

Check if the csv30min,csv60min,csv120min,csv180min,csv360min are global and set as

esri.layers.ArcGISTiledMapServiceLayer or esri.layers.ArcGISDynamicMapServiceLayer

hope this helps.

Regards,
Manish
0 Kudos
CharlesGant
New Contributor III
Hi Charles,

The code snippet seems to be ok. Although unless you can put up your complete code in a jsfiddle it would be just a guessing game.

My guess would be that check the values that you are passing as the parameter in changeMap([csv30min]).

Check if the csv30min,csv60min,csv120min,csv180min,csv360min are global and set as

esri.layers.ArcGISTiledMapServiceLayer or esri.layers.ArcGISDynamicMapServiceLayer

hope this helps.

Regards,
Manish


Thanks for the reply.  They are actually CSVLayer layers.  Does that restrict what I'm trying to do?  Also, regardless, shouldn't the functions output the console message at least?  Nothing happens when clicking the buttons.
0 Kudos