您的位置:首页 > 数据库

Flex for ArcGIS实现数据库地图查询

2009-01-09 10:14 405 查看
昨天把一份shapefile数据导入到数据库(Geodatabase)中,保存为.mxd格式发布到地图服务器上,可开发的时候发现它不支持查询,却切的说应该是不支持<esri:QueryTask>和<esri:Query>,不管是在服务器上还是在客户端都不支持查询,同一份数据,为什么导入到数据库中就不支持呢?

接下来就在baidu和google里查询,最终还是以失败告终,没有我想到的答案,但由于公司下午要开会和聚餐,所以昨天一直没有解决这个问题,很是郁闷。

今天来到公司,首先便想到这个问题,怎么解决呢,既然<esri:QueryTask>和<esri:Query>不支持数据库数据保存为mxd格式的查询,那我可不可以用另外一种方法呢,这不还真给我找到了,无意中我发现了<esri:FindTask>和<esri:FindParameters>,于是我便在服务器端试验能否进行查找,结果不想而知,还真的实现了,服务器端能实现,那客户端也一定能实现,于是赶紧写代码,现在把代码加在下面:

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:esri="http://www.esri.com/2008/ags" layout="absolute">

<mx:Script>

<![CDATA[

import com.esri.ags.Graphic;

import com.esri.ags.geometry.Geometry;

import com.esri.ags.tasks.FeatureSet;

import mx.collections.ArrayCollection;

import mx.controls.Alert;

import mx.events.StateChangeEvent;

import mx.rpc.AsyncResponder;

import mx.rpc.http.mxml.HTTPService;

import mx.collections.ArrayCollection;

import com.esri.ags.Graphic;

import com.esri.ags.events.FindEvent;

import com.esri.ags.geometry.Geometry;

private function doFind():void

{

findTask.execute( myFindParams ); //执行查找

}

private function executeCompleteHandler( event : FindEvent ) : void

{

myGraphicsLayer.clear();

var graphic : Graphic;

resultSummary.text = "Found " + event.findResults.length + " results.";

for (var i : Number = 0; i < event.findResults.length; i++)

{

graphic = event.findResults[i].feature;

graphic.toolTip = event.findResults[i].foundFieldName + ": " + event.findResults[i].value;

graphic.symbol = ifs;

}

}

]]>

</mx:Script>

<!--设置查询-->

<mx:Canvas x="179">

<mx:Label text="请输入要查找的关键字:" fontSize="13" fontFamily="Times New Roman"/>

<mx:TextInput id="qtext" enter="doFind()" width="200" x="143" y="0"/>

<mx:Button label="查找" x="349" fontSize="12" click="doFind()"/>

</mx:Canvas>

<esri:FindTask

id="findTask"

executeComplete="executeCompleteHandler(event)"

url="http://192.168.0.64:8085/ArcGIS/rest/services/222/MapServer"

/>

<esri:FindParameters id="myFindParams"

returnGeometry="true"

contains="true"

searchText="{qtext.text}"

layerIds="[0,1,2]" //设置要查找的图层,0,1,2就是地图服务器上图层的ID

searchFields="['NAME']" //要从哪个字段中查找,你的图层中必须有Name这个字段

/>

<mx:Text id="resultSummary" height="15"/>

<!--设置地图-->

<mx:Canvas width="700" height="468" borderStyle="solid" borderThickness="2" y="28">

<esri:Map id="myMap" logoVisible="false" crosshairVisible="true" y="-2" x="1">

<esri:extent>

<esri:Extent xmax="117.60650084997" ymax="32.0424245742138" xmin="117.04319415003" ymin="31.6761024257862">

<esri:SpatialReference wkid="4326">

</esri:SpatialReference>

</esri:Extent>

</esri:extent>

<esri:ArcGISDynamicMapServiceLayer url="http://192.168.0.64:8085/ArcGIS/rest/services/222/MapServer"/>

<esri:GraphicsLayer id="myGraphicsLayer" />

</esri:Map>

</mx:Canvas>

<!--设置查询结果的显示图标样式,实现Map Tip-->

<esri:InfoSymbol id="ifs">

<esri:infoRenderer>

<mx:Component>

<mx:VBox

click="clickHandler()"

rollOver="rollOverHandler()"

rollOut="rollOutHandler()"

width="100%"

height="100%"

backgroundColor="0xEEEEEE"

>

<mx:Style>

