南沙政府应急系统之GIS一张图(arcgis api for flex)讲解(四)地图导航控件模块

config.xml文件的配置如下:

<widget left="10" top="50" config="widgets/Navigation/NavigationWidget.xml" url="widgets/Navigation/NavigationWidget.swf" />

源代码目录如下:

地图导航控件模块的源代码原理解析,详细的代码在下载的开源flexviewer自带的:

1.地图缩小

2.地图放大

3.地图漫游

4.地图缩放级别工具

5.前视图,后视图

6.向下平移

7.向右平移

8.向上平移

9.向左平移

10.全图

大概的思路如下:NavigationWidget.xml是导航控件的配置文件,NavigationWidget.mxml是widget,里面引用地图导航控件Navigation.mxml,然后Navigation.mxml控件里面具体定义界面如何布局的,布局看上面的截图,Navigation.mxml里面的布局设计引用了很多其他的皮肤组件组成,用来渲染颜色的,比如,nButtonSkin.mxml、neButtonSkin.mxml等等。

(1)NavigationWidget.xml

<?xml version="1.0" ?>
<configuration>
    <!-- 地图全图属性以及的图标设置 -->
    <panwheel visible="true" fullexticon="assets/images/i_globe.png"  />
    <!-- 地图上视图属性设置-->
    <prevextbutton visible="true"/>
    <!-- 地图下视图属性设置-->
    <nextextbutton visible="true"/>
    <!-- 地图移动属性以及图标的设置-->
    <panbutton visible="true" icon="assets/images/i_pan.png" />
    <!-- 地图放大属性以及图标设置-->
    <zoominbutton visible="true" icon="assets/images/i_zoomin.png" />
    <!-- 地图缩小属性以及图标设置-->
    <zoomoutbutton visible="true" icon="assets/images/i_zoomout.png" />
</configuration>

(2)NavigationWidget.mxml

