Skip to content

Commit

Permalink
feat: opacity factor (DHIS2-11969) (#435)
Browse files Browse the repository at this point in the history
  • Loading branch information
turban authored Feb 24, 2022
1 parent 8634808 commit c50206d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
20 changes: 13 additions & 7 deletions src/layers/GeoJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,23 @@ class GeoJson extends Layer {

createLayers() {
const id = this.getId()

const {
style = {},
buffer,
bufferStyle,
label,
labelStyle,
} = this.options
const { radius, color, strokeColor, weight: width } = style

const {
radius,
color,
strokeColor,
weight: width,
opacityFactor,
} = style

const isInteractive = true

if (buffer) {
Expand All @@ -37,17 +46,14 @@ class GeoJson extends Layer {

this.addLayer(polygonLayer({ id, color }), {
isInteractive,
opacityFactor,
})
this.addLayer(outlineLayer({ id, color: strokeColor, width }))
this.addLayer(lineLayer({ id, color, width }), {
isInteractive,
})
this.addLayer(lineLayer({ id, color, width }), { isInteractive })
this.addLayer(pointLayer({ id, color, strokeColor, width, radius }), {
isInteractive,
})
this.addLayer(symbolLayer({ id }), {
isInteractive,
})
this.addLayer(symbolLayer({ id }), { isInteractive })

if (label) {
this.addLayer(labelLayer({ id, label, ...labelStyle }))
Expand Down
11 changes: 9 additions & 2 deletions src/layers/Layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,17 @@ class Layer extends Evented {
}

addLayer(layer, layerOptions = {}) {
const { isInteractive } = layerOptions
const { isInteractive, opacityFactor } = layerOptions

this._layers.push(layer)

if (isInteractive) {
this._interactiveIds.push(layer.id)
}

if (opacityFactor) {
this._opacityFactor = opacityFactor
}
}

getLayers() {
Expand Down Expand Up @@ -268,8 +272,11 @@ class Layer extends Evented {
setOpacity(opacity) {
const mapgl = this.getMapGL()

const opacityFactor =
this._opacityFactor !== undefined ? this._opacityFactor : 1

if (mapgl) {
setLayersOpacity(mapgl, this.getId(), opacity)
setLayersOpacity(mapgl, this.getId(), opacity * opacityFactor)
}

this.options.opacity = opacity
Expand Down

0 comments on commit c50206d

Please sign in to comment.