Merge pull request #1982 from fredj/dnd-event
Add file propery to ol.interaction.DragAndDropEvent
This commit is contained in:
@@ -195,6 +195,9 @@ oli.interaction.DragAndDropEvent.prototype.features;
|
|||||||
oli.interaction.DragAndDropEvent.prototype.projection;
|
oli.interaction.DragAndDropEvent.prototype.projection;
|
||||||
|
|
||||||
|
|
||||||
|
/** @type {File} */
|
||||||
|
oli.interaction.DragAndDropEvent.prototype.file;
|
||||||
|
|
||||||
|
|
||||||
/** @interface */
|
/** @interface */
|
||||||
oli.render.Event;
|
oli.render.Event;
|
||||||
|
|||||||
@@ -76,21 +76,23 @@ ol.interaction.DragAndDrop.prototype.disposeInternal = function() {
|
|||||||
*/
|
*/
|
||||||
ol.interaction.DragAndDrop.prototype.handleDrop_ = function(event) {
|
ol.interaction.DragAndDrop.prototype.handleDrop_ = function(event) {
|
||||||
var files = event.getBrowserEvent().dataTransfer.files;
|
var files = event.getBrowserEvent().dataTransfer.files;
|
||||||
var i, ii;
|
var i, ii, file;
|
||||||
for (i = 0, ii = files.length; i < ii; ++i) {
|
for (i = 0, ii = files.length; i < ii; ++i) {
|
||||||
|
file = files[i];
|
||||||
// The empty string param is a workaround for
|
// The empty string param is a workaround for
|
||||||
// https://code.google.com/p/closure-library/issues/detail?id=524
|
// https://code.google.com/p/closure-library/issues/detail?id=524
|
||||||
var reader = goog.fs.FileReader.readAsText(files[i], '');
|
var reader = goog.fs.FileReader.readAsText(file, '');
|
||||||
reader.addCallback(this.handleResult_, this);
|
reader.addCallback(goog.partial(this.handleResult_, file), this);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param {File} file File.
|
||||||
* @param {string} result Result.
|
* @param {string} result Result.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ol.interaction.DragAndDrop.prototype.handleResult_ = function(result) {
|
ol.interaction.DragAndDrop.prototype.handleResult_ = function(file, result) {
|
||||||
var map = this.getMap();
|
var map = this.getMap();
|
||||||
goog.asserts.assert(!goog.isNull(map));
|
goog.asserts.assert(!goog.isNull(map));
|
||||||
var projection = this.reprojectTo_;
|
var projection = this.reprojectTo_;
|
||||||
@@ -123,8 +125,8 @@ ol.interaction.DragAndDrop.prototype.handleResult_ = function(result) {
|
|||||||
}
|
}
|
||||||
this.dispatchEvent(
|
this.dispatchEvent(
|
||||||
new ol.interaction.DragAndDropEvent(
|
new ol.interaction.DragAndDropEvent(
|
||||||
ol.interaction.DragAndDropEventType.ADD_FEATURES, this, features,
|
ol.interaction.DragAndDropEventType.ADD_FEATURES, this, file,
|
||||||
projection));
|
features, projection));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -192,14 +194,15 @@ ol.interaction.DragAndDropEventType = {
|
|||||||
* @extends {goog.events.Event}
|
* @extends {goog.events.Event}
|
||||||
* @implements {oli.interaction.DragAndDropEvent}
|
* @implements {oli.interaction.DragAndDropEvent}
|
||||||
* @param {ol.interaction.DragAndDropEventType} type Type.
|
* @param {ol.interaction.DragAndDropEventType} type Type.
|
||||||
* @param {Object=} opt_target Target.
|
* @param {Object} target Target.
|
||||||
|
* @param {File} file File.
|
||||||
* @param {Array.<ol.Feature>=} opt_features Features.
|
* @param {Array.<ol.Feature>=} opt_features Features.
|
||||||
* @param {ol.proj.Projection=} opt_projection Projection.
|
* @param {ol.proj.Projection=} opt_projection Projection.
|
||||||
*/
|
*/
|
||||||
ol.interaction.DragAndDropEvent =
|
ol.interaction.DragAndDropEvent =
|
||||||
function(type, opt_target, opt_features, opt_projection) {
|
function(type, target, file, opt_features, opt_projection) {
|
||||||
|
|
||||||
goog.base(this, type, opt_target);
|
goog.base(this, type, target);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {Array.<ol.Feature>|undefined}
|
* @type {Array.<ol.Feature>|undefined}
|
||||||
@@ -207,6 +210,12 @@ ol.interaction.DragAndDropEvent =
|
|||||||
*/
|
*/
|
||||||
this.features = opt_features;
|
this.features = opt_features;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {File}
|
||||||
|
* @todo stability experimental
|
||||||
|
*/
|
||||||
|
this.file = file;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {ol.proj.Projection|undefined}
|
* @type {ol.proj.Projection|undefined}
|
||||||
* @todo stability experimental
|
* @todo stability experimental
|
||||||
|
|||||||
Reference in New Issue
Block a user