GeoModel.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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 * as modelUtil from '../../util/model.js';
  43. import ComponentModel from '../../model/Component.js';
  44. import Model from '../../model/Model.js';
  45. import geoCreator from './geoCreator.js';
  46. import geoSourceManager from './geoSourceManager.js';
  47. import tokens from '../../visual/tokens.js';
  48. ;
  49. var GeoModel = /** @class */function (_super) {
  50. __extends(GeoModel, _super);
  51. function GeoModel() {
  52. var _this = _super !== null && _super.apply(this, arguments) || this;
  53. _this.type = GeoModel.type;
  54. return _this;
  55. }
  56. GeoModel.prototype.init = function (option, parentModel, ecModel) {
  57. this.mergeDefaultAndTheme(option, ecModel);
  58. var source = geoSourceManager.getGeoResource(option.map);
  59. if (source && source.type === 'geoJSON') {
  60. var itemStyle = option.itemStyle = option.itemStyle || {};
  61. if (!('color' in itemStyle)) {
  62. itemStyle.color = option.defaultItemStyleColor || tokens.color.backgroundTint;
  63. }
  64. }
  65. // Default label emphasis `show`
  66. modelUtil.defaultEmphasis(option, 'label', ['show']);
  67. };
  68. GeoModel.prototype.optionUpdated = function () {
  69. var _this = this;
  70. var option = this.option;
  71. option.regions = geoCreator.getFilledRegions(option.regions, option.map, option.nameMap, option.nameProperty);
  72. var selectedMap = {};
  73. this._optionModelMap = zrUtil.reduce(option.regions || [], function (optionModelMap, regionOpt) {
  74. var regionName = regionOpt.name;
  75. if (regionName) {
  76. optionModelMap.set(regionName, new Model(regionOpt, _this, _this.ecModel));
  77. if (regionOpt.selected) {
  78. selectedMap[regionName] = true;
  79. }
  80. }
  81. return optionModelMap;
  82. }, zrUtil.createHashMap());
  83. if (!option.selectedMap) {
  84. option.selectedMap = selectedMap;
  85. }
  86. };
  87. /**
  88. * Get model of region.
  89. */
  90. GeoModel.prototype.getRegionModel = function (name) {
  91. return this._optionModelMap.get(name) || new Model(null, this, this.ecModel);
  92. };
  93. /**
  94. * Format label
  95. * @param name Region name
  96. */
  97. GeoModel.prototype.getFormattedLabel = function (name, status) {
  98. var regionModel = this.getRegionModel(name);
  99. var formatter = status === 'normal' ? regionModel.get(['label', 'formatter']) : regionModel.get(['emphasis', 'label', 'formatter']);
  100. var params = {
  101. name: name
  102. };
  103. if (zrUtil.isFunction(formatter)) {
  104. params.status = status;
  105. return formatter(params);
  106. } else if (zrUtil.isString(formatter)) {
  107. return formatter.replace('{a}', name != null ? name : '');
  108. }
  109. };
  110. GeoModel.prototype.setZoom = function (zoom) {
  111. this.option.zoom = zoom;
  112. };
  113. GeoModel.prototype.setCenter = function (center) {
  114. this.option.center = center;
  115. };
  116. // PENGING If selectedMode is null ?
  117. GeoModel.prototype.select = function (name) {
  118. var option = this.option;
  119. var selectedMode = option.selectedMode;
  120. if (!selectedMode) {
  121. return;
  122. }
  123. if (selectedMode !== 'multiple') {
  124. option.selectedMap = null;
  125. }
  126. var selectedMap = option.selectedMap || (option.selectedMap = {});
  127. selectedMap[name] = true;
  128. };
  129. GeoModel.prototype.unSelect = function (name) {
  130. var selectedMap = this.option.selectedMap;
  131. if (selectedMap) {
  132. selectedMap[name] = false;
  133. }
  134. };
  135. GeoModel.prototype.toggleSelected = function (name) {
  136. this[this.isSelected(name) ? 'unSelect' : 'select'](name);
  137. };
  138. GeoModel.prototype.isSelected = function (name) {
  139. var selectedMap = this.option.selectedMap;
  140. return !!(selectedMap && selectedMap[name]);
  141. };
  142. GeoModel.type = 'geo';
  143. GeoModel.layoutMode = 'box';
  144. GeoModel.defaultOption = {
  145. // zlevel: 0,
  146. z: 0,
  147. show: true,
  148. left: 'center',
  149. top: 'center',
  150. // Default value:
  151. // for geoSVG source: 1,
  152. // for geoJSON source: 0.75.
  153. aspectScale: null,
  154. // /// Layout with center and size
  155. // If you want to put map in a fixed size box with right aspect ratio
  156. // This two properties may be more convenient
  157. // layoutCenter: [50%, 50%]
  158. // layoutSize: 100
  159. silent: false,
  160. // Map type
  161. map: '',
  162. // Define left-top, right-bottom coords to control view
  163. // For example, [ [180, 90], [-180, -90] ]
  164. boundingCoords: null,
  165. // Default on center of map
  166. center: null,
  167. zoom: 1,
  168. scaleLimit: null,
  169. // selectedMode: false
  170. label: {
  171. show: false,
  172. color: tokens.color.tertiary
  173. },
  174. itemStyle: {
  175. borderWidth: 0.5,
  176. borderColor: tokens.color.border
  177. },
  178. emphasis: {
  179. label: {
  180. show: true,
  181. color: tokens.color.primary
  182. },
  183. itemStyle: {
  184. color: tokens.color.highlight
  185. }
  186. },
  187. select: {
  188. label: {
  189. show: true,
  190. color: tokens.color.primary
  191. },
  192. itemStyle: {
  193. color: tokens.color.highlight
  194. }
  195. },
  196. regions: []
  197. // tooltip: {
  198. // show: false
  199. // }
  200. };
  201. return GeoModel;
  202. }(ComponentModel);
  203. export default GeoModel;