BMapView.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. var echarts = require("echarts");
  20. /*
  21. * Licensed to the Apache Software Foundation (ASF) under one
  22. * or more contributor license agreements. See the NOTICE file
  23. * distributed with this work for additional information
  24. * regarding copyright ownership. The ASF licenses this file
  25. * to you under the Apache License, Version 2.0 (the
  26. * "License"); you may not use this file except in compliance
  27. * with the License. You may obtain a copy of the License at
  28. *
  29. * http://www.apache.org/licenses/LICENSE-2.0
  30. *
  31. * Unless required by applicable law or agreed to in writing,
  32. * software distributed under the License is distributed on an
  33. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  34. * KIND, either express or implied. See the License for the
  35. * specific language governing permissions and limitations
  36. * under the License.
  37. */
  38. var _default = echarts.extendComponentView({
  39. type: 'bmap',
  40. render: function (bMapModel, ecModel, api) {
  41. var rendering = true;
  42. var bmap = bMapModel.getBMap();
  43. var viewportRoot = api.getZr().painter.getViewportRoot();
  44. var coordSys = bMapModel.coordinateSystem;
  45. var moveHandler = function (type, target) {
  46. if (rendering) {
  47. return;
  48. }
  49. var offsetEl = viewportRoot.parentNode.parentNode.parentNode;
  50. var mapOffset = [-parseInt(offsetEl.style.left, 10) || 0, -parseInt(offsetEl.style.top, 10) || 0];
  51. viewportRoot.style.left = mapOffset[0] + 'px';
  52. viewportRoot.style.top = mapOffset[1] + 'px';
  53. coordSys.setMapOffset(mapOffset);
  54. bMapModel.__mapOffset = mapOffset;
  55. api.dispatchAction({
  56. type: 'bmapRoam'
  57. });
  58. };
  59. function zoomEndHandler() {
  60. if (rendering) {
  61. return;
  62. }
  63. api.dispatchAction({
  64. type: 'bmapRoam'
  65. });
  66. }
  67. bmap.removeEventListener('moving', this._oldMoveHandler); // FIXME
  68. // Moveend may be triggered by centerAndZoom method when creating coordSys next time
  69. // bmap.removeEventListener('moveend', this._oldMoveHandler);
  70. bmap.removeEventListener('zoomend', this._oldZoomEndHandler);
  71. bmap.addEventListener('moving', moveHandler); // bmap.addEventListener('moveend', moveHandler);
  72. bmap.addEventListener('zoomend', zoomEndHandler);
  73. this._oldMoveHandler = moveHandler;
  74. this._oldZoomEndHandler = zoomEndHandler;
  75. var roam = bMapModel.get('roam');
  76. if (roam && roam !== 'scale') {
  77. bmap.enableDragging();
  78. } else {
  79. bmap.disableDragging();
  80. }
  81. if (roam && roam !== 'move') {
  82. bmap.enableScrollWheelZoom();
  83. bmap.enableDoubleClickZoom();
  84. bmap.enablePinchToZoom();
  85. } else {
  86. bmap.disableScrollWheelZoom();
  87. bmap.disableDoubleClickZoom();
  88. bmap.disablePinchToZoom();
  89. }
  90. /* map 2.0 */
  91. var originalStyle = bMapModel.__mapStyle;
  92. var newMapStyle = bMapModel.get('mapStyle') || {}; // FIXME, Not use JSON methods
  93. var mapStyleStr = JSON.stringify(newMapStyle);
  94. if (JSON.stringify(originalStyle) !== mapStyleStr) {
  95. // FIXME May have blank tile when dragging if setMapStyle
  96. if (Object.keys(newMapStyle).length) {
  97. bmap.setMapStyle(newMapStyle);
  98. }
  99. bMapModel.__mapStyle = JSON.parse(mapStyleStr);
  100. }
  101. /* map 3.0 */
  102. var originalStyle2 = bMapModel.__mapStyle2;
  103. var newMapStyle2 = bMapModel.get('mapStyleV2') || {}; // FIXME, Not use JSON methods
  104. var mapStyleStr2 = JSON.stringify(newMapStyle2);
  105. if (JSON.stringify(originalStyle2) !== mapStyleStr2) {
  106. // FIXME May have blank tile when dragging if setMapStyle
  107. if (Object.keys(newMapStyle2).length) {
  108. bmap.setMapStyleV2(newMapStyle2);
  109. }
  110. bMapModel.__mapStyle2 = JSON.parse(mapStyleStr2);
  111. }
  112. rendering = false;
  113. }
  114. });
  115. module.exports = _default;