leaflet.choosebounds.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. L.Control.MapChoose = L.Control.extend({
  2. options: {
  3. position: 'topright',
  4. },
  5. /**
  6. * 地图实例
  7. * @type {Object}
  8. * @private
  9. */
  10. _map: null,
  11. /**
  12. * 截图容器
  13. * @type {L}
  14. */
  15. _shotGroup: new L.FeatureGroup(),
  16. /**
  17. * 是否正在截图
  18. * @type {Boolean}
  19. * @default false
  20. * @private
  21. */
  22. _isScreenShot: false,
  23. initialize: function(options) {
  24. L.setOptions(this, options);
  25. return this;
  26. },
  27. onAdd: function(map) {
  28. this._map = map;
  29. this._map.addLayer(this._shotGroup);
  30. this.rectangle = new L.Draw.Rectangle(this._map);
  31. this._createControl();
  32. return this._container;
  33. },
  34. _createControl: function() {
  35. var _this = this;
  36. var className = 'leaflet-control-mapchoose',
  37. classNames = className + ' leaflet-bar leaflet-control';
  38. this._container = L.DomUtil.create('div', classNames);
  39. },
  40. /**
  41. * 初始化
  42. * @type {Function}
  43. */
  44. init: function() {
  45. var _this = this;
  46. _this.rectangle.enable();
  47. _this._shotGroup.clearLayers();
  48. _this._isScreenShot = true;
  49. L.DomUtil.addClass(_this._container, 'active');
  50. _this._map.on('draw:created', _this.drawCreated, this);
  51. _this._map.on('singleLayer:addToMap', _this.updatePanel, this);
  52. },
  53. layoutResize:function(){
  54. var curWindowHeigth = $(window).height();
  55. if(curWindowHeigth < 955){
  56. $("#mapHolder .leaflet-mapchoose-info").css({
  57. "left":-130
  58. })
  59. }else{
  60. $("#mapHolder .leaflet-mapchoose-info").css({
  61. "left":-179
  62. })
  63. }
  64. },
  65. /**
  66. * 更新截图信息面板
  67. * @param {[type]} layerObj [description]
  68. * @return {[type]} [description]
  69. */
  70. updatePanel: function(layerObj) {
  71. },
  72. updateShotBounds: function() {
  73. var _this = this;
  74. var bounds = _this.shotLayer.getBounds();
  75. console.log(bounds);
  76. },
  77. /**
  78. * 标注创建 添加到容器
  79. * @param e
  80. */
  81. drawCreated: function(e) {
  82. var _this = this;
  83. var type = e.layerType;
  84. _this.shotLayer = e.layer;
  85. _this._shotGroup.addLayer(_this.shotLayer);
  86. _this.shotLayer.editing.enable();
  87. var thematic = {
  88. curThematic: {
  89. min_zoom: 1,
  90. max_zoom: 19,
  91. translate: "未知",
  92. guid: 'null'
  93. }
  94. };
  95. var baseMapObj = {
  96. translate: null,
  97. guid: null
  98. }
  99. baseMapObj.guid = ONEMAP.M.mapHolder.modValue.mainLayers;
  100. thematic.curThematic.min_zoom = map2DViewer.map.getMinZoom(); //baseMapObj.options.minZoom
  101. thematic.curThematic.max_zoom = map2DViewer.map.getMaxZoom();
  102. if (baseMapObj.guid === 'gm') {
  103. baseMapObj.translate = '交通图';
  104. baseMapObj.guid = 'gm';
  105. }
  106. if (baseMapObj.guid === 'gr') {
  107. baseMapObj.translate = '影像图';
  108. baseMapObj.guid = 'gr';
  109. }
  110. if (baseMapObj.guid === 'gr') {
  111. baseMapObj.translate = '影像叠加地名图';
  112. baseMapObj.guid = 'gr';
  113. }
  114. if (baseMapObj.guid === 'gt') {
  115. baseMapObj.translate = '地势图';
  116. baseMapObj.guid = 'gt';
  117. }
  118. thematic.curThematic.translate = baseMapObj.translate;
  119. thematic.curThematic.guid = baseMapObj.guid;
  120. var thematicData = ONEMAP.D.ThematicInMapData;
  121. if (ONEMAP.D.overLayerCount > 0) {
  122. $(_this.labelThematic).show();
  123. $(_this.selectThematicType).show();
  124. $(_this.labelTypeP).hide();
  125. $(_this.labelTypeL).hide();
  126. } else {
  127. $(_this.labelThematic).hide();
  128. $(_this.selectThematicType).hide();
  129. $(_this.labelTypeP).show();
  130. $(_this.labelTypeL).show();
  131. }
  132. $(_this.selectThematicType).empty();
  133. $.each(thematicData, function(i, t) {
  134. var item = new Option(t.name, t.name);
  135. _this.selectThematicType.options.add(item);
  136. })
  137. _this.curLayerObj = thematic.curThematic;
  138. _this._map.on('editDraging', _this.updateShotBounds, this);
  139. var bounds = _this.shotLayer.getBounds();
  140. // console.log(bounds);
  141. },
  142. /**
  143. * 移除事件
  144. * @type {Function}
  145. */
  146. remove: function() {
  147. var _this = this;
  148. if (_this._map != null) {
  149. _this._isScreenShot = false;
  150. L.DomUtil.removeClass(_this._container, 'active');
  151. _this.rectangle.disable();
  152. _this._shotGroup.clearLayers();
  153. _this._map.off('draw:created', _this.drawCreated, this);
  154. _this._map.off('singleLayer:addToMap', _this.updatePanel, this);
  155. _this._map.off('editDraging', _this.updateShotBounds, this);
  156. }
  157. }
  158. });
  159. L.control.mapChoose = function(options) {
  160. return new L.Control.MapChoose(options);
  161. };