@@ -5,66 +5,85 @@ export default class Importer {
5
5
}
6
6
7
7
#buildDatalayerOptions( layerSelect ) {
8
- let option
8
+ const options = [ ]
9
9
this . map . eachDataLayerReverse ( ( datalayer ) => {
10
10
if ( datalayer . isLoaded ( ) && ! datalayer . isRemoteLayer ( ) ) {
11
- const id = L . stamp ( datalayer )
12
- option = L . DomUtil . add ( 'option' , '' , layerSelect , datalayer . options . name )
13
- option . value = id
11
+ options . push (
12
+ `< option value=" ${ L . stamp ( datalayer ) } "> ${ datalayer . options . name } </option>`
13
+ )
14
14
}
15
15
} )
16
- L . DomUtil . element (
17
- 'option' ,
18
- { value : '' , textContent : L . _ ( 'Import in a new layer' ) } ,
19
- layerSelect
20
- )
16
+ options . push ( `<option value="">${ L . _ ( 'Import in a new layer' ) } </option>` )
17
+ layerSelect . innerHTML = options . join ( '' )
21
18
}
22
19
23
20
#buildPresetsOptions( presetSelect ) {
24
- if ( this . presets . length ) {
25
- const presetBox = this . form . querySelector ( '#preset-box' )
26
- presetBox . removeAttribute ( 'hidden' )
27
- const noPreset = L . DomUtil . create ( 'option' , '' , presetSelect )
28
- noPreset . value = noPreset . textContent = L . _ ( 'Choose a preset' )
29
- for ( const preset of this . presets ) {
30
- option = L . DomUtil . create ( 'option' , '' , presetSelect )
31
- option . value = preset . url
32
- option . textContent = preset . label
33
- }
21
+ if ( ! this . presets . length ) return
22
+ const options = [ ]
23
+ presetSelect . parentElement . removeAttribute ( 'hidden' )
24
+ options . push (
25
+ `<option value="${ L . _ ( 'Choose a preset' ) } ">${ L . _ ( 'Choose a preset' ) } </option>`
26
+ )
27
+ for ( const preset of this . presets ) {
28
+ options . push ( `<option value="${ preset . url } ">${ preset . label } </option>` )
34
29
}
30
+ presetSelect . innerHTML = options . join ( '' )
31
+ }
32
+
33
+ #connectedCallback( ) {
34
+ const controller = new AbortController ( )
35
+ const signal = controller . signal
36
+ this . form
37
+ . querySelector ( '[name="submit-input"]' )
38
+ . addEventListener ( 'click' , this . submit . bind ( this ) , { signal } )
39
+
40
+ this . fileInput . addEventListener (
41
+ 'change' ,
42
+ ( e ) => {
43
+ let type = ''
44
+ let newType
45
+ for ( const file of e . target . files ) {
46
+ newType = L . Util . detectFileType ( file )
47
+ if ( ! type && newType ) {
48
+ type = newType
49
+ }
50
+ if ( type && newType !== type ) {
51
+ type = ''
52
+ break
53
+ }
54
+ }
55
+ this . formatSelect . value = type
56
+ } ,
57
+ { signal }
58
+ )
59
+
60
+ this . map . ui . once (
61
+ 'panel:closed' ,
62
+ ( ) => {
63
+ this . fileInput . value = null
64
+ controller . abort ( )
65
+ } ,
66
+ { signal }
67
+ )
35
68
}
36
69
37
70
build ( ) {
38
71
const template = document . querySelector ( '#umap-upload' )
39
72
this . form = template . content . firstElementChild . cloneNode ( true )
40
- this . presetSelect = this . form . querySelector ( '[name="preset-select"]' )
41
- this . fileInput = this . form . querySelector ( '[name="file-input"]' )
42
- this . map . ui . once ( 'panel:closed' , ( ) => ( this . fileInput . value = null ) )
73
+
43
74
this . typeLabel = this . form . querySelector ( '#type-label' )
44
75
const helpButton = this . typeLabel . querySelector ( 'button' )
45
76
this . map . help . button ( this . typeLabel , 'importFormats' , '' , helpButton )
46
- this . formatSelect = this . form . querySelector ( '[name="format"]' )
77
+
47
78
this . layerSelect = this . form . querySelector ( '[name="datalayer"]' )
48
- this . submitInput = this . form . querySelector ( '[name="submit-input"]' )
49
79
this . #buildDatalayerOptions( this . layerSelect )
80
+ this . presetSelect = this . form . querySelector ( '[name="preset-select"]' )
50
81
this . #buildPresetsOptions( this . presetSelect )
51
82
52
- this . submitInput . addEventListener ( 'click' , this . submit . bind ( this ) )
53
- this . fileInput . addEventListener ( 'change' , ( e ) => {
54
- let type = ''
55
- let newType
56
- for ( const file of e . target . files ) {
57
- newType = L . Util . detectFileType ( file )
58
- if ( ! type && newType ) {
59
- type = newType
60
- }
61
- if ( type && newType !== type ) {
62
- type = ''
63
- break
64
- }
65
- }
66
- this . formatSelect . value = type
67
- } )
83
+ this . fileInput = this . form . querySelector ( '[name="file-input"]' )
84
+ this . formatSelect = this . form . querySelector ( '[name="format"]' )
85
+
86
+ this . #connectedCallback( )
68
87
}
69
88
70
89
open ( ) {
0 commit comments