|
|
|
|

ArcGis for flex查询FeatureLayer数据 - 寻找石头鱼

1. 首先实例化一个FeatureLayer对象 private var featureLayer:FeatureLayer=new FeatureLayer(); 2.指定FeatureLayer对象的url和输出字段 featureLayer.url = FeatureURL; featureLayer.outFields=["OBJECTID","CREATETIME"];(这里的字段用于在地...

作者:来源:|2017年10月21日
1. 首先实例化一个FeatureLayer对象

private var featureLayer:FeatureLayer=new FeatureLayer();

2.指定FeatureLayer对象的url和输出字段

featureLayer.url = FeatureURL;
featureLayer.outFields=["OBJECTID","CREATETIME"];(这里的字段用于在地图上展示时使用)

3. 定义查询条件和查询返回的字段(进行查询时必须有查询条件,如果没有则查不到数据

var query:Query=new Query();
query.where="1=1";

query.outFields=["OBJECTID","CREATETIME"];(这里的字段可以用于显示在表格中)

4. 进行异步查询

featureLayer.queryFeatures(query,new AsyncResponder(resulthandler,faulthandler));

5. 对返回数据进行处理

private function resulthandler(result:FeatureSet,token:Object):void{
tipLayer.clear();//每次查询之后清除图标图层内容,重新添加

resultAC.source=result.attributes;
graphicAC.source=result.features;
featureLayer.graphicProvider=graphicAC;

for each (var graphic:Graphic in result.features){

graphicLayer.add(graphic);
graphic.symbol = new SimpleLineSymbol("solid",0xFF0000,1,3);
//鼠标移动到道路线段上时显示手型,同时添加点击显示气泡的事件
graphic.useHandCursor = true;
graphic.buttonMode = true;
graphic.mouseChildren = false;
graphic.addEventListener(MouseEvent.CLICK,gisinfoWin.mouseOverGraphicTOMS);

//添加道路标注
var word:String = graphic.attributes.ROADSECTIONNAME;
var fmt:TextFormat = new TextFormat();
fmt.size = 12;
fmt.color = 0xffffff;
var symbolWord:TextSymbol = new TextSymbol(null,word,0xffffff,true,0xffffff,true,0x0131c0,TextSymbol.PLACEMENT_MIDDLE,0,0,-25,fmt);
symbolWord.backgroundColor = 0x999933;

//获取中心点
var center:MapPoint = graphic.geometry as MapPoint;
if(graphic.geometry != null && graphic.geometry.type != Geometry.MAPPOINT){
center = graphic.geometry.extent.center; //区域中心点
//交通组织的中心点设置为起点,标注文字
var line:Polyline = graphic.geometry as Polyline;
if(line != null){
try {
var arrPoints:Array = line.paths[0];
center = arrPoints[0] as MapPoint;
}catch(e){}
}
}

if(center != null) {
var tipGraphic:Graphic = new Graphic(center);
tipGraphic.attributes = graphic.attributes;
tipGraphic.useHandCursor = true;
tipGraphic.buttonMode = true;
tipGraphic.mouseChildren = false;
tipGraphic.symbol = symbolWord;
//添加鼠标事件
tipGraphic.addEventListener(MouseEvent.CLICK,gisinfoWin.mouseOverGraphicTOMS);
tipLayer.add(tipGraphic);

//施工占道需要添加小人在地图上
var tomsPic:PictureMarkerSymbol;
if(graphic.attributes.TOMSTYPEID=="02"){
tomsPic = new PictureMarkerSymbol(IconDir+"dev/fs_toms_02.png",this.defaultMarkWidth/2,this.defaultMarkHeight/2); //偏移的位置
}else{
tomsPic = new PictureMarkerSymbol(IconDir+"dev/fs_toms_01.png",this.defaultMarkWidth/2,this.defaultMarkHeight/2); //偏移的位置
}
var arrGraphic:Array = [new Graphic(center)]; //默认的绘制点
if(graphic.geometry.type == Geometry.POLYLINE) {
var line:Polyline = graphic.geometry as Polyline;
var arrPoints:Array = line.paths[0];
arrGraphic = []; //只标记前 1 个点,或者两个点
arrGraphic.push(new Graphic(arrPoints[0]));
if(arrPoints.length > 2){
arrGraphic.push(new Graphic(arrPoints[1]));
}
}
for each(var markGraphic:Graphic in arrGraphic){
markGraphic.symbol = tomsPic;
markGraphic.attributes = graphic.attributes;
//地图上点位显示手型
markGraphic.useHandCursor = true;
markGraphic.buttonMode = true;
markGraphic.mouseChildren = false;
//添加鼠标事件
markGraphic.addEventListener(MouseEvent.CLICK,gisinfoWin.mouseOverGraphicTOMS);
// if(token.fnRollOver != undefined && token.fnRollOver != null){
// markGraphic.addEventListener(MouseEvent.ROLL_OVER, token.fnRollOver);
// }
// if(token.fnMouseOver != undefined && token.fnMouseOver != null){
// markGraphic.addEventListener(MouseEvent.MOUSE_OVER,token.fnMouseOver);
// }
tipLayer.add(markGraphic);
}
}
}
}

因为FeatureLayer图层是不可以修改样式的,所以我将返回来的数据添加到GraphicsLayer图层中进行编辑。如果不修改样式的话,可以直接将FeatureLayer添加到地图中来展示。

6.将图层添加到地图实例上以进行最终展示

this.map.addLayer(graphicLayer);

上一篇:利用GDAL进行工具开源化改造 - 李晓晖

下一篇:没有了!

+ hot
热门推荐
点击排行