Merge pull request #8194 from fredj/cleanup

miscellaneous code cleanup
This commit is contained in:
Frédéric Junod
2018-05-16 08:31:27 +02:00
committed by GitHub
24 changed files with 39 additions and 87 deletions

View File

@@ -1,4 +1,3 @@
// NOCOMPILE
import Map from '../src/ol/Map.js';
import View from '../src/ol/View.js';
import ImageLayer from '../src/ol/layer/Image.js';

1
examples/d3.js vendored
View File

@@ -1,4 +1,3 @@
// NOCOMPILE
import Map from '../src/ol/Map.js';
import View from '../src/ol/View.js';
import {getWidth, getCenter} from '../src/ol/extent.js';

View File

@@ -1,4 +1,3 @@
// NOCOMPILE
import Map from '../src/ol/Map.js';
import View from '../src/ol/View.js';
import {defaults as defaultControls} from '../src/ol/control.js';

View File

@@ -1,5 +1,3 @@
// NOCOMPILE
// this example uses FileSaver.js for which we don't have an externs file.
import Map from '../src/ol/Map.js';
import View from '../src/ol/View.js';
import {defaults as defaultControls} from '../src/ol/control.js';

View File

@@ -1,4 +1,3 @@
// NOCOMPILE
import Map from '../src/ol/Map.js';
import View from '../src/ol/View.js';
import {defaults as defaultControls} from '../src/ol/control.js';

View File

@@ -1,4 +1,3 @@
// NOCOMPILE
import Feature from '../src/ol/Feature.js';
import Map from '../src/ol/Map.js';
import View from '../src/ol/View.js';

View File

@@ -1,4 +1,3 @@
// NOCOMPILE
import Map from '../src/ol/Map.js';
import View from '../src/ol/View.js';
import GeoJSON from '../src/ol/format/GeoJSON.js';

View File

@@ -1,5 +1,3 @@
// NOCOMPILE
// this example uses JSTS for which we don't have an externs file.
import Map from '../src/ol/Map.js';
import View from '../src/ol/View.js';
import GeoJSON from '../src/ol/format/GeoJSON.js';

View File

@@ -1,5 +1,3 @@
// NOCOMPILE
// this example uses d3 for which we don't have an externs file.
import Map from '../src/ol/Map.js';
import View from '../src/ol/View.js';
import {Image as ImageLayer, Tile as TileLayer} from '../src/ol/layer.js';

View File

@@ -1,4 +1,3 @@
// NOCOMPILE
import Map from '../src/ol/Map.js';
import View from '../src/ol/View.js';
import {Image as ImageLayer, Tile as TileLayer} from '../src/ol/layer.js';

View File

@@ -1,4 +1,3 @@
// NOCOMPILE
import Map from '../src/ol/Map.js';
import View from '../src/ol/View.js';
import {Image as ImageLayer, Tile as TileLayer} from '../src/ol/layer.js';

View File

@@ -1,4 +1,3 @@
// NOCOMPILE
import Map from '../src/ol/Map.js';
import View from '../src/ol/View.js';
import {Image as ImageLayer, Tile as TileLayer} from '../src/ol/layer.js';

View File

@@ -1,6 +1,3 @@
// NOCOMPILE
// this example uses topolis and toastr for which we don't have an externs file.
import Feature from '../src/ol/Feature.js';
import Map from '../src/ol/Map.js';
import View from '../src/ol/View.js';

View File

@@ -1,5 +1,3 @@
// NOCOMPILE
// this example uses turf.js for which we don't have an externs file.
import Map from '../src/ol/Map.js';
import View from '../src/ol/View.js';
import GeoJSON from '../src/ol/format/GeoJSON.js';

View File

