Selecting a single layer

2787
12
Jump to solution
02-09-2016 12:46 AM
SaurabhRohilla
New Contributor II

Hi

Actually i am making a layer list . I am able to get all layers at one time.I am accessing map service layers.Anyone knows how to get only one  layer at a time?

0 Kudos
1 Solution

Accepted Solutions
nita14
by
Occasional Contributor III

Hi Saurabh,

there is no way to set visibility to each layer in ArcGISTiledMapServiceLayer since it is just a static 'snapshot' of your data (just like image). You can only set transparency or visibility to the whole service. See TiledMapServiceLayer | API Reference | ArcGIS API for JavaScript  for reference.

Regards,

Adam

View solution in original post

12 Replies
RobertScheitlin__GISP
MVP Emeritus

Saurabh,

   Not sure I understand your question. If you are asking how to set the visibility of a particular layer in a ynamic map service layer then you would use setVisibleLayers method:

ArcGISDynamicMapServiceLayer | API Reference | ArcGIS API for JavaScript | setVisibleLayers

0 Kudos
SaurabhRohilla
New Contributor II

Robert

Thanks for reply.Actually i am new to GIS ,so can you share sample code for that?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Saurabh,

  Sure here is a sample:

<!DOCTYPE html>
<html>
  <head>
<meta name="description" content="Testing sublayer visibility">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
    <title>Create Map and add a dynamic layer</title>
    <link rel="stylesheet" href="https://js.arcgis.com/3.15/esri/css/esri.css"/>
    <style>
      html, body, #mapDiv{
        padding: 0;
        margin: 0;
        height: 100%;
      }
    </style>
    <script src="https://js.arcgis.com/3.15/"></script>
    <script>
      var map;

      require([
        "esri/map",
        "esri/layers/ArcGISDynamicMapServiceLayer"
      ], function (
        Map, ArcGISDynamicMapServiceLayer) {

        map = new Map("mapDiv", {
          basemap: "topo",
          zoom: 10,
          center: [-98.258, 38.236]
        });


        var dynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer");
        map.addLayer(dynamicMapServiceLayer);

        dynamicMapServiceLayer.setVisibleLayers([0,1,3,5]);
      });
    </script>
  </head>
  <body>
    <div id="mapDiv"></div>
  </body>
</html>
SaurabhRohilla
New Contributor II

Robert,

Thanks.Its working absolutely fine.But when i used this for my webmapservice its not working.

I am adding layers  with  ArcGISTiledMapServiceLayer .

Reference :

var TiledMapServiceLayer = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer");

But if i replace  ArcGISDynamicMapServiceLayer with ArcGISTiledMapServiceLayer in the code , the layers are not switchable. So it means that setVisibleLayers method only works with ArcGISDynamicMapServiceLayer.??

0 Kudos
nita14
by
Occasional Contributor III

Hi Saurabh,

there is no way to set visibility to each layer in ArcGISTiledMapServiceLayer since it is just a static 'snapshot' of your data (just like image). You can only set transparency or visibility to the whole service. See TiledMapServiceLayer | API Reference | ArcGIS API for JavaScript  for reference.

Regards,

Adam

SaurabhRohilla
New Contributor II

Hi Nicinski,

Thanks for your response.It helps me a lot.

0 Kudos
SaurabhRohilla
New Contributor II

Hi Nicinski,

One more thing .Actually i am facing problem in writing the classes for require.

Refer code:

require([

  "esri/map",

  "esri/dijit/Scalebar",

  "esri/layers/ArcGISDynamicMapServiceLayer",

  "esri/toolbars/navigation",

    "dojo/on",

  "dojo/parser",

  "esri/dijit/OverviewMap",

   "dijit/registry",

  "esri/tasks/QueryTask",

  "esri/tasks/query",

  "esri/symbols/SimpleMarkerSymbol",

  "esri/InfoTemplate",

  "dojo/_base/Color",

  "dijit/Toolbar",

    "dijit/form/Button",

"dijit/layout/BorderContainer",

  "dijit/layout/ContentPane",

  "dojo/Ready"

], function(Map, Scalebar,ArcGISDynamicMapServiceLayer,Navigation, on, parser,OverviewMap, registry, QueryTask, Query, SimpleMarkerSymbol, InfoTemplate, Color)

Can you please tell me the hierarachy of classes, which to write first and which one to last?

0 Kudos
SaurabhRohilla
New Contributor II

Hi Robert,

One more thing .Actually i am facing problem in writing the classes for require.

Refer code:

require([

  "esri/map",

  "esri/dijit/Scalebar",

  "esri/layers/ArcGISDynamicMapServiceLayer",

  "esri/toolbars/navigation",

    "dojo/on",

  "dojo/parser",

  "esri/dijit/OverviewMap",

   "dijit/registry",

  "esri/tasks/QueryTask",

  "esri/tasks/query",

  "esri/symbols/SimpleMarkerSymbol",

  "esri/InfoTemplate",

  "dojo/_base/Color",

  "dijit/Toolbar",

    "dijit/form/Button",

"dijit/layout/BorderContainer",

  "dijit/layout/ContentPane",

  "dojo/Ready"

], function(Map, Scalebar,ArcGISDynamicMapServiceLayer,Navigation, on, parser,OverviewMap, registry, QueryTask, Query, SimpleMarkerSymbol, InfoTemplate, Color)

Can you please tell me the hierarachy of classes, which to write first and which one to last?

0 Kudos
thejuskambi
Occasional Contributor III

Hello Saurabh,

I dont think it matter what order you add a require as long as the require and parameters are in same order. If a module has a dependency on another module, it will get it with its own require.

Thejus

0 Kudos