Select to view content in your preferred language

Toggle between two layers in c# server application

1637
7
02-08-2011 12:20 AM
ManojrajTeli
Deactivated User
I have difficulty regarding the toggling between two layers as i have many layers in my application and i want to toggel betweeen basemap and imagery in my project using two radio button.Please as soon as possible And thank You in advance,
0 Kudos
7 Replies
HemingZhu
Frequent Contributor
I have difficulty regarding the toggling between two layers as i have many layers in my application and i want to toggel betweeen basemap and imagery in my project using two radio button.Please as soon as possible And thank You in advance,



ESRI has example for this: http://help.arcgis.com/en/webapi/javascript/arcgis/demos/map/map_explicitlayerlist.html

Note: This works for dynamic map services or (feature layer) not the tiled map services.
0 Kudos
derekswingley1
Deactivated User
It's a pretty simple task to take the Toggle multiple ArcGIS Online services sample and convert it to use a radio buttons instead of normal buttons.
0 Kudos
ManojrajTeli
Deactivated User
I really new at this and tried this link:http://help.arcgis.com/en/webapi/jav...layerlist.html and i m totally confused about giving local layer address at this point:layer = new esri.layers.ArcGISDynamicMapServiceLayer("http://gis1/Demo/default.aspx, { "imageParameters": imageParameters });.Please help me out at this point or is there any way round to refer to imagery layer and basemap layer.Is there any way to do this using c# code.Thank you for the your replies.
0 Kudos
ManojrajTeli
Deactivated User
I have Annotation,Assets,Basemap,Satellite Imagery layer now this is the problem:-At one time i have to show Basemap or Satellite Imagery using the radio button
0 Kudos
ManojrajTeli
Deactivated User
I have hosted my local service and i want to switch only those layers and not the arcgisserver layers.how to do that...???
0 Kudos
ManojrajTeli
Deactivated User
I was able to uncheck layers in TOC by doing this
Toc1.Nodes[0].Nodes[0].Checked = false;
Toc1.Nodes[0].Nodes[0].Nodes[0].Checked = false;
Toc1.Nodes[0].Nodes[1].Checked = false;
Toc1.Nodes[0].Nodes[2].Checked = false;
Toc1.Nodes[0].Nodes[3].Checked = false;
Toc1.Nodes[0].Nodes[4].Checked = false;
but the map was not getting refreshed..All the layers were on map.Please help me with this....thank you in advance.
0 Kudos
MarioObendorfer
Emerging Contributor
Hi,

try to link your checkboxes or whatever you use with an event handler ... e.g. 'checkchange'. If you have a dynamic TOC you should give each TOC entry an id, in this case best id is the service id. Save alle services/layers in an array. If checkchange fires you can do something like this:

//Listener on an ExtJS Component
listeners: {
        'checkchange': function(node, checked){
            if(checked){
                node.getUI().addClass('complete');
  var size = node.parentNode.childNodes.length;
  for(var i=0;i<size;i++) {
   if(node.parentNode.childNodes.id != node.id) {
    node.parentNode.childNodes.ui.checkbox.checked = false;
    Ext.getCmp('mappanel).setLayerVisibility(node.parentNode.childNodes.id, false);
   }else {
    Ext.getCmp('mappanel).setLayerVisibility(node.id, true);
   }
  }
           }else{
                node.getUI().removeClass('complete');
           }
       }
}

//function definition in ExtJS
setLayerVisibility: function(id, visible) {
    var size = this.oLayer.length; //in this array all layers/services are saved
   for(var i=0;i<size;i++) {
 if(this.oLayer.id == id) {
  if(visible)
   this.oLayer.show();
  else
   this.oLayer.hide();
 }
   }
}


With this example you activate only one layer/service at a time ... i just c&p parts from an ExtJS  sample of mine and didn't alter it to a common example ... you might have to change some parts.

Summary ... give TOC an evhandler and show/hide layers linked via id to the TOC.

Hope that helps a little bit ... greets Tol
0 Kudos