@@ -78,6 +78,7 @@ export class GttClient {
78
78
layerArray : Layer [ ]
79
79
defaults : DOMStringMap
80
80
contents : DOMStringMap
81
+ i18n : any
81
82
toolbar : Bar
82
83
filters : FilterOption
83
84
vector : VectorLayer < VectorSource < Geometry > >
@@ -123,8 +124,8 @@ export class GttClient {
123
124
this . defaults . geocoder = JSON . stringify ( quick_hack . geocoder )
124
125
}
125
126
126
-
127
127
this . contents = options . target . dataset
128
+ this . i18n = JSON . parse ( this . defaults . i18n )
128
129
129
130
// create map at first
130
131
this . map = new Map ( {
@@ -290,8 +291,6 @@ export class GttClient {
290
291
} )
291
292
}
292
293
293
-
294
-
295
294
// For map div focus settings
296
295
if ( options . target ) {
297
296
if ( options . target . getAttribute ( 'tabindex' ) == null ) {
@@ -313,13 +312,17 @@ export class GttClient {
313
312
this . setGeolocation ( this . map )
314
313
this . parseHistory ( )
315
314
316
- this . map . addControl ( new FullScreen ( ) )
317
- this . map . addControl ( new Rotate ( ) )
315
+ this . map . addControl ( new FullScreen ( {
316
+ tipLabel : this . i18n . control . fullscreen
317
+ } ) )
318
+ this . map . addControl ( new Rotate ( {
319
+ tipLabel : this . i18n . control . rotate
320
+ } ) )
318
321
319
322
// Control button
320
323
const maximizeCtrl = new Button ( {
321
324
html : '<i class="material-icons" >zoom_out_map</i>' ,
322
- title : "Maximize" ,
325
+ title : this . i18n . control . maximize ,
323
326
handleClick : ( ) => {
324
327
this . zoomToExtent ( true ) ;
325
328
}
@@ -489,24 +492,61 @@ export class GttClient {
489
492
editbar . addControl ( control )
490
493
} )
491
494
492
- // Upload button
493
- if ( this . contents . upload === "true" ) {
494
- editbar . addControl ( new Button ( {
495
- html : '<i class="material-icons">file_upload</i>' ,
496
- title : 'Upload GeoJSON' ,
497
- handleClick : ( ) => {
498
- const data = prompt ( "Please paste a GeoJSON geometry here" )
495
+ // Uses jQuery UI for GeoJSON Upload modal window
496
+ const mapObj = this
497
+ const dialog = $ ( "#dialog-geojson-upload" ) . dialog ( {
498
+ autoOpen : false ,
499
+ resizable : true ,
500
+ height : 'auto' ,
501
+ width : 380 ,
502
+ modal : true ,
503
+ buttons : {
504
+ [ mapObj . i18n . modal . load ] : function ( ) {
505
+ const geojson_input = document . querySelector ( '#dialog-geojson-upload textarea' ) as HTMLInputElement
506
+ const data = geojson_input . value
499
507
if ( data !== null ) {
500
508
const features = new GeoJSON ( ) . readFeatures (
501
509
JSON . parse ( data ) , {
502
510
featureProjection : 'EPSG:3857'
503
511
}
504
512
)
505
- this . vector . getSource ( ) . clear ( )
506
- this . vector . getSource ( ) . addFeatures ( features )
507
- this . updateForm ( features )
508
- this . zoomToExtent ( )
513
+ mapObj . vector . getSource ( ) . clear ( )
514
+ mapObj . vector . getSource ( ) . addFeatures ( features )
515
+ mapObj . updateForm ( features )
516
+ mapObj . zoomToExtent ( )
509
517
}
518
+ $ ( this ) . dialog ( 'close' )
519
+ } ,
520
+ [ mapObj . i18n . modal . cancel ] : function ( ) {
521
+ $ ( this ) . dialog ( 'close' )
522
+ }
523
+ }
524
+ } ) ;
525
+
526
+ // Upload button
527
+ if ( this . contents . upload === "true" ) {
528
+
529
+ const fileSelector = document . getElementById ( 'file-selector' )
530
+ fileSelector . addEventListener ( 'change' , ( event : any ) => {
531
+ const file = event . target . files [ 0 ]
532
+ // Check if the file is GeoJSON.
533
+ if ( file . type && ! file . type . startsWith ( 'application/geo' ) ) {
534
+ console . log ( 'File is not a GeoJSON document.' , file . type , file ) ;
535
+ return ;
536
+ }
537
+ const fileReader = new FileReader ( ) ;
538
+ fileReader . addEventListener ( 'load' , ( event : any ) => {
539
+ const geojson_input = document . querySelector ( '#dialog-geojson-upload textarea' ) as HTMLInputElement
540
+ geojson_input . value = JSON . stringify ( event . target . result , null , 2 )
541
+ } ) ;
542
+ fileReader . readAsText ( file ) ;
543
+ } ) ;
544
+
545
+ editbar . addControl ( new Button ( {
546
+ html : '<i class="material-icons">file_upload</i>' ,
547
+ title : this . i18n . control . geojson ,
548
+ handleClick : ( ) => {
549
+ dialog . dialog ( 'open' )
510
550
}
511
551
} ) )
512
552
}
@@ -978,7 +1018,7 @@ export class GttClient {
978
1018
// Control button
979
1019
const geolocationCtrl = new Toggle ( {
980
1020
html : '<i class="material-icons">my_location</i>' ,
981
- title : "Geolocation" ,
1021
+ title : this . i18n . control . geolocation ,
982
1022
active : false ,
983
1023
onToggle : ( active : boolean ) => {
984
1024
geolocation . setTracking ( active )
@@ -1167,7 +1207,7 @@ export class GttClient {
1167
1207
// Control button
1168
1208
const geocodingCtrl = new Toggle ( {
1169
1209
html : '<i class="material-icons">manage_search</i>' ,
1170
- title : "Geocoding" ,
1210
+ title : this . i18n . control . geocoding ,
1171
1211
className : "ctl-geocoding" ,
1172
1212
onToggle : ( active : boolean ) => {
1173
1213
const text = ( document . querySelector ( "div#" + mapId + " .ctl-geocoding div input" ) as HTMLInputElement )
0 commit comments