在地图上以类似于提示框的方式显示查询信息,类似于arcmap中单击图层查看属性 由于Class Graphic有infoWindowRenderer : IFactory这个属性 (注:infoWindowRenderer property

infoWindowRenderer:IFactory  [read-write] The infoWindowRenderer is a UIComponent factory that is added to a graphic. Wen infoWindowRenderer is defined on a graphic,  a mouse "click" listener is automatically added to the graphic. When graphic is clicked, a UIComponent instance is created,  using the factory and if that factory implements the IDataRenderer interface then its data property is set to the graphic attributes.  In addition, if the UIComponent has a dataProvider property, then that property is set to the graphic attributes as well.  Finally, the map info window content is set to the newly created UIComponent and is shown at an anchor location.  If the geometry of the graphic is a map point, then the anchor location will be that map point, otherwise the anchor point will be where the user clicked map point location.

This property can be used as the source for data binding. 详见:http://resources.esri.com/help/9.3/arcgisserver/apis/flex/apiref/com/esri/ags/Graphic.html#infoWindowRenderer

graphic会自动的监听click事件,当用户单击到图层上的某个元素时,infoWindowRenderer会自动创建一个实例,因此我们只需 private var myInfoWindowRenderer:ClassFactory = new ClassFactory(MyInfoWindowRenderer);

(注:ClassFactory 类实现 IFactory 接口。因此,通过该类,您可以创建可分配到 IFactory 类型属性的对象)

新建Component组建,有两种方式:

1)在mxml内部创建,如下

<mx:Component className="MyInfoWindowRenderer">

<mx:VBox label="{data.STATE_NAME}" backgroundColor="0xEEEEEE">

<mx:Label text="State Fips: {data.STATE_FIPS}"/>

<mx:Label text="Abbreviation: {data.STATE_ABBR}"/>

<mx:Label text="Area: {data.AREA}"/>

</mx:VBox>

</mx:Component>

2)File->New->MXML Component文件,然后在<mx:Script>中导入你新建的as文件(MXML最后会编译成as文件,所以以包的形式导入即可)

例如:import component.MyInfoWindowRenderer;//component是我在当前文件目录下创建的文件夹

第二种方式可降低耦合度(耦合度的强弱可根据系统本身来自行决定,如模块设计科采用高内聚低耦合)

最后便可以进行查询之后的操作啦,例如在click事件里添加一些处理函数等等, 例如(这是自带的一些例子example)

private function onMapClick(event:MapMouseEvent):void

{

query.geometry = event.mapPoint;

queryTask.execute(query);

}

private function onQueryExecuteComplete(event:QueryEvent):void

{

graphicsLayer.clear();

var fset:FeatureSet = event.featureSet;

for each (var graphic:Graphic in fset.features)   //因为每次都选定一个要素,

    {                          //循环遍历只进行一次,因此可以采用下面的方式

     graphic.symbol = symbol;

     graphic.infoWindowRenderer = myInfoWindowRenderer;

    graphicsLayer.add(graphic);   //当然你也可以加载地图的时候便把所有图形要素预加载到

     }                    //graphicsLayer之中,这样提高里查询的效率,但可能会影响加载速度

// fset.features[0].symbol = symbol;

// fset.features[0].infoWindowRenderer = myInfoWindowRenderer;

// graphicsLayer.add(fset.features[0]);

}

最新文章

  1. BZOJ 1251: 序列终结者 [splay]
  2. 安装minicom
  3. codeforces 424D
  4. Linux 命令 - df: 报告磁盘空间的占用情况
  5. careercup-中等难度 17.11
  6. NopCommerce架构分析(转载)
  7. mini-httpd源码分析-mini-httpd.c之外总结
  8. 开源html5_kiwijs_helloworld
  9. stringstream clear()的疑问 - yuanshuilee的日志 - 网易博客
  10. 使用c语言实现linux数据库的操作
  11. python爬取安居客二手房网站数据(转)
  12. idea配置.gitignore后无法起作用
  13. .NET西安社区 [拥抱开源,又见 .NET] 活动简报
  14. Linq中比较字符串类型的日期
  15. java ftp上载下传 遇到的问题
  16. Both - Either - Neither English Grammar
  17. php变量什么情况下加大括号{}
  18. C# 图片反色处理 图片夜间模式
  19. js左侧三级菜单导航实例代码
  20. CentOS7.2安装RabbitMQ笔记

热门文章

  1. Import SHA2 SSL cert to Windows IIS7
  2. SQLServer数据库字典维护方法
  3. 使用eclipse创建java程序可执行jar包
  4. 【转】SVN服务器客户端以及环境的搭建和使用
  5. GL_Oracle Erp月结和年节流程讨论(概念)
  6. [物理学与PDEs]第3章习题参考解答
  7. jsp自定义标签1
  8. 拥抱高效、拥抱 Bugtags 之来自用户的声音
  9. ServiceBroker创建流程
  10. JAVA 中关于String的特性