Add file propery to ol.interaction.DragAndDropEvent

This commit is contained in:
Frederic Junod
2014-04-14 10:47:57 +02:00
parent 60ab837025
commit 756f407ef4
2 changed files with 18 additions and 6 deletions

View File

@@ -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.<ol.Feature>=} 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);