目 录
1 Flex Viewer 配置文件 ............................................................................................. 1
2 Widget 配置文件 .................................................................................................... 4
3 Widget 与 WidgetTemplate .................................................................................... 7
4 Widget 与 Map 交互 .............................................................................................. 9
4.1 交互方式 1:map 实例 ............................................................................. 10
4.2 交互方式 2:BaseWidget 封装的方法 ..................................................... 12
5 Widget 与 Widget 交互 ........................................................................................ 17
6 Widget 与共享数据 .............................................................................................. 19
7 Widget 与服务器交互 .......................................................................................... 25
8 后记....................................................................................................................... 26
1
Flex Viewer 的设计原则是 SIMPLICITY(简单)。因为简单原则,Flex Viewer 易于
部署、配置和扩展。为了达到“简单”这个目的,Flex Viewer 在设计和实现上未
引入第三方框架。但是从其框架结构上,我们能捕捉到一些 Flex 框架中最佳实践
的影子,比如事件机制就与 PureMVC 中的 Notification 机制类似。
其实,Flex Viewer 本身就可以被认为是一个框架。在这个框架基础上,可以通过
扩展快速实现业务系统原型。本文档将详细介绍如何在“简单”原则下实现自定
义 Widget,以及 Widget 如何与其它模块交互。
说明
本文档使用的代码位于 widgets.FlexViewerInAction 目录下。
1 Flex Viewer 配置文件
Flex Viewer 通过配置文件配置系统数据和功能,配置文件内容如下:
<?xml version="1.0" ?>
<configuration>
<title>ArcGIS Viewer for Flex</title>①
<subtitle>a configurable web mapping application</subtitle>②
<logo>assets/images/logo.png</logo>③
<style>④
<colors>0xFFFFFF,0x333333,0x101010,0x000000,0xFFD700</colors>
<alpha>0.8</alpha>
</style>
<bing
key="Al0VE_jsmagxk4LFghXGlK5JSHfC0tk-eHRubZv_eMYm6wzgQaStYks8g-w
Wcgk3"/>
<!-- UI elements -->
<widget left="10" top="50"
config="widgets/Navigation/NavigationWidget.xml"
url="widgets/Navigation/NavigationWidget.swf"/>⑤
<widget right="-2" bottom="-2"
config="widgets/OverviewMap/OverviewMapWidget.xml"
url="widgets/OverviewMap/OverviewMapWidget.swf"/>⑥
<widget right="20" top="55"
config="widgets/MapSwitcher/MapSwitcherWidget.xml"
2
url="widgets/MapSwitcher/MapSwitcherWidget.swf"/>⑦
<widget left="0" top="0"
config="widgets/HeaderController/HeaderControllerWidget.xml"
url="widgets/HeaderController/HeaderControllerWidget.swf"/>⑧
<map initialextent="-14083000 3139000 -10879000 5458000" top="40"
wraparound180="true">⑨
<basemaps>
<layer label="Streets" type="tiled" visible="true"
alpha="1"
url="http://server.arcgisonline.com/ArcGIS/rest/services/
World_Street_Map/MapServer"/>
<layer label="Aerial" type="tiled" visible="false"
alpha="1"
url="http://server.arcgisonline.com/ArcGIS/rest/services/
World_Imagery/MapServer"/>
<layer label="Topo" type="tiled" visible="false" alpha="1"
url="http://server.arcgisonline.com/ArcGIS/rest/services/
World_Topo_Map/MapServer"/>
</basemaps>
<operationallayers>
<layer label="Boundaries and Places" type="tiled"
visible="false"
url="http://server.arcgisonline.com/ArcGIS/rest/services/
Reference/World_Boundaries_and_Places_Alternate/MapServer
"/>
<layer label="Fires" type="feature" visible="false"
alpha="1"
info="widgets/InfoTemplates/SimpleInfoWinWidget.swf"
infoconfig="widgets/InfoTemplates/IWT_Fires.xml"
url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/se
rvices/Fire/Sheep/FeatureServer/0"/>
</operationallayers>
</map>
<!-- widgets organized into widget containers that manage close/open
etc -->
<!-- supported layout property options:
horizontal(default)|float|vertical|fix-->
<widgetcontainer layout="horizontal">⑩
<widget label="Bookmarks" left="430" top="90"
icon="assets/images/i_bookmark.png"
config="widgets/Bookmark/BookmarkWidget.xml"
url="widgets/Bookmark/BookmarkWidget.swf"/>
<widget label="Find an address" left="100" top="90"
preload="open" icon="assets/images/i_target.png"
config="widgets/Locate/LocateWidget_Bing.xml"
url="widgets/Locate/LocateWidget.swf"/>
<widget label="Louisville Police" left="590" top="280"
3
icon="assets/images/i_police.png"
config="widgets/Query/QueryWidget_Louisville_PoliceStations.x
ml"
url="widgets/Query/QueryWidget.swf"/>
<widget label="Search" left="80" top="280"
icon="assets/images/i_search.png"
config="widgets/Search/SearchWidget_Louisville.xml"
url="widgets/Search/SearchWidget.swf"/>
<widget label="Earthquakes (GeoRSS)" left="410" top="280"
icon="assets/images/i_rss.png"
config="widgets/GeoRSS/GeoRSSWidget.xml"
url="widgets/GeoRSS/GeoRSSWidget.swf"/>
<widget label="Draw and Measure" left="60" top="400"
icon="assets/images/i_draw2.png"
config="widgets/Draw/DrawWidget.xml"
url="widgets/Draw/DrawWidget.swf"/>
<widget label="Print" left="390" top="400"
icon="assets/images/i_print.png"
config="widgets/Print/PrintWidget.xml"
url="widgets/Print/PrintWidget.swf"/>
</widgetcontainer>
</configuration>
① title:Flex Viewer 自带 Banner 实现的标题;
② subtitle:Flex Viewer 自带 Banner 实现的副标题;
③ logo:Flex Viewer 自带 Banner 实现的 Logo 图标;
④ style:用来设置全局的组件样式,具体详见 UIManager 代码;
⑤⑥⑦⑧ UI Elements:指 Control Widget,比如 HeaderControllerWidget、
NavigationWidget 等这些提供系统级别功能的 Widget;
⑨ map:Flex Viewer 用来设置地图属性,包括底图、业务图层;
⑩ widgetcontainer:Business Widget 的容器,用来管理 Business Widget。Business
Widget 指提供业务功能的 Widget。
上述配置文件并未使用到所有可用的属性,比如在 style 中设置 font 属性,map
中设置 fullextent 等,此处不一一列举,详见 ConfigManager 代码。
- 1
- 2
- 3
- 4
- 5
- 6
前往页