Determining if a layer is a baselayer in layer-add-result event

2463
12
Jump to solution
11-26-2014 08:19 AM
KenBuja
MVP Esteemed Contributor

I am adding several layers (both dynamic and tiled) programmatically to my map. In the layer-add-result event, I am setting the visibility to false and the visibleLayers to -1 for all the layers.

map.on("layer-add-result", function (addedLayer) {
    addedLayer.layer.setVisibility(false);
    addedLayer.layer.setVisibleLayers([-1]);
});

However, when I create the map with a basemap, the basemap layer( or layers, since some basemaps have multiple layers) will also fire this event. Since I want to keep the basemap visible, how can I determine if the layer a basemap?

Tags (2)
0 Kudos
12 Replies
RobertScheitlin__GISP
MVP Emeritus

Ken,

   Why not use Object.prototype.toString.call(addedLayer.layer)?

0 Kudos
KenBuja
MVP Esteemed Contributor

Robert Scheitlin, GISP‌I must be missing something‌. I tried that line but only got back the string "[object Object]"

var test = Object.prototype.toString.call(addedLayer.layer);

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Ken,

   Sorry I thought that this was a method of getting the exact object class name, but It will only give you the JavaScript Basic types (i.e Object.prototype.toString.call(new Date); // "[object Date]").

0 Kudos