@@ -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 > >
@@ -124,6 +125,7 @@ export class GttClient {
124
125
}
125
126
126
127
this . contents = options . target . dataset
128
+ this . i18n = JSON . parse ( this . defaults . i18n )
127
129
128
130
// create map at first
129
131
this . map = new Map ( {
@@ -311,13 +313,17 @@ export class GttClient {
311
313
this . setGeolocation ( this . map )
312
314
this . parseHistory ( )
313
315
314
- this . map . addControl ( new FullScreen ( ) )
315
- this . map . addControl ( new Rotate ( ) )
316
+ this . map . addControl ( new FullScreen ( {
317
+ tipLabel : this . i18n . control . fullscreen
318
+ } ) )
319
+ this . map . addControl ( new Rotate ( {
320
+ tipLabel : this . i18n . control . rotate
321
+ } ) )
316
322
317
323
// Control button
318
324
const maximizeCtrl = new Button ( {
319
325
html : '<i class="material-icons" >zoom_out_map</i>' ,
320
- title : "Maximize" ,
326
+ title : this . i18n . control . maximize ,
321
327
handleClick : ( ) => {
322
328
this . zoomToExtent ( true ) ;
323
329
}
@@ -499,24 +505,61 @@ export class GttClient {
499
505
editbar . addControl ( control )
500
506
} )
501
507
502
- // Upload button
503
- if ( this . contents . upload === "true" ) {
504
- editbar . addControl ( new Button ( {
505
- html : '<i class="material-icons">file_upload</i>' ,
506
- title : 'Upload GeoJSON' ,
507
- handleClick : ( ) => {
508
- const data = prompt ( "Please paste a GeoJSON geometry here" )
508
+ // Uses jQuery UI for GeoJSON Upload modal window
509
+ const mapObj = this
510
+ const dialog = $ ( "#dialog-geojson-upload" ) . dialog ( {
511
+ autoOpen : false ,
512
+ resizable : true ,
513
+ height : 'auto' ,
514
+ width : 380 ,
515
+ modal : true ,
516
+ buttons : {
517
+ [ mapObj . i18n . modal . load ] : function ( ) {
518
+ const geojson_input = document . querySelector ( '#dialog-geojson-upload textarea' ) as HTMLInputElement
519
+ const data = geojson_input . value
509
520
if ( data !== null ) {
510
521
const features = new GeoJSON ( ) . readFeatures (
511
522
JSON . parse ( data ) , {
512
523
featureProjection : 'EPSG:3857'
513
524
}
514
525
)
515
- this . vector . getSource ( ) . clear ( )
516
- this . vector . getSource ( ) . addFeatures ( features )
517
- this . updateForm ( features )
518
- this . zoomToExtent ( )
526
+ mapObj . vector . getSource ( ) . clear ( )
527
+ mapObj . vector . getSource ( ) . addFeatures ( features )
528
+ mapObj . updateForm ( features )
529
+ mapObj . zoomToExtent ( )
519
530
}
531
+ $ ( this ) . dialog ( 'close' )
532
+ } ,
533
+ [ mapObj . i18n . modal . cancel ] : function ( ) {
534
+ $ ( this ) . dialog ( 'close' )
535
+ }
536
+ }
537
+ } ) ;
538
+
539
+ // Upload button
540
+ if ( this . contents . upload === "true" ) {
541
+
542
+ const fileSelector = document . getElementById ( 'file-selector' )
543
+ fileSelector . addEventListener ( 'change' , ( event : any ) => {
544
+ const file = event . target . files [ 0 ]
545
+ // Check if the file is GeoJSON.
546
+ if ( file . type && ! file . type . startsWith ( 'application/geo' ) ) {
547
+ console . log ( 'File is not a GeoJSON document.' , file . type , file ) ;
548
+ return ;
549
+ }
550
+ const fileReader = new FileReader ( ) ;
551
+ fileReader . addEventListener ( 'load' , ( event : any ) => {
552
+ const geojson_input = document . querySelector ( '#dialog-geojson-upload textarea' ) as HTMLInputElement
553
+ geojson_input . value = JSON . stringify ( event . target . result , null , 2 )
554
+ } ) ;
555
+ fileReader . readAsText ( file ) ;
556
+ } ) ;
557
+
558
+ editbar . addControl ( new Button ( {
559
+ html : '<i class="material-icons">file_upload</i>' ,
560
+ title : this . i18n . control . geojson ,
561
+ handleClick : ( ) => {
562
+ dialog . dialog ( 'open' )
520
563
}
521
564
} ) )
522
565
}
@@ -988,7 +1031,7 @@ export class GttClient {
988
1031
// Control button
989
1032
const geolocationCtrl = new Toggle ( {
990
1033
html : '<i class="material-icons">my_location</i>' ,
991
- title : "Geolocation" ,
1034
+ title : this . i18n . control . geolocation ,
992
1035
active : false ,
993
1036
onToggle : ( active : boolean ) => {
994
1037
geolocation . setTracking ( active )
@@ -1177,7 +1220,7 @@ export class GttClient {
1177
1220
// Control button
1178
1221
const geocodingCtrl = new Toggle ( {
1179
1222
html : '<i class="material-icons">manage_search</i>' ,
1180
- title : "Geocoding" ,
1223
+ title : this . i18n . control . geocoding ,
1181
1224
className : "ctl-geocoding" ,
1182
1225
onToggle : ( active : boolean ) => {
1183
1226
const text = ( document . querySelector ( "div#" + mapId + " .ctl-geocoding div input" ) as HTMLInputElement )
0 commit comments