@@ -6,138 +6,144 @@ const defaultOptions = {
6
6
} ;
7
7
8
8
class OpacityControl {
9
+ #map;
10
+ #container;
11
+ #baseLayersOption;
12
+ #overLayersOption;
13
+ #opacityControlOption;
14
+
9
15
constructor ( options ) {
10
16
// オプション設定
11
- this . _baseLayersOption = options . baseLayers || defaultOptions . baseLayers ;
12
- this . _overLayersOption = options . overLayers || defaultOptions . overLayers ;
13
- this . _opacityControlOption = options . opacityControl || defaultOptions . opacityControl ;
17
+ this . #baseLayersOption = options . baseLayers || defaultOptions . baseLayers ;
18
+ this . #overLayersOption = options . overLayers || defaultOptions . overLayers ;
19
+ this . #opacityControlOption = options . opacityControl || defaultOptions . opacityControl ;
14
20
}
15
21
16
22
// ラジオボタン作成
17
- _radioButtonControlAdd ( layerId ) {
23
+ #radioButtonControlAdd ( layerId ) {
18
24
// 初期レイヤ定義
19
- const initLayer = Object . keys ( this . _baseLayersOption ) [ 0 ] ;
25
+ const initLayer = Object . keys ( this . #baseLayersOption ) [ 0 ] ;
20
26
// ラジオボタン追加
21
27
const radioButton = document . createElement ( 'input' ) ;
22
28
radioButton . setAttribute ( 'type' , 'radio' ) ;
23
29
radioButton . id = layerId ;
24
30
// 初期レイヤのみ表示
25
31
if ( layerId === initLayer ) {
26
32
radioButton . checked = true ;
27
- this . _map . setLayoutProperty ( layerId , 'visibility' , 'visible' ) ;
33
+ this . #map . setLayoutProperty ( layerId , 'visibility' , 'visible' ) ;
28
34
} else {
29
- this . _map . setLayoutProperty ( layerId , 'visibility' , 'none' ) ;
35
+ this . #map . setLayoutProperty ( layerId , 'visibility' , 'none' ) ;
30
36
}
31
- this . _container . appendChild ( radioButton ) ;
37
+ this . #container . appendChild ( radioButton ) ;
32
38
// ラジオボタンイベント
33
39
radioButton . addEventListener ( 'change' , ( event ) => {
34
40
// 選択レイヤ表示
35
41
event . target . checked = true ;
36
- this . _map . setLayoutProperty ( layerId , 'visibility' , 'visible' ) ;
42
+ this . #map . setLayoutProperty ( layerId , 'visibility' , 'visible' ) ;
37
43
// 選択レイヤ以外非表示
38
- Object . keys ( this . _baseLayersOption ) . map ( ( layer ) => {
44
+ Object . keys ( this . #baseLayersOption ) . map ( ( layer ) => {
39
45
if ( layer !== event . target . id ) {
40
46
document . getElementById ( layer ) . checked = false ;
41
- this . _map . setLayoutProperty ( layer , 'visibility' , 'none' ) ;
47
+ this . #map . setLayoutProperty ( layer , 'visibility' , 'none' ) ;
42
48
}
43
49
} ) ;
44
50
} ) ;
45
51
// レイヤ名追加
46
52
const layerName = document . createElement ( 'label' ) ;
47
53
layerName . htmlFor = layerId ;
48
- layerName . appendChild ( document . createTextNode ( this . _baseLayersOption [ layerId ] ) ) ;
49
- this . _container . appendChild ( layerName ) ;
54
+ layerName . appendChild ( document . createTextNode ( this . #baseLayersOption [ layerId ] ) ) ;
55
+ this . #container . appendChild ( layerName ) ;
50
56
}
51
57
52
58
// チェックボックス作成
53
- _checkBoxControlAdd ( layerId ) {
59
+ #checkBoxControlAdd ( layerId ) {
54
60
// チェックボックス追加
55
61
const checkBox = document . createElement ( 'input' ) ;
56
62
checkBox . setAttribute ( 'type' , 'checkbox' ) ;
57
63
checkBox . id = layerId ;
58
64
// 全レイヤ非表示
59
- this . _map . setLayoutProperty ( layerId , 'visibility' , 'none' ) ;
60
- this . _container . appendChild ( checkBox ) ;
65
+ this . #map . setLayoutProperty ( layerId , 'visibility' , 'none' ) ;
66
+ this . #container . appendChild ( checkBox ) ;
61
67
// チェックボックスイベント
62
68
checkBox . addEventListener ( 'change' , ( event ) => {
63
69
// レイヤの表示・非表示
64
70
if ( event . target . checked ) {
65
- this . _map . setLayoutProperty ( layerId , 'visibility' , 'visible' ) ;
71
+ this . #map . setLayoutProperty ( layerId , 'visibility' , 'visible' ) ;
66
72
} else {
67
- this . _map . setLayoutProperty ( layerId , 'visibility' , 'none' ) ;
73
+ this . #map . setLayoutProperty ( layerId , 'visibility' , 'none' ) ;
68
74
}
69
75
} ) ;
70
76
// レイヤ名追加
71
77
const layerName = document . createElement ( 'label' ) ;
72
78
layerName . htmlFor = layerId ;
73
- layerName . appendChild ( document . createTextNode ( this . _overLayersOption [ layerId ] ) ) ;
74
- this . _container . appendChild ( layerName ) ;
79
+ layerName . appendChild ( document . createTextNode ( this . #overLayersOption [ layerId ] ) ) ;
80
+ this . #container . appendChild ( layerName ) ;
75
81
}
76
82
77
83
// スライドバー作成
78
- _rangeControlAdd ( layerId ) {
84
+ #rangeControlAdd ( layerId ) {
79
85
// スライドバー追加
80
86
const range = document . createElement ( 'input' ) ;
81
87
range . type = 'range' ;
82
88
range . min = 0 ;
83
89
range . max = 100 ;
84
90
range . value = 100 ;
85
- this . _container . appendChild ( range ) ;
91
+ this . #container . appendChild ( range ) ;
86
92
// スライドバースイベント
87
93
range . addEventListener ( 'input' , ( event ) => {
88
94
// 透過度設定
89
- this . _map . setPaintProperty ( layerId , 'raster-opacity' , Number ( event . target . value / 100 ) ) ;
95
+ this . #map . setPaintProperty ( layerId , 'raster-opacity' , Number ( event . target . value / 100 ) ) ;
90
96
} ) ;
91
97
}
92
98
93
99
// コントロール作成
94
- _opacityControlAdd ( ) {
100
+ #opacityControlAdd ( ) {
95
101
// コントロール設定
96
- this . _container = document . createElement ( 'div' ) ;
97
- this . _container . className = 'maplibregl-ctrl maplibregl-ctrl-group' ;
98
- this . _container . id = 'opacity-control' ;
102
+ this . #container = document . createElement ( 'div' ) ;
103
+ this . #container . className = 'maplibregl-ctrl maplibregl-ctrl-group' ;
104
+ this . #container . id = 'opacity-control' ;
99
105
// 背景レイヤ設定
100
- if ( this . _baseLayersOption ) {
101
- Object . keys ( this . _baseLayersOption ) . map ( ( layer ) => {
106
+ if ( this . #baseLayersOption ) {
107
+ Object . keys ( this . #baseLayersOption ) . map ( ( layer ) => {
102
108
const layerId = layer ;
103
109
const br = document . createElement ( 'br' ) ;
104
110
// ラジオボタン作成
105
- this . _radioButtonControlAdd ( layerId ) ;
106
- this . _container . appendChild ( br ) ;
111
+ this . #radioButtonControlAdd ( layerId ) ;
112
+ this . #container . appendChild ( br ) ;
107
113
} ) ;
108
114
}
109
115
// 区切り線
110
- if ( this . _baseLayersOption && this . _overLayersOption ) {
116
+ if ( this . #baseLayersOption && this . #overLayersOption ) {
111
117
const hr = document . createElement ( 'hr' ) ;
112
- this . _container . appendChild ( hr ) ;
118
+ this . #container . appendChild ( hr ) ;
113
119
}
114
120
// オーバーレイヤ設定
115
- if ( this . _overLayersOption ) {
116
- Object . keys ( this . _overLayersOption ) . map ( ( layer ) => {
121
+ if ( this . #overLayersOption ) {
122
+ Object . keys ( this . #overLayersOption ) . map ( ( layer ) => {
117
123
const layerId = layer ;
118
124
const br = document . createElement ( 'br' ) ;
119
125
// チェックボックス作成
120
- this . _checkBoxControlAdd ( layerId ) ;
121
- this . _container . appendChild ( br ) ;
126
+ this . #checkBoxControlAdd ( layerId ) ;
127
+ this . #container . appendChild ( br ) ;
122
128
// スライドバー作成
123
- if ( this . _opacityControlOption ) {
124
- this . _rangeControlAdd ( layerId ) ;
125
- this . _container . appendChild ( br ) ;
129
+ if ( this . #opacityControlOption ) {
130
+ this . #rangeControlAdd ( layerId ) ;
131
+ this . #container . appendChild ( br ) ;
126
132
}
127
133
} ) ;
128
134
}
129
135
}
130
136
131
137
onAdd ( map ) {
132
- this . _map = map ;
138
+ this . #map = map ;
133
139
// コントロール作成
134
- this . _opacityControlAdd ( ) ;
135
- return this . _container ;
140
+ this . #opacityControlAdd ( ) ;
141
+ return this . #container ;
136
142
}
137
143
138
144
onRemove ( ) {
139
- this . _container . parentNode . removeChild ( this . _container ) ;
140
- this . _map = null ;
145
+ this . #container . parentNode . removeChild ( this . #container ) ;
146
+ this . #map = null ;
141
147
}
142
148
}
143
149
0 commit comments