GeoModel.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. var zrUtil = require("zrender/lib/core/util");
  20. var modelUtil = require("../../util/model");
  21. var ComponentModel = require("../../model/Component");
  22. var Model = require("../../model/Model");
  23. var selectableMixin = require("../../component/helper/selectableMixin");
  24. var geoCreator = require("./geoCreator");
  25. /*
  26. * Licensed to the Apache Software Foundation (ASF) under one
  27. * or more contributor license agreements. See the NOTICE file
  28. * distributed with this work for additional information
  29. * regarding copyright ownership. The ASF licenses this file
  30. * to you under the Apache License, Version 2.0 (the
  31. * "License"); you may not use this file except in compliance
  32. * with the License. You may obtain a copy of the License at
  33. *
  34. * http://www.apache.org/licenses/LICENSE-2.0
  35. *
  36. * Unless required by applicable law or agreed to in writing,
  37. * software distributed under the License is distributed on an
  38. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39. * KIND, either express or implied. See the License for the
  40. * specific language governing permissions and limitations
  41. * under the License.
  42. */
  43. var GeoModel = ComponentModel.extend({
  44. type: 'geo',
  45. /**
  46. * @type {module:echarts/coord/geo/Geo}
  47. */
  48. coordinateSystem: null,
  49. layoutMode: 'box',
  50. init: function (option) {
  51. ComponentModel.prototype.init.apply(this, arguments); // Default label emphasis `show`
  52. modelUtil.defaultEmphasis(option, 'label', ['show']);
  53. },
  54. optionUpdated: function () {
  55. var option = this.option;
  56. var self = this;
  57. option.regions = geoCreator.getFilledRegions(option.regions, option.map, option.nameMap);
  58. this._optionModelMap = zrUtil.reduce(option.regions || [], function (optionModelMap, regionOpt) {
  59. if (regionOpt.name) {
  60. optionModelMap.set(regionOpt.name, new Model(regionOpt, self));
  61. }
  62. return optionModelMap;
  63. }, zrUtil.createHashMap());
  64. this.updateSelectedMap(option.regions);
  65. },
  66. defaultOption: {
  67. zlevel: 0,
  68. z: 0,
  69. show: true,
  70. left: 'center',
  71. top: 'center',
  72. // width:,
  73. // height:,
  74. // right
  75. // bottom
  76. // Aspect is width / height. Inited to be geoJson bbox aspect
  77. // This parameter is used for scale this aspect
  78. // If svg used, aspectScale is 1 by default.
  79. // aspectScale: 0.75,
  80. aspectScale: null,
  81. ///// Layout with center and size
  82. // If you wan't to put map in a fixed size box with right aspect ratio
  83. // This two properties may more conveninet
  84. // layoutCenter: [50%, 50%]
  85. // layoutSize: 100
  86. silent: false,
  87. // Map type
  88. map: '',
  89. // Define left-top, right-bottom coords to control view
  90. // For example, [ [180, 90], [-180, -90] ]
  91. boundingCoords: null,
  92. // Default on center of map
  93. center: null,
  94. zoom: 1,
  95. scaleLimit: null,
  96. // selectedMode: false
  97. label: {
  98. show: false,
  99. color: '#000'
  100. },
  101. itemStyle: {
  102. // color: 各异,
  103. borderWidth: 0.5,
  104. borderColor: '#444',
  105. color: '#eee'
  106. },
  107. emphasis: {
  108. label: {
  109. show: true,
  110. color: 'rgb(100,0,0)'
  111. },
  112. itemStyle: {
  113. color: 'rgba(255,215,0,0.8)'
  114. }
  115. },
  116. regions: []
  117. },
  118. /**
  119. * Get model of region
  120. * @param {string} name
  121. * @return {module:echarts/model/Model}
  122. */
  123. getRegionModel: function (name) {
  124. return this._optionModelMap.get(name) || new Model(null, this, this.ecModel);
  125. },
  126. /**
  127. * Format label
  128. * @param {string} name Region name
  129. * @param {string} [status='normal'] 'normal' or 'emphasis'
  130. * @return {string}
  131. */
  132. getFormattedLabel: function (name, status) {
  133. status = status || 'normal';
  134. var regionModel = this.getRegionModel(name);
  135. var formatter = regionModel.get((status === 'normal' ? '' : status + '.') + 'label.formatter');
  136. var params = {
  137. name: name
  138. };
  139. if (typeof formatter === 'function') {
  140. params.status = status;
  141. return formatter(params);
  142. } else if (typeof formatter === 'string') {
  143. return formatter.replace('{a}', name != null ? name : '');
  144. }
  145. },
  146. setZoom: function (zoom) {
  147. this.option.zoom = zoom;
  148. },
  149. setCenter: function (center) {
  150. this.option.center = center;
  151. }
  152. });
  153. zrUtil.mixin(GeoModel, selectableMixin);
  154. var _default = GeoModel;
  155. module.exports = _default;