WebMap Sublayer Infos in 3.25

511
6
Jump to solution
08-22-2018 08:06 AM
VenkataSrikanth_Dasari
Occasional Contributor

Hi,

I am just trying all the layers to an array.. here i am getting parent node but unfortunately i couldn't able to sublayer information..

The purpose of finding the sublayer is to set the definition expression.

Any answers would be highly appreciated.

Cheers,

Srikanth Dasari

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Esteemed Contributor

You are not going to get a layer object for a MapService layer like that in the 3.x API. You need to set the LayerDefintions array for that layer.

https://developers.arcgis.com/javascript/3/jsapi/arcgisdynamicmapservicelayer-amd.html#setlayerdefin... 

View solution in original post

0 Kudos
6 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Srikanth,

  See if this sample helps:

<!DOCTYPE html>
<html>

<head>
  <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 web map from id</title>

  <link rel="stylesheet" href="https://js.arcgis.com/3.25/dijit/themes/claro/claro.css">
  <link rel="stylesheet" href="https://js.arcgis.com/3.25/esri/css/esri.css">

  <script src="https://js.arcgis.com/3.25/" data-dojo-config="async:true"></script>
  <script>
    require([
      "dojo/parser",
      "dojo/ready",
      "dijit/layout/BorderContainer",
      "dijit/layout/ContentPane",
      "dojo/dom",
      "esri/map",
      "esri/urlUtils",
      "esri/arcgis/utils",
      "esri/dijit/Legend",
      "esri/dijit/Scalebar",
      "dojo/domReady!"
    ], function (
      parser,
      ready,
      BorderContainer,
      ContentPane,
      dom,
      Map,
      urlUtils,
      arcgisUtils,
      Legend,
      Scalebar
    ) {
      ready(function () {

        parser.parse();

        //if accessing webmap from a portal outside of ArcGIS Online, uncomment and replace path with portal URL
        //arcgisUtils.arcgisUrl = "https://pathto/portal/sharing/content/items";
        arcgisUtils.createMap("4abe6a830b8f466dacf8abfde567a781", "map").then(function (response) {
          //update the app
          dom.byId("title").innerHTML = response.itemInfo.item.title;
          dom.byId("subtitle").innerHTML = response.itemInfo.item.snippet;

          var map = response.map;

          //add the scalebar
          var scalebar = new Scalebar({
            map: map,
            scalebarUnit: "english"
          });
          
          var wmLayers = arcgisUtils.getLayerList(response);
          console.info(wmLayers);
//Now you have an array of the operational layers in the webmap.

          //add the legend. Note that we use the utility method getLegendLayers to get
          //the layers to display in the legend from the createMap response.
          var legendLayers = arcgisUtils.getLegendLayers(response);
          var legendDijit = new Legend({
            map: map,
            layerInfos: legendLayers
          }, "legend");
          legendDijit.startup();
        });

      });

    });

  </script>
  <style>
    html,
    body {
      height: 100%;
      width: 100%;
      margin: 0;
      padding: 0;
    }

    body {
      font-family: "Helvetica";
    }

    #header {
      background-color: #E8E8E8;
      height: 65px;
      margin: 5px 5px;
    }

    #mainWindow {
      width: 100%;
      height: 100%;
    }

    #title {
      padding-top: 2px;
      padding-left: 10px;
      font-size: 18pt;
      font-weight: 700;
    }

    #subtitle {
      font-size: small;
      padding-left: 40px;
    }

    #rightPane {
      background-color: #E8E8E8;
      margin: 5px;
      width: 20%;
    }

    #map {
      margin: 5px;
      padding: 0;
    }

  </style>
</head>

<body class="claro">
  <div id="mainWindow" data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="design:'headline'">
    <div id="header" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'top'">
      <div id="title"></div>
      <div id="subtitle"></div>
    </div>
    <div id="map" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'center'"></div>
    <div id="rightPane" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'right'">
      <div id="legend"></div>
    </div>
  </div>
</body>

</html>
0 Kudos
VenkataSrikanth_Dasari
Occasional Contributor

Thanks for the sample however, I got the group layer which includes layerInfos [0,1,2]. I would like to set definition expression to the 0th layer.. I don't see any layer object in the group layer...

Cheers,

Srikanth Dasari

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Srikanth,

   So you do not see the info for layer 0 returned in the array at all?

0 Kudos
VenkataSrikanth_Dasari
Occasional Contributor

I don't see layer object for the sublayer.. You can see in the LayerInfos object in the below screenshot..

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

You are not going to get a layer object for a MapService layer like that in the 3.x API. You need to set the LayerDefintions array for that layer.

https://developers.arcgis.com/javascript/3/jsapi/arcgisdynamicmapservicelayer-amd.html#setlayerdefin... 

0 Kudos
VenkataSrikanth_Dasari
Occasional Contributor

Thanks a lot. 

0 Kudos