• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

geosolutions-it / MapStore2 / 12831531306

17 Jan 2025 03:01PM UTC coverage: 77.182% (+0.07%) from 77.115%
12831531306

Pull #10746

github

web-flow
Merge 501dbaeea into 4e4dabc03
Pull Request #10746: Fix #10739 Changing correctly resolutions limits when switching map CRS

30373 of 47156 branches covered (64.41%)

34 of 43 new or added lines in 2 files covered. (79.07%)

126 existing lines in 15 files now uncovered.

37769 of 48935 relevant lines covered (77.18%)

35.14 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.89
/web/client/actions/map.js
1
/*
2
 * Copyright 2015, GeoSolutions Sas.
3
 * All rights reserved.
4
 *
5
 * This source code is licensed under the BSD-style license found in the
6
 * LICENSE file in the root directory of this source tree.
7
*/
8

9
import { getResolutions, convertResolution } from '../utils/MapUtils';
10
import { layersSelector } from '../selectors/layers';
11
import { projectionSelector } from '../selectors/map';
12
import { updateNode } from '../actions/layers';
13
import minBy from 'lodash/minBy';
14

15
export const CHANGE_MAP_VIEW = 'CHANGE_MAP_VIEW';
1✔
16
export const CLICK_ON_MAP = 'CLICK_ON_MAP';
1✔
17
export const CHANGE_MOUSE_POINTER = 'CHANGE_MOUSE_POINTER';
1✔
18
export const CHANGE_ZOOM_LVL = 'CHANGE_ZOOM_LVL';
1✔
19
export const PAN_TO = 'PAN_TO';
1✔
20
export const ZOOM_TO_EXTENT = 'ZOOM_TO_EXTENT';
1✔
21
export const ZOOM_TO_POINT = 'ZOOM_TO_POINT';
1✔
22
export const CHANGE_MAP_CRS = 'CHANGE_MAP_CRS';
1✔
23
export const CHANGE_MAP_SCALES = 'CHANGE_MAP_SCALES';
1✔
24
export const CHANGE_MAP_STYLE = 'CHANGE_MAP_STYLE';
1✔
25
export const CHANGE_ROTATION = 'CHANGE_ROTATION';
1✔
26
export const CREATION_ERROR_LAYER = 'CREATION_ERROR_LAYER';
1✔
27
export const UPDATE_VERSION = 'UPDATE_VERSION';
1✔
28
export const INIT_MAP = 'INIT_MAP';
1✔
29
export const RESIZE_MAP = 'RESIZE_MAP';
1✔
30
export const CHANGE_MAP_LIMITS = 'CHANGE_MAP_LIMITS';
1✔
31
export const SET_MAP_RESOLUTIONS = 'SET_MAP_RESOLUTIONS';
1✔
32
export const REGISTER_EVENT_LISTENER = 'REGISTER_EVENT_LISTENER';
1✔
33
export const UNREGISTER_EVENT_LISTENER = 'UNREGISTER_EVENT_LISTENER';
1✔
34
export const MOUSE_MOVE = 'MOUSE_MOVE';
1✔
35
export const MOUSE_OUT = 'MOUSE_OUT';
1✔
36
export const MAP_PLUGIN_LOAD = 'MAP:MAP_PLUGIN_LOAD';
1✔
37
export const ORIENTATION = 'MAP:ORIENTATION';
1✔
38
export const UPDATE_MAP_VIEW = 'MAP:UPDATE_MAP_VIEW';
1✔
39
export const UPDATE_MAP_OPTIONS = 'MAP:UPDATE_MAP_OPTIONS';
1✔
40

41

42
/**
43
 * Event triggered when loading a different map type plugins (code for the specific implementation)
44
 * @prop {boolean} loading true when the loading is active. False when the loading is finished.
45
 * @prop {string} maptype
46
 * @prop {boolean} loaded true if the plugin for the map type is effectively loaded. false or undefined if it is not loaded or there was some error loading
47
 * @prop {Error} errorMap if valorized, contains the error occurred during the map plugin loading.
48
 */
49
export function mapPluginLoad(loading, mapType, loaded, errorMap) {
50
    return {
8✔
51
        type: MAP_PLUGIN_LOAD,
52
        mapType,
53
        loading,
54
        loaded,
55
        error: errorMap
56
    };
57
}
58

