geoSourceManager.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 { createHashMap } from 'zrender/lib/core/util.js';
  41. import { GeoSVGResource } from './GeoSVGResource.js';
  42. import { GeoJSONResource } from './GeoJSONResource.js';
  43. var storage = createHashMap();
  44. export default {
  45. /**
  46. * Compatible with previous `echarts.registerMap`.
  47. *
  48. * @usage
  49. * ```js
  50. *
  51. * echarts.registerMap('USA', geoJson, specialAreas);
  52. *
  53. * echarts.registerMap('USA', {
  54. * geoJson: geoJson,
  55. * specialAreas: {...}
  56. * });
  57. * echarts.registerMap('USA', {
  58. * geoJSON: geoJson,
  59. * specialAreas: {...}
  60. * });
  61. *
  62. * echarts.registerMap('airport', {
  63. * svg: svg
  64. * }
  65. * ```
  66. *
  67. * Note:
  68. * Do not support that register multiple geoJSON or SVG
  69. * one map name. Because different geoJSON and SVG have
  70. * different unit. It's not easy to make sure how those
  71. * units are mapping/normalize.
  72. * If intending to use multiple geoJSON or SVG, we can
  73. * use multiple geo coordinate system.
  74. */
  75. registerMap: function (mapName, rawDef, rawSpecialAreas) {
  76. if (rawDef.svg) {
  77. var resource = new GeoSVGResource(mapName, rawDef.svg);
  78. storage.set(mapName, resource);
  79. } else {
  80. // Recommend:
  81. // echarts.registerMap('eu', { geoJSON: xxx, specialAreas: xxx });
  82. // Backward compatibility:
  83. // echarts.registerMap('eu', geoJSON, specialAreas);
  84. // echarts.registerMap('eu', { geoJson: xxx, specialAreas: xxx });
  85. var geoJSON = rawDef.geoJson || rawDef.geoJSON;
  86. if (geoJSON && !rawDef.features) {
  87. rawSpecialAreas = rawDef.specialAreas;
  88. } else {
  89. geoJSON = rawDef;
  90. }
  91. var resource = new GeoJSONResource(mapName, geoJSON, rawSpecialAreas);
  92. storage.set(mapName, resource);
  93. }
  94. },
  95. getGeoResource: function (mapName) {
  96. return storage.get(mapName);
  97. },
  98. /**
  99. * Only for exporting to users.
  100. * **MUST NOT** used internally.
  101. */
  102. getMapForUser: function (mapName) {
  103. var resource = storage.get(mapName);
  104. // Do not support return SVG until some real requirement come.
  105. return resource && resource.type === 'geoJSON' && resource.getMapForUser();
  106. },
  107. load: function (mapName, nameMap, nameProperty) {
  108. var resource = storage.get(mapName);
  109. if (!resource) {
  110. if (process.env.NODE_ENV !== 'production') {
  111. console.error('Map ' + mapName + ' not exists. The GeoJSON of the map must be provided.');
  112. }
  113. return;
  114. }
  115. return resource.load(nameMap, nameProperty);
  116. }
  117. };