关闭

基于ArcGIS API for Flex的区域性助老助残地图服务

561人阅读 评论(0) 收藏 举报
分类:
<?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:esri="http://www.esri.com/2008/ags"
			   xmlns:utils="utils.*"
			   xmlns:local="*"
			   pageTitle="助老助残室内位置服务"
			   minWidth="955" minHeight="600">
	<fx:Script>
		<![CDATA[
			import com.esri.ags.Graphic;
			import com.esri.ags.events.MapEvent;
			import com.esri.ags.events.MapMouseEvent;
			import com.esri.ags.geometry.MapPoint;
			import com.esri.ags.tasks.supportClasses.IdentifyParameters;
			import com.esri.ags.tasks.supportClasses.IdentifyResult;
			import mx.controls.Alert;
			import mx.rpc.AsyncResponder;
			import mx.rpc.events.FaultEvent;
			protected function pMap_mouseMoveHandler(event:MouseEvent):void
			{
				// TODO Auto-generated method stub
				const mapPoint:MapPoint = map2d.toMapFromStage(event.stageX,event.stageY);
				mapCoordinate.text = mapPoint.x.toFixed(1)+","+mapPoint.y.toFixed(1);
			}
			protected function pMap_loadHandler(event:MapEvent):void
			{
				// TODO Auto-generated method stub
				var timer:Timer = new Timer(1000);
				timer.addEventListener(TimerEvent.TIMER,onTimer);
				timer.start();
				var mapTimer:Timer = new Timer(10000);
				mapTimer.addEventListener(TimerEvent.TIMER,mapRefresh);
				mapTimer.start();
				map2d.infoWindow.addEventListener(Event.CLOSE,pMap_infoWindow_CloseHandler);
			}
			private function onTimer(event:TimerEvent):void{
				var date:Date = new Date();
				//txtDate.text = date.toString();
				txtDate.text = dateFormatter.format(date);
			}
			private function mapRefresh(event:TimerEvent):void{
				if(baseLayer!=null)
				{
					peopleLayer.refresh();
					peopleAlarmLayer.refresh();
					baseLayer.refresh();
					//watchLayer.refresh();
					//Alert.show("");
				}
			}
			protected function pMap_mapClickHandler(event:MapMouseEvent):void
			{
				//Alert.show(map2d.scale.toString());
				var identifyParams:IdentifyParameters = new IdentifyParameters();
				identifyParams.layerOption = IdentifyParameters.LAYER_OPTION_VISIBLE;
				identifyParams.layerIds = [0,1];
				identifyParams.returnGeometry = true;
				identifyParams.tolerance = 5;
				identifyParams.width = map2d.width;
				identifyParams.height = map2d.height;
				identifyParams.mapExtent = map2d.extent;
				identifyParams.spatialReference = map2d.spatialReference;
				identifyParams.geometry = event.mapPoint;
				identifyTask.execute(identifyParams,new AsyncResponder(result_identityTask,fault_identityTask));
				
				function result_identityTask(results:Array,token:Object = null):void
				{
					highlightGraphicsLayer.clear();
					var count:int = results.length;
					if(results && count>0){
						var infoPoint:MapPoint = results[0].feature.geometry;
						for(var i:int = 0;i<count;i++){
							var result:IdentifyResult = results[i];
							var pGraphic:Graphic = result.feature;
							pMap_infoWindow_setContentHandler(pGraphic); // 设定信息窗口的显示字段
							highlightGraphicsLayer.add(new Graphic(result.feature.geometry,onSelectionMarker));
							break;
						}
						map2d.infoWindow.show(infoPoint);
					} else {
					}
				}
				function pMap_infoWindow_setContentHandler(graphic:Graphic):void{
					infoWindow.PID = graphic.attributes.PID;
					infoWindow.Name = graphic.attributes.Name;
					infoWindow.Gender = graphic.attributes.Gender;
					infoWindow.Age = graphic.attributes.Age;
					infoWindow.RoomNumber = graphic.attributes.RoomNumber;
				}
				function fault_identityTask(error:Object,token:Object = null):void{
					Alert.show(String(error),"Identity Error");
				}
			}
			private function pMap_infoWindow_CloseHandler(event:Event):void{
				highlightGraphicsLayer.clear();
			}
			protected function peopleLayer_faultHandler(event:FaultEvent):void
			{
				// TODO Auto-generated method stub
				peopleLayer.visible = false;
				Alert.show(event.fault.faultString + "\n\n" + event.fault.faultDetail, "FeatureLayer error " + event.fault.faultCode);
			}
		]]>
	</fx:Script>
		<fx:Style>
		@namespace s "library://ns.adobe.com/flex/spark";
		@namespace mx "library://ns.adobe.com/flex/mx";
		@namespace esri "http://www.esri.com/2008/ags";
		@namespace utils "utils.*";
		@namespace local "*";
		esri|InfoWindow{
			backgroundAlpha: 0.8;
			backgroundColor: #E9FFBE;
			borderThickness: 0;
			infoPlacement: top;
			shadowAlpha: 0.5;
			shadowDistance: 10;
			upperRightRadius: 0;
		}
	</fx:Style>
	<fx:Declarations>
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
		<esri:SpatialReference id="mapSR"
							   wkid="2385" />
		<esri:Extent id="initExtent"
					 xmin="899275"
					 ymin="-170770" 
					 xmax="931980"
					 ymax="-138070"
					 spatialReference="{mapSR}" />
		<esri:IdentifyTask id="identifyTask"
						   concurrency="last"
						   showBusyCursor="true"
						   url="http://192.168.11.90:6080/arcgis/rest/services/Indoor/F20/MapServer" />
		<esri:SimpleMarkerSymbol id="onSelectionMarker"
								 size="10"
								 color="0xB0FFFF"
								 alpha="20" />
		<s:DateTimeFormatter id="dateFormatter"
							 useUTC="false"
							 dateTimePattern="YY-MM-DD h:mm:ss"
							 locale="zh-CN"
							 timeStyle="long" />
		<esri:InfoSymbol id="peopleInfoAlarmSymbol">
			<esri:infoRenderer>
				<fx:Component>
					<s:DataRenderer color="0xBEFFE8">
						<s:Label fontSize="12"
								 fontWeight="bold"
								 paddingBottom="3"
								 paddingLeft="3"
								 paddingRight="3"
								 paddingTop="3"
								 fontFamily="微软雅黑"
								 backgroundColor="0xBEFFE8"
								 color="0xFF5500"
								 text="{data.name}离开!" />
					</s:DataRenderer>
				</fx:Component>
			</esri:infoRenderer>
		</esri:InfoSymbol>
		<esri:InfoSymbol id="peopleInfoSymbol">
			<esri:infoRenderer>
				<fx:Component>
					<s:DataRenderer color="0xBEFFE8">
						<s:Label fontSize="12"
								 fontWeight="bold"
								 paddingBottom="3"
								 paddingLeft="3"
								 paddingRight="3"
								 paddingTop="3"
								 fontFamily="微软雅黑"
								 backgroundColor="0xBEFFE8"
								 color="0xFF5500"
								 text="{data.name}" />
					</s:DataRenderer>
				</fx:Component>
			</esri:infoRenderer>
		</esri:InfoSymbol>
	</fx:Declarations>
	<s:layout>
		<s:VerticalLayout />
	</s:layout>
	<esri:Map id="map2d"
			  logoVisible="false"
			  scaleBarVisible="false"
			  zoomSliderVisible="false"
			  width="100%"
			  height="100%"
			  extent="{initExtent}" 
			  scrollWheelZoomEnabled="false"
			  rubberbandZoomEnabled="false"
			  doubleClickZoomEnabled="false"
			  clickRecenterEnabled="false"
			  panEnabled="true"
			  keyboardNavigationEnabled="false"
			  mouseMove="pMap_mouseMoveHandler(event)"
			  mapClick="pMap_mapClickHandler(event)"
			  load="pMap_loadHandler(event)">
		<esri:ArcGISDynamicMapServiceLayer id="baseLayer"
										 url = "http://192.168.11.90:6080/arcgis/rest/services/Indoor/F20/MapServer" />
		<esri:FeatureLayer id="peopleAlarmLayer"
						   mode="onDemand"
						   outFields="[*]"
						   fault="peopleLayer_faultHandler(event)"
						   visible="true"
						   disableClientCaching="true"
						   symbol="{peopleInfoAlarmSymbol}"
						   url="http://192.168.11.90:6080/arcgis/rest/services/Indoor/F20/MapServer/1" /> <!-- OPM 报警位置 -->
		<esri:FeatureLayer id="peopleLayer"
						   mode="onDemand"
						   outFields="[*]"
						   fault="peopleLayer_faultHandler(event)"
						   visible="true"
						   disableClientCaching="true"
						   symbol="{peopleInfoSymbol}"
						   url="http://192.168.11.90:6080/arcgis/rest/services/Indoor/F20/MapServer/0" /> <!-- OPM 正常位置 -->
		<esri:GraphicsLayer id="highlightGraphicsLayer" />
		<esri:infoWindowContent>
			<utils:InfoWindow id="infoWindow" />
		</esri:infoWindowContent>
	</esri:Map>
	<s:Group>
		<s:layout>
			<s:HorizontalLayout />
		</s:layout>
		<s:RichText id="mapCoordinate"
					text="显示地图坐标"  />
		<s:RichText id="txtDate"
					text="显示时间"  />
	</s:Group>
</s:Application>

第一个项目顺利验收通过。
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:27581次
    • 积分:587
    • 等级:
    • 排名:千里之外
    • 原创:33篇
    • 转载:8篇
    • 译文:1篇
    • 评论:2条
    最新评论