Skip to content

Commit 8eabac3

Browse files
authored
Vector tile layer opacity and visible (#1210)
* Vector tile layer opacity and visible * lint
1 parent 52f4cb7 commit 8eabac3

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

python/ipyleaflet/ipyleaflet/leaflet.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,10 @@ class VectorTileLayer(Layer):
11061106
Minimum zoom number the tile source has available. If it is specified, the tiles on all zoom levels lower than min_native_zoom will be loaded from min_native_zoom level and auto-scaled.
11071107
max_native_zoom: int, default None
11081108
Maximum zoom number the tile source has available. If it is specified, the tiles on all zoom levels higher than max_native_zoom will be loaded from max_native_zoom level and auto-scaled.
1109+
opacity: float, default 1.
1110+
Opacity of the layer between 0. (fully transparent) and 1. (fully opaque).
1111+
visible: boolean, default True
1112+
Whether the layer is visible or not.
11091113
"""
11101114

11111115
_view_name = Unicode("LeafletVectorTileLayerView").tag(sync=True)
@@ -1115,7 +1119,8 @@ class VectorTileLayer(Layer):
11151119
attribution = Unicode().tag(sync=True, o=True)
11161120

11171121
vector_tile_layer_styles = Union([Dict(), Unicode()]).tag(sync=True, o=True)
1118-
1122+
opacity = Float(1.0, min=0.0, max=1.0).tag(sync=True)
1123+
visible = Bool(True).tag(sync=True)
11191124
min_zoom = Int(0).tag(sync=True, o=True)
11201125
max_zoom = Int(18).tag(sync=True, o=True)
11211126
min_native_zoom = Int(default_value=None, allow_none=True).tag(sync=True, o=True)

python/jupyter_leaflet/src/layers/VectorTileLayer.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ export class LeafletVectorTileLayerModel extends LeafletLayerModel {
1717
max_zoom: 18,
1818
min_native_zoom: null,
1919
max_native_zoom: null,
20+
interactive: true,
21+
visible: true,
22+
opacity: 1.0,
2023
};
2124
}
2225
}
@@ -30,7 +33,7 @@ export class LeafletVectorTileLayerView extends LeafletLayerView {
3033
};
3134
options['rendererFactory'] = L.canvas.tile;
3235

33-
let x: any = this.model.get('vectorTileLayerStyles');
36+
let x: any = options['vectorTileLayerStyles'];
3437
if (typeof x === 'string') {
3538
try {
3639
let blobCode = `const jsStyle=${x}; export { jsStyle };`;
@@ -55,6 +58,18 @@ export class LeafletVectorTileLayerView extends LeafletLayerView {
5558
this.listenTo(this.model, 'change:url', () => {
5659
this.obj.setUrl(this.model.get('url'));
5760
});
61+
this.listenTo(this.model, 'change:opacity', () => {
62+
if (this.model.get('visible')) {
63+
this.obj.setOpacity(this.model.get('opacity'));
64+
}
65+
});
66+
this.listenTo(this.model, 'change:visible', () => {
67+
if (this.model.get('visible')) {
68+
this.obj.setOpacity(this.model.get('opacity'));
69+
} else {
70+
this.obj.setOpacity(0);
71+
}
72+
});
5873
}
5974

6075
handle_message(content: { msg: string }) {

0 commit comments

Comments
 (0)