关于supermap api for Flex 中FeaturesLayer的clear方法连续执行167次后报空的问题

首先来看下报错信息:



TypeError: Error #1009: 无法访问空对象引用的属性或方法。
	at Hashtable/http://www.supermap.com/iclient/2010/internal::add()[E:\SuperMapiClient60\01_SourceCode\branches\Flex_610_8129_B\iClientFlexLib6R\src\com\supermap\web\mapping\Hashtable.as:56]
	at com.supermap.web.mapping::FeaturesLayer/addHashTableIDs()[E:\SuperMapiClient60\01_SourceCode\branches\Flex_610_8129_B\iClientFlexLib6R\src\com\supermap\web\mapping\FeaturesLayer.as:683]
	at com.supermap.web.mapping::FeaturesLayer/collectionAddHandler()[E:\SuperMapiClient60\01_SourceCode\branches\Flex_610_8129_B\iClientFlexLib6R\src\com\supermap\web\mapping\FeaturesLayer.as:594]
	at com.supermap.web.mapping::FeaturesLayer/collectionChangeHandler()[E:\SuperMapiClient60\01_SourceCode\branches\Flex_610_8129_B\iClientFlexLib6R\src\com\supermap\web\mapping\FeaturesLayer.as:549]
	at flash.events::EventDispatcher/dispatchEventFunction()
	at flash.events::EventDispatcher/dispatchEvent()
	at mx.collections::ListCollectionView/dispatchEvent()[E:\dev\4.x\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:1024]
	at mx.collections::ListCollectionView/addItemsToView()[E:\dev\4.x\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:1137]
	at mx.collections::ListCollectionView/listChangeHandler()[E:\dev\4.x\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:1284]
	at flash.events::EventDispatcher/dispatchEventFunction()
	at flash.events::EventDispatcher/dispatchEvent()
	at mx.collections::ArrayList/internalDispatchEvent()[E:\dev\4.x\frameworks\projects\framework\src\mx\collections\ArrayList.as:673]
	at mx.collections::ArrayList/addItemAt()[E:\dev\4.x\frameworks\projects\framework\src\mx\collections\ArrayList.as:394]
	at mx.collections::ListCollectionView/addItemAt()[E:\dev\4.x\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:596]
	at mx.collections::ListCollectionView/addItem()[E:\dev\4.x\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:560]
	at com.supermap.web.mapping::FeaturesLayer/addFeature()[E:\SuperMapiClient60\01_SourceCode\branches\Flex_610_8129_B\iClientFlexLib6R\src\com\supermap\web\mapping\FeaturesLayer.as:889]
	at Test/add()[D:\Object\Obj8.6\Flex\Test\src\Test.mxml:61]
	at Function/Test/protected:application1_creationCompleteHandler/a()[D:\Object\Obj8.6\Flex\Test\src\Test.mxml:42]
	at flash.utils::Timer/_timerDispatch()
	at flash.utils::Timer/tick()


测试代码:



<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:s="library://ns.adobe.com/flex/spark" 
			   xmlns:mx="library://ns.adobe.com/flex/mx" 
			   xmlns:ic="http://www.supermap.com/iclient/2010"
			   xmlns:is="http://www.supermap.com/iserverjava/2010"
			   width="100%" height="100%" 
			   pageTitle="点样式示例" creationComplete="application1_creationCompleteHandler(event)">
	<!--点要素样式-->
	<fx:Declarations>
		<!--定义点要素的默认显示样式-->
		<!--样式1-->
		
		
		<s:ArrayCollection id="alist">
			<fx:Object LGTD="113.224" LTTD="22.34" STNM="123" STCD="1"/>
			<fx:Object LGTD="113.234" LTTD="22.34" STNM="123" STCD="1"/>
			<fx:Object LGTD="113.124" LTTD="22.34" STNM="123" STCD="1"/>
		</s:ArrayCollection>
		
	</fx:Declarations>
	
	<fx:Script>
		<![CDATA[
			import com.supermap.web.core.Feature;
			import com.supermap.web.core.Point2D;
			import com.supermap.web.core.geometry.GeoPoint;
			import com.supermap.web.mapping.FeaturesLayer;
			
			import mx.controls.Alert;
			import mx.events.FlexEvent;
			
			public var fl:FeaturesLayer=new FeaturesLayer();
			
			protected function application1_creationCompleteHandler(event:FlexEvent):void
			{
				map.addLayer(fl);
				var i:int=0;
				var ti:Timer=new Timer(100);
				ti.addEventListener(TimerEvent.TIMER,a);
				function a(e:TimerEvent):void{
					add(alist);
					//Alert.show("a");
					
					i=i+1;
					mess.text=i.toString();
				}
				ti.start();
			}
			
			private function add(list:ArrayCollection):void{
				fl.clear();
				if(list && list.length>0)
				{
					
					for(var i:int=0;i<list.length;i++)
					{						
						var p:GeoPoint=new GeoPoint(list[i].LGTD,list[i].LTTD);
						var f:Feature=new Feature(p);
						
						fl.addFeature(f);
					}
				}
			}
			
		]]>
	</fx:Script>
	
	
	<!--加载地图-->
	<ic:Map id="map" scales="{[3.35e-7,6.7e-7,1.34e-6,2.68e-6,5.36e-6,1.07e-5]}">
		<is:TiledDynamicRESTLayer url="http://localhost:8090/iserver/services/map-gd22/rest/maps/gd"/>			
	</ic:Map>
	
	
	<s:Label id="mess"/>
</s:Application>

理论上来说,上面的代码将永远执行下去不会发生错误,但是当程序执行到167次时,发生报错,而且这个次数随着所添加的点,即alist记录的条数面变化,如果alist.lenght=6,则执行83次后报错,相当诡异!暂时认为是supermap api的问题






你可能感兴趣的:(关于supermap api for Flex 中FeaturesLayer的clear方法连续执行167次后报空的问题)