Skip to content

Commit

Permalink
Merge pull request #151 from Geoportail-Luxembourg/GSLUX-705-modify-f…
Browse files Browse the repository at this point in the history
…eature

GSLUX-705: Modify feature geometry
  • Loading branch information
tkohr authored Sep 27, 2024
2 parents f4c2e1d + 1307a59 commit 5138c33
Show file tree
Hide file tree
Showing 17 changed files with 328 additions and 147 deletions.
4 changes: 2 additions & 2 deletions cypress/e2e/background-selection.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('Background selector', () => {
const layers = (<AUTWindowOlMap>window).olMap
.getLayers()
.getArray()
.filter((l: any) => l.get('featureID') != 'featureLayer')
.filter((l: any) => l.get('cyLayerType') !== 'featureLayer')

Check warning on line 25 in cypress/e2e/background-selection.cy.ts

View workflow job for this annotation

GitHub Actions / build-lint-test

Unexpected any. Specify a different type
expect(layers[0].get('id')).to.eq(556)
})

Expand Down Expand Up @@ -52,7 +52,7 @@ describe('Background selector', () => {
const layers = (<AUTWindowOlMap>window).olMap
.getLayers()
.getArray()
.filter((l: any) => l.get('featureID') != 'featureLayer')
.filter((l: any) => l.get('cyLayerType') !== 'featureLayer')

Check warning on line 55 in cypress/e2e/background-selection.cy.ts

View workflow job for this annotation

GitHub Actions / build-lint-test

Unexpected any. Specify a different type
expect(layers[0].get('id')).to.eq(502)
})
})
Expand Down
84 changes: 49 additions & 35 deletions cypress/e2e/draw/draw-bar.cy.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import {
checkDrawInteractionActive,
checkModifyInteractionActive,
testFeatItem,
} from './draw-feat.utils'