59
/**
60
 * zoom to a specific point
61
 * @memberof actions.map
62
 * @param {object} pos as array [x, y] or object {x: ..., y:...}
63
 * @param {number} zoom level to zoom to
64
 * @param {string} crs of the point
65
*/
66
export function zoomToPoint(pos, zoom, crs) {
67
    return {
12✔
68
        type: ZOOM_TO_POINT,
69
        pos,
70
        zoom,
71
        crs
72
    };
73
}
74

75
export function changeMapView(center, zoom, bbox, size, mapStateSource, projection, viewerOptions, resolution) {
76
    return {
31✔
77
        type: CHANGE_MAP_VIEW,
78
        center,
79
        zoom,
80
        bbox,
81
        size,
82
        mapStateSource,
83
        projection,
84
        viewerOptions,
85
        resolution
86
    };
87
}
88

89
export const changeCRS = (crs) => ({
4✔
90
    type: CHANGE_MAP_CRS,
91
    crs: crs
92
});
93
export function changeMapCrs(crs) {
94
    return (dispatch, getState = () => {}) => {
1!
95
        const state =  getState();
1✔
96
        const sourceCRS = projectionSelector(state);
1✔
97
        const layersWithLimits = layersSelector(state).filter(l => l.minResolution || l.maxResolution);
2!
98
        layersWithLimits.forEach(layer => {
1✔
99
            const options = {};
2✔
100
            const newResolutions = getResolutions(crs);
2✔
101
            if (layer.minResolution) {
2!
102
                options.minResolution = convertResolution(sourceCRS, crs, layer.minResolution).transformedResolution;
2✔
103
                const diffs = newResolutions.map((resolution, zoom) => ({ diff: Math.abs(resolution - options.minResolution), zoom }));
62✔
104
                const { zoom } = minBy(diffs, 'diff');
2✔
105
                options.minResolution = newResolutions[zoom];
2✔
106
            }
107
            if (layer.maxResolution) {
2✔
108
                options.maxResolution = convertResolution(sourceCRS, crs, layer.maxResolution).transformedResolution;
1✔
109
                const diffs = newResolutions.map((resolution, zoom) => ({ diff: Math.abs(resolution - options.maxResolution), zoom }));
31✔
110
                const { zoom } = minBy(diffs, 'diff');
1✔
111
                // check if min and max resolutions are not the same
112
                options.maxResolution = newResolutions[zoom];
1✔
113
                if (options.minResolution === options.maxResolution) {
1!
NEW
114
                    if ((zoom - 1) >= 0) {
×
115
                        // increase max res if possible
NEW
116
                        options.maxResolution = newResolutions[zoom - 1];
×
NEW
117
                    } else if (zoom + 1 < newResolutions.length) {
×
118
                        // decrease max res if possible
NEW
119
                        options.minResolution = newResolutions[zoom + 1];
×
120
                    } else {
121
                        // keep only min res if none of the previous is happening
NEW
122
                        options.maxResolution = undefined;
×
123
                    }
124
                }
125
            }
126
            // the minimum difference represents the nearest zoom to the target resolution
127
            dispatch(updateNode(layer.id, "layer", options));
2✔
128
        });
129
        dispatch(changeCRS(crs));
1✔
130
    };
131
}
132

133
export function changeMapScales(scales) {
134
    return {
1✔
135
        type: CHANGE_MAP_SCALES,
136
        scales: scales
137
    };
138
}
139

140
export function clickOnMap(point, layer) {
141
    return {
10✔
142
        type: CLICK_ON_MAP,
143
        point: point,
144
        layer
145
    };
146
}
147

148
export function changeMousePointer(pointerType) {
149
    return {
3✔
150
        type: CHANGE_MOUSE_POINTER,
151
        pointer: pointerType
152
    };
153
}
154

155
export function changeZoomLevel(zoomLvl, mapStateSource) {
156
    return {
1✔
157
        type: CHANGE_ZOOM_LVL,
158
        zoom: zoomLvl,
159
        mapStateSource: mapStateSource
160
    };
161
}
162

163

