MapSeries.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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 zrUtil from 'zrender/lib/core/util.js';
  42. import createSeriesDataSimply from '../helper/createSeriesDataSimply.js';
  43. import SeriesModel from '../../model/Series.js';
  44. import geoSourceManager from '../../coord/geo/geoSourceManager.js';
  45. import { makeSeriesEncodeForNameBased } from '../../data/helper/sourceHelper.js';
  46. import { createTooltipMarkup } from '../../component/tooltip/tooltipMarkup.js';
  47. import { createSymbol } from '../../util/symbol.js';
  48. var MapSeries = /** @class */function (_super) {
  49. __extends(MapSeries, _super);
  50. function MapSeries() {
  51. var _this = _super !== null && _super.apply(this, arguments) || this;
  52. _this.type = MapSeries.type;
  53. // Only first map series of same mapType will drawMap.
  54. _this.needsDrawMap = false;
  55. // Group of all map series with same mapType
  56. _this.seriesGroup = [];
  57. _this.getTooltipPosition = function (dataIndex) {
  58. if (dataIndex != null) {
  59. var name_1 = this.getData().getName(dataIndex);
  60. var geo = this.coordinateSystem;
  61. var region = geo.getRegion(name_1);
  62. return region && geo.dataToPoint(region.getCenter());
  63. }
  64. };
  65. return _this;
  66. }
  67. MapSeries.prototype.getInitialData = function (option) {
  68. var data = createSeriesDataSimply(this, {
  69. coordDimensions: ['value'],
  70. encodeDefaulter: zrUtil.curry(makeSeriesEncodeForNameBased, this)
  71. });
  72. var dataNameMap = zrUtil.createHashMap();
  73. var toAppendNames = [];
  74. for (var i = 0, len = data.count(); i < len; i++) {
  75. var name_2 = data.getName(i);
  76. dataNameMap.set(name_2, true);
  77. }
  78. var geoSource = geoSourceManager.load(this.getMapType(), this.option.nameMap, this.option.nameProperty);
  79. zrUtil.each(geoSource.regions, function (region) {
  80. var name = region.name;
  81. if (!dataNameMap.get(name)) {
  82. toAppendNames.push(name);
  83. }
  84. });
  85. // Complete data with missing regions. The consequent processes (like visual
  86. // map and render) can not be performed without a "full data". For example,
  87. // find `dataIndex` by name.
  88. data.appendValues([], toAppendNames);
  89. return data;
  90. };
  91. /**
  92. * If no host geo model, return null, which means using a
  93. * inner exclusive geo model.
  94. */
  95. MapSeries.prototype.getHostGeoModel = function () {
  96. var geoIndex = this.option.geoIndex;
  97. return geoIndex != null ? this.ecModel.getComponent('geo', geoIndex) : null;
  98. };
  99. MapSeries.prototype.getMapType = function () {
  100. return (this.getHostGeoModel() || this).option.map;
  101. };
  102. // _fillOption(option, mapName) {
  103. // Shallow clone
  104. // option = zrUtil.extend({}, option);
  105. // option.data = geoCreator.getFilledRegions(option.data, mapName, option.nameMap);
  106. // return option;
  107. // }
  108. MapSeries.prototype.getRawValue = function (dataIndex) {
  109. // Use value stored in data instead because it is calculated from multiple series
  110. // FIXME Provide all value of multiple series ?
  111. var data = this.getData();
  112. return data.get(data.mapDimension('value'), dataIndex);
  113. };
  114. /**
  115. * Get model of region
  116. */
  117. MapSeries.prototype.getRegionModel = function (regionName) {
  118. var data = this.getData();
  119. return data.getItemModel(data.indexOfName(regionName));
  120. };
  121. /**
  122. * Map tooltip formatter
  123. */
  124. MapSeries.prototype.formatTooltip = function (dataIndex, multipleSeries, dataType) {
  125. // FIXME orignalData and data is a bit confusing
  126. var data = this.getData();
  127. var value = this.getRawValue(dataIndex);
  128. var name = data.getName(dataIndex);
  129. var seriesGroup = this.seriesGroup;
  130. var seriesNames = [];
  131. for (var i = 0; i < seriesGroup.length; i++) {
  132. var otherIndex = seriesGroup[i].originalData.indexOfName(name);
  133. var valueDim = data.mapDimension('value');
  134. if (!isNaN(seriesGroup[i].originalData.get(valueDim, otherIndex))) {
  135. seriesNames.push(seriesGroup[i].name);
  136. }
  137. }
  138. return createTooltipMarkup('section', {
  139. header: seriesNames.join(', '),
  140. noHeader: !seriesNames.length,
  141. blocks: [createTooltipMarkup('nameValue', {
  142. name: name,
  143. value: value
  144. })]
  145. });
  146. };
  147. MapSeries.prototype.setZoom = function (zoom) {
  148. this.option.zoom = zoom;
  149. };
  150. MapSeries.prototype.setCenter = function (center) {
  151. this.option.center = center;
  152. };
  153. MapSeries.prototype.getLegendIcon = function (opt) {
  154. var iconType = opt.icon || 'roundRect';
  155. var icon = createSymbol(iconType, 0, 0, opt.itemWidth, opt.itemHeight, opt.itemStyle.fill);
  156. icon.setStyle(opt.itemStyle);
  157. // Map do not use itemStyle.borderWidth as border width
  158. icon.style.stroke = 'none';
  159. // No rotation because no series visual symbol for map
  160. if (iconType.indexOf('empty') > -1) {
  161. icon.style.stroke = icon.style.fill;
  162. icon.style.fill = '#fff';
  163. icon.style.lineWidth = 2;
  164. }
  165. return icon;
  166. };
  167. MapSeries.type = 'series.map';
  168. MapSeries.dependencies = ['geo'];
  169. MapSeries.layoutMode = 'box';
  170. MapSeries.defaultOption = {
  171. // 一级层叠
  172. // zlevel: 0,
  173. // 二级层叠
  174. z: 2,
  175. coordinateSystem: 'geo',
  176. // map should be explicitly specified since ec3.
  177. map: '',
  178. // If `geoIndex` is not specified, a exclusive geo will be
  179. // created. Otherwise use the specified geo component, and
  180. // `map` and `mapType` are ignored.
  181. // geoIndex: 0,
  182. // 'center' | 'left' | 'right' | 'x%' | {number}
  183. left: 'center',
  184. // 'center' | 'top' | 'bottom' | 'x%' | {number}
  185. top: 'center',
  186. // right
  187. // bottom
  188. // width:
  189. // height
  190. // Aspect is width / height. Inited to be geoJson bbox aspect
  191. // This parameter is used for scale this aspect
  192. // Default value:
  193. // for geoSVG source: 1,
  194. // for geoJSON source: 0.75.
  195. aspectScale: null,
  196. // Layout with center and size
  197. // If you want to put map in a fixed size box with right aspect ratio
  198. // This two properties may be more convenient.
  199. // layoutCenter: [50%, 50%]
  200. // layoutSize: 100
  201. showLegendSymbol: true,
  202. // Define left-top, right-bottom coords to control view
  203. // For example, [ [180, 90], [-180, -90] ],
  204. // higher priority than center and zoom
  205. boundingCoords: null,
  206. // Default on center of map
  207. center: null,
  208. zoom: 1,
  209. scaleLimit: null,
  210. selectedMode: true,
  211. label: {
  212. show: false,
  213. color: '#000'
  214. },
  215. // scaleLimit: null,
  216. itemStyle: {
  217. borderWidth: 0.5,
  218. borderColor: '#444',
  219. areaColor: '#eee'
  220. },
  221. emphasis: {
  222. label: {
  223. show: true,
  224. color: 'rgb(100,0,0)'
  225. },
  226. itemStyle: {
  227. areaColor: 'rgba(255,215,0,0.8)'
  228. }
  229. },
  230. select: {
  231. label: {
  232. show: true,
  233. color: 'rgb(100,0,0)'
  234. },
  235. itemStyle: {
  236. color: 'rgba(255,215,0,0.8)'
  237. }
  238. },
  239. nameProperty: 'name'
  240. };
  241. return MapSeries;
  242. }(SeriesModel);
  243. export default MapSeries;