Better variables scoping
This commit is contained in:
@@ -128,12 +128,10 @@ inherits(DragAndDrop, Interaction);
|
|||||||
*/
|
*/
|
||||||
function handleDrop(event) {
|
function handleDrop(event) {
|
||||||
const files = event.dataTransfer.files;
|
const files = event.dataTransfer.files;
|
||||||
let i, ii, file;
|
for (let i = 0, ii = files.length; i < ii; ++i) {
|
||||||
for (i = 0, ii = files.length; i < ii; ++i) {
|
const file = files.item(i);
|
||||||
file = files.item(i);
|
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.addEventListener(EventType.LOAD,
|
reader.addEventListener(EventType.LOAD, this.handleResult_.bind(this, file));
|
||||||
this.handleResult_.bind(this, file));
|
|
||||||
reader.readAsText(file);
|
reader.readAsText(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -165,8 +163,7 @@ DragAndDrop.prototype.handleResult_ = function(file, event) {
|
|||||||
|
|
||||||
const formatConstructors = this.formatConstructors_;
|
const formatConstructors = this.formatConstructors_;
|
||||||
let features = [];
|
let features = [];
|
||||||
let i, ii;
|
for (let i = 0, ii = formatConstructors.length; i < ii; ++i) {
|
||||||
for (i = 0, ii = formatConstructors.length; i < ii; ++i) {
|
|
||||||
/**
|
/**
|
||||||
* Avoid "cannot instantiate abstract class" error.
|
* Avoid "cannot instantiate abstract class" error.
|
||||||
* @type {Function}
|
* @type {Function}
|
||||||
@@ -202,14 +199,10 @@ DragAndDrop.prototype.registerListeners_ = function() {
|
|||||||
if (map) {
|
if (map) {
|
||||||
const dropArea = this.target ? this.target : map.getViewport();
|
const dropArea = this.target ? this.target : map.getViewport();
|
||||||
this.dropListenKeys_ = [
|
this.dropListenKeys_ = [
|
||||||
listen(dropArea, EventType.DROP,
|
listen(dropArea, EventType.DROP, handleDrop, this),
|
||||||
handleDrop, this),
|
listen(dropArea, EventType.DRAGENTER, handleStop, this),
|
||||||
listen(dropArea, EventType.DRAGENTER,
|
listen(dropArea, EventType.DRAGOVER, handleStop, this),
|
||||||
handleStop, this),
|
listen(dropArea, EventType.DROP, handleStop, this)
|
||||||
listen(dropArea, EventType.DRAGOVER,
|
|
||||||
handleStop, this),
|
|
||||||
listen(dropArea, EventType.DROP,
|
|
||||||
handleStop, this)
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -465,10 +465,9 @@ Modify.prototype.writePointGeometry_ = function(feature, geometry) {
|
|||||||
*/
|
*/
|
||||||
Modify.prototype.writeMultiPointGeometry_ = function(feature, geometry) {
|
Modify.prototype.writeMultiPointGeometry_ = function(feature, geometry) {
|
||||||
const points = geometry.getCoordinates();
|
const points = geometry.getCoordinates();
|
||||||
let coordinates, i, ii, segmentData;
|
for (let i = 0, ii = points.length; i < ii; ++i) {
|
||||||
for (i = 0, ii = points.length; i < ii; ++i) {
|
const coordinates = points[i];
|
||||||
coordinates = points[i];
|
const segmentData = /** @type {ol.ModifySegmentDataType} */ ({
|
||||||
segmentData = /** @type {ol.ModifySegmentDataType} */ ({
|
|
||||||
feature: feature,
|
feature: feature,
|
||||||
geometry: geometry,
|
geometry: geometry,
|
||||||
depth: [i],
|
depth: [i],
|
||||||
@@ -487,10 +486,9 @@ Modify.prototype.writeMultiPointGeometry_ = function(feature, geometry) {
|
|||||||
*/
|
*/
|
||||||
Modify.prototype.writeLineStringGeometry_ = function(feature, geometry) {
|
Modify.prototype.writeLineStringGeometry_ = function(feature, geometry) {
|
||||||
const coordinates = geometry.getCoordinates();
|
const coordinates = geometry.getCoordinates();
|
||||||
let i, ii, segment, segmentData;
|
for (let i = 0, ii = coordinates.length - 1; i < ii; ++i) {
|
||||||
for (i = 0, ii = coordinates.length - 1; i < ii; ++i) {
|
const segment = coordinates.slice(i, i + 2);
|
||||||
segment = coordinates.slice(i, i + 2);
|
const segmentData = /** @type {ol.ModifySegmentDataType} */ ({
|
||||||
segmentData = /** @type {ol.ModifySegmentDataType} */ ({
|
|
||||||
feature: feature,
|
feature: feature,
|
||||||
geometry: geometry,
|
geometry: geometry,
|
||||||
index: i,
|
index: i,
|
||||||
@@ -508,12 +506,11 @@ Modify.prototype.writeLineStringGeometry_ = function(feature, geometry) {
|
|||||||
*/
|
*/
|
||||||
Modify.prototype.writeMultiLineStringGeometry_ = function(feature, geometry) {
|
Modify.prototype.writeMultiLineStringGeometry_ = function(feature, geometry) {
|
||||||
const lines = geometry.getCoordinates();
|
const lines = geometry.getCoordinates();
|
||||||
let coordinates, i, ii, j, jj, segment, segmentData;
|
for (let j = 0, jj = lines.length; j < jj; ++j) {
|
||||||
for (j = 0, jj = lines.length; j < jj; ++j) {
|
const coordinates = lines[j];
|
||||||
coordinates = lines[j];
|
for (let i = 0, ii = coordinates.length - 1; i < ii; ++i) {
|
||||||
for (i = 0, ii = coordinates.length - 1; i < ii; ++i) {
|
const segment = coordinates.slice(i, i + 2);
|
||||||
segment = coordinates.slice(i, i + 2);
|
const segmentData = /** @type {ol.ModifySegmentDataType} */ ({
|
||||||
segmentData = /** @type {ol.ModifySegmentDataType} */ ({
|
|
||||||
feature: feature,
|
feature: feature,
|
||||||
geometry: geometry,
|
geometry: geometry,
|
||||||
depth: [j],
|
depth: [j],
|
||||||
@@ -533,12 +530,11 @@ Modify.prototype.writeMultiLineStringGeometry_ = function(feature, geometry) {
|
|||||||
*/
|
*/
|
||||||
Modify.prototype.writePolygonGeometry_ = function(feature, geometry) {
|
Modify.prototype.writePolygonGeometry_ = function(feature, geometry) {
|
||||||
const rings = geometry.getCoordinates();
|
const rings = geometry.getCoordinates();
|
||||||
let coordinates, i, ii, j, jj, segment, segmentData;
|
for (let j = 0, jj = rings.length; j < jj; ++j) {
|
||||||
for (j = 0, jj = rings.length; j < jj; ++j) {
|
const coordinates = rings[j];
|
||||||
coordinates = rings[j];
|
for (let i = 0, ii = coordinates.length - 1; i < ii; ++i) {
|
||||||
for (i = 0, ii = coordinates.length - 1; i < ii; ++i) {
|
const segment = coordinates.slice(i, i + 2);
|
||||||
segment = coordinates.slice(i, i + 2);
|
const segmentData = /** @type {ol.ModifySegmentDataType} */ ({
|
||||||
segmentData = /** @type {ol.ModifySegmentDataType} */ ({
|
|
||||||
feature: feature,
|
feature: feature,
|
||||||
geometry: geometry,
|
geometry: geometry,
|
||||||
depth: [j],
|
depth: [j],
|
||||||
@@ -558,14 +554,13 @@ Modify.prototype.writePolygonGeometry_ = function(feature, geometry) {
|
|||||||
*/
|
*/
|
||||||
Modify.prototype.writeMultiPolygonGeometry_ = function(feature, geometry) {
|
Modify.prototype.writeMultiPolygonGeometry_ = function(feature, geometry) {
|
||||||
const polygons = geometry.getCoordinates();
|
const polygons = geometry.getCoordinates();
|
||||||
let coordinates, i, ii, j, jj, k, kk, rings, segment, segmentData;
|
for (let k = 0, kk = polygons.length; k < kk; ++k) {
|
||||||
for (k = 0, kk = polygons.length; k < kk; ++k) {
|
const rings = polygons[k];
|
||||||
rings = polygons[k];
|
for (let j = 0, jj = rings.length; j < jj; ++j) {
|
||||||
for (j = 0, jj = rings.length; j < jj; ++j) {
|
const coordinates = rings[j];
|
||||||
coordinates = rings[j];
|
for (let i = 0, ii = coordinates.length - 1; i < ii; ++i) {
|
||||||
for (i = 0, ii = coordinates.length - 1; i < ii; ++i) {
|
const segment = coordinates.slice(i, i + 2);
|
||||||
segment = coordinates.slice(i, i + 2);
|
const segmentData = /** @type {ol.ModifySegmentDataType} */ ({
|
||||||
segmentData = /** @type {ol.ModifySegmentDataType} */ ({
|
|
||||||
feature: feature,
|
feature: feature,
|
||||||
geometry: geometry,
|
geometry: geometry,
|
||||||
depth: [j, k],
|
depth: [j, k],
|
||||||
@@ -811,11 +806,9 @@ function handleDragEvent(evt) {
|
|||||||
* @this {ol.interaction.Modify}
|
* @this {ol.interaction.Modify}
|
||||||
*/
|
*/
|
||||||
function handleUpEvent(evt) {
|
function handleUpEvent(evt) {
|
||||||
let segmentData;
|
|
||||||
let geometry;
|
|
||||||
for (let i = this.dragSegments_.length - 1; i >= 0; --i) {
|
for (let i = this.dragSegments_.length - 1; i >= 0; --i) {
|
||||||
segmentData = this.dragSegments_[i][0];
|
const segmentData = this.dragSegments_[i][0];
|
||||||
geometry = segmentData.geometry;
|
const geometry = segmentData.geometry;
|
||||||
if (geometry.getType() === GeometryType.CIRCLE) {
|
if (geometry.getType() === GeometryType.CIRCLE) {
|
||||||
// Update a circle object in the R* bush:
|
// Update a circle object in the R* bush:
|
||||||
const coordinates = geometry.getCenter();
|
const coordinates = geometry.getCenter();
|
||||||
@@ -826,13 +819,11 @@ function handleUpEvent(evt) {
|
|||||||
this.rBush_.update(createOrUpdateFromCoordinate(coordinates), centerSegmentData);
|
this.rBush_.update(createOrUpdateFromCoordinate(coordinates), centerSegmentData);
|
||||||
this.rBush_.update(geometry.getExtent(), circumferenceSegmentData);
|
this.rBush_.update(geometry.getExtent(), circumferenceSegmentData);
|
||||||
} else {
|
} else {
|
||||||
this.rBush_.update(boundingExtent(segmentData.segment),
|
this.rBush_.update(boundingExtent(segmentData.segment), segmentData);
|
||||||
segmentData);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.modified_) {
|
if (this.modified_) {
|
||||||
this.dispatchEvent(new ModifyEvent(
|
this.dispatchEvent(new ModifyEvent(ModifyEventType.MODIFYEND, this.features_, evt));
|
||||||
ModifyEventType.MODIFYEND, this.features_, evt));
|
|
||||||
this.modified_ = false;
|
this.modified_ = false;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -927,9 +918,8 @@ Modify.prototype.handlePointerAtPixel_ = function(pixel, map) {
|
|||||||
vertex = squaredDist1 > squaredDist2 ? closestSegment[1] : closestSegment[0];
|
vertex = squaredDist1 > squaredDist2 ? closestSegment[1] : closestSegment[0];
|
||||||
}
|
}
|
||||||
this.createOrUpdateVertexFeature_(vertex);
|
this.createOrUpdateVertexFeature_(vertex);
|
||||||
let segment;
|
|
||||||
for (let i = 1, ii = nodes.length; i < ii; ++i) {
|
for (let i = 1, ii = nodes.length; i < ii; ++i) {
|
||||||
segment = nodes[i].segment;
|
const segment = nodes[i].segment;
|
||||||
if ((coordinatesEqual(closestSegment[0], segment[0]) &&
|
if ((coordinatesEqual(closestSegment[0], segment[0]) &&
|
||||||
coordinatesEqual(closestSegment[1], segment[1]) ||
|
coordinatesEqual(closestSegment[1], segment[1]) ||
|
||||||
(coordinatesEqual(closestSegment[0], segment[1]) &&
|
(coordinatesEqual(closestSegment[0], segment[1]) &&
|
||||||
|
|||||||
@@ -269,11 +269,11 @@ function handleEvent(mapBrowserEvent) {
|
|||||||
clear(this.featureLayerAssociation_);
|
clear(this.featureLayerAssociation_);
|
||||||
map.forEachFeatureAtPixel(mapBrowserEvent.pixel,
|
map.forEachFeatureAtPixel(mapBrowserEvent.pixel,
|
||||||
(
|
(
|
||||||
/**
|
/**
|
||||||
* @param {ol.Feature|ol.render.Feature} feature Feature.
|
* @param {ol.Feature|ol.render.Feature} feature Feature.
|
||||||
* @param {ol.layer.Layer} layer Layer.
|
* @param {ol.layer.Layer} layer Layer.
|
||||||
* @return {boolean|undefined} Continue to iterate over the features.
|
* @return {boolean|undefined} Continue to iterate over the features.
|
||||||
*/
|
*/
|
||||||
function(feature, layer) {
|
function(feature, layer) {
|
||||||
if (this.filter_(feature, layer)) {
|
if (this.filter_(feature, layer)) {
|
||||||
selected.push(feature);
|
selected.push(feature);
|
||||||
@@ -284,8 +284,7 @@ function handleEvent(mapBrowserEvent) {
|
|||||||
layerFilter: this.layerFilter_,
|
layerFilter: this.layerFilter_,
|
||||||
hitTolerance: this.hitTolerance_
|
hitTolerance: this.hitTolerance_
|
||||||
});
|
});
|
||||||
let i;
|
for (let i = features.getLength() - 1; i >= 0; --i) {
|
||||||
for (i = features.getLength() - 1; i >= 0; --i) {
|
|
||||||
const feature = features.item(i);
|
const feature = features.item(i);
|
||||||
const index = selected.indexOf(feature);
|
const index = selected.indexOf(feature);
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
@@ -303,11 +302,11 @@ function handleEvent(mapBrowserEvent) {
|
|||||||
// Modify the currently selected feature(s).
|
// Modify the currently selected feature(s).
|
||||||
map.forEachFeatureAtPixel(mapBrowserEvent.pixel,
|
map.forEachFeatureAtPixel(mapBrowserEvent.pixel,
|
||||||
(
|
(
|
||||||
/**
|
/**
|
||||||
* @param {ol.Feature|ol.render.Feature} feature Feature.
|
* @param {ol.Feature|ol.render.Feature} feature Feature.
|
||||||
* @param {ol.layer.Layer} layer Layer.
|
* @param {ol.layer.Layer} layer Layer.
|
||||||
* @return {boolean|undefined} Continue to iterate over the features.
|
* @return {boolean|undefined} Continue to iterate over the features.
|
||||||
*/
|
*/
|
||||||
function(feature, layer) {
|
function(feature, layer) {
|
||||||
if (this.filter_(feature, layer)) {
|
if (this.filter_(feature, layer)) {
|
||||||
if ((add || toggle) && !includes(features.getArray(), feature)) {
|
if ((add || toggle) && !includes(features.getArray(), feature)) {
|
||||||
@@ -323,8 +322,7 @@ function handleEvent(mapBrowserEvent) {
|
|||||||
layerFilter: this.layerFilter_,
|
layerFilter: this.layerFilter_,
|
||||||
hitTolerance: this.hitTolerance_
|
hitTolerance: this.hitTolerance_
|
||||||
});
|
});
|
||||||
let j;
|
for (let j = deselected.length - 1; j >= 0; --j) {
|
||||||
for (j = deselected.length - 1; j >= 0; --j) {
|
|
||||||
features.remove(deselected[j]);
|
features.remove(deselected[j]);
|
||||||
}
|
}
|
||||||
features.extend(selected);
|
features.extend(selected);
|
||||||
|
|||||||
Reference in New Issue
Block a user