GeoModel.js 6.5 KB

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