From 7f0043694de60ba26dd21a268abff29f390ceb07 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Mon, 14 May 2018 14:23:01 +0200 Subject: [PATCH 1/3] Remove NOCOMPILE from examples --- examples/color-manipulation.js | 1 - examples/d3.js | 1 - examples/device-orientation.js | 1 - examples/export-map.js | 2 -- examples/export-pdf.js | 1 - examples/flight-animation.js | 1 - examples/geojson-vt.js | 1 - examples/jsts.js | 2 -- examples/raster.js | 2 -- examples/region-growing.js | 1 - examples/sea-level.js | 1 - examples/shaded-relief.js | 1 - examples/topolis.js | 3 --- examples/turf.js | 2 -- 14 files changed, 20 deletions(-) diff --git a/examples/color-manipulation.js b/examples/color-manipulation.js index 22dae736fc..0097f9db16 100644 --- a/examples/color-manipulation.js +++ b/examples/color-manipulation.js @@ -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'; diff --git a/examples/d3.js b/examples/d3.js index 3776d11f2f..70a431d2b8 100644 --- a/examples/d3.js +++ b/examples/d3.js @@ -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'; diff --git a/examples/device-orientation.js b/examples/device-orientation.js index 3ffe639e8e..b5b1cb0549 100644 --- a/examples/device-orientation.js +++ b/examples/device-orientation.js @@ -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'; diff --git a/examples/export-map.js b/examples/export-map.js index 7fb05dad10..c39805e347 100644 --- a/examples/export-map.js +++ b/examples/export-map.js @@ -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'; diff --git a/examples/export-pdf.js b/examples/export-pdf.js index 3e9993ea35..32b58cc791 100644 --- a/examples/export-pdf.js +++ b/examples/export-pdf.js @@ -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'; diff --git a/examples/flight-animation.js b/examples/flight-animation.js index a3a5b15685..e05aaf53ec 100644 --- a/examples/flight-animation.js +++ b/examples/flight-animation.js @@ -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'; diff --git a/examples/geojson-vt.js b/examples/geojson-vt.js index 15409bad05..e36cfb7883 100644 --- a/examples/geojson-vt.js +++ b/examples/geojson-vt.js @@ -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'; diff --git a/examples/jsts.js b/examples/jsts.js index a0bbb8c29a..5375e71ccb 100644 --- a/examples/jsts.js +++ b/examples/jsts.js @@ -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'; diff --git a/examples/raster.js b/examples/raster.js index 81a4802c57..5f9314b734 100644 --- a/examples/raster.js +++ b/examples/raster.js @@ -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'; diff --git a/examples/region-growing.js b/examples/region-growing.js index dd249fb4a2..0503ff7127 100644 --- a/examples/region-growing.js +++ b/examples/region-growing.js @@ -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'; diff --git a/examples/sea-level.js b/examples/sea-level.js index 83642218e4..81b4b1edfe 100644 --- a/examples/sea-level.js +++ b/examples/sea-level.js @@ -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'; diff --git a/examples/shaded-relief.js b/examples/shaded-relief.js index 7e0d127884..e0b9db7040 100644 --- a/examples/shaded-relief.js +++ b/examples/shaded-relief.js @@ -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'; diff --git a/examples/topolis.js b/examples/topolis.js index 86777e2023..71102b20cf 100644 --- a/examples/topolis.js +++ b/examples/topolis.js @@ -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'; diff --git a/examples/turf.js b/examples/turf.js index 069544b426..a9e3fa6f35 100644 --- a/examples/turf.js +++ b/examples/turf.js @@ -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'; From 9f3b103bbf7aeb2ddc8479cb42911fbc0f36c2c0 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Mon, 14 May 2018 14:28:31 +0200 Subject: [PATCH 2/3] Better variables scoping --- src/ol/Collection.js | 9 +++------ src/ol/pointer/PointerEventHandler.js | 6 ++---- src/ol/pointer/TouchSource.js | 17 +++++++---------- src/ol/proj.js | 7 +++---- 4 files changed, 15 insertions(+), 24 deletions(-) diff --git a/src/ol/Collection.js b/src/ol/Collection.js index bca2a49ba8..8e8abff5a8 100644 --- a/src/ol/Collection.js +++ b/src/ol/Collection.js @@ -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); diff --git a/src/ol/pointer/PointerEventHandler.js b/src/ol/pointer/PointerEventHandler.js index bd3f004fc2..588d168e8e 100644 --- a/src/ol/pointer/PointerEventHandler.js +++ b/src/ol/pointer/PointerEventHandler.js @@ -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()); } }; diff --git a/src/ol/pointer/TouchSource.js b/src/ol/pointer/TouchSource.js index 24be859017..6aedb98c82 100644 --- a/src/ol/pointer/TouchSource.js +++ b/src/ol/pointer/TouchSource.js @@ -219,9 +219,8 @@ TouchSource.prototype.processTouches_ = function(inEvent, inFunction) { 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 +236,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,10 +265,9 @@ 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. @@ -279,7 +276,7 @@ TouchSource.prototype.vacuumTouches_ = function(inEvent) { d.push(value.out); } } - for (i = 0; i < d.length; ++i) { + for (let i = 0; i < d.length; ++i) { this.cancelOut_(inEvent, d[i]); } } diff --git a/src/ol/proj.js b/src/ol/proj.js index e2633575b0..42e2ea8f0a 100644 --- a/src/ol/proj.js +++ b/src/ol/proj.js @@ -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]; } } From 90ce02941a24559ef811ffee7efdd8a3abe7f25e Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Mon, 14 May 2018 14:42:08 +0200 Subject: [PATCH 3/3] Better code indentation --- src/ol/PluggableMap.js | 9 +++------ src/ol/TileQueue.js | 22 +++++++++------------- src/ol/View.js | 12 ++++-------- src/ol/pointer/MouseSource.js | 3 +-- src/ol/pointer/MsSource.js | 6 ++---- src/ol/pointer/TouchSource.js | 9 +++------ src/ol/style/AtlasManager.js | 6 ++---- 7 files changed, 24 insertions(+), 43 deletions(-) diff --git a/src/ol/PluggableMap.js b/src/ol/PluggableMap.js index a510c66f1d..bf7cbd6942 100644 --- a/src/ol/PluggableMap.js +++ b/src/ol/PluggableMap.js @@ -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.} diff --git a/src/ol/TileQueue.js b/src/ol/TileQueue.js index f6fd1b533f..5403e1e1a0 100644 --- a/src/ol/TileQueue.js +++ b/src/ol/TileQueue.js @@ -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]; diff --git a/src/ol/View.js b/src/ol/View.js index 5d3e73e98e..13a7dfeee2 100644 --- a/src/ol/View.js +++ b/src/ol/View.js @@ -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; }); }; diff --git a/src/ol/pointer/MouseSource.js b/src/ol/pointer/MouseSource.js index 924bba2efd..7703b473f8 100644 --- a/src/ol/pointer/MouseSource.js +++ b/src/ol/pointer/MouseSource.js @@ -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; } } diff --git a/src/ol/pointer/MsSource.js b/src/ol/pointer/MsSource.js index 2e1b7618c5..09f4a941d0 100644 --- a/src/ol/pointer/MsSource.js +++ b/src/ol/pointer/MsSource.js @@ -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; diff --git a/src/ol/pointer/TouchSource.js b/src/ol/pointer/TouchSource.js index 6aedb98c82..ae9919e654 100644 --- a/src/ol/pointer/TouchSource.js +++ b/src/ol/pointer/TouchSource.js @@ -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,8 +212,7 @@ 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(); @@ -271,8 +269,7 @@ TouchSource.prototype.vacuumTouches_ = function(inEvent) { // 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); } } diff --git a/src/ol/style/AtlasManager.js b/src/ol/style/AtlasManager.js index ff88dc11b1..09fe03b476 100644 --- a/src/ol/style/AtlasManager.js +++ b/src/ol/style/AtlasManager.js @@ -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) {