MapSeries.js 8.8 KB

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