describe('Map controls', () => {
beforeEach(() => {
cy.visit('/')
Expand All @@ -10,20 +16,27 @@ describe('Map controls', () => {
})
})

describe('when clicking button to draw point', () => {
beforeEach(() => {
describe('When clicking button to close draw tools', () => {
it('should deactivate active ol draw interaction', () => {
cy.get('button[data-cy="drawPointButton"]').click()
})

it('activates ol Draw interaction in mode Point', () => {
checkDrawInteractionActive('Point')
cy.get('button[data-cy="drawButton"]').click()
cy.getDrawInteractions().then(drawInteractions => {
const activeInteractions = drawInteractions.filter(interaction => {
return interaction.getActive() === true
})
expect(activeInteractions).to.have.length(1)
expect(activeInteractions[0].mode_).to.be.equal('Point')
expect(activeInteractions).to.have.length(0)
})
})
})

describe('when clicking button to draw point', () => {
beforeEach(() => {
cy.get('button[data-cy="drawPointButton"]').click()
})
it('activates ol Draw interaction in mode Point', () => {
checkDrawInteractionActive('Point')
})

describe('When drawing the point on the map', () => {
beforeEach(() => {
Expand All @@ -34,6 +47,11 @@ describe('Map controls', () => {
cy.get('div[data-cy="drawPanel"]').should('exist')
})

it('activates edition in panel and on map (ol modify interaction)', () => {
checkModifyInteractionActive(true)
testFeatItem()
})

it('does not display a tooltip overlay when clicking on the map', () => {
cy.get('div.lux-tooltip').should('not.exist')
})
Expand All @@ -46,13 +64,7 @@ describe('Map controls', () => {
})

it('activates ol Draw interaction in mode Point', () => {
cy.getDrawInteractions().then(drawInteractions => {
const activeInteractions = drawInteractions.filter(interaction => {
return interaction.getActive() === true
})
expect(activeInteractions).to.have.length(1)
expect(activeInteractions[0].mode_).to.be.equal('Point')
})
checkDrawInteractionActive('Point')
})

describe('When drawing the label on the map', () => {
Expand All @@ -64,6 +76,11 @@ describe('Map controls', () => {
cy.get('div[data-cy="drawPanel"]').should('exist')
})

it('activates edition in panel and on map (ol modify interaction)', () => {
checkModifyInteractionActive(true)
testFeatItem()
})

it('does not display a tooltip overlay when clicking on the map', () => {
cy.get('div.lux-tooltip').should('not.exist')
})
Expand All @@ -76,13 +93,7 @@ describe('Map controls', () => {
})

it('activates ol Draw interaction in mode LineString', () => {
cy.getDrawInteractions().then(drawInteractions => {
const activeInteractions = drawInteractions.filter(interaction => {
return interaction.getActive() === true
})
expect(activeInteractions).to.have.length(1)
expect(activeInteractions[0].mode_).to.be.equal('LineString')
})
checkDrawInteractionActive('LineString')
})

it('displays a tooltip when clicking on the map and hides it on draw end (second point double click)', () => {
Expand All @@ -101,6 +112,11 @@ describe('Map controls', () => {
it('displays the draw Panel', () => {
cy.get('div[data-cy="drawPanel"]').should('exist')
})

it('activates edition in panel and on map (ol modify interaction)', () => {
checkModifyInteractionActive(true)
testFeatItem()
})
})
})

Expand All @@ -110,13 +126,7 @@ describe('Map controls', () => {
})

it('activates ol Draw interaction in mode Polygon', () => {
cy.getDrawInteractions().then(drawInteractions => {
const activeInteractions = drawInteractions.filter(interaction => {
return interaction.getActive() === true
})
expect(activeInteractions).to.have.length(1)
expect(activeInteractions[0].mode_).to.be.equal('Polygon')
})
checkDrawInteractionActive('Polygon')
})

it('displays a tooltip when clicking on the map and hides it on draw end (third point double click)', () => {
Expand All @@ -137,6 +147,11 @@ describe('Map controls', () => {
it('displays the draw Panel', () => {
cy.get('div[data-cy="drawPanel"]').should('exist')
})

it('activates edition in panel and on map (ol modify interaction)', () => {
checkModifyInteractionActive(true)
testFeatItem()
})
})
})

Expand All @@ -146,13 +161,7 @@ describe('Map controls', () => {
})

it('activates ol Draw interaction in mode Circle', () => {
cy.getDrawInteractions().then(drawInteractions => {
const activeInteractions = drawInteractions.filter(interaction => {
return interaction.getActive() === true
})
expect(activeInteractions).to.have.length(1)
expect(activeInteractions[0].mode_).to.be.equal('Circle')
})
checkDrawInteractionActive('Circle')
})

it('displays a tooltip when clicking on the map and hides it on draw end (second point simple click)', () => {
Expand All @@ -171,6 +180,11 @@ describe('Map controls', () => {
it('displays the draw Panel', () => {
cy.get('div[data-cy="drawPanel"]').should('exist')
})

it('activates edition in panel and on map (ol modify interaction)', () => {
checkModifyInteractionActive(true)
testFeatItem()
})
})
})
})
22 changes: 22 additions & 0 deletions cypress/e2e/draw/draw-feat.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,25 @@ export function testFeatItemDocking() {
cy.get('*[data-cy="featItemDock"]').click()
cy.get('*[data-cy="mapPopup"]').should('exist')
}

export function checkDrawInteractionActive(
type: 'Point' | 'LineString' | 'Polygon' | 'Circle'
) {
cy.getDrawInteractions().then(drawInteractions => {
const activeInteractions = drawInteractions.filter(interaction => {
return interaction.getActive() === true
})
expect(activeInteractions).to.have.length(1)
expect(activeInteractions[0].mode_).to.be.equal(type)
})
}

export function checkModifyInteractionActive(exists: boolean) {
cy.getModifyInteraction().then(modifyInteraction => {
if (exists) {
expect(modifyInteraction).to.exist
} else {
expect(modifyInteraction).to.equal(undefined)
}
})
}
14 changes: 14 additions & 0 deletions cypress/e2e/draw/draw-panel.cy.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { checkModifyInteractionActive, testFeatItem } from './draw-feat.utils'

describe('Draw panel', () => {
beforeEach(() => {
cy.visit('/')
Expand Down Expand Up @@ -33,4 +35,16 @@ describe('Draw panel', () => {
cy.get('@menuItem').eq(4).should('contain.text', 'Couper une ligne')
})
})

describe('When clicking toggle edit button', () => {
it('should toggle edit in panel and on map (ol modify interaction)', () => {
checkModifyInteractionActive(true)
testFeatItem()
cy.get('*[data-cy="featItemToggleEdit"]').click()
checkModifyInteractionActive(false)
cy.get('*[data-cy="featItemToggleEdit"]').click()
checkModifyInteractionActive(true)
testFeatItem()
})
})
})
4 changes: 2 additions & 2 deletions cypress/e2e/layers-selection.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('Catalogue', () => {
const layers = (<AUTWindowOlMap>window).olMap
.getLayers()
.getArray()
.filter((l: any) => l.get('featureID') != 'featureLayer')
.filter((l: any) => l.get('cyLayerType') !== 'featureLayer')

Check warning on line 69 in cypress/e2e/layers-selection.cy.ts

View workflow job for this annotation

GitHub Actions / build-lint-test

Unexpected any. Specify a different type
expect(layers[0].get('id')).to.eq(556)
})
cy.get('[data-cy="catalog"]').find('[data-cy="layerLabel-359"]').click()
Expand All @@ -76,7 +76,7 @@ describe('Catalogue', () => {
const layers = (<AUTWindowOlMap>window).olMap
.getLayers()
.getArray()
.filter((l: any) => l.get('featureID') != 'featureLayer')
.filter((l: any) => l.get('cyLayerType') !== 'featureLayer')

Check warning on line 79 in cypress/e2e/layers-selection.cy.ts

View workflow job for this annotation

GitHub Actions / build-lint-test

Unexpected any. Specify a different type
expect(layers[0].get('id')).to.eq(359)
expect(layers[1].get('id')).to.eq(353)
})
Expand Down
19 changes: 18 additions & 1 deletion cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Cypress.Commands.add('getDrawInteractions', () => {
.getInteractions()
.getArray()
.filter(interaction => {
// workaround for 'instance of Draw' not working with Draw2 class
// workaround for 'instance of Draw' not working (with Draw2 class?)
return (
'finishDrawing' in interaction &&
typeof interaction.finishDrawing === 'function'
Expand All @@ -45,10 +45,27 @@ Cypress.Commands.add('getDrawInteractions', () => {
})
})

Cypress.Commands.add('getModifyInteraction', () => {
cy.window().then(win => {
const map = win.olMap
const modifyInteraction = map
.getInteractions()
.getArray()
.find(interaction => {
return (
'removePoint' in interaction &&
typeof interaction.removePoint === 'function'
)
})
cy.wrap(modifyInteraction)
})
})

declare global {
namespace Cypress {
interface Chainable {
getDrawInteractions(): Chainable<Array<Interaction>>
getModifyInteraction(): Chainable<Interaction>
// login(email: string, password: string): Chainable<void>
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
Expand Down
2 changes: 0 additions & 2 deletions src/components/draw/feature-item.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ function onToggleFeatureSub() {
function onToggleEditFeature() {
emit('toggleFeatureEdit', getUid(props.feature), !props.isEditing)
alert('TODO: Toggle edition mode')
}
function onClickDelete() {
Expand Down
45 changes: 29 additions & 16 deletions src/components/footer/toolbar-draw.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
import { useTranslation } from 'i18next-vue'
import { storeToRefs } from 'pinia'
import useDraw from '@/composables/draw/draw.composable'
import { useDrawStore } from '@/stores/draw.store'
import ButtonText from './button-text.vue'
import { onBeforeUnmount } from 'vue'
const { t } = useTranslation()
const drawStore = useDrawStore()
const { toggleActiveState } = drawStore
const { drawStateActive } = storeToRefs(drawStore)
// keep logic in composable
useDraw()
const { toggleDrawActiveState, setDrawActiveState } = drawStore
const { drawStateActive, editStateActive } = storeToRefs(drawStore)
onBeforeUnmount(() => {
setDrawActiveState(undefined)
})
</script>
<template>
<div data-cy="toolbarDraw">
Expand All @@ -22,52 +24,63 @@ useDraw()
<li>
<button-text
:label="t('Draw Point', { ns: 'client' })"
:active="drawStateActive === 'drawPoint'"
@click="() => toggleActiveState('drawPoint')"
:active="
drawStateActive === 'drawPoint' || editStateActive === 'editPoint'
"
@click="() => toggleDrawActiveState('drawPoint')"
data-cy="drawPointButton"
>
</button-text>
</li>
<li>
<button-text
:label="t('Label', { ns: 'client' })"
:active="drawStateActive === 'drawLabel'"
@click="() => toggleActiveState('drawLabel')"
:active="
drawStateActive === 'drawLabel' || editStateActive === 'editLabel'
"
@click="() => toggleDrawActiveState('drawLabel')"
data-cy="drawLabelButton"
>
</button-text>
</li>
<li>
<button-text
:label="t('Line', { ns: 'client' })"
:active="drawStateActive === 'drawLine'"
@click="() => toggleActiveState('drawLine')"
:active="
drawStateActive === 'drawLine' || editStateActive === 'editLine'
"
@click="() => toggleDrawActiveState('drawLine')"
data-cy="drawLineButton"
>
</button-text>
</li>
<li>
<button-text
:label="t('Polygon', { ns: 'client' })"
:active="drawStateActive === 'drawPolygon'"
@click="() => toggleActiveState('drawPolygon')"
:active="
drawStateActive === 'drawPolygon' ||
editStateActive === 'editPolygon'
"
@click="() => toggleDrawActiveState('drawPolygon')"
data-cy="drawPolygonButton"
>
</button-text>
</li>
<li>
<button-text
:label="t('Circle', { ns: 'client' })"
:active="drawStateActive === 'drawCircle'"
@click="() => toggleActiveState('drawCircle')"
:active="
drawStateActive === 'drawCircle' || editStateActive === 'editCircle'
"
@click="() => toggleDrawActiveState('drawCircle')"
data-cy="drawCircleButton"
>
</button-text>
</li>
</ul>
<ul
class="absolute bottom-full top-auto z-10 pl-[130px] pb-16 w-[326px]"
v-if="drawStateActive === 'drawLine'"
v-if="drawStateActive === 'drawLine' || editStateActive === 'editLine'"
data-cy="followRoads"
>
<li
Expand Down
Loading

0 comments on commit 5138c33

Please sign in to comment.