geoRoam.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 echarts = require("../echarts");
  20. var zrUtil = require("zrender/lib/core/util");
  21. var _roamHelper = require("./roamHelper");
  22. var updateCenterAndZoom = _roamHelper.updateCenterAndZoom;
  23. /*
  24. * Licensed to the Apache Software Foundation (ASF) under one
  25. * or more contributor license agreements. See the NOTICE file
  26. * distributed with this work for additional information
  27. * regarding copyright ownership. The ASF licenses this file
  28. * to you under the Apache License, Version 2.0 (the
  29. * "License"); you may not use this file except in compliance
  30. * with the License. You may obtain a copy of the License at
  31. *
  32. * http://www.apache.org/licenses/LICENSE-2.0
  33. *
  34. * Unless required by applicable law or agreed to in writing,
  35. * software distributed under the License is distributed on an
  36. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37. * KIND, either express or implied. See the License for the
  38. * specific language governing permissions and limitations
  39. * under the License.
  40. */
  41. /**
  42. * @payload
  43. * @property {string} [componentType=series]
  44. * @property {number} [dx]
  45. * @property {number} [dy]
  46. * @property {number} [zoom]
  47. * @property {number} [originX]
  48. * @property {number} [originY]
  49. */
  50. echarts.registerAction({
  51. type: 'geoRoam',
  52. event: 'geoRoam',
  53. update: 'updateTransform'
  54. }, function (payload, ecModel) {
  55. var componentType = payload.componentType || 'series';
  56. ecModel.eachComponent({
  57. mainType: componentType,
  58. query: payload
  59. }, function (componentModel) {
  60. var geo = componentModel.coordinateSystem;
  61. if (geo.type !== 'geo') {
  62. return;
  63. }
  64. var res = updateCenterAndZoom(geo, payload, componentModel.get('scaleLimit'));
  65. componentModel.setCenter && componentModel.setCenter(res.center);
  66. componentModel.setZoom && componentModel.setZoom(res.zoom); // All map series with same `map` use the same geo coordinate system
  67. // So the center and zoom must be in sync. Include the series not selected by legend
  68. if (componentType === 'series') {
  69. zrUtil.each(componentModel.seriesGroup, function (seriesModel) {
  70. seriesModel.setCenter(res.center);
  71. seriesModel.setZoom(res.zoom);
  72. });
  73. }
  74. });
  75. });