您的位置:首页 > 编程语言

将地图服务导出成经续度数组代码(supermap版本)

2013-03-26 16:24 309 查看
<?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%"
creationComplete="initApp()">
<!--SQL查询-->
<fx:Script>
<![CDATA[
import com.supermap.web.actions.Edit;
import com.supermap.web.actions.Pan;
import com.supermap.web.components.FeatureDataGrid;
import com.supermap.web.core.Feature;
import com.supermap.web.core.Point2D;
import com.supermap.web.core.geometry.GeoLine;
import com.supermap.web.core.geometry.GeoRegion;
import com.supermap.web.events.DrawEvent;
import com.supermap.web.iServerJava6R.FilterParameter;
import com.supermap.web.iServerJava6R.Recordset;
import com.supermap.web.iServerJava6R.dataServices.EditFeaturesParameters;
import com.supermap.web.iServerJava6R.dataServices.EditType;
import com.supermap.web.iServerJava6R.queryServices.*;
import com.supermap.web.iServerJava6R.serverTypes.*;
import com.supermap.web.iServerJava6R.spatialAnalystServices.*;
import com.supermap.web.mapping.HighlightLayer;

import mx.controls.Alert;
import mx.events.CloseEvent;
import mx.events.ListEvent;
import mx.rpc.AsyncResponder;

import spark.events.IndexChangeEvent;

[Bindable]
private var queryLayers:Array = ["poerL@mapDB_pe"];//查询图层列表
private var highlayer:HighlightLayer;//高亮图层
private var recordGrid:FeatureDataGrid;
private var currentQueryLayer:String = "poerL@mapDB_pe";//当前查询图层
[Bindable]
private var mapUrl:String;
private var resultFeatures:Array = [];
private function initApp():void
{
mapUrl="http://192.1.0.162:8090/iserver/services/map-typeSQLserver192106/rest/maps/mapDB_pe";
map.addLayer(fl);
}

//查询
private function onExcuteQueryClick(event:MouseEvent):void
{
//定义 SQL 查询参数
var queryBySQLParam:QueryBySQLParameters = new QueryBySQLParameters();
var filter:FilterParameter = new FilterParameter();
filter.name = this.querylayer.selectedItem.toString();
filter.attributeFilter = this.txtSqlExpress.text;
queryBySQLParam.filterParameters = [filter];
queryBySQLParam.returnContent = this.ishighLightLayer.selectedIndex == 0;

/* 执行 SQL 查询 */
var queryByDistanceService:QueryBySQLService = new QueryBySQLService(mapUrl);
queryByDistanceService.processAsync(queryBySQLParam, new AsyncResponder(this.dispalyQueryRecords,
function (object:Object, mark:Object = null):void
{
Alert.show("与服务端交互失败", "抱歉", 4, this);
}, null));

}
private var editAction:Edit;
public var fl:FeaturesLayer=new FeaturesLayer();
//显示查询结果
private function dispalyQueryRecords(queryResult:QueryResult, mark:Object = null):void
{
//使用要素图层 FeatureLayer 显示查询结果
if(this.ishighLightLayer.selectedIndex == 0)
{
var recordSets:Array = queryResult.recordsets;
if(recordSets.length != 0)
{
for each(var recordSet:Recordset in recordSets)
{

var i:int=0;
var txtXY:String="";
for each (var feature:Feature in recordSet.features)
{
fl.addFeature(feature);
var name:String=feature.attributes.NAME;
var snid:String=feature.attributes.SMID;
var po:GeoLine=feature.geometry as GeoLine;
//var po:GeoRegion=feature.geometry as GeoRegion;
var z:int=0;
txtXY="";
for(z=0;z<po.parts.length;z++)
{
var pArr:Array=po.parts[z];
for (var k:int=0;k<pArr.length;k++)
{
var p:Point2D=pArr[k] as Point2D;
var o:Object=new Object();
o.x=p.x;
o.y=p.y;
//AC.addItem(o);
txtXY+=p.x+","+p.y+";";
}
txtXY+="/";
//AC.push(pArr);
}
Alert.show(txtXY);
trace(snid+"-"+name+":"+txtXY);
}
}
}
editAction = new Edit(map,fl);
editAction.addEventListener(DrawEvent.DRAW_END,executeEdit);
map.action = editAction;
}
//使用高亮图层 HighlightLayer 显示查询结果
//				else
//				{
//					if(this.recordGrid)
//					{
//						this.recordGrid.clear();
//					}
//					this.featuresLayer.clear();
//					this.result.visible = false;
//					if (queryResult.resourceInfo!= null)
//					{
//						highlayer.visible = true;
//						highlayer.queryResultID = queryResult.resourceInfo.newResourceID;
//						var serverstyle:ServerStyle = new ServerStyle();
//						serverstyle.lineWidth = 0.5;
//						serverstyle.fillOpaqueRate = 80;
//						highlayer.style = serverstyle;
//						this.map.addLayer(highlayer);
//					}
//				}
}

//修改地物
private function executeEdit(event:DrawEvent):void
{
var editParams:EditFeaturesParameters = new EditFeaturesParameters();
editParams.features = [event.feature];
editParams.editType = EditType.UPDATE;
var editIDs:Array = new Array;
//				for each(var i:int in this.ids)
//				{
//					var id:int = event.feature.attributes.SMID;
//					if(id == i)
//						editIDs.push(i);
//				}
//				editParams.IDs = editIDs;
//
//				var editService:EditFeaturesService = new EditFeaturesService(this.editFeatureUrl);
//				editService.processAsync(editParams, new AsyncResponder(editComplete, excuteErros, null));
}

//查询图层改变事件
private function onQueryLayerChange(event:ListEvent):void
{
featuresLayer.clear();
var queryLayer:String = ComboBox(event.target).selectedItem.toString();
currentQueryLayer = queryLayer;
}

//平移
private function pan(event:MouseEvent):void
{
map.action = new Pan(map);
}

//清除查询结果
private function clearFeature(event:MouseEvent):void
{
if(highlayer && highlayer.numChildren > 0)
{
this.map.removeLayer(highlayer);
}
if(this.featuresLayer.numFeatures > 0)
{
resultFeatures = [];
if(this.recordGrid)
{
this.recordGrid.clear();
}
this.featuresLayer.clear();
this.result.removeAllChildren();
this.result.visible = false;
}
}

//查询参数设置窗口关闭事件
private function titleWinClose(event:CloseEvent):void
{
this.result.visible = false;
}

private function resultWin_mouseUp(event:MouseEvent):void
{
result.stopDrag();
}

private function resultWin_mouseDown(event:MouseEvent):void
{
result.startDrag();
}

protected function ishighLightLayer_changeHandler(event:IndexChangeEvent):void
{
if(this.ishighLightLayer.selectedIndex == 1)
{
this.bQueryResultSaved.enabled = false;
this.bQueryResultSaved.selected = false;
}
else
this.bQueryResultSaved.enabled = true;
}

]]>
</fx:Script>

