MapView.js 7.2 KB

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