toolChooseBounds.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /**
  2. * @fileoverview 工具 测量地图面积 模块
  3. * @author Song.Huang
  4. * @version 1.0.0
  5. */
  6. define(['vendorDir/map23dlib/leaflet.choosebounds'],
  7. function(){
  8. /**
  9. * 状态值
  10. * @type {Boolean}
  11. * @default false
  12. * @private
  13. */
  14. var status ={
  15. initialized:false//是否初始化
  16. }
  17. /**
  18. * 模块数据 用于数据存储和外部调用
  19. * @type {Object}
  20. * 数据存放
  21. */
  22. var modValue ={
  23. loopAjaxTimeOut:{},
  24. time_stamp:'',
  25. postData:null,
  26. mapChoose:null
  27. }
  28. var status = {
  29. countingLock:false
  30. }
  31. /**
  32. * 初始化
  33. * 监听事件
  34. * @type {Function}
  35. */
  36. function init(){
  37. if(!status.initialized){
  38. status.initialized = true;
  39. setLayout();
  40. bindEvent();
  41. subscribe();
  42. modValue.mapChoose = L.control.mapChoose().addTo(map2DViewer.map);
  43. //map2DViewer.map.on('mapShot:postData',modValue.mapShotPostData,this);
  44. }
  45. ONEMAP.C.publisher.publish({
  46. modName:'toolMapChoose'
  47. },'tools:active');
  48. };
  49. function setLayout(){
  50. $('body').append($('<div id="mapShotDownload"><p></p></div>'));
  51. $(window).resize(function() {
  52. layoutResize();
  53. });
  54. };
  55. function bindEvent(){
  56. };
  57. function layoutResize(){
  58. var curWindowHeigth = $(window).height();
  59. if(map23DData.display.map2D){
  60. if(curWindowHeigth < 955){
  61. $("#mapHolder .leaflet-mapshot-info").css({
  62. "left":-130
  63. })
  64. }else{
  65. $("#mapHolder .leaflet-mapshot-info").css({
  66. "left":-179
  67. })
  68. }
  69. }else{
  70. $("#mapHolder .leaflet-mapshot-info").css({
  71. "left":-179
  72. })
  73. }
  74. };
  75. function mapShotPostData(postData){
  76. modValue.postData = postData;
  77. var LTpx = map2DViewer.map.project(
  78. new L.LatLng(JSON.parse(postData.bbox)[1],JSON.parse(postData.bbox)[0]),
  79. postData.zoom
  80. );
  81. var RBpx = map2DViewer.map.project(
  82. new L.LatLng(JSON.parse(postData.bbox)[3],JSON.parse(postData.bbox)[2]),
  83. postData.zoom
  84. );
  85. var countDownTF = parseInt(((RBpx.x-LTpx.x)*(RBpx.y-LTpx.y))/(5120*5120));
  86. if(countDownTF > onemapUrlConfig.mapShotMaxPicCount){
  87. $('#mapShotDownload p').html('当前范围产生'+countDownTF+'个图幅数,'+
  88. '<br/>已经超过单次下载'+onemapUrlConfig.mapShotMaxPicCount+'个最大图幅数(5120×5120像素/图幅),请分开截图!<br/>'+
  89. '<span id="continueMapShot" onclick="ONEMAP.M.toolMapChoose.continueMapShot()">修改区域</span>')
  90. $('#mapShotDownload').show();
  91. return false;
  92. }
  93. $('#mapShotDownload').show();
  94. var nDate = new Date();
  95. modValue.time_stamp = nDate.getTime();
  96. var url = onemapUrlConfig.mapShotDownServerUrl+'/puzzles/?bbox='+postData.bbox+'&zoom='+postData.zoom+'&type='+postData.guid+'&ext='+postData.ext+'&time_stamp='+modValue.time_stamp+'&name='+encodeURI(postData.name);
  97. $.ajax({
  98. type:"get",
  99. url:url,
  100. dataType:'jsonp',
  101. jsonp:'callback',
  102. success:function(data){
  103. //modValue._loopGetResult({ajaxKey:'1'});
  104. }
  105. });
  106. setTimeout(function(){
  107. loopGetResult({ajaxKey:modValue.time_stamp});
  108. }, 1000);
  109. };
  110. function againMapShotPostData(){
  111. mapShotPostData(modValue.postData);
  112. }
  113. function loopGetResult(options){
  114. };
  115. function continueMapShot(){
  116. if(modValue.loopAjaxTimeOut.hasOwnProperty(modValue.time_stamp)){
  117. clearTimeout(modValue.loopAjaxTimeOut[modValue.time_stamp]);
  118. }
  119. $('#mapShotDownload').hide().html('<p>正在提交截图数据到服务器</p>');
  120. }
  121. function exitMapShot(){
  122. $('#mapshotScreen').click();
  123. modValue.mapChoose.remove();
  124. $('#mapShotDownload').hide()
  125. }
  126. /**
  127. * 注册监听
  128. */
  129. function subscribe(){
  130. ONEMAP.C.publisher.subscribe(remove, 'tools:active');
  131. ONEMAP.C.publisher.subscribe(mapShotPostData,'mapShot:postData');
  132. };
  133. /**
  134. * 功能移除
  135. */
  136. function remove(options){
  137. // console.log(options.modName);
  138. // 防止与截图功能发生混乱
  139. if(options.modName == 'toolMapShot'){
  140. return false;
  141. } else{
  142. modValue.mapChoose.init();
  143. }
  144. };
  145. return ONEMAP.M.toolMapChoose = {
  146. init:init
  147. }
  148. });