config.xml文件的配置例如以下:

1
2
<widget
left=
"3" bottom="3"
config="widgets/Coordinate/CoordinateWidget.xml" url="widgets/Coordinate/CoordinateWidget.swf" />

源码文件夹例如以下:

地图坐标系模块的源码原理解析,具体的代码在下载的开源flexviewer自带的:

(1)CoordinateWidget.xml

  1. 1 <?
  2.  
  3. xml version="1.0" ?>
  4. 2 <configuration label="Coordinates (default)">
  5. 3 <!-- geo, dms, mercator 主要是坐标输出单位。默认的是经纬度 -->
  6. 4 <outputunit>geo</outputunit>
  7. 5 </configuration>

(2)CoordinateWidget.mxml

  1. 1 <?xml version="1.0" encoding="utf-8"?>
  2. 19 <viewer:BaseWidget xmlns:fx="http://ns.adobe.com/mxml/2009"
  3. 20 xmlns:s="library://ns.adobe.com/flex/spark"
  4. 21 xmlns:mx="library://ns.adobe.com/flex/mx"
  5. 22 xmlns:viewer="com.esri.viewer.*"
  6. 23 layout="horizontal"
  7. 24 widgetConfigLoaded="basewidget_widgetConfigLoadedHandler(event)">
  8. 25 <fx:Script>
  9. 26 <![CDATA[
  10. 27 import com.esri.ags.events.MapEvent;
  11. 28 import com.esri.ags.geometry.MapPoint;
  12. 29 import com.esri.ags.utils.WebMercatorUtil;
  13. 30
  14. 31 import mx.formatters.NumberBaseRoundType;
  15. 32 import mx.utils.StringUtil;
  16. 33
  17. 34 private var m_template:String;
  18. 35 private var m_func:Function = substitute;
  19. 36
  20. 37 protected function basewidget_widgetConfigLoadedHandler(event:Event):void
  21. 38 {
  22. 39 if (configXML)
  23. 40 {
  24. //以下是读取CoordinateWidget.xml配置文件的资源。要是配置了的话
  25. 41 const decimalSeparator:String = configXML.numberformatter.@decimalseparator;
  26. 42 numberFormatter.decimalSeparatorTo = decimalSeparator ? decimalSeparator : ".";
  27. 43 const thousandsSeparator:String = configXML.numberformatter.@thousandsseparator;
  28. 44 numberFormatter.thousandsSeparatorTo = thousandsSeparator ?
  29.  
  30. thousandsSeparator : ",";
  31. 45 numberFormatter.useThousandsSeparator = configXML.numberformatter.@usethousandsseparator == "true";
  32. 46 numberFormatter.precision = parseFloat(configXML.numberformatter.@precision || "-1");
  33. 47 const rounding:String = configXML.numberformatter.@rounding;
  34. 48 numberFormatter.rounding = rounding ? rounding : NumberBaseRoundType.NONE;
  35. 49 //获取设置坐标显示的字体和颜色样式等
  36. 50 const color:String = configXML.labelstyle.@color[0] || configXML.label.@color[0];
  37. 51 coords.setStyle("color", toNumber(color ? color : "0x000000"));
  38. 52 const fontFamily:String = configXML.labelstyle.@fontfamily[0] || configXML.label.@fontfamily[0];
  39. 53 coords.setStyle("fontFamily", fontFamily ? fontFamily : "Verdana");
  40. 54 const fontSize:String = configXML.labelstyle.@fontsize[0] || configXML.label.@fontsize[0];
  41. 55 coords.setStyle("fontSize", parseInt(fontSize ?
  42.  
  43. fontSize : "9"));
  44. 56 const fontWeight:String = configXML.labelstyle.@fontweight[0] || configXML.label.@fontweight[0];
  45. 57 coords.setStyle("fontWeight", fontWeight ?
  46.  
  47. fontWeight : "bold");
  48. 58
  49. 59 // If no template specified, show them with a space in between (except for special case below)
  50. 60 m_template = configXML.labels.template[0] || configXML.label.@template[0] || "{0} {1}";
  51. 61
  52. 62 if (map.loaded)
  53. 63 {
  54. 64 map_loadHandler(null);
  55. 65 }
  56. 66 else
  57. 67 {
  58. 68 map.addEventListener(MapEvent.LOAD, map_loadHandler);//载入地图
  59. 69 }
  60. 70 }
  61. 71
  62. 72 function map_loadHandler(event:MapEvent):void
  63. 73 {
  64. 74 map.removeEventListener(MapEvent.LOAD, map_loadHandler);
  65. 75 const wkid:int = map.spatialReference.wkid; //获取地图的空间坐标參考系
  66. 76 m_func = substitute;
  67. 77 const outputUnit:String = configXML.outputunit;//获取地图的坐标显示单位,从配置文件获取
  68. 78 if (outputUnit === "mercator")//推断地图的坐标体系。墨卡托情况下运行
  69. 79 {
  70. 80 if (wkid === 4326 || wkid === 4269 || wkid === 4267)
  71. 81 {
  72. 82 m_func = geographicToMercator;//调用地理坐标系转换墨卡托坐标系
  73. 83 }
  74. 84 }
  75. 85 else if (outputUnit === "geo")//地理坐标系情况下运行
  76. 86 {
  77. 87 if (wkid === 102100 || wkid === 102113 || wkid === 3857)
  78. 88 {
  79. 89 m_func = mercatorToGeographic;//调用墨卡托坐标系转换地理坐标系
  80. 90 // special default for geographic outputs
  81. 91 m_template = configXML.labels.template[0] || configXML.label.@template[0] || getDefaultString("latitudeLabel") + ":{1} " + getDefaultString("longitudeLabel") + ":{0}";//设置坐标显示的文字,比方经度,纬度
  82. 92 numberFormatter.precision = parseFloat(configXML.numberformatter.@precision || "6");//设置坐标显示的位数
  83. 93 }
  84. 94 else if (wkid === 4326 || wkid === 4269 || wkid === 4267)
  85. 95 {
  86. 96 // special default for geographic outputs
  87. 97 m_template = configXML.labels.template[0] || configXML.label.@template[0] || getDefaultString("latitudeLabel") + ":{1} " + getDefaultString("longitudeLabel") + ":{0}";
  88. 98 numberFormatter.precision = parseFloat(configXML.numberformatter.@precision || "6");
  89. 99 }
  90. 100 }
  91. 101 else if (outputUnit === "dms")//经纬度显示单位为度分秒形式情况下运行
  92. 102 {
  93. 103 if (wkid === 102100 || wkid === 102113 || wkid === 3857)
  94. 104 {
  95. 105 m_func = mercatorToDMS;
  96. 106 }
  97. 107 else if (wkid === 4326 || wkid === 4269 || wkid === 4267)
  98. 108 {
  99. 109 m_func = geographicToDMS;
  100. 110 }
  101. 111 }
  102. 112 map.addEventListener(MouseEvent.MOUSE_MOVE, map_mouseMoveHandler);//监听地图鼠标移动事件,用来获取地图经纬度的
  103. 113 }
  104. 114 }
  105. 115
  106. 116 private function toNumber(value:String):int//转换单位计算
  107. 117 {
  108. 118 if (value.substr(0, 2) == "0x")
  109. 119 {
  110. 120 return parseInt(value, 16);
  111. 121 }
  112. 122 return parseInt(value, 10);
  113. 123 }
  114. 124
  115. 125 private function mercatorToGeographic(web:MapPoint):String//墨卡托转换地理坐标系的函数
  116. 126 {
  117. 127 const geo:MapPoint = WebMercatorUtil.webMercatorToGeographic(web) as MapPoint;//arcgis api封装好的转换函数
  118. 128 return StringUtil.substitute(m_template,
  119. 129 numberFormatter.format(geo.x),
  120. 130 numberFormatter.format(geo.y));
  121. 131 }
  122. 132
  123. 133 private function mercatorToDMS(web:MapPoint):String//墨卡托转换经纬度度分秒形式的函数
  124. 134 {
  125. 135 const geo:MapPoint = WebMercatorUtil.webMercatorToGeographic(web) as MapPoint;
  126. 136 return StringUtil.substitute(m_template, DegToDMS.format(geo.x, DegToDMS.LON), DegToDMS.format(geo.y, DegToDMS.LAT));
  127. 137 }
  128. 138
  129. 139 private function geographicToMercator(geo:MapPoint):String//地理坐标系转换墨卡托的函数
  130. 140 {
  131. 141 const web:MapPoint = WebMercatorUtil.geographicToWebMercator(geo) as MapPoint;
  132. 142 return StringUtil.substitute(m_template,
  133. 143 numberFormatter.format(web.x),
  134. 144 numberFormatter.format(web.y));
  135. 145 }
  136. 146
  137. 147 private function substitute(mapPoint:MapPoint):String
  138. 148 {
  139. 149 return StringUtil.substitute(m_template,
  140. 150 numberFormatter.format(mapPoint.x),
  141. 151 numberFormatter.format(mapPoint.y));
  142. 152 }
  143. 153
  144. 154 private function geographicToDMS(mapPoint:MapPoint):String
  145. 155 {
  146. 156 const x:String = DegToDMS.format(mapPoint.x, DegToDMS.LON);
  147. 157 const y:String = DegToDMS.format(mapPoint.y, DegToDMS.LAT);
  148. 158 return StringUtil.substitute(m_template, x, y);
  149. 159 }
  150. 160
  151. 161 private function map_mouseMoveHandler(event:MouseEvent):void
  152. 162 {
  153. 163 const mapPoint:MapPoint = map.toMapFromStage(event.stageX, event.stageY);//获取鼠标移动的地图经纬度
  154. 164 coords.text = m_func(mapPoint);
  155. 165 }
  156. 166 ]]>
  157. 167 </fx:Script>
  158. 168
  159. 169 <fx:Declarations>
  160. 170 <mx:NumberFormatter id="numberFormatter"/>
  161. 171 </fx:Declarations>
  162. 172 <viewer:filters>
  163. 173 <mx:GlowFilter alpha="1"
  164. 174 blurX="3"
  165. 175 blurY="3"
  166. 176 color="0xFFFFFF"
  167. 177 strength="7"/>
  168. 178 </viewer:filters>
  169. 179 <s:Label id="coords" color="0x000000"/>//显示经纬度的位置。显示label
  170. 180 </viewer:BaseWidget>

