前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ArcGis for flex查询FeatureLayer数据

ArcGis for flex查询FeatureLayer数据

作者头像
寻找石头鱼
发布2019-09-11 16:24:39
4900
发布2019-09-11 16:24:39
举报
文章被收录于专栏:寻找石头鱼寻找石头鱼

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);

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017-10-20 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
区块链
云链聚未来,协同无边界。腾讯云区块链作为中国领先的区块链服务平台和技术提供商,致力于构建技术、数据、价值、产业互联互通的区块链基础设施,引领区块链底层技术及行业应用创新,助力传统产业转型升级,推动实体经济与数字经济深度融合。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档