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