<?xml version="1.0" encoding="utf-8"?>
<viewer:BaseWidget xmlns:fx="http://ns.adobe.com/mxml/2009"
                   xmlns:s="library://ns.adobe.com/flex/spark"
                   xmlns:viewer="com.esri.viewer.*"
                   xmlns:Navigation="widgets.Navigation.*"
                   initialize="basewidget_initializeHandler(event)"
                   widgetConfigLoaded="init()">
    <fx:Declarations>
		<!--设置动画效果,淡入的透明度-->
        <s:Fade id="rollOverFade" target="{navigation}"/>
		<!--设置动画效果,淡出的透明度-->
        <s:Fade id="rollOutFade" target="{navigation}"/>
    </fx:Declarations>
    <fx:Script>
        <![CDATA[
            import com.esri.viewer.AppEvent;

            import mx.events.FlexEvent;

            private var buttonBarLastSelectedIndex:int;

            protected function basewidget_initializeHandler(event:FlexEvent):void
            {
                AppEvent.addListener(AppEvent.DATA_PUBLISH, sharedDataUpdated);//widget加载初始化时候触发事件
            }

            private function sharedDataUpdated(event:AppEvent):void
            {
                var data:Object = event.data;

                if (data.key == "Edit_Widget") // 在线编辑工具打开状态下,导航的工具下面按钮禁用
                {
                    if (data.collection[0])
                    {
                        map.cursorManager.removeAllCursors();
                        buttonBarLastSelectedIndex = navigation.btnBar.selectedIndex;
                        navigation.btnBar.selectedIndex = 0;
                        navigation.btnBar.enabled = false;
                    }
                    else
                    {
                        navigation.btnBar.selectedIndex = buttonBarLastSelectedIndex;
                        navigation.btnBar.enabled = true;
                    }
                }
            }

            private function init():void
            {
				//下面是widget初始化函数,为了读取配置文件xml数据
                if (configXML)
                {
                    var rollOverAlpha:Number = configXML.rolloveralpha[0] ? parseFloat(configXML.rolloveralpha) : 1;//设置动画效果的透明度
                    var rollOutAlpha:Number = configXML.rolloutalpha[0] ? parseFloat(configXML.rolloutalpha) : 0.39;

                    rollOutFade.alphaTo = rollOutAlpha;
                    rollOverFade.alphaTo = rollOverAlpha;
                    navigation.alpha = rollOutAlpha;//导航控件的透明度
                    navigation.visible = true;//设置导航控件可见

                    navigation.panwheelItem = new NavToolItem("PanWheel", "", [email protected] == ‘true‘);//导航控件的漫游菜单
                    navigation.zoomFullextItem = new NavToolItem([email protected] || getDefaultString("fullExtentLabel"), [email protected], true);//导航控件的全图菜单
                    navigation.pandownItem = new NavToolItem([email protected] || getDefaultString("panDownLabel"), "", true);//导航控件的向下菜单
                    navigation.panleftItem = new NavToolItem([email protected] || getDefaultString("panLeftLabel"), "", true);//导航控件的向左菜单
                    navigation.panrightItem = new NavToolItem([email protected] || getDefaultString("panRightLabel"), "", true);//导航控件的向右菜单
                    navigation.panupItem = new NavToolItem([email protected] || getDefaultString("panUpLabel"), "", true);//导航控件的向上菜单
                    navigation.prevextItem = new NavToolItem([email protected] || getDefaultString("previousExtentLabel"), "", [email protected] == ‘true‘);//导航控件的前视图菜单
                    navigation.nextextItem = new NavToolItem([email protected] || getDefaultString("nextExtentLabel"), "", [email protected] == ‘true‘);//导航控件的后视图菜单
                    navigation.panItem = new NavToolItem([email protected] || getDefaultString("panLabel"), [email protected], [email protected] == ‘true‘);
                    navigation.zoominItem = new NavToolItem([email protected] || getDefaultString("zoomInLabel"), [email protected], [email protected] == ‘true‘);//导航控件的放大菜单
                    navigation.zoomoutItem = new NavToolItem([email protected] || getDefaultString("zoomOutLabel"), [email protected], [email protected] == ‘true‘);//导航控件的缩小菜单
                    navigation.initButtonBar();//加载导航控件的菜单
                }
            }
        ]]>
    </fx:Script>
	<!--引用自定义地图导航控件-->
    <Navigation:Navigation id="navigation"
                           focusIn="rollOverFade.play()"
                           focusOut="rollOutFade.play()"
                           includeInLayout="false"
                           map="{map}"
                           rollOut="rollOutFade.play()"
                           rollOver="rollOverFade.play()"
                           visible="false"/>
</viewer:BaseWidget>

(3)Navigation.mxml

