Skip to content

Commit 2acd0f8

Browse files
committed
Improve performance of annotation group style changes
1 parent dec029f commit 2acd0f8

File tree

1 file changed

+40
-35
lines changed

1 file changed

+40
-35
lines changed

src/viewer.js

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3434,17 +3434,18 @@ class VolumeImageViewer {
34343434
)
34353435
}
34363436
const annotationGroup = this[_annotationGroups][annotationGroupUID]
3437+
console.info(
3438+
`set style for annotation group "${annotationGroupUID}"`,
3439+
styleOptions
3440+
)
3441+
34373442
if (styleOptions.opacity != null) {
34383443
annotationGroup.style.opacity = styleOptions.opacity
34393444
annotationGroup.layer.setOpacity(styleOptions.opacity)
34403445
}
34413446
if (styleOptions.color != null) {
34423447
annotationGroup.style.color = styleOptions.color
34433448
}
3444-
console.info(
3445-
`set style for annotation group "${annotationGroupUID}"`,
3446-
styleOptions
3447-
)
34483449

34493450
const metadata = annotationGroup.metadata
34503451
const source = annotationGroup.layer.getSource()
@@ -3513,40 +3514,44 @@ class VolumeImageViewer {
35133514
annotationGroup.layer = newLayer
35143515
}
35153516
} else {
3516-
const style = {
3517-
symbol: {
3518-
symbolType: 'circle',
3519-
size: [
3520-
'interpolate',
3521-
['linear'],
3522-
['zoom'],
3523-
1,
3524-
2,
3525-
this[_pyramid].metadata.length,
3526-
15
3527-
],
3528-
color: [
3529-
'match',
3530-
['get', 'selected'],
3531-
1,
3532-
rgb2hex(this[_options].highlightColor),
3533-
rgb2hex(annotationGroup.style.color)
3534-
],
3535-
opacity: annotationGroup.style.opacity
3517+
if (styleOptions.color != null) {
3518+
// Only replace the layer if necessary
3519+
const style = {
3520+
symbol: {
3521+
symbolType: 'circle',
3522+
size: [
3523+
'interpolate',
3524+
['linear'],
3525+
['zoom'],
3526+
1,
3527+
2,
3528+
this[_pyramid].metadata.length,
3529+
15
3530+
],
3531+
color: [
3532+
'match',
3533+
['get', 'selected'],
3534+
1,
3535+
rgb2hex(this[_options].highlightColor),
3536+
rgb2hex(annotationGroup.style.color)
3537+
],
3538+
opacity: annotationGroup.style.opacity
3539+
}
35363540
}
3541+
const newLayer = new PointsLayer({
3542+
source,
3543+
style,
3544+
disableHitDetection: false,
3545+
visible: false
3546+
})
3547+
this[_map].addLayer(newLayer)
3548+
this[_map].removeLayer(annotationGroup.layer)
3549+
const isVisible = annotationGroup.layer.getVisible()
3550+
annotationGroup.layer.dispose()
3551+
annotationGroup.layer = newLayer
3552+
annotationGroup.layer.setVisible(isVisible)
35373553
}
3538-
const newLayer = new PointsLayer({
3539-
source,
3540-
style,
3541-
disableHitDetection: false,
3542-
visible: false
3543-
})
3544-
this[_map].addLayer(newLayer)
3545-
this[_map].removeLayer(annotationGroup.layer)
3546-
annotationGroup.layer.dispose()
3547-
annotationGroup.layer = newLayer
35483554
}
3549-
annotationGroup.layer.setVisible(true)
35503555
}
35513556

35523557
/**

0 commit comments

Comments
 (0)