Skip to content

Commit ca47389

Browse files
mgermeriegchoqueux
authored andcommitted
refacto(PlanarControls): refactor zoom speed management
1 parent a86e3f8 commit ca47389

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

examples/view_2d_map.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@
3535
placement: new itowns.Extent('EPSG:3857', -20000000, 20000000, -8000000, 20000000),
3636
controls: {
3737
// Faster zoom in/out speed
38-
zoomInFactor: 3,
39-
zoomOutFactor: 0.3,
38+
zoomFactor: 3,
4039
},
4140
});
4241

src/Controls/PlanarControls.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ const defaultOptions = {
8484
minPanSpeed: 0.05,
8585
maxPanSpeed: 15,
8686
zoomTravelTime: 0.2, // must be a number
87-
zoomInFactor: 2,
88-
zoomOutFactor: 0.5,
87+
zoomFactor: 2,
8988
maxAltitude: 50000000,
9089
groundLevel: 200,
9190
autoTravelTimeMin: 1.5,
@@ -132,8 +131,8 @@ export const PLANAR_CONTROL_EVENT = {
132131
* @param {number} [options.maxPanSpeed=15] Pan speed when close to maxAltitude.
133132
* @param {number} [options.minPanSpeed=0.05] Pan speed when close to the ground.
134133
* @param {number} [options.zoomTravelTime=0.2] Animation time when zooming.
135-
* @param {number} [options.zoomInFactor=2] The factor the scale is multiplied by when zooming in.
136-
* @param {number} [options.zoomOutFactor=2] The factor the scale is multiplied by when zooming out.
134+
* @param {number} [options.zoomFactor=2] The factor the scale is multiplied by when zooming
135+
* in and divided by when zooming out. This factor can't be null.
137136
* @param {number} [options.maxAltitude=12000] Maximum altitude reachable when panning or zooming out.
138137
* @param {number} [options.groundLevel=200] Minimum altitude reachable when panning.
139138
* @param {number} [options.autoTravelTimeMin=1.5] Minimum duration for animated travels with the `auto`
@@ -200,8 +199,20 @@ class PlanarControls extends THREE.EventDispatcher {
200199
}
201200

202201
// zoom movement is equal to the distance to the zoom target, multiplied by zoomFactor
203-
this.zoomInFactor = options.zoomInFactor || defaultOptions.zoomInFactor;
204-
this.zoomOutFactor = options.zoomOutFactor || defaultOptions.zoomOutFactor;
202+
if (options.zoomInFactor) {
203+
console.warn('Controls zoomInFactor parameter is deprecated. Use zoomFactor instead.');
204+
options.zoomFactor = options.zoomFactor || options.zoomInFactor;
205+
}
206+
if (options.zoomOutFactor) {
207+
console.warn('Controls zoomOutFactor parameter is deprecated. Use zoomFactor instead.');
208+
options.zoomFactor = options.zoomFactor || options.zoomInFactor || 1 / options.zoomOutFactor;
209+
}
210+
if (options.zoomFactor === 0) {
211+
console.warn('Controls zoomFactor parameter can not be equal to 0. Its value will be set to default.');
212+
options.zoomFactor = defaultOptions.zoomFactor;
213+
}
214+
this.zoomInFactor = options.zoomFactor || defaultOptions.zoomFactor;
215+
this.zoomOutFactor = 1 / (options.zoomFactor || defaultOptions.zoomFactor);
205216

206217
// approximate ground altitude value. Camera altitude is clamped above groundLevel
207218
this.groundLevel = options.groundLevel || defaultOptions.groundLevel;

0 commit comments

Comments
 (0)