-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: rotate openlayers image (#2491)
* experiment: rotate openlayers image * feat: add rotate left/right icons * chore: bump size limit * test: spec useRotation composable * test: spec display of rotation buttons * fix: revert to global state so that multiple components can share * test: fix rotation specs * feat: reset rotation when creating new view
- Loading branch information
Showing
11 changed files
with
361 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { ref } from 'vue'; | ||
|
||
// current rotation in radians | ||
const rotation = ref(0); | ||
|
||
const reset = () => { | ||
rotation.value = 0; | ||
}; | ||
const rotateLess = () => { | ||
rotation.value = rotation.value - (Math.PI / 2); | ||
}; | ||
const rotateMore = () => { | ||
rotation.value = rotation.value + (Math.PI / 2); | ||
}; | ||
const setRotation = (value) => { | ||
rotation.value = value; | ||
}; | ||
|
||
export default function useRotation() { | ||
return { | ||
reset, | ||
rotateLess, | ||
rotateMore, | ||
rotation, | ||
setRotation | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import sinon from 'sinon'; | ||
import useRotation from '@/composables/rotation.js'; | ||
|
||
describe('useRotation', () => { | ||
afterEach(sinon.resetHistory); | ||
afterAll(sinon.restore); | ||
|
||
describe('refs', () => { | ||
describe('rotation', () => { | ||
it('defaults to 0', () => { | ||
const { rotation } = useRotation(); | ||
|
||
expect(rotation.value).toBe(0); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('methods', () => { | ||
describe('reset', () => { | ||
it('resets rotation value to 0', () => { | ||
const value = 1; | ||
const { rotation, reset, setRotation } = useRotation(); | ||
setRotation(value); | ||
|
||
reset(); | ||
|
||
expect(rotation.value).toBe(0); | ||
}); | ||
}); | ||
|
||
describe('setRotation', () => { | ||
it('sets rotation value', () => { | ||
const value = 1; | ||
const { rotation, setRotation } = useRotation(); | ||
|
||
setRotation(value); | ||
|
||
expect(rotation.value).toBe(value); | ||
}); | ||
}); | ||
|
||
describe('rotateLess', () => { | ||
it('reduces rotation by quarter circle', () => { | ||
const { reset, rotation, rotateLess } = useRotation(); | ||
|
||
reset(); | ||
rotateLess(); | ||
|
||
expect(rotation.value).toBe(0 - (Math.PI / 2)); | ||
}); | ||
}); | ||
|
||
describe('rotateMore', () => { | ||
it('increases rotation by quarter circle', () => { | ||
const { reset, rotation, rotateMore } = useRotation(); | ||
|
||
reset(); | ||
rotateMore(); | ||
|
||
expect(rotation.value).toBe(0 + (Math.PI / 2)); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.