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

最新文章

  1. BeautifulSoup学习笔记
  2. 51nod 1138 连续整数的和(数学公式)
  3. JAVA设计模式--抽象工厂模式
  4. change和onchange触发为什么不立马生效?
  5. jQuery+php+ajax+PHPExcel实现上传excel文件导入数据库
  6. Quartz定时任务学习(七)Cron 触发器
  7. uva10617 - Again Palindrome(dp)
  8. OCP读书笔记(15) - 管理SQL性能调优
  9. javascript图片延迟加载(转载)
  10. server
  11. Java学习笔记2(输入与随机数简单介绍)
  12. jQuery 效果 – 滑动
  13. qtpy.PythonQtError: No Qt bindings could be found
  14. Unity添加多个可视镜头Preview功能(一)
  15. MySQL 锁信息和事务
  16. spring activemq 整合
  17. problem:vue组件局部刷新,在组件销毁(destroyed)时取消刷新无效问题
  18. Ubuntu 16.04 python和OpenCV安装
  19. Workbox 缓存
  20. keystone令牌三种生成方式

热门文章

  1. 201521123093 java 第七周学习总结
  2. 201521123089《Java程序设计》第6周学习总结
  3. 201521123013 《Java程序设计》第1周学习总结
  4. 201521123119《Java程序设计》第1周学习总结
  5. .net异步性能测试(包括ASP.NET MVC WebAPI异步方法)
  6. 如何查看maven plugin所包含的goal
  7. idea导出war包
  8. WPA/WPA2加密破解
  9. 用postal.js在AngularJS中实现订阅发布消息
  10. DotNetCore跨平台~linux上还原自主nuget包需要注意的问题