.InfoCloseButton {

disabledSkin: Embed(source="assets/skins.swf",symbol="Callout_closeButtonDisabledSkin");

downSkin: Embed(source="assets/skins.swf",symbol="Callout_closeButtonDownSkin");

overSkin: Embed(source="assets/skins.swf",symbol="Callout_closeButtonOverSkin");

upSkin: Embed(source="assets/skins.swf",symbol="Callout_closeButtonUpSkin");

}

.InfoExpandButton {

disabledSkin: Embed(source="assets/skins.swf",symbol="Callout_expandButtonDisabledSkin");

downSkin: Embed(source="assets/skins.swf",symbol="Callout_expandButtonDownSkin");

overSkin: Embed(source="assets/skins.swf",symbol="Callout_expandButtonOverSkin");

upSkin: Embed(source="assets/skins.swf",symbol="Callout_expandButtonUpSkin");

}

</mx:Style>

<mx:Script>

<![CDATA[

import mx.collections.ArrayCollection;

private function clickHandler() : void

{

switch( currentState )

{

case "" :

currentState = "TitleState";

break;

case "TitleState":

currentState = "DetailState";

break;

case "DetailState":

currentState = "TitleState";

break;

}

}

private function rollOverHandler() : void

{

if( currentState == null || currentState == "" )

{

currentState = "TitleState";

}

}

private function rollOutHandler() : void

{

if( currentState == "TitleState" )

{

currentState = "";

}

}

]]>

</mx:Script>

<mx:states>

<mx:State name="TitleState">

<mx:AddChild relativeTo="{titleBar}" position="lastChild">

<mx:Label

id="titleLabel"

text="{data.Name}"

rollOver ="{Label(event.currentTarget).setStyle('textDecoration', 'underline');}"

rollOut ="{Label(event.currentTarget).setStyle('textDecoration', 'none');}"

mouseDown="{Label(event.currentTarget).setStyle('textDecoration', 'none');}"

mouseUp ="{Label(event.currentTarget).setStyle('textDecoration', 'underline');}"

fontWeight="bold"

fontSize="15"

/>

</mx:AddChild>

<mx:AddChild relativeTo="{titleBar}" position="lastChild">

<mx:Button

id="expandButton"

styleName="InfoExpandButton"

width="18" height="18"

/>

</mx:AddChild>

</mx:State>

<mx:State name="DetailState" basedOn="TitleState">

<mx:RemoveChild target="{expandButton}"/>

<mx:AddChild relativeTo="{titleBar}" position="lastChild">

<mx:Spacer width="100%"/>

</mx:AddChild>

<mx:AddChild relativeTo="{titleBar}" position="lastChild">

<mx:Button

id="closeButton"

styleName="InfoCloseButton"

width="18" height="18"

/>

</mx:AddChild>

<mx:AddChild relativeTo="{this}">

<mx:Label text="分类:{data.fenlei}" fontSize="14" />

</mx:AddChild>

<mx:AddChild relativeTo="{this}" >

<mx:Label text="地址:{data.dizhi}" fontSize="14" />

</mx:AddChild>

</mx:State>

</mx:states>

<mx:transitions>

<mx:Transition fromState="*" toState="TitleState">

<mx:Sequence targets="{[titleLabel, expandButton]}">

<mx:Resize target="{this}" duration="100"/>

<mx:AddChildAction/>

<mx:AddChildAction/>

</mx:Sequence>

</mx:Transition>

<mx:Transition fromState="TitleState" toState="DetailState">

<mx:Sequence targets="{[closeButton]}">

<mx:Resize target="{this}" duration="100"/>

<mx:AddChildAction/>

<mx:AddChildAction/>

</mx:Sequence>

</mx:Transition>

<mx:Transition fromState="DetailState" toState="*">

<mx:Resize target="{this}" duration="100"/>

</mx:Transition>

<mx:Transition fromState="TitleState" toState="*">

<mx:Resize target="{this}" duration="100"/>

</mx:Transition>

</mx:transitions>

<mx:HBox id="titleBar" width="100%" height="100%">

<mx:Image source="@Embed(source='assets/pie_chart.gif')"

width="18" height="18"/>

</mx:HBox>

</mx:VBox>

</mx:Component>

</esri:infoRenderer>

</esri:InfoSymbol>

</mx:Application>

对以上代码进行说明一下,data.fenlei和data.dizhi 是设置子图的字段,你所查询的图层中必须有fenlei 和dizhi 两个字段。否则无法显示。

搞定,大功告成,下一步将实现用Flex + ArcGIS Server保存客户端增加的地图数据。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: