install.js 4.5 KB

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