install.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 GeoModel from '../../coord/geo/GeoModel.js';
  41. import geoCreator from '../../coord/geo/geoCreator.js';
  42. import { each } from 'zrender/lib/core/util.js';
  43. import { updateCenterAndZoom } from '../../action/roamHelper.js';
  44. import GeoView from './GeoView.js';
  45. import geoSourceManager from '../../coord/geo/geoSourceManager.js';
  46. function registerMap(mapName, geoJson, specialAreas) {
  47. geoSourceManager.registerMap(mapName, geoJson, specialAreas);
  48. }
  49. export function install(registers) {
  50. registers.registerCoordinateSystem('geo', geoCreator);
  51. registers.registerComponentModel(GeoModel);
  52. registers.registerComponentView(GeoView);
  53. registers.registerImpl('registerMap', registerMap);
  54. registers.registerImpl('getMap', function (mapName) {
  55. return geoSourceManager.getMapForUser(mapName);
  56. });
  57. function makeAction(method, actionInfo) {
  58. actionInfo.update = 'geo:updateSelectStatus';
  59. registers.registerAction(actionInfo, function (payload, ecModel) {
  60. var selected = {};
  61. var allSelected = [];
  62. ecModel.eachComponent({
  63. mainType: 'geo',
  64. query: payload
  65. }, function (geoModel) {
  66. geoModel[method](payload.name);
  67. var geo = geoModel.coordinateSystem;
  68. each(geo.regions, function (region) {
  69. selected[region.name] = geoModel.isSelected(region.name) || false;
  70. }); // Notice: there might be duplicated name in different regions.
  71. var names = [];
  72. each(selected, function (v, name) {
  73. selected[name] && names.push(name);
  74. });
  75. allSelected.push({
  76. geoIndex: geoModel.componentIndex,
  77. // Use singular, the same naming convention as the event `selectchanged`.
  78. name: names
  79. });
  80. });
  81. return {
  82. selected: selected,
  83. allSelected: allSelected,
  84. name: payload.name
  85. };
  86. });
  87. }
  88. makeAction('toggleSelected', {
  89. type: 'geoToggleSelect',
  90. event: 'geoselectchanged'
  91. });
  92. makeAction('select', {
  93. type: 'geoSelect',
  94. event: 'geoselected'
  95. });
  96. makeAction('unSelect', {
  97. type: 'geoUnSelect',
  98. event: 'geounselected'
  99. });
  100. /**
  101. * @payload
  102. * @property {string} [componentType=series]
  103. * @property {number} [dx]
  104. * @property {number} [dy]
  105. * @property {number} [zoom]
  106. * @property {number} [originX]
  107. * @property {number} [originY]
  108. */
  109. registers.registerAction({
  110. type: 'geoRoam',
  111. event: 'geoRoam',
  112. update: 'updateTransform'
  113. }, function (payload, ecModel, api) {
  114. var componentType = payload.componentType || 'series';
  115. ecModel.eachComponent({
  116. mainType: componentType,
  117. query: payload
  118. }, function (componentModel) {
  119. var geo = componentModel.coordinateSystem;
  120. if (geo.type !== 'geo') {
  121. return;
  122. }
  123. var res = updateCenterAndZoom(geo, payload, componentModel.get('scaleLimit'), api);
  124. componentModel.setCenter && componentModel.setCenter(res.center);
  125. componentModel.setZoom && componentModel.setZoom(res.zoom); // All map series with same `map` use the same geo coordinate system
  126. // So the center and zoom must be in sync. Include the series not selected by legend
  127. if (componentType === 'series') {
  128. each(componentModel.seriesGroup, function (seriesModel) {
  129. seriesModel.setCenter(res.center);
  130. seriesModel.setZoom(res.zoom);
  131. });
  132. }
  133. });
  134. });
  135. }