<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:s="library://ns.adobe.com/flex/spark"
         xmlns:fx="http://ns.adobe.com/mxml/2009"
         xmlns:esri="http://www.esri.com/2008/ags"
         xmlns:Navigation="widgets.Navigation.*">

    <fx:Script>
        <![CDATA[
            import com.esri.ags.Map;
            import com.esri.viewer.AppEvent;
            import com.esri.viewer.utils.LocalizationUtil;

            import mx.events.FlexEvent;

            import spark.events.IndexChangeEvent;

            [Bindable]
            public var map:Map;//地图对象

            [Bindable]
            public var panwheelItem:NavToolItem;

            [Bindable]
            public var zoomFullextItem:NavToolItem;//全图菜单

            [Bindable]
            public var panupItem:NavToolItem;//向上平移菜单
            [Bindable]
            public var pandownItem:NavToolItem;//向下平移菜单

            [Bindable]
            public var panleftItem:NavToolItem;//向左菜单

            [Bindable]
            public var panrightItem:NavToolItem;//向右菜单

            [Bindable]
            public var prevextItem:NavToolItem;//前视图菜单

            [Bindable]
            public var nextextItem:NavToolItem;//后视图菜单

            [Bindable]
            public var zoominItem:NavToolItem;//放大菜单

            [Bindable]
            public var zoomoutItem:NavToolItem;//缩小菜单

            [Bindable]
            public var panItem:NavToolItem;//漫游菜单

			/*
			 * 导航控件菜单变化函数
			*/
            protected function buttonbar1_changeHandler(event:IndexChangeEvent):void
            {
                doNavAction(event.currentTarget.dataProvider[event.newIndex].action,
                            event.currentTarget.dataProvider[event.newIndex].label);
            }

			/*
			* 导航控件菜单切换函数
			*/
            protected function buttonbar1_valueCommitHandler(event:FlexEvent):void
            {
                if (event.currentTarget.selectedIndex != -1)
                {
                    doNavAction(event.currentTarget.dataProvider[event.currentTarget.selectedIndex].action,
                                event.currentTarget.dataProvider[event.currentTarget.selectedIndex].label);
                }
            }

            private function doNavAction(action:String, label:String):void
            {
                var data:Object =
                    {
                        tool: action,
                        status: label
                }
                AppEvent.dispatch(AppEvent.SET_MAP_NAVIGATION, data);//调用flexviewer封装好的地图导航接口
            }

			/*
			* 导航控件菜单初始化函数
			*/
            public function initButtonBar():void
            {
                var navAC:ArrayCollection = new ArrayCollection();

                if (panItem.toolVisible == true)
                {
                    navAC.addItem({ label: panItem.toolName, action: "pan", imageIcon: panItem.toolIcon });
                }

                if (zoominItem.toolVisible == true)
                {
                    navAC.addItem({ label: zoominItem.toolName, action: "zoomin", imageIcon: zoominItem.toolIcon });
                }

                if (zoomoutItem.toolVisible == true)
                {
                    navAC.addItem({ label: zoomoutItem.toolName, action: "zoomout", imageIcon: zoomoutItem.toolIcon });
                }

                if (zoominItem.toolVisible == false && zoomoutItem.toolVisible == false && panItem.toolVisible == false)
                {
                    btnBar.visible = false;
                }

                btnBar.dataProvider = navAC;
            }
        ]]>
    </fx:Script>
    <s:layout>
        <s:VerticalLayout gap="3" horizontalAlign="center"/>
    </s:layout>
    <s:filters>
        <s:DropShadowFilter alpha="0.5"
                            blurX="10"
                            blurY="10"/>
    </s:filters>
	<!--控件的界面布局-->
    <s:Group enabled="{map.loaded}"
             includeInLayout="{panwheelItem.toolVisible}"
             layoutDirection="ltr"
             visible="{panwheelItem.toolVisible}">
        <s:Button id="nwButton"
                  x="2" y="2"
                  click="map.panUpperLeft()"
                  skinClass="widgets.Navigation.nwButtonSkin"/>
		<!--向左平移菜单的布局-->
        <s:Button id="wButton"
                  x="0" y="19"
                  click="map.panLeft()"
                  skinClass="widgets.Navigation.wButtonSkin"
                  toolTip="{panleftItem.toolName}"/>
        <s:Button id="swButton"
                  x="2" y="36"
                  click="map.panLowerLeft()"
                  skinClass="widgets.Navigation.swButtonSkin"/>
		<!--向下平移菜单的布局-->
        <s:Button id="sButton"
                  x="18" y="43"
                  click="map.panDown()"
                  skinClass="widgets.Navigation.sButtonSkin"
                  toolTip="{pandownItem.toolName}"/>
        <s:Button id="seButton"
                  x="35" y="35"
                  click="map.panLowerRight()"
                  skinClass="widgets.Navigation.seButtonSkin"/>
		<!--向右平移菜单的布局-->
        <s:Button id="eButton"
                  x="43" y="18"
                  click="map.panRight()"
                  skinClass="widgets.Navigation.eButtonSkin"
                  toolTip="{panrightItem.toolName}"/>
        <s:Button id="neButton"
                  x="35" y="2"
                  click="map.panUpperRight()"
                  skinClass="widgets.Navigation.neButtonSkin"/>
		<!--向上平移菜单的布局-->
        <s:Button id="nButton"
                  x="18" y="0"
                  click="map.panUp()"
                  skinClass="widgets.Navigation.nButtonSkin"
                  toolTip="{panupItem.toolName}"/>
		<!--全图菜单的布局-->
        <Navigation:IconButton id="innerButton"
                               x="18" y="18"
                               click="doNavAction(‘zoomfull‘, zoomFullextItem.toolName)"
                               iconUp="{zoomFullextItem.toolIcon}"
                               skinClass="widgets.Navigation.InnerButtonSkin"
                               toolTip="{zoomFullextItem.toolName}"
                               visible="{zoomFullextItem.toolVisible}"/>
    </s:Group>
	<!--前视图后视图菜单的布局-->
    <s:HGroup enabled="{map.loaded}" gap="0">
        <s:Button id="prevExt"
                  x="0" y="19"
                  click="doNavAction(‘zoomprevious‘, prevextItem.toolName)"
                  includeInLayout="{prevextItem.toolVisible}"
                  skinClass="widgets.Navigation.wButtonSkin"
                  toolTip="{prevextItem.toolName}"
                  visible="{prevextItem.toolVisible}"/>
        <s:Button id="nextExt"
                  x="0" y="19"
                  click="doNavAction(‘zoomnext‘, nextextItem.toolName)"
                  includeInLayout="{nextextItem.toolVisible}"
                  skinClass="widgets.Navigation.eButtonSkin"
                  toolTip="{nextextItem.toolName}"
                  visible="{nextextItem.toolVisible}"/>
    </s:HGroup>
	<!--引用arcgis api导航控件-->
    <esri:Navigation top="0"
                     map="{map}"
                     skinClass="widgets.Navigation.NavigationSkin"/>
    <s:VGroup enabled="{map.loaded}" paddingTop="3">
        <s:ButtonBar id="btnBar"
                     change="buttonbar1_changeHandler(event)"
                     requireSelection="true"
                     selectedIndex="0"
                     skinClass="widgets.Navigation.VerticalButtonBarSkin"
                     valueCommit="buttonbar1_valueCommitHandler(event)">
            <s:layout>
                <s:VerticalLayout gap="0"/>
            </s:layout>
            <s:dataProvider>
                <s:ArrayCollection>
					<!--漫游菜单的布局-->
                    <fx:Object action="pan"
                               imageIcon="assets/images/i_pan.png"
                               label="{LocalizationUtil.getDefaultString(‘panLabel‘)}"/>
					<!--放大菜单的布局-->
                    <fx:Object action="zoomin"
                               imageIcon="assets/images/i_zoomin.png"
                               label="{LocalizationUtil.getDefaultString(‘zoomInLabel‘)}"
                               visible="false"/>
					<!--缩小菜单的布局-->
                    <fx:Object action="zoomout"
                               imageIcon="assets/images/i_zoomout.png"
                               label="{LocalizationUtil.getDefaultString(‘zoomOutLabel‘)}"/>
                </s:ArrayCollection>
            </s:dataProvider>
        </s:ButtonBar>
    </s:VGroup>
