From 756f407ef462eda9cffec52754d854c4f57495d5 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Mon, 14 Apr 2014 10:47:57 +0200 Subject: [PATCH 1/2] Add file propery to ol.interaction.DragAndDropEvent --- externs/oli.js | 3 +++ src/ol/interaction/draganddropinteraction.js | 21 ++++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/externs/oli.js b/externs/oli.js index 3fd705bc78..7a951c1a2c 100644 --- a/externs/oli.js +++ b/externs/oli.js @@ -195,6 +195,9 @@ oli.interaction.DragAndDropEvent.prototype.features; oli.interaction.DragAndDropEvent.prototype.projection; +/** @type {File} */ +oli.interaction.DragAndDropEvent.prototype.file; + /** @interface */ oli.render.Event; diff --git a/src/ol/interaction/draganddropinteraction.js b/src/ol/interaction/draganddropinteraction.js index 3a8c5a911d..b2e8e482ac 100644 --- a/src/ol/interaction/draganddropinteraction.js +++ b/src/ol/interaction/draganddropinteraction.js @@ -76,21 +76,23 @@ ol.interaction.DragAndDrop.prototype.disposeInternal = function() { */ ol.interaction.DragAndDrop.prototype.handleDrop_ = function(event) { var files = event.getBrowserEvent().dataTransfer.files; - var i, ii; + var i, ii, file; for (i = 0, ii = files.length; i < ii; ++i) { + file = files[i]; // The empty string param is a workaround for // https://code.google.com/p/closure-library/issues/detail?id=524 - var reader = goog.fs.FileReader.readAsText(files[i], ''); - reader.addCallback(this.handleResult_, this); + var reader = goog.fs.FileReader.readAsText(file, ''); + reader.addCallback(goog.partial(this.handleResult_, file), this); } }; /** + * @param {File} file File. * @param {string} result Result. * @private */ -ol.interaction.DragAndDrop.prototype.handleResult_ = function(result) { +ol.interaction.DragAndDrop.prototype.handleResult_ = function(file, result) { var map = this.getMap(); goog.asserts.assert(!goog.isNull(map)); var projection = this.reprojectTo_; @@ -124,7 +126,7 @@ ol.interaction.DragAndDrop.prototype.handleResult_ = function(result) { this.dispatchEvent( new ol.interaction.DragAndDropEvent( ol.interaction.DragAndDropEventType.ADD_FEATURES, this, features, - projection)); + projection, file)); }; @@ -195,9 +197,10 @@ ol.interaction.DragAndDropEventType = { * @param {Object=} opt_target Target. * @param {Array.=} opt_features Features. * @param {ol.proj.Projection=} opt_projection Projection. + * @param {File=} opt_file File. */ ol.interaction.DragAndDropEvent = - function(type, opt_target, opt_features, opt_projection) { + function(type, opt_target, opt_features, opt_projection, opt_file) { goog.base(this, type, opt_target); @@ -213,5 +216,11 @@ ol.interaction.DragAndDropEvent = */ this.projection = opt_projection; + /** + * @type {File|undefined} + * @todo stability experimental + */ + this.file = opt_file; + }; goog.inherits(ol.interaction.DragAndDropEvent, goog.events.Event); From ef27f14376f3b30093767aac27facf98d6695970 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Mon, 14 Apr 2014 12:01:48 +0200 Subject: [PATCH 2/2] Remove undefined type from opt_target and opt_file --- src/ol/interaction/draganddropinteraction.js | 24 ++++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/ol/interaction/draganddropinteraction.js b/src/ol/interaction/draganddropinteraction.js index b2e8e482ac..f2a62ba773 100644 --- a/src/ol/interaction/draganddropinteraction.js +++ b/src/ol/interaction/draganddropinteraction.js @@ -125,8 +125,8 @@ ol.interaction.DragAndDrop.prototype.handleResult_ = function(file, result) { } this.dispatchEvent( new ol.interaction.DragAndDropEvent( - ol.interaction.DragAndDropEventType.ADD_FEATURES, this, features, - projection, file)); + ol.interaction.DragAndDropEventType.ADD_FEATURES, this, file, + features, projection)); }; @@ -194,15 +194,15 @@ ol.interaction.DragAndDropEventType = { * @extends {goog.events.Event} * @implements {oli.interaction.DragAndDropEvent} * @param {ol.interaction.DragAndDropEventType} type Type. - * @param {Object=} opt_target Target. + * @param {Object} target Target. + * @param {File} file File. * @param {Array.=} opt_features Features. * @param {ol.proj.Projection=} opt_projection Projection. - * @param {File=} opt_file File. */ ol.interaction.DragAndDropEvent = - function(type, opt_target, opt_features, opt_projection, opt_file) { + function(type, target, file, opt_features, opt_projection) { - goog.base(this, type, opt_target); + goog.base(this, type, target); /** * @type {Array.|undefined} @@ -210,17 +210,17 @@ ol.interaction.DragAndDropEvent = */ this.features = opt_features; + /** + * @type {File} + * @todo stability experimental + */ + this.file = file; + /** * @type {ol.proj.Projection|undefined} * @todo stability experimental */ this.projection = opt_projection; - /** - * @type {File|undefined} - * @todo stability experimental - */ - this.file = opt_file; - }; goog.inherits(ol.interaction.DragAndDropEvent, goog.events.Event);