BMapView.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. // @ts-nocheck
  41. import * as echarts from 'echarts';
  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. export default echarts.extendComponentView({
  51. type: 'bmap',
  52. render: function (bMapModel, ecModel, api) {
  53. var rendering = true;
  54. var bmap = bMapModel.getBMap();
  55. var viewportRoot = api.getZr().painter.getViewportRoot();
  56. var coordSys = bMapModel.coordinateSystem;
  57. var moveHandler = function (type, target) {
  58. if (rendering) {
  59. return;
  60. }
  61. var offsetEl = viewportRoot.parentNode.parentNode.parentNode;
  62. var mapOffset = [-parseInt(offsetEl.style.left, 10) || 0, -parseInt(offsetEl.style.top, 10) || 0]; // only update style when map offset changed
  63. var viewportRootStyle = viewportRoot.style;
  64. var offsetLeft = mapOffset[0] + 'px';
  65. var offsetTop = mapOffset[1] + 'px';
  66. if (viewportRootStyle.left !== offsetLeft) {
  67. viewportRootStyle.left = offsetLeft;
  68. }
  69. if (viewportRootStyle.top !== offsetTop) {
  70. viewportRootStyle.top = offsetTop;
  71. }
  72. coordSys.setMapOffset(mapOffset);
  73. bMapModel.__mapOffset = mapOffset;
  74. api.dispatchAction({
  75. type: 'bmapRoam',
  76. animation: {
  77. duration: 0
  78. }
  79. });
  80. };
  81. function zoomEndHandler() {
  82. if (rendering) {
  83. return;
  84. }
  85. api.dispatchAction({
  86. type: 'bmapRoam',
  87. animation: {
  88. duration: 0
  89. }
  90. });
  91. }
  92. bmap.removeEventListener('moving', this._oldMoveHandler);
  93. bmap.removeEventListener('moveend', this._oldMoveHandler);
  94. bmap.removeEventListener('zoomend', this._oldZoomEndHandler);
  95. bmap.addEventListener('moving', moveHandler);
  96. bmap.addEventListener('moveend', moveHandler);
  97. bmap.addEventListener('zoomend', zoomEndHandler);
  98. this._oldMoveHandler = moveHandler;
  99. this._oldZoomEndHandler = zoomEndHandler;
  100. var roam = bMapModel.get('roam');
  101. if (roam && roam !== 'scale') {
  102. bmap.enableDragging();
  103. } else {
  104. bmap.disableDragging();
  105. }
  106. if (roam && roam !== 'move') {
  107. bmap.enableScrollWheelZoom();
  108. bmap.enableDoubleClickZoom();
  109. bmap.enablePinchToZoom();
  110. } else {
  111. bmap.disableScrollWheelZoom();
  112. bmap.disableDoubleClickZoom();
  113. bmap.disablePinchToZoom();
  114. }
  115. /* map 2.0 */
  116. var originalStyle = bMapModel.__mapStyle;
  117. var newMapStyle = bMapModel.get('mapStyle') || {}; // FIXME, Not use JSON methods
  118. var mapStyleStr = JSON.stringify(newMapStyle);
  119. if (JSON.stringify(originalStyle) !== mapStyleStr) {
  120. // FIXME May have blank tile when dragging if setMapStyle
  121. if (!isEmptyObject(newMapStyle)) {
  122. bmap.setMapStyle(echarts.util.clone(newMapStyle));
  123. }
  124. bMapModel.__mapStyle = JSON.parse(mapStyleStr);
  125. }
  126. /* map 3.0 */
  127. var originalStyle2 = bMapModel.__mapStyle2;
  128. var newMapStyle2 = bMapModel.get('mapStyleV2') || {}; // FIXME, Not use JSON methods
  129. var mapStyleStr2 = JSON.stringify(newMapStyle2);
  130. if (JSON.stringify(originalStyle2) !== mapStyleStr2) {
  131. // FIXME May have blank tile when dragging if setMapStyle
  132. if (!isEmptyObject(newMapStyle2)) {
  133. bmap.setMapStyleV2(echarts.util.clone(newMapStyle2));
  134. }
  135. bMapModel.__mapStyle2 = JSON.parse(mapStyleStr2);
  136. }
  137. rendering = false;
  138. }
  139. });