</s:Group>

以上就是核心的三个文件,其他的皮肤组件可以再flexviewer框架详细的看看源代码,这里知道导航控件的思路原理就好了。

备注:

GIS技术交流QQ群:432512093

时间: 2024-10-14 16:13:01

南沙政府应急系统之GIS一张图(arcgis api for flex)讲解(四)地图导航控件模块的相关文章

南沙政府应急系统之GIS一张图(arcgis api for flex)讲解(一)GIS一张图的系统开发环境以及flexviewer框架

系统的GIS功能实现是基于arcgis api for flex,首先附上系统的主界面图,接下来的是对主界面的模块功能详细讲解: 一.GIS环境软件安装 (1)arcgis desktop的安装,要是不想对地图数据进行样式配置或者数据加工的话,这步可以跳过不用安装,详细的安装步骤见这里: (2)arcgis server的安装,这个是必须的,用来发布webgis的地图服务,比如地图基础服务,路径分析的网络服务,地理编码服务等等,详细的安装步骤见这里: (3)arcsde直连创建地理企业数据库,为

南沙政府应急系统之GIS一张图(arcgis api for flex)讲解(二)鹰眼模块

讲解GIS功能模块实现之前,先大概说一下flexviewer的核心配置文件config.xml,系统额GIS功能widget菜单布局.系统的样式.地图资源等等都是在这里配置的,这里对flexviewer不熟悉的朋友,要先去flexviewer官网了解或者网上的其他资源了解才行; 鹰眼模块在config.xml文件的配置如下: <widget right="0" bottom="0" config="widgets/OverviewMap/Overvi

