Re-implementing basic scale and shift actions (without reevaluating the scope).

This commit is contained in:
Eric van der Vlist 2022-09-14 11:21:39 +02:00
parent 2eb9a6cb47
commit d5196f4340
2 changed files with 22 additions and 5 deletions

View File

@ -1,5 +1,5 @@
import react, { useMemo, useEffect, Fragment } from 'react'; import react, { useMemo, useEffect, Fragment } from 'react';
import { useDispatch, useSelector } from 'react-redux'; import { useDispatch } from 'react-redux';
import { mapActions } from '../../store/map'; import { mapActions } from '../../store/map';
import _ from 'lodash'; import _ from 'lodash';

View File

@ -1,5 +1,5 @@
import { createSlice } from '@reduxjs/toolkit'; import { createSlice } from '@reduxjs/toolkit';
import _, { round } from 'lodash'; import _ from 'lodash';
import { tileSize } from '../components/map/tiled-map'; import { tileSize } from '../components/map/tiled-map';
import { geoPoint, Point, lon2tile, lat2tile } from '../lib/geo'; import { geoPoint, Point, lon2tile, lat2tile } from '../lib/geo';
@ -107,8 +107,25 @@ const mapSlice = createSlice({
resize: (state) => { resize: (state) => {
return computeStateFromScope(state.scope); return computeStateFromScope(state.scope);
}, },
shift: (state, action) => {}, shift: (state, action) => {
scale: (state, action) => {}, state.slippy.translation = {
x: state.slippy.translation.x + action.payload.x,
y: state.slippy.translation.y + action.payload.y,
};
},
scale: (state, action) => {
state.slippy.scale = state.slippy.scale * action.payload.factor;
state.slippy.translation = {
x:
state.slippy.translation.x +
(state.slippy.translation.x - action.payload.center.x) *
(action.payload.factor - 1),
y:
state.slippy.translation.y +
(state.slippy.translation.y - action.payload.center.y) *
(action.payload.factor - 1),
};
},
}, },
}); });