@@ -70,6 +70,7 @@ define([
70
70
i18n : i18n ,
71
71
72
72
topicID : 'exportWidget' ,
73
+ modulesPath : module . uri . substring ( 0 , module . uri . lastIndexOf ( '.' ) ) + '/lib' ,
73
74
74
75
defaultOptions : {
75
76
excel : true , // allow attributes to be exported to Excel
@@ -143,11 +144,11 @@ define([
143
144
144
145
this . addTopics ( ) ;
145
146
this . setExportDefaults ( ) ;
146
- this . loadXLSXParser ( ) ;
147
- this . loadFeatureParser ( ) ;
148
147
this . initExportSelect ( ) ;
149
148
this . onWkidChange ( this . inputWkid . get ( 'value' ) ) ;
150
149
this . own ( on ( this . inputWkid , 'keyup' , lang . hitch ( this , 'wkidOnKeyUp' ) ) ) ;
150
+
151
+ window . setTimeout ( lang . hitch ( this , 'loadParsers' ) , 1000 ) ;
151
152
} ,
152
153
153
154
addTopics : function ( ) {
@@ -222,17 +223,25 @@ define([
222
223
domStyle . set ( this . divWkidSection , 'display' , 'none' ) ;
223
224
this . inputWkid . set ( 'disabled' , true ) ;
224
225
}
226
+ this . resetWkid ( ) ;
225
227
this . removeLink ( ) ;
226
228
this . btnExport . set ( 'disabled' , false ) ;
227
229
} ,
228
230
229
231
onWkidChange : function ( ) {
230
232
var wkid = this . inputWkid . get ( 'value' ) ;
233
+ this . removeLink ( ) ;
231
234
if ( wkid && ! isNaN ( wkid ) && wkid . length > 3 ) {
232
235
wkid = parseInt ( wkid , 10 ) ;
233
236
if ( wkid === 102100 ) { // ESRI --> EPSG
234
237
wkid = 3857 ;
235
238
}
239
+
240
+ var key = this . proj4Catalog + ':' + String ( wkid ) ;
241
+ if ( window . proj4 && ! window . proj4 . defs [ key ] ) {
242
+ require ( [ this . proj4BaseURL + String ( wkid ) + '.js' ] ) ;
243
+ }
244
+
236
245
require ( [ 'dojo/text!' + this . proj4BaseURL + String ( wkid ) + '.esriwkt' ] , lang . hitch ( this , function ( prj ) {
237
246
if ( wkid !== 4326 ) {
238
247
this . proj4DestWKT = prj ;
@@ -272,6 +281,12 @@ define([
272
281
this . wkidChangeTimeoutID = window . setTimeout ( lang . hitch ( this , 'onWkidChange' ) , 200 ) ;
273
282
} ,
274
283
284
+ resetWkid : function ( ) {
285
+ this . proj4DestWkid = 4326 ;
286
+ this . proj4DestKey = 'EPSG:4326' ;
287
+ this . proj4DestWKT = null ;
288
+ } ,
289
+
275
290
openDialog : function ( options ) {
276
291
this . getExportDefaults ( ) ;
277
292
this . featureSet = options . featureSet ;
@@ -297,6 +312,7 @@ define([
297
312
this . topojsonOptions = ( typeof ( options . topojsonOptions ) !== 'undefined' ) ? options . topojsonOptions : this . topojsonOptions ;
298
313
299
314
this . initExportSelect ( ) ;
315
+ this . removeLink ( ) ;
300
316
301
317
if ( options . show ) {
302
318
this . parentWidget . show ( ) ;
@@ -448,6 +464,7 @@ define([
448
464
exportToGeoJSON : function ( ) {
449
465
// force export to 4326
450
466
this . inputWkid . set ( 'value' , 4326 ) ;
467
+ this . resetWkid ( ) ;
451
468
452
469
var geojson = this . createGeoJSON ( ) ;
453
470
if ( ! geojson ) {
@@ -462,6 +479,7 @@ define([
462
479
exportToKML : function ( ) {
463
480
// force export to 4326
464
481
this . inputWkid . set ( 'value' , 4326 ) ;
482
+ this . resetWkid ( ) ;
465
483
466
484
var geojson = this . createGeoJSON ( ) ;
467
485
if ( ! geojson ) {
@@ -472,7 +490,7 @@ define([
472
490
// customized version of mapbox's tokml for higher fidelity exports
473
491
// handles more attributes than defined in the simple-spec v1.1
474
492
// source: https://cdn.rawgit.com/mapbox/tokml/v0.4.0/tokml.js'
475
- require ( [ module . id + '/tokml' ] , lang . hitch ( this , function ( tokml ) {
493
+ require ( [ this . modulesPath + '/tokml.min.js ' ] , lang . hitch ( this , function ( tokml ) {
476
494
var kml = tokml ( geojson , this . kmlOptions ) ;
477
495
if ( ! kml ) {
478
496
this . reportError ( i18n . errorKML ) ;
@@ -482,13 +500,15 @@ define([
482
500
if ( exportType === 'kml' ) {
483
501
this . downloadFile ( kml , 'application/vnd.google-earth.kml+xml;charset=utf-8;' , this . getFileName ( '.kml' ) , true ) ;
484
502
} else {
485
- /*global JSZip */
486
- var jszip = new JSZip ( ) ;
503
+ /*global JSZip3 */
504
+ var jszip = new JSZip3 ( ) ;
487
505
jszip . file ( this . getFileName ( '.kml' ) , kml ) ;
488
- var zipFile = jszip . generate ( {
489
- compression : 'STORE' }
490
- ) ;
491
- this . downloadFile ( zipFile , 'application/vnd.google-earth.kmz;base64;' , this . getFileName ( '.kmz' ) , false ) ;
506
+ jszip . generateAsync ( {
507
+ type : 'blob' ,
508
+ compression : 'STORE'
509
+ } ) . then ( lang . hitch ( this , function ( zipFile ) {
510
+ this . downloadFile ( zipFile , 'application/vnd.google-earth.kmz;base64;' , this . getFileName ( '.kmz' ) , true ) ;
511
+ } ) ) ;
492
512
}
493
513
494
514
} ) ) ;
@@ -499,6 +519,7 @@ define([
499
519
var wkid = this . inputWkid . get ( 'value' ) ;
500
520
if ( ! wkid || wkid === '' ) {
501
521
this . inputWkid . set ( 'value' , 4326 ) ;
522
+ this . resetWkid ( ) ;
502
523
}
503
524
504
525
var geojson = this . createGeoJSON ( ) ;
@@ -507,30 +528,33 @@ define([
507
528
return ;
508
529
}
509
530
510
- require ( [ module . id + '/shpwrite' ] , lang . hitch ( this , function ( shpWrite ) {
531
+ require ( [ this . modulesPath + '/shpwrite.min.js ' ] , lang . hitch ( this , function ( shpWrite ) {
511
532
var options = lang . clone ( this . shapefileOptions ) ;
512
533
options . wkt = this . proj4DestWKT ;
513
534
var zipFile = shpWrite . zip ( geojson , options ) ;
514
535
if ( ! zipFile ) {
515
536
this . reportError ( i18n . errorShapeFile ) ;
516
537
return ;
517
538
}
518
- this . downloadFile ( zipFile , 'application/zip;base64;' , this . getFileName ( '.zip' ) , false ) ;
539
+ zipFile . then ( lang . hitch ( this , function ( content ) {
540
+ this . downloadFile ( content , 'application/zip;base64;' , this . getFileName ( '.zip' ) , true ) ;
541
+ } ) ) ;
519
542
} ) ) ;
520
543
521
544
} ,
522
545
523
546
exportToTopoJSON : function ( ) {
524
547
// force export to 4326
525
548
this . inputWkid . set ( 'value' , 4326 ) ;
549
+ this . resetWkid ( ) ;
526
550
527
551
var geojson = this . createGeoJSON ( ) ;
528
552
if ( ! geojson ) {
529
553
this . reportError ( i18n . errorTopoJSON ) ;
530
554
return ;
531
555
}
532
556
533
- require ( [ module . id + '/topojson' ] , lang . hitch ( this , function ( ) {
557
+ require ( [ this . modulesPath + '/topojson.min.js ' ] , lang . hitch ( this , function ( ) {
534
558
var options = lang . clone ( this . topojsonOptions ) ;
535
559
if ( options [ 'property-transform' ] === null ) {
536
560
//options['property-transform'] = this.allProperties;
@@ -553,6 +577,7 @@ define([
553
577
var wkid = this . inputWkid . get ( 'value' ) ;
554
578
if ( ! wkid || wkid === '' ) {
555
579
this . inputWkid . set ( 'value' , 4326 ) ;
580
+ this . resetWkid ( ) ;
556
581
}
557
582
558
583
var geojson = this . createGeoJSON ( ) ;
@@ -561,7 +586,7 @@ define([
561
586
return ;
562
587
}
563
588
564
- require ( [ 'https://cdn.rawgit.com/mapbox/ wellknown/ v0.4.2/wellknown .js'] , lang . hitch ( this , function ( wellknown ) {
589
+ require ( [ this . modulesPath + '/ wellknown- v0.4.2.min .js'] , lang . hitch ( this , function ( wellknown ) {
565
590
var wkt = geojson . features . map ( wellknown . stringify ) . join ( '\n' ) ;
566
591
if ( ! wkt ) {
567
592
this . reportError ( i18n . errorWKT ) ;
@@ -767,21 +792,27 @@ define([
767
792
includeStyle = true ;
768
793
}
769
794
795
+ var sourceProj = window . proj4 . defs [ this . proj4SrcKey ] ;
796
+ var destProj = window . proj4 . defs [ this . proj4DestKey ] ;
770
797
array . forEach ( features , lang . hitch ( this , function ( feature ) {
771
798
var attr = feature . attributes ;
772
799
if ( typeof ( attr . feature ) === 'object' ) {
773
800
delete attr . feature ;
774
801
}
802
+ var newFeature = {
803
+ attributes : lang . clone ( attr ) ,
804
+ geometry : lang . clone ( feature . geometry )
805
+ } ;
775
806
if ( feature . symbol && includeStyle ) {
776
- feature . attributes = this . convertSymbolToAttributes ( feature ) ;
807
+ newFeature . attributes = this . convertSymbolToAttributes ( feature ) ;
777
808
}
778
809
779
- if ( feature . geometry ) {
780
- if ( window . proj4 . defs [ this . proj4SrcKey ] && window . proj4 . defs [ this . proj4DestKey ] ) {
781
- feature . geometry = this . projectGeometry ( feature . geometry , exportType ) ;
810
+ if ( newFeature . geometry ) {
811
+ if ( sourceProj && destProj ) {
812
+ newFeature . geometry = this . projectGeometry ( newFeature . geometry ) ;
782
813
}
783
814
784
- var geoFeature = window . Terraformer . ArcGIS . parse ( feature ) ;
815
+ var geoFeature = window . Terraformer . ArcGIS . parse ( newFeature ) ;
785
816
geojson . features . push ( geoFeature ) ;
786
817
} else {
787
818
topic . publish ( 'viewer/handleError' , 'feature has no geometry' ) ;
@@ -792,7 +823,6 @@ define([
792
823
return geojson ;
793
824
} ,
794
825
795
-
796
826
/*******************************
797
827
* Projection Functions
798
828
*******************************/
@@ -945,19 +975,39 @@ define([
945
975
* load parsers
946
976
*******************************/
947
977
978
+ loadParsers : function ( ) {
979
+
980
+ window . dojoConfig . packages . push ( {
981
+ name : 'JSZip3' ,
982
+ location : this . modulesPath ,
983
+ main : 'jszip-v3.1.3.min'
984
+ } ) ;
985
+ require ( window . dojoConfig , [
986
+ 'JSZip3'
987
+ ] , lang . hitch ( this , function ( JSZip3 ) {
988
+ if ( ! window . JSZip3 ) {
989
+ window . JSZip3 = JSZip3 ;
990
+ }
991
+ this . loadXLSXParser ( ) ;
992
+ this . loadFeatureParser ( ) ;
993
+ } ) ) ;
994
+
995
+ } ,
996
+
948
997
loadXLSXParser : function ( ) {
949
998
if ( this . excel || this . csv || this . xlsExcel ) {
999
+ //xlsx requires jszip version 2.x. version 3.x for everything else
950
1000
require ( [
951
- 'https://cdnjs.cloudflare.com/ajax/libs/ xlsx/0.7.8/xlsx.core .min.js'
1001
+ this . modulesPath + '/ xlsx.core-v0.9.12 .min.js'
952
1002
] ) ;
953
1003
}
954
1004
} ,
955
1005
956
1006
loadFeatureParser : function ( ) {
957
1007
if ( this . geojson || this . kml || this . kmz || this . shapefile || this . topojson || this . wkt ) {
958
1008
require ( [
959
- 'https://cdnjs.cloudflare.com/ajax/libs/ proj4js/2.3.14/ proj4.js ' ,
960
- 'https://cdn-geoweb.s3.amazonaws.com/terraformer/1.0.5/terraformer .min.js'
1009
+ 'proj4js/proj4' ,
1010
+ this . modulesPath + '/terraformer-v1.0.8 .min.js'
961
1011
] , lang . hitch ( this , function ( proj4 ) {
962
1012
if ( ! window . proj4 ) {
963
1013
window . proj4 = proj4 ;
@@ -966,14 +1016,14 @@ define([
966
1016
967
1017
// arcgis parser must be loaded after the terraformer core module
968
1018
require ( [
969
- 'https://cdn-geoweb.s3.amazonaws.com/ terraformer-arcgis-parser/1 .0.4/terraformer-arcgis-parser .min.js'
1019
+ this . modulesPath + '/ terraformer-arcgis-parser-v1 .0.5 .min.js'
970
1020
] ) ;
971
1021
} ) ) ;
972
1022
}
973
1023
} ,
974
1024
975
1025
loadSourceProj4 : function ( ) {
976
- // which wikid are we projecting from?
1026
+ // which wkid are we projecting from?
977
1027
if ( window . proj4 && this . featureSet && this . featureSet . features ) {
978
1028
var features = this . featureSet . features ;
979
1029
if ( features && features . length > 0 ) {
@@ -1037,7 +1087,7 @@ define([
1037
1087
} ,
1038
1088
1039
1089
removeLink : function ( ) {
1040
- if ( this . link ) {
1090
+ if ( this . link && this . divExportLink ) {
1041
1091
this . divExportLink . removeChild ( this . link ) ;
1042
1092
this . divExportLink . innerHTML = ' ' ;
1043
1093
}
0 commit comments