flex中ArcGISDynamicMapServiceLayer图层layerInfos属性为空

代码:
var arcLay:ArcGISDynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer(url);
for each(var layerInfo:LayerInfo in arcLay.layerInfos){
layerId = Number(layerInfo.layerId);
}
url地址正确,但是layerInfos属性一直为null,为什么
已邀请:

谢军

赞同来自: ArcGIS知乎 Curry

因为对server的请求是异步的,必须要等到图层加载完之后,才能去读取图层的layerinfos。可以尝试以下两种解决方法:
方法一:提前把图层添加到map容器中;
方法二:为图层增加一个监听,当图层load完成后,再读取图层的layerinfos。参考以下代码:
	<fx:Script>
<![CDATA[

import com.esri.ags.layers.ArcGISDynamicMapServiceLayer;
import com.esri.ags.layers.supportClasses.LayerInfo;
import com.esri.ags.events.LayerEvent;

private var myLayer:ArcGISDynamicMapServiceLayer

private function loadLayer():void
{

myLayer = new ArcGISDynamicMapServiceLayer("url");
myLayer.addEventListener(LayerEvent.LOAD, layerLoadHandler);

}

private function layerLoadHandler(event:LayerEvent):void
{

for each(var layerInfo:LayerInfo in myLayer.layerInfos)
{
//to do you want
}
}

]]>
</fx:Script>

Curry

赞同来自:

谢谢你的回答,很完美

要回复问题请先登录注册