164
/**
165
 * pan to a specific point
166
 * @memberof actions.map
167
 * @param {object} center as {x, y, crs}
168
*/
169
export function panTo(center) {
170
    return {
×
171
        type: PAN_TO,
172
        center
173
    };
174
}
175

176
/**
177
 * zoom to the specified extent
178
 * @memberof actions.map
179
 * @param {number[]} extent in the form of [minx, miny, maxx, maxy]
180
 * @param {string} crs related the extent
181
 * @param {number} maxZoom the max zoom limit
182
 * @param {object} options additional options `{nearest: true}`is the only supported
183
 * (See {@link https://openlayers.org/en/latest/apidoc/module-ol_View-View.html#fit| Openlayers View, fit method} )
184
 */
185
export function zoomToExtent(extent, crs, maxZoom, options) {
186
    return {
80✔
187
        type: ZOOM_TO_EXTENT,
188
        extent,
189
        crs,
190
        maxZoom,
191
        options
192
    };
193
}
194

195
export function changeRotation(rotation, mapStateSource) {
196
    return {
1✔
197
        type: CHANGE_ROTATION,
198
        rotation,
199
        mapStateSource
200
    };
201
}
202

203
export function changeMapStyle(style, mapStateSource) {
204
    return {
1✔
205
        type: CHANGE_MAP_STYLE,
206
        style,
207
        mapStateSource
208
    };
209
}
210
export function updateVersion(version) {
211
    return {
1✔
212
        type: UPDATE_VERSION,
213
        version
214
    };
215
}
216

217
export function initMap(disableFeedbackMask) {
218
    return {
8✔
219
        type: INIT_MAP,
220
        disableFeedbackMask
221
    };
222
}
223

224
export function resizeMap() {
225
    return {
1✔
226
        type: RESIZE_MAP
227
    };
228
}
229
export function changeMapLimits({restrictedExtent, crs, minZoom}) {
230
    return {
5✔
231
        type: CHANGE_MAP_LIMITS,
232
        restrictedExtent,
233
        crs,
234
        minZoom
235
    };
236
}
237

238
export function setMapResolutions(resolutions) {
239
    return {
4✔
240
        type: SET_MAP_RESOLUTIONS,
241
        resolutions
242
    };
243
}
244

245
/**
246
 * Add a tool to the list of event listeners for the map plugin.
247
 * This can help to trigger actions only if some tool is effectively listen. Useful for
248
 * events that are triggered frequently and so can slow down the application.
249
 * @param {string} eventName the event name. One of ``pointermove`,
250
 * @param {string} toolName an identifier for the tool
251
 */
252
export const registerEventListener = (eventName, toolName) => ({
12✔
253
    type: REGISTER_EVENT_LISTENER,
254
    eventName,
255
    toolName
256
});
257

258
/**
259
 * Remove the listeners added using `registerEventListener` .
260
 * @param {string} eventName the event name. One of ``pointermove`,
261
 * @param {string} toolName an identifier for the tool
262
 */
263
export const unRegisterEventListener = (eventName, toolName) => ({
7✔
264
    type: UNREGISTER_EVENT_LISTENER,
265
    eventName,
266
    toolName
267
});
268

269
/**
270
 * Triggered on mouse move. (only if some tool is registered on this event. See `registerEventListener`).
271
 * @param {object} position the position of the mouse on the map.
272
 */
273
export const mouseMove = (position) => ({
1✔
274
    type: MOUSE_MOVE,
275
    position
276
});
277

278
/**
279
 * Triggered when the mouse goes out from the map
280
 */
281
export const mouseOut = () => ({
1✔
282
    type: MOUSE_OUT
283
});
284

285
/**
286
 * Dispatch orientation co-ordinates (head, pitch and roll)
287
 * @param orientation
288
 * @returns {{orientation, type: string}}
289
 */
290
export const orientateMap = (orientation) => ({
3✔
291
    type: ORIENTATION,
292
    orientation
293
});
294

295
export const updateMapView = (data) => ({
1✔
296
    type: UPDATE_MAP_VIEW,
297
    data
298
});
299

300
export const updateMapOptions = (configUpdate) => ({
2✔
301
    type: UPDATE_MAP_OPTIONS,
302
    configUpdate
303
});
304

305
/**
306
 * Actions for map
307
 * @name actions.map
308
 */
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc