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 Map from '../src/ol/Map.js';
import View from '../src/ol/View.js'; import View from '../src/ol/View.js';
import ImageLayer from '../src/ol/layer/Image.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 Map from '../src/ol/Map.js';
import View from '../src/ol/View.js'; import View from '../src/ol/View.js';
import {getWidth, getCenter} from '../src/ol/extent.js'; import {getWidth, getCenter} from '../src/ol/extent.js';

View File

@@ -1,4 +1,3 @@
// NOCOMPILE
import Map from '../src/ol/Map.js'; import Map from '../src/ol/Map.js';
import View from '../src/ol/View.js'; import View from '../src/ol/View.js';
import {defaults as defaultControls} from '../src/ol/control.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 Map from '../src/ol/Map.js';
import View from '../src/ol/View.js'; import View from '../src/ol/View.js';
import {defaults as defaultControls} from '../src/ol/control.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 Map from '../src/ol/Map.js';
import View from '../src/ol/View.js'; import View from '../src/ol/View.js';
import {defaults as defaultControls} from '../src/ol/control.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 Feature from '../src/ol/Feature.js';
import Map from '../src/ol/Map.js'; import Map from '../src/ol/Map.js';
import View from '../src/ol/View.js'; import View from '../src/ol/View.js';

View File

@@ -1,4 +1,3 @@
// NOCOMPILE
import Map from '../src/ol/Map.js'; import Map from '../src/ol/Map.js';
import View from '../src/ol/View.js'; import View from '../src/ol/View.js';
import GeoJSON from '../src/ol/format/GeoJSON.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 Map from '../src/ol/Map.js';
import View from '../src/ol/View.js'; import View from '../src/ol/View.js';
import GeoJSON from '../src/ol/format/GeoJSON.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 Map from '../src/ol/Map.js';
import View from '../src/ol/View.js'; import View from '../src/ol/View.js';
import {Image as ImageLayer, Tile as TileLayer} from '../src/ol/layer.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 Map from '../src/ol/Map.js';
import View from '../src/ol/View.js'; import View from '../src/ol/View.js';
import {Image as ImageLayer, Tile as TileLayer} from '../src/ol/layer.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 Map from '../src/ol/Map.js';
import View from '../src/ol/View.js'; import View from '../src/ol/View.js';
import {Image as ImageLayer, Tile as TileLayer} from '../src/ol/layer.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 Map from '../src/ol/Map.js';
import View from '../src/ol/View.js'; import View from '../src/ol/View.js';
import {Image as ImageLayer, Tile as TileLayer} from '../src/ol/layer.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 Feature from '../src/ol/Feature.js';
import Map from '../src/ol/Map.js'; import Map from '../src/ol/Map.js';
import View from '../src/ol/View.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 Map from '../src/ol/Map.js';
import View from '../src/ol/View.js'; import View from '../src/ol/View.js';
import GeoJSON from '../src/ol/format/GeoJSON.js'; import GeoJSON from '../src/ol/format/GeoJSON.js';

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -317,12 +317,11 @@ export function createTransformFromCoordinateTransform(coordTransform) {
const length = input.length; const length = input.length;
const dimension = opt_dimension !== undefined ? opt_dimension : 2; const dimension = opt_dimension !== undefined ? opt_dimension : 2;
const output = opt_output !== undefined ? opt_output : new Array(length); const output = opt_output !== undefined ? opt_output : new Array(length);
let point, i, j; for (let i = 0; i < length; i += dimension) {
for (i = 0; i < length; i += dimension) { const point = coordTransform([input[i], input[i + 1]]);
point = coordTransform([input[i], input[i + 1]]);
output[i] = point[0]; output[i] = point[0];
output[i + 1] = point[1]; 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]; 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} */ /** @type {?module:ol/style/Atlas~AtlasInfo} */
const info = this.add_(false, const info = this.add_(false, id, width, height, renderCallback, opt_this);
id, width, height, renderCallback, opt_this);
if (!info) { if (!info) {
return null; 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, * @return {?module:ol/style/Atlas~AtlasInfo} The position and atlas image for the entry,
* or `null` if the image is too big. * or `null` if the image is too big.
*/ */
AtlasManager.prototype.add_ = function(isHitAtlas, id, width, height, AtlasManager.prototype.add_ = function(isHitAtlas, id, width, height, renderCallback, opt_this) {
renderCallback, opt_this) {
const atlases = (isHitAtlas) ? this.hitAtlases_ : this.atlases_; const atlases = (isHitAtlas) ? this.hitAtlases_ : this.atlases_;
let atlas, info, i, ii; let atlas, info, i, ii;
for (i = 0, ii = atlases.length; i < ii; ++i) { for (i = 0, ii = atlases.length; i < ii; ++i) {