toolJumpToLatlng.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. define(['html!templates/tools/toolJumpToLatlng',
  2. 'modDir/service/poiSearch',
  3. 'css!styles/tools/toolPublicPopup'],
  4. function (tplLayout, poiSearchF) {
  5. /**
  6. * 模块状态,用于存储模块的状态 例如:收起,关闭
  7. * @type {Object}
  8. */
  9. var status = {
  10. initialized: false//是否初始化
  11. };
  12. /**
  13. * 模块数据 用于数据存储和外部调用
  14. * @type {Object}
  15. * 数据存放
  16. */
  17. var modValue = {
  18. InputType: 1,//查询方式
  19. jumpLatLng: {//查询默认参数
  20. lat: 0,
  21. lng: 0,
  22. zoom: 1
  23. },
  24. marker: null,//图标
  25. jumpObj: {}//收藏数据
  26. };
  27. /**
  28. * 初始化并订阅事件
  29. * @return {[type]} [description]
  30. */
  31. function init() {
  32. if (!status.initialized) {
  33. setLayout();
  34. bindEvent();
  35. subscribe();
  36. status.initialized = true;
  37. $("#jumpToLatlngForm .input").val('0');
  38. $("#jumpToLatlngModal #lngD").val("");
  39. }
  40. if ($(".tools-painting").hasClass('cur')) {
  41. // var r = confirm("是否离开标注并保存当前标注?");
  42. // if(r){
  43. // $(".tsAct li.save").click();
  44. // $(".modal .modal-header .close,#userDrawAddModal .form .sure").bind("click",function(){
  45. afac()
  46. // })
  47. // }
  48. } else {
  49. afac()
  50. }
  51. };
  52. function afac() {
  53. $('#jumpToZoom').val(map23DData.view.zoom);
  54. if (map23DData.display.map2D) {
  55. $('#jumpToLatlngModal').removeClass('class3d');
  56. } else if (map23DData.display.map3D) {
  57. $('#jumpToLatlngModal').addClass('class3d');
  58. }
  59. $("#jumpToLatlngModal").show();
  60. $("#jumpToLatlngModal #lngD").focus();
  61. ONEMAP.C.publisher.publish({
  62. modName: 'toolJumpToLatlng'
  63. }, 'tools:active');
  64. }
  65. function setLayout() {
  66. $('body').append(tplLayout);
  67. //拖拽
  68. $("#jumpToLatlngModal .popup-ct").dragmove($('#jumpToLatlngModal'));
  69. };
  70. function change23D(options) {
  71. if (options == '2d') {
  72. $('#jumpToLatlngModal').removeClass('class3d');
  73. } else {
  74. $('#jumpToLatlngModal').addClass('class3d');
  75. }
  76. }
  77. /**
  78. * 注册监听
  79. * @type {Function}
  80. */
  81. function subscribe() {
  82. ONEMAP.C.publisher.subscribe(change23D, 'change23D');
  83. ONEMAP.C.publisher.subscribe(clearMarker, 'cleanMap');
  84. ONEMAP.C.publisher.subscribe(remove, 'tools:active');
  85. };
  86. /**
  87. * 关闭模块
  88. * @return {[type]} [description]
  89. */
  90. function remove(options) {
  91. if (options.modName != 'toolJumpToLatlng') {
  92. removeCurClass();
  93. } else {
  94. if ($('.tools-toolJumpToLatlng').hasClass('cur')) {
  95. removeCurClass();
  96. } else {
  97. $('.tools-toolJumpToLatlng').addClass('cur');
  98. }
  99. }
  100. }
  101. /**
  102. * 工具栏状态控制
  103. */
  104. function removeCurClass(options) {
  105. $('#toolsBar .tools-toolJumpToLatlng').removeClass('cur');
  106. $('#topBar .tools-toolJumpToLatlng').removeClass('cur');
  107. $("#jumpToLatlngModal").hide();
  108. };
  109. /**
  110. * 获取并计算经纬度
  111. * @private
  112. */
  113. function getLatLng() {
  114. if (modValue.InputType === 1) {
  115. modValue.jumpLatLng.lng = L.Util.HMStoLatLng(
  116. $('#jumpToLatlngForm dt .lng').attr('v'),
  117. ($('#lngD').val() ? $('#lngD').val() : 0),
  118. ($('#lngF').val() ? $('#lngF').val() : 0),
  119. ($('#lngM').val() ? $('#lngM').val() : 0)
  120. );
  121. modValue.jumpLatLng.lat = L.Util.HMStoLatLng(
  122. $('#jumpToLatlngForm dt .lat').attr('v'),
  123. ($('#latD').val() ? $('#latD').val() : 0),
  124. ($('#latF').val() ? $('#latF').val() : 0),
  125. ($('#latM').val() ? $('#latM').val() : 0)
  126. );
  127. } else if (modValue.InputType === 2) {
  128. var lng = parseFloat($('#jumpToLngInput').val() ? $('#jumpToLngInput').val() : 0);
  129. var lat = parseFloat($('#jumpToLatInput').val() ? $('#jumpToLatInput').val() : 0);
  130. if ($('#jumpToLatlngForm dt .lat').attr('v') === 's') {
  131. lat = -1 * lat;
  132. }
  133. if ($('#jumpToLatlngForm dt .lng').attr('v') === 'w') {
  134. lng = -1 * lng;
  135. }
  136. modValue.jumpLatLng.lat = lat;
  137. modValue.jumpLatLng.lng = lng;
  138. }
  139. modValue.jumpLatLng.zoom = parseInt($('#jumpToZoom').val());
  140. jumpTo()
  141. };
  142. /**
  143. * 清除marker
  144. * @return {[type]} [description]
  145. */
  146. function clearMarker() {
  147. var key = modValue.marker;
  148. map23DControl.marker({
  149. action: 'remove',
  150. guid: key
  151. })
  152. }
  153. /**
  154. * 获取输入信息并跳转到指定的坐标
  155. * @type {Function}
  156. * @private
  157. */
  158. function jumpTo() {
  159. if (!L.Util.verifyLatLng(modValue.jumpLatLng.lat, modValue.jumpLatLng.lng)) {
  160. alert('请正确输入经纬范围(经度0-180、纬度0-90)');
  161. return false;
  162. }
  163. clearMarker();
  164. if (map23DData.display.map2D) {
  165. map2DViewer.setView({
  166. center: {
  167. lat: modValue.jumpLatLng.lat,
  168. lng: modValue.jumpLatLng.lng
  169. },
  170. zoom: modValue.jumpLatLng.zoom
  171. });
  172. } else if (map23DData.display.map3D) {
  173. map3DViewer.setView({
  174. center: {
  175. lat: modValue.jumpLatLng.lat,
  176. lng: modValue.jumpLatLng.lng
  177. },
  178. zoom: modValue.jumpLatLng.zoom,
  179. distance: map3DViewer.getZoomFrom2DZoom(modValue.jumpLatLng.zoom),
  180. heading: 0,//摄像机平面角度 正北为0
  181. tilt: 0//摄像机倾斜角
  182. });
  183. }
  184. $("#jumpToLatlngModal").hide();
  185. removeCurClass();
  186. ONEMAP.V.loading.load();
  187. ONEMAP.C.publisher.publish('jumpToLatLng', 'mapChange');
  188. };
  189. //设为目标
  190. function setPoint() {
  191. _setDirectionsPoint(modValue.jumpObj.latlng[0], modValue.jumpObj.latlng[1], 'start', modValue.jumpObj.name);
  192. };
  193. //设为起点
  194. function setStart() {
  195. _setDirectionsPoint(modValue.jumpObj.latlng[0], modValue.jumpObj.latlng[1], 'start', modValue.jumpObj.name);
  196. };
  197. //途经点
  198. function setAcross() {
  199. _setDirectionsPoint(modValue.jumpObj.latlng[0], modValue.jumpObj.latlng[1], 'start', modValue.jumpObj.name);
  200. };
  201. //规避点
  202. function setAvoid() {
  203. _setDirectionsPoint(modValue.jumpObj.latlng[0], modValue.jumpObj.latlng[1], 'start', modValue.jumpObj.name);
  204. };
  205. //终点
  206. function setStop() {
  207. _setDirectionsPoint(modValue.jumpObj.latlng[0], modValue.jumpObj.latlng[1], 'start', modValue.jumpObj.name);
  208. };
  209. function _setDirectionsPoint(_lat, _lng, _type, _name) {
  210. switch (_type) {
  211. case "start":
  212. if (ONEMAP.M.directions) {
  213. ONEMAP.M.directions.setStartPoint(new L.LatLng(_lat, _lng), _name);
  214. } else {
  215. require(['mod/directions'], function (directions) {
  216. directions.init();
  217. directions.setStartPoint(new L.LatLng(_lat, _lng), _name);
  218. });
  219. }
  220. break;
  221. case "across":
  222. if (ONEMAP.M.directions) {
  223. ONEMAP.M.directions.setAcrossPoint(new L.LatLng(_lat, _lng), _name);
  224. } else {
  225. require(['mod/directions'], function (directions) {
  226. directions.init();
  227. directions.setAcrossPoint(new L.LatLng(_lat, _lng), _name);
  228. });
  229. }
  230. break;
  231. case "avoid":
  232. if (ONEMAP.M.directions) {
  233. ONEMAP.M.directions.setAvoidPoint(new L.LatLng(_lat, _lng), _name);
  234. } else {
  235. require(['mod/directions'], function (directions) {
  236. directions.init();
  237. directions.setAvoidPoint(new L.LatLng(_lat, _lng), _name);
  238. });
  239. }
  240. break;
  241. case "stop":
  242. if (ONEMAP.M.directions) {
  243. ONEMAP.M.directions.setStopPoint(new L.LatLng(_lat, _lng), _name);
  244. } else {
  245. require(['mod/directions'], function (directions) {
  246. directions.init();
  247. directions.setStopPoint(new L.LatLng(_lat, _lng), _name);
  248. });
  249. }
  250. break;
  251. }
  252. };
  253. //
  254. /**
  255. * 事件绑定
  256. */
  257. function bindEvent() {
  258. $("#jumpToLatlngForm .input").bind('click', function () {
  259. $(this).val('');
  260. });
  261. $("#jumpToLatlngModal .close").bind('click', function () {
  262. removeCurClass();
  263. });
  264. $("#jumpToLatlngModal .btn-default.sure").bind('click', function () {
  265. getLatLng();
  266. if (!$("#showShiZi").hasClass('cur')) {
  267. $("#showShiZi").click();
  268. }
  269. //removeCurClass();
  270. });
  271. //回车执行
  272. $('#jumpToLngInput, #jumpToLatInput').bind('keydown', function (e) {
  273. if (e.keyCode === 13) {
  274. getLatLng();
  275. //removeCurClass();
  276. }
  277. });
  278. $('#jumpToLatlngForm dt .lng').bind('click', function () {
  279. if ($(this).attr('v') === 'e') {
  280. $(this).attr('v', 'w');
  281. $(this).html('西经');
  282. } else {
  283. $(this).attr('v', 'e');
  284. $(this).html('东经');
  285. }
  286. });
  287. $('#jumpToLatlngForm dt .lat').bind('click', function () {
  288. if ($(this).attr('v') === 'n') {
  289. $(this).attr('v', 's');
  290. $(this).html('南纬');
  291. } else {
  292. $(this).attr('v', 'n');
  293. $(this).html('北纬');
  294. }
  295. });
  296. $("#shi").bind('click', function () {
  297. if (modValue.InputType === 1) {
  298. $('#jumpToLatlngForm').removeClass().addClass('type-2');
  299. // $(this).html('度分秒');
  300. modValue.InputType = 2;
  301. }
  302. })
  303. $("#du").bind('click', function () {
  304. if (modValue.InputType === 2) {
  305. $('#jumpToLatlngForm').removeClass().addClass('type-1');
  306. // $(this).html('十进制');
  307. modValue.InputType = 1;
  308. }
  309. })
  310. // $('#jumpToLatlngInputType').bind('click',function(){
  311. // if(modValue.InputType === 1){
  312. // $('#jumpToLatlngForm').removeClass().addClass('type-2');
  313. // $(this).html('度分秒');
  314. // modValue.InputType = 2;
  315. // }else if(modValue.InputType === 2){
  316. // $('#jumpToLatlngForm').removeClass().addClass('type-1');
  317. // $(this).html('十进制');
  318. // modValue.InputType = 1;
  319. // }
  320. // });
  321. };
  322. return ONEMAP.M.toolJumpToLatlng = {
  323. init: init,
  324. setStop: setStop,
  325. setAvoid: setAvoid,
  326. setAcross: setAcross,
  327. setStart: setStart,
  328. setStop: setStop,
  329. setPoint: setPoint,
  330. clearMarker: clearMarker
  331. };
  332. })