Skip to content

Commit

Permalink
[feat] Ajout du useEffect de type componentdidMount pour le drag&drop
Browse files Browse the repository at this point in the history
  • Loading branch information
maximeperrault committed May 21, 2024
1 parent 4b9c228 commit b599ed0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import { describe, expect, it } from '@jest/globals'
import { THEME } from '@mtes-mct/monitor-ui'
import { Icon, Stroke, Style } from 'ol/style'

import { getInterestPointStyle } from './interestPoint.style'
import {
INTEREST_POINT_STYLE_ICON_FILENAME,
INTEREST_POINT_STYLE_ZINDEX
} from '../../../../domain/entities/interestPoints'
import { getIconStyle, getInterestPointStyle, getStrokeStyles } from './interestPoint.style'

describe('getInterestPointStyle', () => {
it('should return stroke style when it should style it', async () => {
Expand All @@ -18,15 +12,7 @@ describe('getInterestPointStyle', () => {
const strokeStyle = getInterestPointStyle(shouldStyleStroke, dummyResolution)

// Then
const styleExpected = [
new Style({
stroke: new Stroke({
color: THEME.color.slateGray,
lineDash: [4, 4],
width: 2
})
})
]
const styleExpected = getStrokeStyles()

expect(strokeStyle).toEqual(styleExpected)
})
Expand All @@ -39,15 +25,7 @@ describe('getInterestPointStyle', () => {
const strokeStyle = getInterestPointStyle(shouldStyleStroke, dummyResolution)

// Then
const styleExpected = new Style({
image: new Icon({
offset: [0, 0],
scale: 1 / dummyResolution ** (1 / 8) + 0.3,
size: [30, 79],
src: INTEREST_POINT_STYLE_ICON_FILENAME
}),
zIndex: INTEREST_POINT_STYLE_ZINDEX
})
const styleExpected = getIconStyle(dummyResolution)

expect(styleExpected).toEqual(strokeStyle)
})
Expand Down
22 changes: 12 additions & 10 deletions frontend/src/features/map/layers/styles/interestPoint.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,17 @@ import {
INTEREST_POINT_STYLE_ZINDEX
} from '../../../../domain/entities/interestPoints'

const getStrokeStyles = () => [
export const getIconStyle = (resolution: number) =>
new Style({
image: new Icon({
displacement: [0, 10],
scale: 1 / resolution ** (1 / 8) + 0.3,
src: INTEREST_POINT_STYLE_ICON_FILENAME
}),
zIndex: INTEREST_POINT_STYLE_ZINDEX
})

export const getStrokeStyles = () => [
new Style({
stroke: new Stroke({
color: THEME.color.slateGray,
Expand All @@ -23,16 +33,8 @@ export const getInterestPointStyle = (shouldStyleStroke: boolean | undefined, re
if (shouldStyleStroke) {
return getStrokeStyles()
}
const style = new Style({
image: new Icon({
displacement: [0, 10],
scale: 1 / resolution ** (1 / 8) + 0.3,
src: INTEREST_POINT_STYLE_ICON_FILENAME
}),
zIndex: INTEREST_POINT_STYLE_ZINDEX
})

return style
return getIconStyle(resolution)
}

export const POIStyle = new Style({
Expand Down

0 comments on commit b599ed0

Please sign in to comment.