Interesting problem

621
2
09-20-2013 08:07 AM
AjaySisodia2
New Contributor
Hello:

I hope somebody can provide me some insight and help to resolve the issue I am having.

The issue is to change the layer opacity - I am using JS APIs 3.2

I have base layer and a dynamic layer mapservice which has 4 layers.

the code:
for (j = 0; j < self.map.layerIds.length; j += 1) {
    currentLayer = self.map.getLayer(self.map.layerIds);
    console.log("curentLayer:", currentLayer);
    if (currentLayer.id !== "baseLayer") {
     currentLayer.setOpacity(value);
     currentLayer.refresh();

This does not refreshes the dynamic layer opacity, but later as the part of the workflow if I reloads the layers, it works!

And on looking is closely thru Chrome developer tools I found that map.getLayer method does not return the same layer object.

The layer object in both instace when it does not work and when it works is very similar except when it does not work, the layer object does not have OnOpacityChange method. Please see the attached images.

I am just very confused as why same method (map.getLayer) returns two different object and what I should do to fix it.

Any help and insight is greatly appreciated.
0 Kudos
2 Replies
by Anonymous User
Not applicable
Original User: zj_zou

More than likely, it is because the first image is the scenario that the layer has not been fully loaded, while the second one is when the layer is loaded. Make sure to set the layer opacity after the layer is loaded.
0 Kudos
AjaySisodia2
New Contributor
Hi Jason: thanks for the response.
Yes, I have verified that layers are loaded. the first image looks to me as the raw mapservice definition rather than the complete layer object but I checked the APIs and could not find the returned object's methods and properties matching any API objects such as layer, layerInfo, ArcGISDynamicMapServiceLayer etc.
0 Kudos