Skip to content

Commit

Permalink
Export's refactoring (use of builtin jimu.js utils)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcornet committed Oct 4, 2016
1 parent 26f7d1f commit 7a239ac
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 46 deletions.
4 changes: 1 addition & 3 deletions Widget.html
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,7 @@ <h2>${nls.listDrawTitle}</h2>
<span title="${nls.zoomAllLabel}" class="zoom blue-button" data-dojo-attach-event="onclick:zoomAll">&nbsp;</span>
<span title="${nls.copyLabel}" class="copy blue-button" data-dojo-attach-event="onclick:copy">&nbsp;</span>
<span title="${nls.deleteAllLabel}" class="clear red-button" data-dojo-attach-event="onclick:clear">&nbsp;</span>
<a data-dojo-attach-point="exportSelectionButton" data-dojo-attach-event="onclick:exportSelectionInFile">
<span title="${nls.exportLabel}" class="export blue-button" >&nbsp;</span>
</a>
<span title="${nls.exportLabel}" class="export blue-button" data-dojo-attach-event="onclick:exportSelectionInFile">&nbsp;</span>
</div>
<span title="${nls.importTitle}" class="import-button blue-button" data-dojo-attach-event="onclick:launchImportFile">&nbsp;</span>
</div>
Expand Down
70 changes: 29 additions & 41 deletions Widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ define([
'jimu/BaseWidget',
'esri/config',
'dojo/Deferred',
'jimu/exportUtils',
'esri/graphic',
'esri/symbols/SimpleMarkerSymbol',
'esri/geometry/Polyline',
Expand Down Expand Up @@ -60,7 +61,7 @@ define([
'esri/layers/GraphicsLayer',
'./proj4'
],
function (declare, _WidgetsInTemplateMixin, BaseWidget, esriConfig, Deferred, Graphic, SimpleMarkerSymbol, Polyline, SimpleLineSymbol, Polygon, graphicsUtils, SimpleFillSymbol,
function (declare, _WidgetsInTemplateMixin, BaseWidget, esriConfig, Deferred, exportUtils, Graphic, SimpleMarkerSymbol, Polyline, SimpleLineSymbol, Polygon, graphicsUtils, SimpleFillSymbol,
TextSymbol, Font, esriUnits, Edit, webMercatorUtils, GeometryService, AreasAndLengthsParameters, LengthsParameters, ProjectParameters, wkidUtils, SRUtils, geodesicUtils, geometryEngine, lang, on,
html, has, Color, array, domConstruct, dom, Select, NumberSpinner, ViewStack, SymbolChooser, DrawBox, Message, jimuUtils, jimuSymbolUtils, localStore, InfoTemplate, GraphicsLayer, proj4js) {

Expand Down Expand Up @@ -973,9 +974,9 @@ define([
this.showMessage(this.nls.importErrorMessageNavigator, 'error');
return false;
}

// var dragAndDropSupport = ()

var content = '<div class="eDraw-import-message" id="'+this.id+'___div_import_message">'
+ '<input class="file" type="file" id="'+this.id+'___input_file_import"/>'
+ '<div class="eDraw-import-draganddrop-message">'+this.nls.importDragAndDropMessage+'</div>'
Expand All @@ -991,7 +992,7 @@ define([

//Init file's choice up watching
on(this.importInput, "change", this.importFile);

//Init drag & drop
var div_message = dojo.byId(this.id+'___div_import_message');
on(div_message, "dragover", function(e){
Expand Down Expand Up @@ -1057,7 +1058,7 @@ define([
var g = json.features[0];
var fields_possible = ["name", "title", "label"];
if (g.attributes) {
for (var i =0, len = fields_possible.length; i< len; i++) {
for (var i in fields_possible) {
if (g.attributes[fields_possible[i]]) {
nameField = fields_possible[i];
break;
Expand Down Expand Up @@ -1151,56 +1152,41 @@ define([
},

exportInFile : function () {
this.launchExport(this.exportButton, false);
this.launchExport(false);
},

exportSelectionInFile : function (evt) {
if(evt && evt.preventDefault)
evt.preventDefault();
this.launchExport(this.exportSelectionButton, true);
this.launchExport(true);
},

launchExport : function (link, only_graphics_checked) {
// Be sure the link will not open if not asked :
link.href = "#";
link.target = "_self";

var drawing_json = this.drawingsGetJson(true, only_graphics_checked);
launchExport : function (only_graphics_checked) {
var drawing_json = this.drawingsGetJson(false, only_graphics_checked);

// Control if there are drawings
if (drawing_json == '') {
if (!drawing_json) {
this.showMessage(this.nls.importWarningNoExport0Draw, 'warning');
return false;
}

var export_name = (this.config.exportFileName) ? (this.config.exportFileName) : 'myDrawings.json';

// Case IE with blob support (IE >= 10) : use MS save blob
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
var fileData = [drawing_json];
blobObject = new Blob(fileData, {
type : 'application/octet-stream'
});
window.navigator.msSaveOrOpenBlob(blobObject, export_name);
return false;
}
//We could use FeatureSet (which is required) but this workaround keeps symbols !
var drawing_seems_featureset = {
toJson:function(){
return drawing_json;
}
};

// Case IE without blob support : write in tab. Doesn't allways work....
if (has("ie")) {
var exportWin = window.top.open("about:blank", "_blank");
exportWin.document.write(drawing_json);
exportWin.document.close();
exportWin.focus();
exportWin.document.execCommand('SaveAs', true, export_name);
exportWin.close();
return false;
}
//Create datasource and download !
var ds = exportUtils.createDataSource({
"type" : exportUtils.TYPE_FEATURESET,
"data": drawing_seems_featureset,
"filename" : (this.config.exportFileName) ? (this.config.exportFileName) : 'myDrawings'
});
ds.setFormat(exportUtils.FORMAT_FEATURESET)
ds.download();

// Case HTML5 (Firefox > 25, Chrome > 30....) : use data link with download attribute
link.href = 'data:application/octet-stream;charset=utf-8,' + encodeURIComponent(drawing_json);
link.target = "_blank";
link.download = export_name;
return true;
return false;
},

///////////////////////// EDIT METHODS ///////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1351,6 +1337,8 @@ define([
this._addLineMeasure(geometry, graphic);
else if(geometry.type=='polygon')
this._addPolygonMeasure(geometry, graphic);
else
console.log("Erreur de type : "+geometry.type);
}
if (commontype == 'text' && this.editorSymbolChooser.inputText.value.trim() == "") {
//Message
Expand Down Expand Up @@ -2280,7 +2268,7 @@ define([
//Init list Drag & Drop
this._initListDragAndDrop();

//Load SRID ressources
//Load ressources
SRUtils.loadResource();
},

Expand Down
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"exportFileName" : "myDrawing.json",
"exportFileName" : "myDrawing",
"confirmOnDelete" : true,
"allowLocalStorage" : true,
"localStorageKey" : false,
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "eDraw",
"platform": "HTML",
"version": "2.1.1",
"version": "2.1.2",
"wabVersion": "2.1",
"author" : "Esri R&D Center Beijing modified by MAGIS NC",
"description": "Enhanced draw widget for WebApp Builder for Arcgis.",
Expand Down

0 comments on commit 7a239ac

Please sign in to comment.