BMapView.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. var _util = require("zrender/lib/core/util");
  21. var clone = _util.clone;
  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. var _default = echarts.extendComponentView({
  41. type: 'bmap',
  42. render: function (bMapModel, ecModel, api) {
  43. var rendering = true;
  44. var bmap = bMapModel.getBMap();
  45. var viewportRoot = api.getZr().painter.getViewportRoot();
  46. var coordSys = bMapModel.coordinateSystem;
  47. var moveHandler = function (type, target) {
  48. if (rendering) {
  49. return;
  50. }
  51. var offsetEl = viewportRoot.parentNode.parentNode.parentNode;
  52. var mapOffset = [-parseInt(offsetEl.style.left, 10) || 0, -parseInt(offsetEl.style.top, 10) || 0];
  53. viewportRoot.style.left = mapOffset[0] + 'px';
  54. viewportRoot.style.top = mapOffset[1] + 'px';
  55. coordSys.setMapOffset(mapOffset);
  56. bMapModel.__mapOffset = mapOffset;
  57. api.dispatchAction({
  58. type: 'bmapRoam'
  59. });
  60. };
  61. function zoomEndHandler() {
  62. if (rendering) {
  63. return;
  64. }
  65. api.dispatchAction({
  66. type: 'bmapRoam'
  67. });
  68. }
  69. bmap.removeEventListener('moving', this._oldMoveHandler); // FIXME
  70. // Moveend may be triggered by centerAndZoom method when creating coordSys next time
  71. // bmap.removeEventListener('moveend', this._oldMoveHandler);
  72. bmap.removeEventListener('zoomend', this._oldZoomEndHandler);
  73. bmap.addEventListener('moving', moveHandler); // bmap.addEventListener('moveend', moveHandler);
  74. bmap.addEventListener('zoomend', zoomEndHandler);
  75. this._oldMoveHandler = moveHandler;
  76. this._oldZoomEndHandler = zoomEndHandler;
  77. var roam = bMapModel.get('roam');
  78. if (roam && roam !== 'scale') {
  79. bmap.enableDragging();
  80. } else {
  81. bmap.disableDragging();
  82. }
  83. if (roam && roam !== 'move') {
  84. bmap.enableScrollWheelZoom();
  85. bmap.enableDoubleClickZoom();
  86. bmap.enablePinchToZoom();
  87. } else {
  88. bmap.disableScrollWheelZoom();
  89. bmap.disableDoubleClickZoom();
  90. bmap.disablePinchToZoom();
  91. }
  92. /* map 2.0 */
  93. var originalStyle = bMapModel.__mapStyle;
  94. var newMapStyle = bMapModel.get('mapStyle') || {}; // FIXME, Not use JSON methods
  95. var mapStyleStr = JSON.stringify(newMapStyle);
  96. if (JSON.stringify(originalStyle) !== mapStyleStr) {
  97. // FIXME May have blank tile when dragging if setMapStyle
  98. if (Object.keys(newMapStyle).length) {
  99. bmap.setMapStyle(clone(newMapStyle));
  100. }
  101. bMapModel.__mapStyle = JSON.parse(mapStyleStr);
  102. }
  103. /* map 3.0 */
  104. var originalStyle2 = bMapModel.__mapStyle2;
  105. var newMapStyle2 = bMapModel.get('mapStyleV2') || {}; // FIXME, Not use JSON methods
  106. var mapStyleStr2 = JSON.stringify(newMapStyle2);
  107. if (JSON.stringify(originalStyle2) !== mapStyleStr2) {
  108. // FIXME May have blank tile when dragging if setMapStyle
  109. if (Object.keys(newMapStyle2).length) {
  110. bmap.setMapStyleV2(clone(newMapStyle2));
  111. }
  112. bMapModel.__mapStyle2 = JSON.parse(mapStyleStr2);
  113. }
  114. rendering = false;
  115. }
  116. });
  117. module.exports = _default;