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保存客户端增加的地图数据。
接下来就在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保存客户端增加的地图数据。
相关文章推荐
- Flex for ArcGIS实现数据库地图查询
- arcgis for flex全国地图天气预报的具体实现过程解析
- arcgis for flex全国地图天气预报的具体实现过程解析
- ArcGIS.Server.9.3和ArcGIS API for Flex实现Query查询定位中心功能(七)
- 地图自动缩放功能实现 arcgis for flex
- ArcGIS API For Javascript之地图基本加载与显示,地图切换、缩放、定位、比例尺、鹰眼图、坐标显示、查询搜索功能实现
- arcgis for flex或silverlight全国地图天气预报的实现
- ArcGis for JS 利用QueryTask查询实现对地图的定位功能
- arcgis for flex api version3.7 教程:3.如何使用QueryTask查询地图服务
- [转]ArcGIS.Server.9.3和ArcGIS API for Flex实现Query查询定位中心功能(七)
- arcgis for flex或silverlight全国地图天气预报的实现
- ArcGIS Api For Flex 划选查询功能的实现
- ArcGIS.Server.9.3和ArcGIS API for Flex实现基本的地图浏览(一)
- ArcGIS.Server.9.3和ArcGIS API for Flex实现Query查询定位中心功能(七)
- [转]ArcGIS.Server.9.3和ArcGIS API for Flex实现基本的地图浏览(一)
- ArcGIS.Server.9.3和ArcGIS API for Flex实现基本的地图浏览(一)
- ArcGIS.Server.9.3和ArcGIS API for Flex实现Query查询定位中心功能(七)
- ArcGIS Server for flex地图控件的常用属性
- ArcGIS.Server.9.3和ArcGIS API for Flex实现自己的Toc控件(三)
- Arcgis API for JavaScript在地图上实现手机定位信息的追踪显示