Skip to content

Commit 21d5576

Browse files
committed
More typescript
1 parent 69c781b commit 21d5576

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

packages/viewer/src/modules/map/components/CompareSlider.vue

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ function registerRenderingEvents(layerId: string, layerUuid: string) {
9898
// context to ensure it is also cut correctly upon activating the compare slider
9999
// or loading a new COG layer on top.
100100
layer?.once('prerender', (event) => {
101-
if (shouldUseWebGlContext.value && event.context) {
102-
;(event.context as WebGLRenderingContext).clear(
101+
if (event.context && useWebGLContext(event.context)) {
102+
event.context.clear(
103103
// sorry
104-
(event.context as WebGLRenderingContext).COLOR_BUFFER_BIT
104+
event.context.COLOR_BUFFER_BIT
105105
)
106106
}
107107
})
@@ -159,29 +159,37 @@ function onPreRender2d(event: RenderEvent, context: CanvasRenderingContext2D) {
159159
context.clip()
160160
}
161161
162+
function useWebGLContext(
163+
context: WebGLRenderingContext | CanvasRenderingContext2D
164+
): context is WebGLRenderingContext {
165+
return shouldUseWebGlContext.value
166+
}
167+
162168
function onPreRender(event: RenderEvent) {
163169
const context = event.context
164170
165171
if (!context) {
166172
return
167173
}
168174
169-
if (shouldUseWebGlContext.value) {
170-
onPreRenderWebGL(event, context as WebGLRenderingContext)
175+
if (useWebGLContext(context)) {
176+
onPreRenderWebGL(event, context)
171177
} else {
172-
onPreRender2d(event, context as CanvasRenderingContext2D)
178+
onPreRender2d(event, context)
173179
}
174180
}
175181
176182
function onPostRender(event: RenderEvent) {
177183
const context = event.context
178184
179-
// probably could do some generic magic here
180-
if (shouldUseWebGlContext.value) {
181-
const _context = context as WebGLRenderingContext
182-
_context.disable(_context.SCISSOR_TEST)
185+
if (!context) {
186+
return
187+
}
188+
189+
if (useWebGLContext(context)) {
190+
context.disable(context.SCISSOR_TEST)
183191
} else {
184-
;(context as CanvasRenderingContext2D).restore()
192+
context.restore()
185193
}
186194
}
187195

packages/viewer/src/utils/__tests__/kmlUtils.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
parseIconUrl,
1919
parseKml,
2020
} from '@/utils/kmlUtils'
21-
import type EditableFeature from '@/api/features/EditableFeature.class'
21+
import type { EditableFeature } from '@/api/features.api'
2222

2323
describe('Test KML utils', () => {
2424
describe('get KML Extent', () => {
@@ -148,8 +148,8 @@ describe('Test KML utils', () => {
148148
const olFeatures: OLFeature[] = parseKml(
149149
kmlLayer,
150150
WEBMERCATOR,
151-
resolution,
152-
fakeIconSets
151+
fakeIconSets,
152+
resolution
153153
)
154154
features = olFeatures.map((f) => {
155155
const ef = f.get('editableFeature')

packages/viewer/src/utils/__tests__/legacyKmlUtils.spec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { resolve } from 'path'
55
import { beforeEach, describe, expect, it } from 'vitest'
66
import type { default as OLFeature } from 'ol/Feature'
77

8-
import EditableFeature, { EditableFeatureTypes } from '@/api/features/EditableFeature.class'
98
import type { DrawingIconSet } from '@/api/icon.api'
109
import { getServiceKmlBaseUrl } from '@/config/baseUrl.config'
1110
import {
@@ -20,6 +19,7 @@ import {
2019
YELLOW,
2120
} from '@/utils/featureStyleUtils'
2221
import { parseKml } from '@/utils/kmlUtils'
22+
import { EditableFeatureTypes, type EditableFeature } from '@/api/features.api'
2323

2424
const fakeDefaultIconSet: DrawingIconSet = {
2525
name: 'default',
@@ -89,11 +89,13 @@ function performStandardChecks(
8989
expect(feature).toBeDefined()
9090
expect(feature!.coordinates).toBeDefined()
9191
expect(feature!.coordinates).to.have.length.greaterThan(0)
92-
if (feature!.coordinates!.length === 1) {
93-
expect(feature!.coordinates![0]).to.have.length(expectedCoordinateCount)
92+
93+
if (feature!.coordinates.length === 1) {
94+
expect(feature!.coordinates[0]).to.have.length(expectedCoordinateCount)
9495
} else {
9596
expect(feature!.coordinates).to.have.length(expectedCoordinateCount)
9697
}
98+
9799
expect(feature!.title).to.be.equal(expectedTitle)
98100
expect(feature!.description).to.equal(expectedDescription)
99101
expect(feature!.featureType).to.be.equal(expectedFeatureType)
@@ -113,7 +115,7 @@ describe('Validate deserialization of the mf-geoadmin3 viewer kml format', () =>
113115
kmlData: kml,
114116
})
115117
const resolution = 12345
116-
const olFeatures: OLFeature[] = parseKml(kmlLayer, WEBMERCATOR, resolution, fakeIconSets)
118+
const olFeatures: OLFeature[] = parseKml(kmlLayer, WEBMERCATOR, fakeIconSets, resolution)
117119
features = olFeatures.map((f) => f.get('editableFeature'))
118120
})
119121
describe('icon parsing', () => {

0 commit comments

Comments
 (0)