Select to view content in your preferred language

MapImageLayer allSublayers

2512
5
Jump to solution
08-15-2017 03:56 PM
TristanSebens
New Contributor II

Using ArcGIS JS 4.x.

I am attempting to add all of the Layers contained within a Map Server to a Map object. The MapServer can be found at this URL: ShoreZoneMapService (MapServer) 

Here is the relevant code:

var szMapService = new MapImageLayer({
url: "https://alaskafisheries.noaa.gov/arcgis/rest/services/ShoreZoneMapService/MapServer"
});

The real goal is to parse through all of the layers and only load those that meet certain criteria, but for now I'm trying to load all of them. To check if the layer has loaded, I use console.log( szMapService ) to print out a JSON object of the MapImageLayer. 

When I do this, the MapImageLayer seems to have been created successfully, but the allSublayers object contains no layers. 

Am I doing something wrong? Why aren't any of my layers being loaded?

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Tristan,

   Sure look at the sublayers property:

https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-MapImageLayer.html#sublaye... 

// Only includes the first sublayer from the map service
var layer = new MapImageLayer({
  url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer",
  sublayers: [{
    id: 0
  }]
});

View solution in original post

0 Kudos
5 Replies
RobertScheitlin__GISP
MVP Emeritus

Tristan,

   You have to watch the loaded property.

var szMapService = new MapImageLayer({
url: "https://alaskafisheries.noaa.gov/arcgis/rest/services/ShoreZoneMapService/MapServer"
});
szMapService.watch("loaded", function(){
  console.log(szMapService);
});
TristanSebens
New Contributor II

Thanks for your quick reply!

I added the code you suggested. I also added a function that would print

the status of the 'loaded' attribute when I clicked a button.

It's been over 10 minutes, and the object still hasn't loaded. There are

about 60 items, so it's possible that it really is just slogging through

all of that data. So, is there a way to limit the layers that are loaded? I

only need about a dozen of them.

On Tue, Aug 15, 2017 at 3:11 PM, Robert Scheitlin, GISP <geonet@esri.com>

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Tristan,

   Sure look at the sublayers property:

https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-MapImageLayer.html#sublaye... 

// Only includes the first sublayer from the map service
var layer = new MapImageLayer({
  url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer",
  sublayers: [{
    id: 0
  }]
});
0 Kudos
TristanSebens
New Contributor II

Okay, I altered the MapImageLayer to the following:

var szMapService = new MapImageLayer();

just to test the sublayers property. My understanding of the property is

that if I pass an empty array, then no layers will be included in the

MapImageLayer, which should mean that the layer loads more or less

instantly. I'm not seeing that though, the layer is still failing to load.

Am I not using the sublayer's property properly?

I also tried:

var szMapService = new MapImageLayer();

as id=5 refers to a layer within the map server that will be used in the

final application. Still no response. Any thoughts?

On Tue, Aug 15, 2017 at 3:57 PM, Robert Scheitlin, GISP <geonet@esri.com>

0 Kudos
TristanSebens
New Contributor II

Nevermind, I realized my mistake. Since this code is still proof of

concept, the MapImageLayer isn't loaded into any kind of view, which means

that the load() function is never executed. Once I manually called the

load() function, it works as expected, including the sublayer functionality.

On Wed, Aug 16, 2017 at 12:41 PM, Tristan Sebens <

0 Kudos