<!--添加地图-->
<s:Panel fontFamily="宋体" width="100%" height="100%" fontSize="18" title="操作指南:直接点击“查询”">
<ic:Map id="map">
<is:TiledDynamicRESTLayer url="{this.mapUrl}"/>
<ic:FeaturesLayer id="featuresLayer" />
</ic:Map>
</s:Panel>

<!--定义结果显示窗口-->
<mx:TitleWindow id="result" right="50" left="50" height="150" title="查询结果:" visible="false" mouseDown="resultWin_mouseDown(event)" layout="absolute" showCloseButton="true"
bottom="10" horizontalCenter="10" close="titleWinClose(event)" backgroundColor="#737171" backgroundAlpha="0.60" mouseUp="resultWin_mouseUp(event)">
</mx:TitleWindow>

<!--查询参数设置窗口-->
<s:Panel id="titlewin" title="SQL 查询:" fontFamily="宋体" fontSize="12" right="5" top="10" backgroundColor="#454343" backgroundAlpha="0.48">
<s:VGroup gap="10" left="5" top="5" bottom="5" right="5">
<s:HGroup>
<mx:Label text="查询图层:"/>
<mx:Spacer width="6"/>
<mx:ComboBox  id="querylayer" dataProvider="{queryLayers}" change="onQueryLayerChange(event)" width="160"/>
</s:HGroup>
<s:HGroup>
<mx:Label text="SQL 语句:"/>
<mx:Spacer width="3"/>
<mx:TextInput id="txtSqlExpress" text="smid=247"/>
</s:HGroup>
<s:HGroup gap="30" horizontalAlign="center" width="100%" height="100%">
<s:DropDownList id="ishighLightLayer"
horizontalCenter="0"
fontSize="12"
fontFamily="宋体"
selectedIndex="0" width="162" change="ishighLightLayer_changeHandler(event)">
<s:ArrayList>
<fx:String>使用要素图层显示结果</fx:String>
<fx:String>使用高亮图层显示结果</fx:String>
</s:ArrayList>
</s:DropDownList>
</s:HGroup>
<s:HGroup gap="30" horizontalAlign="center" width="100%" height="100%">
<s:CheckBox id="bQueryResultSaved" label="保留查询结果" selected="false"/>
</s:HGroup>
<s:HGroup gap="10" width="100%" height="100%" horizontalAlign="center">
<mx:Button label="查询" id="excuteQuery" click="onExcuteQueryClick(event)"/>
<mx:Button label="清除" id="clear" click="clearFeature(event)"/>
<mx:Button label="平移" id="panMap" click="pan(event)"/>
</s:HGroup>
</s:VGroup>
</s:Panel>
</s:Application>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: