config.xml文件的配置如下:
- <widget label="地图定位" config="widgets/esri/Location/LocationWidget.xml"
- icon="assets/images/ditudingwei.png" url="widgets/esri/Location/LocationWidget.swf" />
复制代码源代码目录如下: 界面效果: 大概的思路如下:定位有两种方式:1.后台数据库关联的,即是从后台数据库读取事故列表的定位数据,然后加载出来显示在地图上;2.直接在地图上点击某处,获取该处的定位点信息。两者的共同点都是根据经纬度来定位。 LocationWidget.xml:配置数据库事故列表的字段信息 - <?xml version="1.0" encoding="UTF-8"?>
- <configuration>
- <!-- <icon>assets/images/i_target.png</icon>-->
- <icon>assets/images/Red_glow.swf</icon>
- <title>{name}</title>
- <fields>
- <field name="type" alias="事件类别" visible="true" />
- <field name="event_level_display" alias="事件级别" visible="true" />
- <field name="event_level" alias="事件级别Id" visible="false" />
- <field name="event_time" alias="事发时间" visible="true" />
- <field name="event_man" alias="联系人" visible="true" />
- <field name="event_status" alias="状态" visible="false" />
- <field name="event_status_display" alias="状态" visible="true" />
- </fields>
- </configuration>
复制代码LocationWidget.mxml:这里截取核心实现部分 - protected function list1_clickHandler(event:ListEvent):void
- {
- graphicsLayer.clear();
- // TODO Auto-generated method stub
- var graphic:Graphic=lstEvent.selectedItem as Graphic;//获取事故列表某项数据,转换graphic
- if(graphic.attributes.X==0 || graphic.attributes.Y==0){//判断事故定位数据是否合法
- Alert.show("此事件没有坐标信息,");
- }else{
- zoomToFeature(graphic);//跳转到定位函数
- }
-
- }
- //定位函数
- private function zoomToFeature(feature:Graphic):void{
- var mapPoint:MapPoint = feature.geometry as MapPoint;//获取经纬度
- mapPoint.spatialReference=new SpatialReference(4326);
- this.longitudeText.text="";
- this.latitudeText.text="";
- longitudeText.text="经度:"+mapPoint.x.toFixed(4).toString();
- latitudeText.text="纬度:"+mapPoint.y.toFixed(4).toString();
- // var popUpRenderer:CustomPopUpRenderer=new CustomPopUpRenderer();
- var popUpRenderer:PopUpRenderer=new PopUpRenderer();//设置气泡窗口
- //popUpRenderer.forceSetMap(this._featureLayer.map);
- var popUpInfo:PopUpInfo=(this.graphicLayer.infoWindowRenderer as ClassFactory).properties.popUpInfo;
- popUpInfo.showZoomToButton=true;
- popUpRenderer.popUpInfo=popUpInfo;
- popUpRenderer.graphic=feature;
- // if(!popUpRenderer.map)popUpRenderer.userMap=this.map;
- this.map.infoWindow.content=popUpRenderer;
- this.map.level=7;
- this.map.zoomTo(feature.geometry);
- this.map.infoWindow.show(mapPoint);
- this.addSharedData("event_point", new ArrayCollection([mapPoint]));
- var message:String="确定接入点,坐标为:x=" + mapPoint.x + " y=" + mapPoint.y;
- doBufferByPoint(mapPoint);
- }
-
- //添加分析的方法 start
- private var lastDrawGraphic:Graphic;
- private function doBufferByPoint(mapPoint:MapPoint):void
- {
- var base:Number=Number(500);
- var classNumber:Number=Number(1);
- var interval:Number=Number(500);
- var distances:Array=[];
- if (classNumber >= 1)
- {
- for (var i:int=0; i < classNumber; i++)
- {
- distances.push(base + i * interval);
- }
- }
- doBuffer(mapPoint, distances);
-
- }
-
-
- private function doBuffer(geometry:Geometry, distances:Array):void
- {
- var radius:Number=Number(500);
- var param:BufferParameters=new BufferParameters();
- param.geometries=[geometry];
- param.distances=distances;
- //param.geodesic=true;
- //4326需要加上这个单位
- param.unit=GeometryService.UNIT_METER;
- //param.outSpatialReference=new SpatialReference(4326);
- geometryService.buffer(param);
-
- lastDrawGraphic = new Graphic(geometry);
- var label:String = "面积:" + numFormatter.format(3.14*radius*radius/1000000) + "平方千米";
- label += "\n" + "半径:" + numFormatter.format(radius/1000) + "千米";
- addDrawLabel(label, lastDrawGraphic);
- }
-
- private function addDrawLabel(label:String, lastDrawnGraphic:Graphic):void
- {
- var txtSym:TextSymbol = new TextSymbol(label);
- txtSym.yoffset = 8;
- var txtFormat:TextFormat = new TextFormat("Arial", 12, 0x000000, true); // black label
- txtSym.textFormat = txtFormat;
- lastDrawnGraphic.symbol = txtSym;
- }
复制代码
GIS作品:百度搜索:GIS之家(https://shop116521643.taobao.com/shop/view_shop.htm); QQ兴趣部落GIS技术交流:gis之家(http://buluo.qq.com/p/barindex.html?bid=327395); GIS技术交流群:432512093
|