Skip to content

Commit f41d033

Browse files
committed
1 parent 2b47d02 commit f41d033

File tree

4 files changed

+51
-22
lines changed

4 files changed

+51
-22
lines changed

src/modules/map/components/cesium/CesiumKMLLayer.vue

+1-7
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,6 @@ export default {
4040
availableIconSets: (state) => state.drawing.iconSets,
4141
}),
4242
},
43-
watch: {
44-
url() {
45-
this.olLayer.getSource().clear()
46-
this.removeLayer(this.layer)
47-
this.loadLayer()
48-
},
49-
},
5043
methods: {
5144
async loadLayer() {
5245
try {
@@ -71,6 +64,7 @@ export default {
7164
} catch (error) {
7265
log.error(`Failed to load kml from ${this.url}`, error)
7366
}
67+
return undefined
7468
},
7569
},
7670
}

src/modules/map/components/cesium/constants.js

+7
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,10 @@ export const CAMERA_MIN_PITCH = -Math.PI / 2
3434
* @type {number}
3535
*/
3636
export const CAMERA_MAX_PITCH = Math.PI / 4
37+
38+
/**
39+
* Distance on which depth test will be disabled for primitive to avoid cutting by terrain
40+
*
41+
* @type {number}
42+
*/
43+
export const PRIMITIVE_DISABLE_DEPTH_TEST_DISTANCE = 75000

src/modules/map/components/cesium/utils/addPrimitiveLayer-mixins.js

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import addLayerToViewer from './addLayerToViewer-mixins'
2-
import { updateCollectionOpacity } from '@/modules/map/components/cesium/utils/primitiveLayerUtils'
2+
import { updateCollectionProperties } from '@/modules/map/components/cesium/utils/primitiveLayerUtils'
33
import { PrimitiveCollection } from 'cesium'
44
import { Vector as VectorLayer } from 'ol/layer'
55
import FeatureConverter from 'ol-cesium/src/olcs/FeatureConverter'
66
import { IS_TESTING_WITH_CYPRESS } from '@/config'
7+
import { PRIMITIVE_DISABLE_DEPTH_TEST_DISTANCE } from '@/modules/map/components/cesium/constants'
78

89
const STYLE_RESOLUTION = 20
910

@@ -25,9 +26,16 @@ const addPrimitiveLayerMixins = {
2526
mixins: [addLayerToViewer],
2627
watch: {
2728
opacity(newOpacity) {
28-
updateCollectionOpacity(this.layer, newOpacity)
29+
updateCollectionProperties(this.layer, { opacity: newOpacity })
2930
this.getViewer().scene.requestRender()
3031
},
32+
url() {
33+
this.olLayer.getSource().clear()
34+
this.removeLayer(this.layer)
35+
this.loadLayer().then((projection) => {
36+
if (projection) this.addPrimitive(projection)
37+
})
38+
},
3139
},
3240
created() {
3341
this.layer = new PrimitiveCollection()
@@ -37,7 +45,7 @@ const addPrimitiveLayerMixins = {
3745
properties: { altitudeMode: 'clampToGround' },
3846
})
3947
this.loadLayer().then((projection) => {
40-
this.addPrimitive(projection)
48+
if (projection) this.addPrimitive(projection)
4149
})
4250
},
4351
methods: {
@@ -65,16 +73,20 @@ const addPrimitiveLayerMixins = {
6573
)
6674
// need to wait for terrain loaded otherwise primitives will be placed wrong
6775
if (this.layer) {
76+
const collectionProperties = {
77+
opacity: this.opacity,
78+
disableDepthTestDistance: PRIMITIVE_DISABLE_DEPTH_TEST_DISTANCE,
79+
}
6880
if (scene.globe.tilesLoaded || IS_TESTING_WITH_CYPRESS) {
6981
this.layer.add(counterpart.getRootPrimitive())
70-
updateCollectionOpacity(this.layer, this.opacity)
82+
updateCollectionProperties(this.layer, collectionProperties)
7183
this.getViewer().scene.requestRender()
7284
} else {
7385
const unlisten = scene.globe.tileLoadProgressEvent.addEventListener(
7486
(queueLength) => {
7587
if (scene.globe.tilesLoaded && queueLength === 0) {
7688
this.layer.add(counterpart.getRootPrimitive())
77-
updateCollectionOpacity(this.layer, this.opacity)
89+
updateCollectionProperties(this.layer, collectionProperties)
7890
this.getViewer().scene.requestRender()
7991
unlisten()
8092
}

src/modules/map/components/cesium/utils/primitiveLayerUtils.js

+26-10
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,46 @@ import {
99
PrimitiveCollection,
1010
} from 'cesium'
1111

12-
export function updateCollectionOpacity(collection, opacity) {
12+
/**
13+
* This function goes throw the primitive collection and update passed properties
14+
* @param {PrimitiveCollection} collection
15+
* @param {{opacity: number | undefined, disableDepthTestDistance: number | undefined}} properties
16+
*/
17+
export function updateCollectionProperties(collection, properties) {
18+
const opacity =
19+
typeof properties.opacity === 'number' && properties.opacity >= 0 && properties.opacity <= 1
20+
? properties.opacity
21+
: undefined
22+
const disableDepthTestDistance =
23+
typeof properties.disableDepthTestDistance === 'number'
24+
? properties.disableDepthTestDistance
25+
: undefined
26+
1327
for (let i = 0; i < collection.length; i++) {
1428
const primitive = collection.get(i)
1529
if (primitive instanceof Primitive || primitive instanceof GroundPolylinePrimitive) {
16-
if (primitive.appearance) {
30+
if (primitive.appearance && opacity !== undefined) {
1731
const material = primitive.appearance.material
1832
const color = material.uniforms.color || material.uniforms.evenColor
1933
material.uniforms.color = new Color(color.red, color.green, color.blue, opacity)
2034
}
2135
} else if (primitive instanceof Billboard) {
22-
// todo just for test, will be moved in appropriate place
23-
primitive.disableDepthTestDistance = 75000
24-
if (primitive.color) {
36+
if (disableDepthTestDistance !== undefined) {
37+
primitive.disableDepthTestDistance = disableDepthTestDistance
38+
}
39+
if (primitive.color && opacity !== undefined) {
2540
const color = primitive.color
2641
primitive.color = new Color(color.red, color.green, color.blue, opacity)
2742
}
2843
} else if (primitive instanceof Label) {
29-
// todo just for test, will be moved in appropriate place
30-
primitive.disableDepthTestDistance = 75000
31-
if (primitive.fillColor) {
44+
if (disableDepthTestDistance !== undefined) {
45+
primitive.disableDepthTestDistance = disableDepthTestDistance
46+
}
47+
if (primitive.fillColor && opacity !== undefined) {
3248
const color = primitive.fillColor
3349
primitive.fillColor = new Color(color.red, color.green, color.blue, opacity)
3450
}
35-
if (primitive.outlineColor) {
51+
if (primitive.outlineColor && opacity !== undefined) {
3652
const color = primitive.outlineColor
3753
primitive.outlineColor = new Color(color.red, color.green, color.blue, opacity)
3854
}
@@ -41,7 +57,7 @@ export function updateCollectionOpacity(collection, opacity) {
4157
primitive instanceof BillboardCollection ||
4258
primitive instanceof LabelCollection
4359
) {
44-
updateCollectionOpacity(primitive, opacity)
60+
updateCollectionProperties(primitive, properties)
4561
}
4662
}
4763
}

0 commit comments

Comments
 (0)