BMapView.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. /**
  20. * AUTO-GENERATED FILE. DO NOT MODIFY.
  21. */
  22. /*
  23. * Licensed to the Apache Software Foundation (ASF) under one
  24. * or more contributor license agreements. See the NOTICE file
  25. * distributed with this work for additional information
  26. * regarding copyright ownership. The ASF licenses this file
  27. * to you under the Apache License, Version 2.0 (the
  28. * "License"); you may not use this file except in compliance
  29. * with the License. You may obtain a copy of the License at
  30. *
  31. * http://www.apache.org/licenses/LICENSE-2.0
  32. *
  33. * Unless required by applicable law or agreed to in writing,
  34. * software distributed under the License is distributed on an
  35. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36. * KIND, either express or implied. See the License for the
  37. * specific language governing permissions and limitations
  38. * under the License.
  39. */
  40. import { extendComponentView, util as zrUtil } from 'echarts';
  41. import { COMPONENT_MAIN_TYPE_BMAP } from './BMapModel.js';
  42. function isEmptyObject(obj) {
  43. for (var key in obj) {
  44. if (obj.hasOwnProperty(key)) {
  45. return false;
  46. }
  47. }
  48. return true;
  49. }
  50. var proto = {
  51. type: COMPONENT_MAIN_TYPE_BMAP,
  52. _oldMoveHandler: undefined,
  53. _oldZoomEndHandler: undefined,
  54. render: function (bMapModel, ecModel, api) {
  55. var rendering = true;
  56. var bmap = bMapModel.getBMap();
  57. var viewportRoot = api.getZr().painter.getViewportRoot();
  58. var coordSys = bMapModel.coordinateSystem;
  59. var moveHandler = function () {
  60. if (rendering) {
  61. return;
  62. }
  63. var offsetEl = viewportRoot.parentNode.parentNode.parentNode;
  64. var mapOffset = [-parseInt(offsetEl.style.left, 10) || 0, -parseInt(offsetEl.style.top, 10) || 0];
  65. // only update style when map offset changed
  66. var viewportRootStyle = viewportRoot.style;
  67. var offsetLeft = mapOffset[0] + 'px';
  68. var offsetTop = mapOffset[1] + 'px';
  69. if (viewportRootStyle.left !== offsetLeft) {
  70. viewportRootStyle.left = offsetLeft;
  71. }
  72. if (viewportRootStyle.top !== offsetTop) {
  73. viewportRootStyle.top = offsetTop;
  74. }
  75. coordSys.setMapOffset(mapOffset);
  76. bMapModel.__mapOffset = mapOffset;
  77. api.dispatchAction({
  78. type: 'bmapRoam',
  79. animation: {
  80. duration: 0
  81. }
  82. });
  83. };
  84. function zoomEndHandler() {
  85. if (rendering) {
  86. return;
  87. }
  88. api.dispatchAction({
  89. type: 'bmapRoam',
  90. animation: {
  91. duration: 0
  92. }
  93. });
  94. }
  95. bmap.removeEventListener('moving', this._oldMoveHandler);
  96. bmap.removeEventListener('moveend', this._oldMoveHandler);
  97. bmap.removeEventListener('zoomend', this._oldZoomEndHandler);
  98. bmap.addEventListener('moving', moveHandler);
  99. bmap.addEventListener('moveend', moveHandler);
  100. bmap.addEventListener('zoomend', zoomEndHandler);
  101. this._oldMoveHandler = moveHandler;
  102. this._oldZoomEndHandler = zoomEndHandler;
  103. var roam = bMapModel.get('roam');
  104. if (roam && roam !== 'scale') {
  105. bmap.enableDragging();
  106. } else {
  107. bmap.disableDragging();
  108. }
  109. if (roam && roam !== 'move') {
  110. bmap.enableScrollWheelZoom();
  111. bmap.enableDoubleClickZoom();
  112. bmap.enablePinchToZoom();
  113. } else {
  114. bmap.disableScrollWheelZoom();
  115. bmap.disableDoubleClickZoom();
  116. bmap.disablePinchToZoom();
  117. }
  118. /* map 2.0 */
  119. var originalStyle = bMapModel.__mapStyle;
  120. var newMapStyle = bMapModel.get('mapStyle') || {};
  121. // FIXME, Not use JSON methods
  122. var mapStyleStr = JSON.stringify(newMapStyle);
  123. if (JSON.stringify(originalStyle) !== mapStyleStr) {
  124. // FIXME May have blank tile when dragging if setMapStyle
  125. if (!isEmptyObject(newMapStyle)) {
  126. bmap.setMapStyle(zrUtil.clone(newMapStyle));
  127. }
  128. bMapModel.__mapStyle = JSON.parse(mapStyleStr);
  129. }
  130. /* map 3.0 */
  131. var originalStyle2 = bMapModel.__mapStyle2;
  132. var newMapStyle2 = bMapModel.get('mapStyleV2') || {};
  133. // FIXME, Not use JSON methods
  134. var mapStyleStr2 = JSON.stringify(newMapStyle2);
  135. if (JSON.stringify(originalStyle2) !== mapStyleStr2) {
  136. // FIXME May have blank tile when dragging if setMapStyle
  137. if (!isEmptyObject(newMapStyle2)) {
  138. bmap.setMapStyleV2(zrUtil.clone(newMapStyle2));
  139. }
  140. bMapModel.__mapStyle2 = JSON.parse(mapStyleStr2);
  141. }
  142. rendering = false;
  143. }
  144. };
  145. extendComponentView(proto);