MapView.js 6.9 KB

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