basemapLayerIds & map.getBasemap() are null when using arcgisUtils.createMap

5910
13
01-12-2015 06:22 AM
TommyBramble
New Contributor III

Hello all,

I have an application using the arcgisUtils.createMap method. In the application, properly formatted WebMapJson is passed into the createMap() method and a working map is returned. However, I have a problem with the returned map when accessing the map.basemapLayerIds property or using map.getBasemap() and map.setBasemap(). Basically, in the response map the basemapLayerIds property is null, which affects the getBasemap() and setBasemap() methods.

Further, if I do call the map.setBasemap() method a second basemap will get added to the map underneath the original basemap that was uspplied in the JSON.

This Esri JS API sample has the same issue from what I can tell. Run this sample in debug mode and put a breakpoint before the legend is started (or change the map to a global variable) and test the basemapLayerId property and getBasemap() method.

Is this an oversight in the JS API?

Edit:

In the meantime, to get around this issue, I'm just traversing the WebMapJson in my code and if the baseMapLayers array is populated then I am manually populating the response Map's basemapLayerIds array.

Any insight is much appreciated!

Thanks,

0 Kudos
13 Replies
JohnGravois
Frequent Contributor

based on the baseMap spec here, i would expect the following:

response.map.getBasemap();
>>> "World_Terrain_Base"

i'll do some snooping and let you know what i find, but it looks like we are currently just parsing the JSON and adding the basemap layers to the map without actually handling them as an explicit basemap.

is this causing any major difficulty in your project, or is it just more of a minor annoyance?

0 Kudos
JohnGravois
Frequent Contributor

looking at this a little more, i actually can see the logic in how we're doing things now.  the Basemap object in the API has both a 'title' and 'id' property.  i'd guess we don't use title from the WebMap JSON automatically to set the 'id' in case there are spaces in the name.

this makes your workaround seem a pretty sensible approach.  all that being said, im happy to dig in deeper if it turns out the current behavior causes deeper underlying problems.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

John,

   This is a issue for the Web AppBuilder product as the only option that is available is to use a web map and the fact that getBasemap function and setBasemap have this issue definitely has caused me some heartache in WAB widget development.

TommyBramble
New Contributor III

If it helps, here is the block I use in the deferred response of the createMap() method to populate the basemapLayerIds property:

   map.basemapLayerIds = [];
   for (var i = 0, length = config.itemData.baseMap.baseMapLayers.length; i < length; i++) {
     var b = config.itemData.baseMap.baseMapLayers;
     map.basemapLayerIds.push(b.id);
  }

After running the above code the getBasemap() and setBasemap() methods work without problems for me.

In my particular application I know there will be a basemap in my WebMapJson, otherwise you might want to add logic to verify the parent object(s) exist (baseMap, baseMapLayers).

0 Kudos
JohnGravois
Frequent Contributor

Tommy,

We're getting into confusing territory here, but in WebmapJSON a single baseMap can be composed of multiple individual basemapLayers (ex: gray basemap + reference labels) that are drawn simultaneously.  This means that the baseMap - title tag makes the appropriate equivalent to a basemapLayerId in the map object itself, right?

Robert,

thanks for chiming in.  are you just suggesting that it'd be helpful for the JSAPI to make sure 'title' (if present) is returned by a call to map.getBasemap() or am i missing something else?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

John,

   That would be a good start. As it is right now the basemapLayerIds property does not even return anything when using a web map. My biggest concern is the basemapLayerIds and setBasemap do not function properly when using a web map. If map.getBasemap() could return 'custom' or something generic would work too.

0 Kudos
JohnGravois
Frequent Contributor

Tommy,

i think i was the only one confused in my last post.  despite its appropriate name, i didn't realize that for normally instantiated maps, map.basemapLayerIds returns an array of individual layerIds, and not a basemap title like 'topo' or 'osm'.

i'll definitely pass along this feedback to the team.

0 Kudos
TommyBramble
New Contributor III

I would have to disagree here. From what I have observed you would not use the title. You would use the individual basemap layer ids.

So if a WebMapJson baseMapLayers collection has two layers (like the hybrid imagery basemap would), then the map.basemapLayerIds would have two values (i.e. ["layer0", "layer1"]).

If a layer in the baseMapLayers collection in the WebMapJson doesn't have the "id" property assigned then the API would need to auto assign the ids (i.e. "layer0"). This is similar to the behavior I've observed with the API already I believe.

Correct me if I'm wrong, but in order for setBasemap() and getBasemap() to function correctly then .basemapLayerIds need to have the ids of each basemap layer. Not the title of the collection of basemap layers.

0 Kudos
JohnGravois
Frequent Contributor

beat ya to it

agreed.