console.log("---- OBJECT DEBUG STARTS HERE ----"); console.log(layer); console.log(layer.version); console.log(layer.layerInfos); console.log("---- OBJECT DEBUG END HERE ----");
---- OBJECT DEBUG STARTS HERE ---- basemapviewer.html:118 a _defaultVisibleLayers: Array[29] _div: HTMLDivElement _divAlphaImageFunc: function (){return _bb.apply(_ba,arguments||[]);} _errorHandler: function (){return _bb.apply(_ba,arguments||[]);} _exportMapImageHandler: function (){return _bb.apply(_ba,arguments||[]);} _img: HTMLImageElement _imgSrcFunc: function (){return _bb.apply(_ba,arguments||[]);} _img_dragOrigin: Object _img_loading: HTMLImageElement _inherited: Object _initLayer: function (){return _bb.apply(_ba,arguments||[]);} _layerIndex: 2 _load: function (){return _bb.apply(_ba,arguments||[]);} _loadCallback: undefined _map: a _onExtentChangeHandler_connect: Array[4] _onPanHandler_connect: Array[4] _onResizeHandler_connect: Array[4] _onZoomHandler_connect: Array[4] _opacityChangeHandler_connect: Array[4] _params: Object _setIsPNG32: function (){return _bb.apply(_ba,arguments||[]);} _startRect: Object _tileErrorHandler: a _tileLoadHandler: a _titleForLegend: "INFORMATION" _unsetMap_connect: Array[4] _updateStarted: true _url: Object _visibilityChangeHandler_connect: Array[4] capabilities: "Map,Query,Data" copyright: "" description: "" dpi: 96 fullExtent: a getImageUrl: function (){return _bb.apply(_ba,arguments||[]);} id: "layer2" imageFormat: "png8" imageTransparency: true initialExtent: a isPNG32: undefined layerInfos: Array[29] legendResponse: Object loaded: true onLoad: function (){var ap=Array.prototype,c=arguments.callee,ls=c._listeners,t=c.target;var r=t&&t.apply(this,arguments);var i,lls;lls=[].concat(ls);for(i in lls){if(!(i in ap)){lls.apply(this,arguments);}}return r;} onOpacityChange: function (){var ap=Array.prototype,c=arguments.callee,ls=c._listeners,t=c.target;var r=t&&t.apply(this,arguments);var i,lls;lls=[].concat(ls);for(i in lls){if(!(i in ap)){lls.apply(this,arguments);}}return r;} onUpdateEnd: function (){var ap=Array.prototype,c=arguments.callee,ls=c._listeners,t=c.target;var r=t&&t.apply(this,arguments);var i,lls;lls=[].concat(ls);for(i in lls){if(!(i in ap)){lls.apply(this,arguments);}}return r;} onVisibilityChange: function (){var ap=Array.prototype,c=arguments.callee,ls=c._listeners,t=c.target;var r=t&&t.apply(this,arguments);var i,lls;lls=[].concat(ls);for(i in lls){if(!(i in ap)){lls.apply(this,arguments);}}return r;} opacity: 0.75 ovcConnect: Array[4] spatialReference: a units: "esriDecimalDegrees" url: "--removed--" useMapImage: false version: 10.01 visibleLayers: Array[29] __proto__: anonymous basemapviewer.html:119undefined basemapviewer.html:120[] basemapviewer.html:122---- OBJECT DEBUG END HERE ----
Hello,
I am having trouble accessing the objects of a dynamiclayer using JSAPI v2.1. Its strange, because Im almost certain that I have done it before..
I have the following lines executing:console.log("---- OBJECT DEBUG STARTS HERE ----"); console.log(layer); console.log(layer.version); console.log(layer.layerInfos); console.log("---- OBJECT DEBUG END HERE ----");
Chrome console shows the following:---- OBJECT DEBUG STARTS HERE ---- basemapviewer.html:118 a _defaultVisibleLayers: Array[29] _div: HTMLDivElement _divAlphaImageFunc: function (){return _bb.apply(_ba,arguments||[]);} _errorHandler: function (){return _bb.apply(_ba,arguments||[]);} _exportMapImageHandler: function (){return _bb.apply(_ba,arguments||[]);} _img: HTMLImageElement _imgSrcFunc: function (){return _bb.apply(_ba,arguments||[]);} _img_dragOrigin: Object _img_loading: HTMLImageElement _inherited: Object _initLayer: function (){return _bb.apply(_ba,arguments||[]);} _layerIndex: 2 _load: function (){return _bb.apply(_ba,arguments||[]);} _loadCallback: undefined _map: a _onExtentChangeHandler_connect: Array[4] _onPanHandler_connect: Array[4] _onResizeHandler_connect: Array[4] _onZoomHandler_connect: Array[4] _opacityChangeHandler_connect: Array[4] _params: Object _setIsPNG32: function (){return _bb.apply(_ba,arguments||[]);} _startRect: Object _tileErrorHandler: a _tileLoadHandler: a _titleForLegend: "INFORMATION" _unsetMap_connect: Array[4] _updateStarted: true _url: Object _visibilityChangeHandler_connect: Array[4] capabilities: "Map,Query,Data" copyright: "" description: "" dpi: 96 fullExtent: a getImageUrl: function (){return _bb.apply(_ba,arguments||[]);} id: "layer2" imageFormat: "png8" imageTransparency: true initialExtent: a isPNG32: undefined layerInfos: Array[29] legendResponse: Object loaded: true onLoad: function (){var ap=Array.prototype,c=arguments.callee,ls=c._listeners,t=c.target;var r=t&&t.apply(this,arguments);var i,lls;lls=[].concat(ls);for(i in lls){if(!(i in ap)){lls.apply(this,arguments);}}return r;} onOpacityChange: function (){var ap=Array.prototype,c=arguments.callee,ls=c._listeners,t=c.target;var r=t&&t.apply(this,arguments);var i,lls;lls=[].concat(ls);for(i in lls){if(!(i in ap)){lls.apply(this,arguments);}}return r;} onUpdateEnd: function (){var ap=Array.prototype,c=arguments.callee,ls=c._listeners,t=c.target;var r=t&&t.apply(this,arguments);var i,lls;lls=[].concat(ls);for(i in lls){if(!(i in ap)){lls.apply(this,arguments);}}return r;} onVisibilityChange: function (){var ap=Array.prototype,c=arguments.callee,ls=c._listeners,t=c.target;var r=t&&t.apply(this,arguments);var i,lls;lls=[].concat(ls);for(i in lls){if(!(i in ap)){lls.apply(this,arguments);}}return r;} opacity: 0.75 ovcConnect: Array[4] spatialReference: a units: "esriDecimalDegrees" url: "--removed--" useMapImage: false version: 10.01 visibleLayers: Array[29] __proto__: anonymous basemapviewer.html:119undefined basemapviewer.html:120[] basemapviewer.html:122---- OBJECT DEBUG END HERE ----
What you can see here is that the first console line prints the layer object ("a") - have expanded it to show all the objects stored within it (including "version" and "layerInfos"). However, when it is required to write one of these objects, it shows "undefined" and an empty array.
I have tried accessing by looping through the object as well, with the same results. I have tried calling the object using different JS notation, without success. I have also (out of desperation) re-published and restarted the service and tried on a different service all with the same results.
What is (clearly) incongruous here is that the full object can be read fine, but the embedded objects cannot. Presumably I am missing something OBVIOUS, but Ive tried re-writing a million times without success.
Please help!
Regards,
Richard.
dojo.connect(operationalLayer,"onLoad",function(){ console.log(operationalLayer.version); console.log(operationalLayer.layerInfos); console.log(operationalLayer.layerInfos[0].name); });
Here's a snippet that shows how to access the layer properties- in order to access all the information you'll need to wait until the layer is loaded.dojo.connect(operationalLayer,"onLoad",function(){ console.log(operationalLayer.version); console.log(operationalLayer.layerInfos); console.log(operationalLayer.layerInfos[0].name); });
Well it certainly give an answer. However, there are cases where you want to access and/or change the properties such as layer visibility before adding the layer to the map. How do you address those cases?
Ok, here goes:
After literally playing around with pretty much every combination of code, in the blind hope that something would "appear" to me, I have discovered the following:
When passing the layer object via a parameter to my function (after the layer has loaded):
- the object can be written in full to the console
- specific object properties are empty/null/bank and cannot be written
However, when I run the exact same procedure, but call the layer object directly (i.e. no variables are passed as arguments to the function):
- the object can be written in full to the console
- any object property can be successfully read - including the layerInfos array
The function argument seems to be the culprit, because even if I reference the original layer object, when an arbitrary (unused) argument is shared to the function, it stops working again.
Now, Im not a professional developer, but that sure seems strange to me! Dont suppose anyone can throw some light on this conundrum?
Richard.