mapUtil.test.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. import Map from 'ol/Map.js';
  20. import OSM from 'ol/source/OSM.js';
  21. import TileLayer from 'ol/layer/Tile.js';
  22. import View from 'ol/View.js';
  23. import { ChartConfig } from '../../src/types';
  24. import { fitMapToCharts } from '../../src/util/mapUtil';
  25. describe('mapUtil', () => {
  26. describe('fitMapToCharts', () => {
  27. it('changes the center of the map', () => {
  28. const chartConfig: ChartConfig = {
  29. type: 'FeatureCollection',
  30. features: [
  31. {
  32. type: 'Feature',
  33. geometry: {
  34. type: 'Point',
  35. coordinates: [8.793, 53.04117],
  36. },
  37. properties: {
  38. setDataMask: '',
  39. labelMap: '',
  40. labelMapB: '',
  41. groupby: '',
  42. selectedValues: '',
  43. formData: '',
  44. groupbyB: '',
  45. seriesBreakdown: '',
  46. legendData: '',
  47. echartOptions: '',
  48. },
  49. },
  50. {
  51. type: 'Feature',
  52. geometry: {
  53. type: 'Point',
  54. coordinates: [10.61833, 51.8],
  55. },
  56. properties: {
  57. setDataMask: '',
  58. labelMap: '',
  59. labelMapB: '',
  60. groupby: '',
  61. selectedValues: '',
  62. formData: '',
  63. groupbyB: '',
  64. seriesBreakdown: '',
  65. legendData: '',
  66. echartOptions: '',
  67. },
  68. },
  69. {
  70. type: 'Feature',
  71. geometry: {
  72. type: 'Point',
  73. coordinates: [6.86883, 50.35667],
  74. },
  75. properties: {
  76. setDataMask: '',
  77. labelMap: '',
  78. labelMapB: '',
  79. groupby: '',
  80. selectedValues: '',
  81. formData: '',
  82. groupbyB: '',
  83. seriesBreakdown: '',
  84. legendData: '',
  85. echartOptions: '',
  86. },
  87. },
  88. ],
  89. };
  90. const initialCenter = [0, 0];
  91. const olMap = new Map({
  92. layers: [
  93. new TileLayer({
  94. source: new OSM(),
  95. }),
  96. ],
  97. target: 'map',
  98. view: new View({
  99. center: initialCenter,
  100. zoom: 2,
  101. }),
  102. });
  103. // should set center
  104. fitMapToCharts(olMap, chartConfig);
  105. const updatedCenter = olMap.getView().getCenter();
  106. expect(initialCenter).not.toEqual(updatedCenter);
  107. });
  108. });
  109. });