@@ -115,8 +115,7 @@ Collection.prototype.clear = function() {
* @api
*/
Collection.prototype.extend = function(arr) {
let i, ii;
for (i = 0, ii = arr.length; i < ii; ++i) {
for (let i = 0, ii = arr.length; i < ii; ++i) {
this.push(arr[i]);
}
return this;
@@ -225,8 +224,7 @@ Collection.prototype.push = function(elem) {
*/
Collection.prototype.remove = function(elem) {
const arr = this.array_;
let i, ii;
for (i = 0, ii = arr.length; i < ii; ++i) {
for (let i = 0, ii = arr.length; i < ii; ++i) {
if (arr[i] === elem) {
return this.removeAt(i);
}
@@ -270,8 +268,7 @@ Collection.prototype.setAt = function(index, elem) {
this.dispatchEvent(
new CollectionEvent(CollectionEventType.ADD, elem));
} else {
let j;
for (j = n; j < index; ++j) {
for (let j = n; j < index; ++j) {
this.insertAt(j, undefined);
}
this.insertAt(index, elem);

View File

@@ -303,12 +303,9 @@ const PluggableMap = function(options) {
*/
this.keyHandlerKeys_ = null;
listen(this.viewport_, EventType.CONTEXTMENU,
this.handleBrowserEvent, this);
listen(this.viewport_, EventType.WHEEL,
this.handleBrowserEvent, this);
listen(this.viewport_, EventType.MOUSEWHEEL,
this.handleBrowserEvent, this);
listen(this.viewport_, EventType.CONTEXTMENU, this.handleBrowserEvent, this);
listen(this.viewport_, EventType.WHEEL, this.handleBrowserEvent, this);
listen(this.viewport_, EventType.MOUSEWHEEL, this.handleBrowserEvent, this);
/**
* @type {module:ol/Collection.<module:ol/control/Control>}

View File

@@ -27,20 +27,18 @@ const TileQueue = function(tilePriorityFunction, tileChangeCallback) {
PriorityQueue.call(
this,
/**
* @param {Array} element Element.
* @return {number} Priority.
*/
* @param {Array} element Element.
* @return {number} Priority.
*/
function(element) {
return tilePriorityFunction.apply(null, element);
},
/**
* @param {Array} element Element.
* @return {string} Key.
*/
* @param {Array} element Element.
* @return {string} Key.
*/
function(element) {
return (
/** @type {module:ol/Tile} */ (element[0]).getKey()
);
return (/** @type {module:ol/Tile} */ (element[0]).getKey());
});
/**
@@ -73,8 +71,7 @@ TileQueue.prototype.enqueue = function(element) {
const added = PriorityQueue.prototype.enqueue.call(this, element);
if (added) {
const tile = element[0];
listen(tile, EventType.CHANGE,
this.handleTileChange, this);
listen(tile, EventType.CHANGE, this.handleTileChange, this);
}
return added;
};
@@ -97,8 +94,7 @@ TileQueue.prototype.handleTileChange = function(event) {
const state = tile.getState();
if (state === TileState.LOADED || state === TileState.ERROR ||
state === TileState.EMPTY || state === TileState.ABORT) {
unlisten(tile, EventType.CHANGE,
this.handleTileChange, this);
unlisten(tile, EventType.CHANGE, this.handleTileChange, this);
const tileKey = tile.getKey();
if (tileKey in this.tilesLoadingKeys_) {
delete this.tilesLoadingKeys_[tileKey];

View File

@@ -280,8 +280,7 @@ View.prototype.applyOptions_ = function(options) {
properties[ViewProperty.CENTER] = options.center !== undefined ?
options.center : null;
const resolutionConstraintInfo = createResolutionConstraint(
options);
const resolutionConstraintInfo = createResolutionConstraint(options);
/**
* @private
@@ -638,10 +637,8 @@ View.prototype.calculateCenterZoom = function(resolution, anchor) {
const currentCenter = this.getCenter();
const currentResolution = this.getResolution();
if (currentCenter !== undefined && currentResolution !== undefined) {
const x = anchor[0] -
resolution * (anchor[0] - currentCenter[0]) / currentResolution;
const y = anchor[1] -
resolution * (anchor[1] - currentCenter[1]) / currentResolution;
const x = anchor[0] - resolution * (anchor[0] - currentCenter[0]) / currentResolution;
const y = anchor[1] - resolution * (anchor[1] - currentCenter[1]) / currentResolution;
center = [x, y];
}
return center;
@@ -922,8 +919,7 @@ View.prototype.getValueForResolutionFunction = function(opt_power) {
* @return {number} Value.
*/
function(resolution) {
const value =
(Math.log(maxResolution / resolution) / Math.log(power)) / max;
const value = (Math.log(maxResolution / resolution) / Math.log(power)) / max;
return value;
});
};

View File

@@ -117,8 +117,7 @@ MouseSource.prototype.isEventSimulatedFromTouch_ = function(inEvent) {
// simulated mouse events will be swallowed near a primary touchend
const dx = Math.abs(x - t[0]);
const dy = Math.abs(y - t[1]);
if (dx <= DEDUP_DIST &&
dy <= DEDUP_DIST) {
if (dx <= DEDUP_DIST && dy <= DEDUP_DIST) {
return true;
}
}

View File

@@ -177,8 +177,7 @@ MsSource.prototype.msPointerCancel = function(inEvent) {
* @param {MSPointerEvent} inEvent The in event.
*/
MsSource.prototype.msLostPointerCapture = function(inEvent) {
const e = this.dispatcher.makeEvent('lostpointercapture',
inEvent, inEvent);
const e = this.dispatcher.makeEvent('lostpointercapture', inEvent, inEvent);
this.dispatcher.dispatchEvent(e);
};
@@ -189,8 +188,7 @@ MsSource.prototype.msLostPointerCapture = function(inEvent) {
* @param {MSPointerEvent} inEvent The in event.
*/
MsSource.prototype.msGotPointerCapture = function(inEvent) {
const e = this.dispatcher.makeEvent('gotpointercapture',
inEvent, inEvent);
const e = this.dispatcher.makeEvent('gotpointercapture', inEvent, inEvent);
this.dispatcher.dispatchEvent(e);
};
export default MsSource;

View File

@@ -172,9 +172,8 @@ PointerEventHandler.prototype.registerSource = function(name, source) {
*/
PointerEventHandler.prototype.register_ = function() {
const l = this.eventSourceList_.length;
let eventSource;
for (let i = 0; i < l; i++) {
eventSource = this.eventSourceList_[i];
const eventSource = this.eventSourceList_[i];
this.addEvents_(eventSource.getEvents());
}
};
@@ -186,9 +185,8 @@ PointerEventHandler.prototype.register_ = function() {
*/
PointerEventHandler.prototype.unregister_ = function() {
const l = this.eventSourceList_.length;
let eventSource;
for (let i = 0; i < l; i++) {
eventSource = this.eventSourceList_[i];
const eventSource = this.eventSourceList_[i];
this.removeEvents_(eventSource.getEvents());
}
};

View File

@@ -122,8 +122,7 @@ TouchSource.prototype.isPrimaryTouch_ = function(inTouch) {
*/
TouchSource.prototype.setPrimaryTouch_ = function(inTouch) {
const count = Object.keys(this.pointerMap).length;
if (count === 0 || (count === 1 &&
POINTER_ID.toString() in this.pointerMap)) {
if (count === 0 || (count === 1 && POINTER_ID.toString() in this.pointerMap)) {
this.firstTouchId_ = inTouch.identifier;
this.cancelResetClickCount_();
}
@@ -213,15 +212,13 @@ TouchSource.prototype.touchToPointer_ = function(browserEvent, inTouch) {
* @param {function(Event, Object)} inFunction In function.
*/
TouchSource.prototype.processTouches_ = function(inEvent, inFunction) {
const touches = Array.prototype.slice.call(
inEvent.changedTouches);
const touches = Array.prototype.slice.call(inEvent.changedTouches);
const count = touches.length;
function preventDefault() {
inEvent.preventDefault();
}
let i, pointer;
for (i = 0; i < count; ++i) {
pointer = this.touchToPointer_(inEvent, touches[i]);
for (let i = 0; i < count; ++i) {
const pointer = this.touchToPointer_(inEvent, touches[i]);
// forward touch preventDefaults
pointer.preventDefault = preventDefault;
inFunction.call(this, inEvent, pointer);
@@ -237,9 +234,8 @@ TouchSource.prototype.processTouches_ = function(inEvent, inFunction) {
*/
TouchSource.prototype.findTouch_ = function(touchList, searchId) {
const l = touchList.length;
let touch;
for (let i = 0; i < l; i++) {
touch = touchList[i];
const touch = touchList[i];
if (touch.identifier === searchId) {
return true;
}
@@ -267,19 +263,17 @@ TouchSource.prototype.vacuumTouches_ = function(inEvent) {
const count = keys.length;
if (count >= touchList.length) {
const d = [];
let i, key, value;
for (i = 0; i < count; ++i) {
key = keys[i];
value = this.pointerMap[key];
for (let i = 0; i < count; ++i) {
const key = keys[i];
const value = this.pointerMap[key];
// Never remove pointerId == 1, which is mouse.
// Touch identifiers are 2 smaller than their pointerId, which is the
// index in pointermap.
if (key != POINTER_ID &&
!this.findTouch_(touchList, key - 2)) {
if (key != POINTER_ID && !this.findTouch_(touchList, key - 2)) {
d.push(value.out);
}
}
for (i = 0; i < d.length; ++i) {
for (let i = 0; i < d.length; ++i) {
this.cancelOut_(inEvent, d[i]);
}
}

View File

@@ -317,12 +317,11 @@ export function createTransformFromCoordinateTransform(coordTransform) {
const length = input.length;
const dimension = opt_dimension !== undefined ? opt_dimension : 2;
const output = opt_output !== undefined ? opt_output : new Array(length);
let point, i, j;
for (i = 0; i < length; i += dimension) {
point = coordTransform([input[i], input[i + 1]]);
for (let i = 0; i < length; i += dimension) {
const point = coordTransform([input[i], input[i + 1]]);
output[i] = point[0];
output[i + 1] = point[1];
for (j = dimension - 1; j >= 2; --j) {
for (let j = dimension - 1; j >= 2; --j) {
output[i + j] = input[i + j];
}
}

View File

@@ -195,8 +195,7 @@ AtlasManager.prototype.add = function(id, width, height,
}
/** @type {?module:ol/style/Atlas~AtlasInfo} */
const info = this.add_(false,
id, width, height, renderCallback, opt_this);
const info = this.add_(false, id, width, height, renderCallback, opt_this);
if (!info) {
return null;
}
@@ -227,8 +226,7 @@ AtlasManager.prototype.add = function(id, width, height,
* @return {?module:ol/style/Atlas~AtlasInfo} The position and atlas image for the entry,
* or `null` if the image is too big.
*/
AtlasManager.prototype.add_ = function(isHitAtlas, id, width, height,
renderCallback, opt_this) {
AtlasManager.prototype.add_ = function(isHitAtlas, id, width, height, renderCallback, opt_this) {
const atlases = (isHitAtlas) ? this.hitAtlases_ : this.atlases_;
let atlas, info, i, ii;
for (i = 0, ii = atlases.length; i < ii; ++i) {