(3)DegToDMS.as

  1. 1 package widgets.Coordinate
  2. 2 {
  3. 3
  4. 4 /**
  5. 5 * Utility class to pretty print decimal degree numbers.
  6. 6 * @private
  7. 7 */
  8. 8 public final class DegToDMS
  9. 9 {
  10. 10 // Constants to define the format.
  11. 11 public static const LAT:String = "lat";
  12. 12
  13. 13 public static const LON:String = "lon";
  14. 14
  15. 15 /**
  16. 16 * Utility function to format a decimal degree number into a pretty string with degrees, minutes and seconds.
  17. 17 * @param decDeg the decimal degree number.
  18. 18 * @param decDir "lat" for a latitude number, "lon" for a longitude value.
  19. 19 * @return A pretty print string with degrees, minutes and seconds.
  20. 20 */
  21. 21 public static function format(decDeg:Number, decDir:String):String//这个函数主要是用来把经纬度转换度分秒的形式来展示经纬度,比方113度23分23秒等等
  22. 22 {
  23. 23 var d:Number = Math.abs(decDeg);
  24. 24 var deg:Number = Math.floor(d);
  25. 25 d = d - deg;
  26. 26 var min:Number = Math.floor(d * 60);
  27. 27 var av:Number = d - min / 60;
  28. 28 var sec:Number = Math.floor(av * 60 * 60);
  29. 29 if (sec == 60)
  30. 30 {
  31. 31 min++;
  32. 32 sec = 0;
  33. 33 }
  34. 34 if (min == 60)
  35. 35 {
  36. 36 deg++;
  37. 37 min = 0;
  38. 38 }
  39. 39 var smin:String = min < 10 ? "0" + min + "' " : min + "' ";
  40. 40 var ssec:String = sec < 10 ?
  41.  
  42. "0" + sec + "\" " : sec + "\" ";
  43. 41 var sdir:String = (decDir == LAT) ? (decDeg < 0 ? "S" : "N") : (decDeg < 0 ?
  44.  
  45. "W" : "E");
  46. 42 return deg + "\xB0 " + smin + ssec + sdir;
  47. 43 }
  48. 44 }
  49. 45
  50. 46 }