南沙政府应急系统之GIS一张图(arcgis api for flex)讲解(六)地图搜索模块

config.xml文件的配置如下: 1 <widget label="地图搜索" icon="assets/images/emergency_resource_over.png" 2 config="widgets/Search/SearchWidget.xml" url="widgets/Search/SearchWidget.swf" /> 源代码目录如下: 地图搜索模块的源代码原理解析,详细的代码在下载的开

南沙政府应急系统之GIS一张图(arcgis api for flex)讲解(十三)台风模块

config.xml文件的配置如下: <widget label="台风" icon="assets/images/typhoon.png" config="" url="widgets/ActualWeather/TyphoonWarningWidget.swf"/> 源代码目录如下: 界面效果: 大概的思路如下:从后台数据库获取台风的信息列表,展示在界面的表格里面:点击某条台风选项时候,会动态的在地图上展示台风

南沙政府应急系统之GIS一张图(arcgis api for flex)讲解(三)显示地图坐标系模块

config.xml文件的配置如下: 1 2 <widget left="3" bottom="3" config="widgets/Coordinate/CoordinateWidget.xml" url="widgets/Coordinate/CoordinateWidget.swf" /> 源代码目录如下: 地图坐标系模块的源代码原理解析,详细的代码在下载的开源flexviewer自带的: (1)Coordi

南沙政府应急系统之GIS一张图(arcgis api for flex)讲解(五)地图切换以及图层显示模块

config.xml文件的配置如下: <widget right="20" top="55" config="widgets/MapSwitcher/MapSwitcherWidget.xml" url="widgets/MapSwitcher/MapSwitcherWidget.swf" /> 源代码目录如下: 该模块的源代码原理解析,详细的代码在下载的开源flexviewer自带的: 大概的思路如下:MapSw

南沙政府应急系统之GIS一张图(arcgis api for flex)讲解(九)地图定位模块

config.xml文件的配置如下: <widget label="地图定位" config="widgets/esri/Location/LocationWidget.xml" icon="assets/images/ditudingwei.png" url="widgets/esri/Location/LocationWidget.swf" /> 源代码目录如下: 界面效果: 大概的思路如下:定位有两种方式:1

南沙政府应急系统之GIS一张图(arcgis api for flex)讲解(七)地图打印模块

config.xml文件的配置如下: 1 <widget label="地图打印" 2 icon="assets/images/map_print.png" config="widgets/Print/PrintWidget.xml" 3 url="widgets/Print/PrintWidget.swf" /> 源代码目录如下: 模块的源代码原理解析,详细的代码在下载的开源flexviewer自带的: 大概的思

天津政府应急系统之GIS一张图(arcgis api for flex)解说(二)鹰眼模块

解说GIS功能模块实现之前,先大概说一下flexviewer的核心配置文件config.xml,系统额GIS功能widget菜单布局.系统的样式.地图资源等等都是在这里配置的,这里对flexviewer不熟悉的朋友,要先去flexviewer官网了解或者网上的其它资源了解才行; 鹰眼模块在config.xml文件的配置例如以下: <widget right="0" bottom="0" config="widgets/OverviewMap/Over