@@ -29,6 +29,28 @@ export class LeafletVectorTileLayerModel extends LeafletLayerModel {
29
29
export class LeafletVectorTileLayerView extends LeafletLayerView {
30
30
obj : VectorGrid . Protobuf ;
31
31
32
+ async set_vector_tile_layer_styles ( options : any ) {
33
+ if ( 'layerStyles' in options ) {
34
+ let x : any = options [ 'layerStyles' ] ;
35
+ options [ 'vectorTileLayerStyles' ] = x ;
36
+ if ( typeof x === 'string' ) {
37
+ try {
38
+ let blobCode = `const jsStyle=${ x } ; export { jsStyle };` ;
39
+
40
+ const blob = new Blob ( [ blobCode ] , { type : 'text/javascript' } ) ;
41
+ const url = URL . createObjectURL ( blob ) ;
42
+ const module = await import ( /* webpackIgnore: true*/ url ) ;
43
+ const jsStyle = module . jsStyle ;
44
+
45
+ options [ 'vectorTileLayerStyles' ] = jsStyle ;
46
+ } catch ( error ) {
47
+ options [ 'vectorTileLayerStyles' ] = { } ;
48
+ }
49
+ }
50
+ }
51
+ return options ;
52
+ }
53
+
32
54
async create_obj ( ) {
33
55
let options = {
34
56
...this . get_options ( ) ,
@@ -50,24 +72,7 @@ export class LeafletVectorTileLayerView extends LeafletLayerView {
50
72
}
51
73
}
52
74
53
- if ( 'layerStyles' in options ) {
54
- let x : any = options [ 'layerStyles' ] ;
55
- options [ 'vectorTileLayerStyles' ] = x ;
56
- if ( typeof x === 'string' ) {
57
- try {
58
- let blobCode = `const jsStyle=${ x } ; export { jsStyle };` ;
59
-
60
- const blob = new Blob ( [ blobCode ] , { type : 'text/javascript' } ) ;
61
- const url = URL . createObjectURL ( blob ) ;
62
- const module = await import ( /* webpackIgnore: true*/ url ) ;
63
- const jsStyle = module . jsStyle ;
64
-
65
- options [ 'vectorTileLayerStyles' ] = jsStyle ;
66
- } catch ( error ) {
67
- options [ 'vectorTileLayerStyles' ] = { } ;
68
- }
69
- }
70
- }
75
+ options = await this . set_vector_tile_layer_styles ( options ) ;
71
76
72
77
this . obj = L . vectorGrid . protobuf ( this . model . get ( 'url' ) , options ) ;
73
78
this . model . on ( 'msg:custom' , this . handle_message . bind ( this ) ) ;
@@ -76,6 +81,18 @@ export class LeafletVectorTileLayerView extends LeafletLayerView {
76
81
this . obj . setOpacity ( 0 ) ;
77
82
}
78
83
84
+ this . model . on ( 'change:layer_styles' , async ( ) => {
85
+ let options = {
86
+ ...this . get_options ( ) ,
87
+ } ;
88
+ options = await this . set_vector_tile_layer_styles ( options ) ;
89
+ this . obj . options . vectorTileLayerStyles = options [ 'vectorTileLayerStyles' ] ;
90
+ if ( this . model . get ( 'visible' ) == false ) {
91
+ this . obj . setOpacity ( 0 ) ;
92
+ }
93
+ this . obj . redraw ( ) ;
94
+ } ) ;
95
+
79
96
this . model . on ( 'change:feature_style' , ( ) => {
80
97
const feature_style = this . model . get ( 'feature_style' ) ;
81
98
const reset = feature_style [ 'reset' ] ;
0 commit comments