备注:

GIS作品:百度搜索:GIS之家(https://shop116521643.taobao.com/shop/view_shop.htm);

QQ兴趣部落GIS技术交流:gis之家(http://buluo.qq.com/p/barindex.html?bid=327395);

GIS毕业设计&项目承接群:238339408;

GIS技术交流群:432512093

天津政府应急系统之GIS一张图(arcgis api for flex)解说(三)显示地图坐标系模块的更多相关文章

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

    系统的GIS功能实现是基于arcgis api for flex,首先附上系统的主界面图,接下来的是对主界面的模块功能详细讲解: 一.GIS环境软件安装 (1)arcgis desktop的安装,要是 ...

  2. 天津政府应急系统之GIS一张图(arcgis api for flex)讲解(十)态势标绘模块

    config.xml文件的配置如下: <widget label="态势标绘" icon="assets/images/impact_area_over.png&q ...

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

    config.xml文件的配置如下: <widget left="3" bottom="3" config="widgets/Coordinat ...

  4. 天津政府应急系统之GIS一张图(arcgis api for flex)讲解(八)资源搜索模块

    config.xml文件的配置如下: <widget label="资源搜索" icon="assets/images/public_impact_over.png ...

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

    讲解GIS功能模块实现之前,先大概说一下flexviewer的核心配置文件config.xml,系统额GIS功能widget菜单布局.系统的样式.地图资源等等都是在这里配置的,这里对flexviewe ...

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

    解说GIS功能模块实现之前,先大概说一下flexviewer的核心配置文件config.xml,系统额GIS功能widget菜单布局.系统的样式.地图资源等等都是在这里配置的,这里对flexviewe ...

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

    config.xml文件的配置如下: <widget label="台风" icon="assets/images/typhoon.png" config ...

  8. 天津政府应急系统之GIS一张图(arcgis api for flex)讲解(十一)路径导航模块

    config.xml文件的配置如下: <widget label="路径导航" icon="assets/images/lujingdaohang.png" ...

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

    config.xml文件的配置如下: <widget label="地图搜索" icon="assets/images/emergency_resource_ove ...

随机推荐

  1. JAVAWEB开发环境搭建,附JDK开发环境一键配置批处理bat

    JDK配置: CLASSPATH: .;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar   JAVA_HOME: C:\Program Files\J ...

  2. React + Node 单页应用「二」OAuth 2.0 授权认证 & GitHub 授权实践

    关于项目 项目地址 预览地址 记录最近做的一个 demo,前端使用 React,用 React Router 实现前端路由,Koa 2 搭建 API Server, 最后通过 Nginx 做请求转发. ...

  3. 基于gitHub+hexo搭建的个人博客

    文章导航 前期准备 安装hexo 修改hexo主题 自定义主题 部署本地文件到github查看 我的第一篇博客 前期准备 下载安装git命令行工具.node及npm环境 注册自己的GitHub账号 安 ...

  4. 【深度学习笔记】(一)TensorFlow安装及环境搭建

    在学习了一段时间台大李宏毅关于deep learning的课程,以及一些其他机器学习的书之后,终于打算开始动手进行一些实践了. 感觉保完研之后散养状态下,学习效率太低了,于是便想白天学习,晚上对白天学 ...

  5. spring AOP 和自定义注解进行身份验证

    一个SSH的项目(springmvc+hibernate),需要提供接口给app使用.首先考虑的就是权限问题,app要遵循极简模式,部分内容无需验证,用过滤器不能解决某些无需验证的方法 所以最终选择用 ...

  6. 项目实战3—Keepalived 实现高可用

    实现基于Keepalived高可用集群网站架构 环境:随着业务的发展,网站的访问量越来越大,网站访问量已经从原来的1000QPS,变为3000QPS,目前业务已经通过集群LVS架构可做到随时拓展,后端 ...

  7. 主机和VMware中的Linux如实现共享文件夹

    当我在网上查了几小时的挂载文件夹方法后发现,VMware中的Linux的挂载和双系统的挂载不同 最终目的就是在/mnt目录下有个hgfs的文件夹 效果图: 首先打开VMware中的Linux系统 具体 ...

  8. Python之getopt模块

    1.getopt——C风格命令行解析 http://docs.python.org/2.7/library/getopt.html#module-getopt getopt.getopt(args, ...

  9. Winform界面中主从表编辑界面的快速处理

    在Winform开发中,我们往往除了常规的单表信息录入外,有时候设计到多个主从表的数据显示.编辑等界面,单表的信息一般就是控件和对象实体一一对应,然后调用API保存即可,主从表就需要另外特殊处理,本随 ...

  10. canvas图表(2) - 折线图

    原文地址:canvas图表(2) - 折线图 话说这天气一冷啊, 就患懒癌, 就不想码代码, 就想着在床上舒舒服服看视频. 那顺便就看blender视频, 学习下3D建模, 如果学会了建3D模型, 那 ...