install.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. });
  71. // Notice: there might be duplicated name in different regions.
  72. var names = [];
  73. each(selected, function (v, name) {
  74. selected[name] && names.push(name);
  75. });
  76. allSelected.push({
  77. geoIndex: geoModel.componentIndex,
  78. // Use singular, the same naming convention as the event `selectchanged`.
  79. name: names
  80. });
  81. });
  82. return {
  83. selected: selected,
  84. allSelected: allSelected,
  85. name: payload.name
  86. };
  87. });
  88. }
  89. makeAction('toggleSelected', {
  90. type: 'geoToggleSelect',
  91. event: 'geoselectchanged'
  92. });
  93. makeAction('select', {
  94. type: 'geoSelect',
  95. event: 'geoselected'
  96. });
  97. makeAction('unSelect', {
  98. type: 'geoUnSelect',
  99. event: 'geounselected'
  100. });
  101. /**
  102. * @payload
  103. * @property {string} [componentType=series]
  104. * @property {number} [dx]
  105. * @property {number} [dy]
  106. * @property {number} [zoom]
  107. * @property {number} [originX]
  108. * @property {number} [originY]
  109. */
  110. registers.registerAction({
  111. type: 'geoRoam',
  112. event: 'geoRoam',
  113. update: 'updateTransform'
  114. }, function (payload, ecModel, api) {
  115. var componentType = payload.componentType || 'series';
  116. ecModel.eachComponent({
  117. mainType: componentType,
  118. query: payload
  119. }, function (componentModel) {
  120. var geo = componentModel.coordinateSystem;
  121. if (geo.type !== 'geo') {
  122. return;
  123. }
  124. var res = updateCenterAndZoom(geo, payload, componentModel.get('scaleLimit'), api);
  125. componentModel.setCenter && componentModel.setCenter(res.center);
  126. componentModel.setZoom && componentModel.setZoom(res.zoom);
  127. // All map series with same `map` use the same geo coordinate system
  128. // So the center and zoom must be in sync. Include the series not selected by legend
  129. if (componentType === 'series') {
  130. each(componentModel.seriesGroup, function (seriesModel) {
  131. seriesModel.setCenter(res.center);
  132. seriesModel.setZoom(res.zoom);
  133. });
  134. }
  135. });
  136. });
  137. }