MapView.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 { __extends } from "tslib";
  41. import * as graphic from '../../util/graphic.js';
  42. import MapDraw from '../../component/helper/MapDraw.js';
  43. import ChartView from '../../view/Chart.js';
  44. import { setLabelStyle, getLabelStatesModels } from '../../label/labelStyle.js';
  45. import { setStatesFlag, Z2_EMPHASIS_LIFT } from '../../util/states.js';
  46. var MapView = /** @class */function (_super) {
  47. __extends(MapView, _super);
  48. function MapView() {
  49. var _this = _super !== null && _super.apply(this, arguments) || this;
  50. _this.type = MapView.type;
  51. return _this;
  52. }
  53. MapView.prototype.render = function (mapModel, ecModel, api, payload) {
  54. // Not render if it is an toggleSelect action from self
  55. if (payload && payload.type === 'mapToggleSelect' && payload.from === this.uid) {
  56. return;
  57. }
  58. var group = this.group;
  59. group.removeAll();
  60. if (mapModel.getHostGeoModel()) {
  61. return;
  62. }
  63. if (this._mapDraw && payload && payload.type === 'geoRoam') {
  64. this._mapDraw.resetForLabelLayout();
  65. }
  66. // Not update map if it is an roam action from self
  67. if (!(payload && payload.type === 'geoRoam' && payload.componentType === 'series' && payload.seriesId === mapModel.id)) {
  68. if (mapModel.needsDrawMap) {
  69. var mapDraw = this._mapDraw || new MapDraw(api);
  70. group.add(mapDraw.group);
  71. mapDraw.draw(mapModel, ecModel, api, this, payload);
  72. this._mapDraw = mapDraw;
  73. } else {
  74. // Remove drawn map
  75. this._mapDraw && this._mapDraw.remove();
  76. this._mapDraw = null;
  77. }
  78. } else {
  79. var mapDraw = this._mapDraw;
  80. mapDraw && group.add(mapDraw.group);
  81. }
  82. mapModel.get('showLegendSymbol') && ecModel.getComponent('legend') && this._renderSymbols(mapModel, ecModel, api);
  83. };
  84. MapView.prototype.remove = function () {
  85. this._mapDraw && this._mapDraw.remove();
  86. this._mapDraw = null;
  87. this.group.removeAll();
  88. };
  89. MapView.prototype.dispose = function () {
  90. this._mapDraw && this._mapDraw.remove();
  91. this._mapDraw = null;
  92. };
  93. MapView.prototype._renderSymbols = function (mapModel, ecModel, api) {
  94. var originalData = mapModel.originalData;
  95. var group = this.group;
  96. originalData.each(originalData.mapDimension('value'), function (value, originalDataIndex) {
  97. if (isNaN(value)) {
  98. return;
  99. }
  100. var layout = originalData.getItemLayout(originalDataIndex);
  101. if (!layout || !layout.point) {
  102. // Not exists in map
  103. return;
  104. }
  105. var point = layout.point;
  106. var offset = layout.offset;
  107. var circle = new graphic.Circle({
  108. style: {
  109. // Because the special of map draw.
  110. // Which needs statistic of multiple series and draw on one map.
  111. // And each series also need a symbol with legend color
  112. //
  113. // Layout and visual are put one the different data
  114. // TODO
  115. fill: mapModel.getData().getVisual('style').fill
  116. },
  117. shape: {
  118. cx: point[0] + offset * 9,
  119. cy: point[1],
  120. r: 3
  121. },
  122. silent: true,
  123. // Do not overlap the first series, on which labels are displayed.
  124. z2: 8 + (!offset ? Z2_EMPHASIS_LIFT + 1 : 0)
  125. });
  126. // Only the series that has the first value on the same region is in charge of rendering the label.
  127. // But consider the case:
  128. // series: [
  129. // {id: 'X', type: 'map', map: 'm', {data: [{name: 'A', value: 11}, {name: 'B', {value: 22}]},
  130. // {id: 'Y', type: 'map', map: 'm', {data: [{name: 'A', value: 21}, {name: 'C', {value: 33}]}
  131. // ]
  132. // The offset `0` of item `A` is at series `X`, but of item `C` is at series `Y`.
  133. // For backward compatibility, we follow the rule that render label `A` by the
  134. // settings on series `X` but render label `C` by the settings on series `Y`.
  135. if (!offset) {
  136. var fullData = mapModel.mainSeries.getData();
  137. var name_1 = originalData.getName(originalDataIndex);
  138. var fullIndex_1 = fullData.indexOfName(name_1);
  139. var itemModel = originalData.getItemModel(originalDataIndex);
  140. var labelModel = itemModel.getModel('label');
  141. var regionGroup = fullData.getItemGraphicEl(fullIndex_1);
  142. // `getFormattedLabel` needs to use `getData` inside. Here
  143. // `mapModel.getData()` is shallow cloned from `mainSeries.getData()`.
  144. // FIXME
  145. // If this is not the `mainSeries`, the item model (like label formatter)
  146. // set on original data item will never get. But it has been working
  147. // like that from the beginning, and this scenario is rarely encountered.
  148. // So it won't be fixed until we have to.
  149. setLabelStyle(circle, getLabelStatesModels(itemModel), {
  150. labelFetcher: {
  151. getFormattedLabel: function (idx, state) {
  152. return mapModel.getFormattedLabel(fullIndex_1, state);
  153. }
  154. },
  155. defaultText: name_1
  156. });
  157. circle.disableLabelAnimation = true;
  158. if (!labelModel.get('position')) {
  159. circle.setTextConfig({
  160. position: 'bottom'
  161. });
  162. }
  163. regionGroup.onHoverStateChange = function (toState) {
  164. setStatesFlag(circle, toState);
  165. };
  166. }
  167. group.add(circle);
  168. });
  169. };
  170. MapView.type = 'map';
  171. return MapView;
  172. }(ChartView);
  173. export default MapView;