Remove use of goog.bind and use ES5 .bind

This commit is contained in:
Nicholas L
2016-01-08 23:41:24 +13:00
parent ace3ac4f1d
commit db3ad70a3d
27 changed files with 64 additions and 58 deletions

View File

@@ -11,7 +11,7 @@
<link rel="stylesheet" href="./resources/layout.css" type="text/css"> <link rel="stylesheet" href="./resources/layout.css" type="text/css">
{{{ extraHead.local }}} {{{ extraHead.local }}}
{{{ css.tag }}} {{{ css.tag }}}
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=fetch"></script> <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=fetch,Function.prototype.bind|gated"></script>
<script src="./resources/zeroclipboard/ZeroClipboard.min.js"></script> <script src="./resources/zeroclipboard/ZeroClipboard.min.js"></script>
<title>{{ title }}</title> <title>{{ title }}</title>
</head> </head>

View File

@@ -13,6 +13,7 @@ tags: "fullscreen, geolocation, orientation, mobile"
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" type="text/css"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" type="text/css">
<link rel="stylesheet" href="../css/ol.css" type="text/css"> <link rel="stylesheet" href="../css/ol.css" type="text/css">
<link rel="stylesheet" href="./resources/layout.css" type="text/css"> <link rel="stylesheet" href="./resources/layout.css" type="text/css">
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=Function.prototype.bind|gated"></script>
<title>Mobile Geolocation Tracking with Orientation</title> <title>Mobile Geolocation Tracking with Orientation</title>
<style type="text/css"> <style type="text/css">
html, body, .map { html, body, .map {

View File

@@ -13,6 +13,7 @@ cloak:
<meta http-equiv="X-UA-Compatible" content="chrome=1"> <meta http-equiv="X-UA-Compatible" content="chrome=1">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width"> <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<title>Mobile full screen example</title> <title>Mobile full screen example</title>
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=Function.prototype.bind|gated"></script>
<style type="text/css"> <style type="text/css">
html, body, .map { html, body, .map {
margin: 0; margin: 0;

View File

@@ -1763,8 +1763,8 @@ ol.format.KML.prototype.readDocumentOrFolder_ = function(node, objectStack) {
'Document': ol.xml.makeArrayExtender(this.readDocumentOrFolder_, this), 'Document': ol.xml.makeArrayExtender(this.readDocumentOrFolder_, this),
'Folder': ol.xml.makeArrayExtender(this.readDocumentOrFolder_, this), 'Folder': ol.xml.makeArrayExtender(this.readDocumentOrFolder_, this),
'Placemark': ol.xml.makeArrayPusher(this.readPlacemark_, this), 'Placemark': ol.xml.makeArrayPusher(this.readPlacemark_, this),
'Style': goog.bind(this.readSharedStyle_, this), 'Style': this.readSharedStyle_.bind(this),
'StyleMap': goog.bind(this.readSharedStyleMap_, this) 'StyleMap': this.readSharedStyleMap_.bind(this)
}); });
var features = ol.xml.pushParseAndPop(/** @type {Array.<ol.Feature>} */ ([]), var features = ol.xml.pushParseAndPop(/** @type {Array.<ol.Feature>} */ ([]),
parsersNS, node, objectStack, this); parsersNS, node, objectStack, this);

View File

@@ -135,8 +135,8 @@ ol.Geolocation.prototype.handleTrackingChanged_ = function() {
var tracking = this.getTracking(); var tracking = this.getTracking();
if (tracking && this.watchId_ === undefined) { if (tracking && this.watchId_ === undefined) {
this.watchId_ = goog.global.navigator.geolocation.watchPosition( this.watchId_ = goog.global.navigator.geolocation.watchPosition(
goog.bind(this.positionChange_, this), this.positionChange_.bind(this),
goog.bind(this.positionError_, this), this.positionError_.bind(this),
this.getTrackingOptions()); this.getTrackingOptions());
} else if (!tracking && this.watchId_ !== undefined) { } else if (!tracking && this.watchId_ !== undefined) {
goog.global.navigator.geolocation.clearWatch(this.watchId_); goog.global.navigator.geolocation.clearWatch(this.watchId_);

View File

@@ -80,7 +80,7 @@ ol.ImageCanvas.prototype.load = function() {
goog.asserts.assert(this.loader_, 'this.loader_ must be set'); goog.asserts.assert(this.loader_, 'this.loader_ must be set');
this.state = ol.ImageState.LOADING; this.state = ol.ImageState.LOADING;
this.changed(); this.changed();
this.loader_(goog.bind(this.handleLoad_, this)); this.loader_(this.handleLoad_.bind(this));
} }
}; };

View File

@@ -98,7 +98,7 @@ ol.interaction.MouseWheelZoom.handleEvent = function(mapBrowserEvent) {
goog.global.clearTimeout(this.timeoutId_); goog.global.clearTimeout(this.timeoutId_);
this.timeoutId_ = goog.global.setTimeout( this.timeoutId_ = goog.global.setTimeout(
goog.bind(this.doZoom_, this, map), timeLeft); this.doZoom_.bind(this, map), timeLeft);
mapBrowserEvent.preventDefault(); mapBrowserEvent.preventDefault();
stopEvent = true; stopEvent = true;

View File

@@ -120,7 +120,7 @@ ol.interaction.Snap = function(opt_options) {
* @type {function(ol.interaction.Snap.SegmentDataType, ol.interaction.Snap.SegmentDataType): number} * @type {function(ol.interaction.Snap.SegmentDataType, ol.interaction.Snap.SegmentDataType): number}
* @private * @private
*/ */
this.sortByDistance_ = goog.bind(ol.interaction.Snap.sortByDistance, this); this.sortByDistance_ = ol.interaction.Snap.sortByDistance.bind(this);
/** /**
@@ -170,7 +170,7 @@ ol.interaction.Snap.prototype.addFeature = function(feature, opt_listen) {
if (listen) { if (listen) {
this.geometryModifyListenerKeys_[feature_uid] = geometry.on( this.geometryModifyListenerKeys_[feature_uid] = geometry.on(
goog.events.EventType.CHANGE, goog.events.EventType.CHANGE,
goog.bind(this.handleGeometryModify_, this, feature), this.handleGeometryModify_.bind(this, feature),
this); this);
this.geometryChangeListenerKeys_[feature_uid] = feature.on( this.geometryChangeListenerKeys_[feature_uid] = feature.on(
ol.Object.getChangeEventType(feature.getGeometryName()), ol.Object.getChangeEventType(feature.getGeometryName()),

View File

@@ -102,7 +102,7 @@ ol.layer.Heatmap = function(opt_options) {
goog.asserts.assert(goog.isFunction(weightFunction), goog.asserts.assert(goog.isFunction(weightFunction),
'weightFunction should be a function'); 'weightFunction should be a function');
this.setStyle(goog.bind(function(feature, resolution) { this.setStyle(function(feature, resolution) {
goog.asserts.assert(this.styleCache_, 'this.styleCache_ expected'); goog.asserts.assert(this.styleCache_, 'this.styleCache_ expected');
goog.asserts.assert(this.circleImage_ !== undefined, goog.asserts.assert(this.circleImage_ !== undefined,
'this.circleImage_ should be defined'); 'this.circleImage_ should be defined');
@@ -123,7 +123,7 @@ ol.layer.Heatmap = function(opt_options) {
this.styleCache_[index] = style; this.styleCache_[index] = style;
} }
return style; return style;
}, this)); }.bind(this));
// For performance reasons, don't sort the features before rendering. // For performance reasons, don't sort the features before rendering.
// The render order is not relevant for a heatmap representation. // The render order is not relevant for a heatmap representation.

View File

@@ -392,8 +392,8 @@ ol.Map = function(options) {
* @type {ol.TileQueue} * @type {ol.TileQueue}
*/ */
this.tileQueue_ = new ol.TileQueue( this.tileQueue_ = new ol.TileQueue(
goog.bind(this.getTilePriority, this), this.getTilePriority.bind(this),
goog.bind(this.handleTileChange_, this)); this.handleTileChange_.bind(this));
/** /**
* Uids of features to skip at rendering time. * Uids of features to skip at rendering time.

View File

@@ -236,12 +236,12 @@ ol.MapBrowserEventHandler.prototype.emulateClick_ = function(pointerEvent) {
this.dispatchEvent(newEvent); this.dispatchEvent(newEvent);
} else { } else {
// click // click
this.clickTimeoutId_ = goog.global.setTimeout(goog.bind(function() { this.clickTimeoutId_ = goog.global.setTimeout(function() {
this.clickTimeoutId_ = 0; this.clickTimeoutId_ = 0;
var newEvent = new ol.MapBrowserPointerEvent( var newEvent = new ol.MapBrowserPointerEvent(
ol.MapBrowserEvent.EventType.SINGLECLICK, this.map_, pointerEvent); ol.MapBrowserEvent.EventType.SINGLECLICK, this.map_, pointerEvent);
this.dispatchEvent(newEvent); this.dispatchEvent(newEvent);
}, this), 250); }.bind(this), 250);
} }
}; };

View File

@@ -120,7 +120,7 @@ ol.pointer.PointerEventHandler.prototype.registerSource = function(name, source)
var handler = s.getHandlerForEvent(e); var handler = s.getHandlerForEvent(e);
if (handler) { if (handler) {
this.eventMap_[e] = goog.bind(handler, s); this.eventMap_[e] = handler.bind(s);
} }
}, this); }, this);
this.eventSourceList_.push(s); this.eventSourceList_.push(s);

View File

@@ -150,7 +150,7 @@ ol.pointer.TouchSource.prototype.removePrimaryPointer_ = function(inPointer) {
*/ */
ol.pointer.TouchSource.prototype.resetClickCount_ = function() { ol.pointer.TouchSource.prototype.resetClickCount_ = function() {
this.resetId_ = goog.global.setTimeout( this.resetId_ = goog.global.setTimeout(
goog.bind(this.resetClickCountHandler_, this), this.resetClickCountHandler_.bind(this),
ol.pointer.TouchSource.CLICK_COUNT_TIMEOUT); ol.pointer.TouchSource.CLICK_COUNT_TIMEOUT);
}; };

View File

@@ -368,7 +368,7 @@ ol.renderer.Map.prototype.scheduleRemoveUnusedLayerRenderers = function(frameSta
for (layerKey in this.layerRenderers_) { for (layerKey in this.layerRenderers_) {
if (!(layerKey in frameState.layerStates)) { if (!(layerKey in frameState.layerStates)) {
frameState.postRenderFunctions.push( frameState.postRenderFunctions.push(
goog.bind(this.removeUnusedLayerRenderers_, this)); this.removeUnusedLayerRenderers_.bind(this));
return; return;
} }
} }

View File

@@ -128,20 +128,19 @@ ol.renderer.webgl.Map = function(container, map) {
* @type {ol.structs.PriorityQueue.<Array>} * @type {ol.structs.PriorityQueue.<Array>}
*/ */
this.tileTextureQueue_ = new ol.structs.PriorityQueue( this.tileTextureQueue_ = new ol.structs.PriorityQueue(
goog.bind( /**
/** * @param {Array.<*>} element Element.
* @param {Array.<*>} element Element. * @return {number} Priority.
* @return {number} Priority. * @this {ol.renderer.webgl.Map}
* @this {ol.renderer.webgl.Map} */
*/ (function(element) {
function(element) { var tileCenter = /** @type {ol.Coordinate} */ (element[1]);
var tileCenter = /** @type {ol.Coordinate} */ (element[1]); var tileResolution = /** @type {number} */ (element[2]);
var tileResolution = /** @type {number} */ (element[2]); var deltaX = tileCenter[0] - this.focus_[0];
var deltaX = tileCenter[0] - this.focus_[0]; var deltaY = tileCenter[1] - this.focus_[1];
var deltaY = tileCenter[1] - this.focus_[1]; return 65536 * Math.log(tileResolution) +
return 65536 * Math.log(tileResolution) + Math.sqrt(deltaX * deltaX + deltaY * deltaY) / tileResolution;
Math.sqrt(deltaX * deltaX + deltaY * deltaY) / tileResolution; }).bind(this),
}, this),
/** /**
* @param {Array.<*>} element Element. * @param {Array.<*>} element Element.
* @return {string} Key. * @return {string} Key.
@@ -150,11 +149,14 @@ ol.renderer.webgl.Map = function(container, map) {
return /** @type {ol.Tile} */ (element[0]).getKey(); return /** @type {ol.Tile} */ (element[0]).getKey();
}); });
/**
* @private /**
* @type {ol.PostRenderFunction} * @param {ol.Map} map Map.
*/ * @param {?olx.FrameState} frameState Frame state.
this.loadNextTileTexture_ = goog.bind( * @return {boolean} false.
* @this {ol.renderer.webgl.Map}
*/
this.loadNextTileTexture_ =
function(map, frameState) { function(map, frameState) {
if (!this.tileTextureQueue_.isEmpty()) { if (!this.tileTextureQueue_.isEmpty()) {
this.tileTextureQueue_.reprioritize(); this.tileTextureQueue_.reprioritize();
@@ -165,7 +167,9 @@ ol.renderer.webgl.Map = function(container, map) {
this.bindTileTexture( this.bindTileTexture(
tile, tileSize, tileGutter, goog.webgl.LINEAR, goog.webgl.LINEAR); tile, tileSize, tileGutter, goog.webgl.LINEAR, goog.webgl.LINEAR);
} }
}, this); return false;
}.bind(this);
/** /**
* @private * @private
@@ -514,7 +518,7 @@ ol.renderer.webgl.Map.prototype.renderFrame = function(frameState) {
if (this.textureCache_.getCount() - this.textureCacheFrameMarkerCount_ > if (this.textureCache_.getCount() - this.textureCacheFrameMarkerCount_ >
ol.WEBGL_TEXTURE_CACHE_HIGH_WATER_MARK) { ol.WEBGL_TEXTURE_CACHE_HIGH_WATER_MARK) {
frameState.postRenderFunctions.push(goog.bind(this.expireCache_, this)); frameState.postRenderFunctions.push(this.expireCache_.bind(this));
} }
if (!this.tileTextureQueue_.isEmpty()) { if (!this.tileTextureQueue_.isEmpty()) {

View File

@@ -321,7 +321,7 @@ ol.reproj.Tile.prototype.load = function() {
}); });
if (leftToLoad === 0) { if (leftToLoad === 0) {
goog.global.setTimeout(goog.bind(this.reproject_, this), 0); goog.global.setTimeout(this.reproject_.bind(this), 0);
} }
} }
}; };

View File

@@ -55,7 +55,7 @@ ol.source.BingMaps = function(options) {
'include': 'ImageryProviders', 'include': 'ImageryProviders',
'uriScheme': 'https', 'uriScheme': 'https',
'key': options.key 'key': options.key
}, goog.bind(this.handleImageryMetadataResponse, this)); }, this.handleImageryMetadataResponse.bind(this));
}; };
goog.inherits(ol.source.BingMaps, ol.source.TileImage); goog.inherits(ol.source.BingMaps, ol.source.TileImage);

View File

@@ -130,10 +130,10 @@ ol.source.Image.prototype.getImage = function(extent, resolution, pixelRatio, pr
this.reprojectedImage_ = new ol.reproj.Image( this.reprojectedImage_ = new ol.reproj.Image(
sourceProjection, projection, extent, resolution, pixelRatio, sourceProjection, projection, extent, resolution, pixelRatio,
goog.bind(function(extent, resolution, pixelRatio) { function(extent, resolution, pixelRatio) {
return this.getImageInternal(extent, resolution, return this.getImageInternal(extent, resolution,
pixelRatio, sourceProjection); pixelRatio, sourceProjection);
}, this)); }.bind(this));
this.reprojectedRevision_ = this.getRevision(); this.reprojectedRevision_ = this.getRevision();
return this.reprojectedImage_; return this.reprojectedImage_;

View File

@@ -65,7 +65,7 @@ ol.source.ImageVector = function(options) {
goog.base(this, { goog.base(this, {
attributions: options.attributions, attributions: options.attributions,
canvasFunction: goog.bind(this.canvasFunctionInternal_, this), canvasFunction: this.canvasFunctionInternal_.bind(this),
logo: options.logo, logo: options.logo,
projection: options.projection, projection: options.projection,
ratio: options.ratio, ratio: options.ratio,

View File

@@ -80,7 +80,7 @@ ol.source.Raster = function(options) {
function() { function() {
return 1; return 1;
}, },
goog.bind(this.changed, this)); this.changed.bind(this));
var layerStatesArray = ol.source.Raster.getLayerStatesArray_(this.renderers_); var layerStatesArray = ol.source.Raster.getLayerStatesArray_(this.renderers_);
var layerStates = {}; var layerStates = {};

View File

@@ -42,7 +42,7 @@ ol.source.TileArcGISRest = function(opt_options) {
reprojectionErrorThreshold: options.reprojectionErrorThreshold, reprojectionErrorThreshold: options.reprojectionErrorThreshold,
tileGrid: options.tileGrid, tileGrid: options.tileGrid,
tileLoadFunction: options.tileLoadFunction, tileLoadFunction: options.tileLoadFunction,
tileUrlFunction: goog.bind(this.tileUrlFunction_, this), tileUrlFunction: this.tileUrlFunction_.bind(this),
url: options.url, url: options.url,
urls: options.urls, urls: options.urls,
wrapX: options.wrapX !== undefined ? options.wrapX : true wrapX: options.wrapX !== undefined ? options.wrapX : true

View File

@@ -229,9 +229,9 @@ ol.source.TileImage.prototype.getTile = function(z, x, y, pixelRatio, projection
sourceProjection, sourceTileGrid, sourceProjection, sourceTileGrid,
projection, targetTileGrid, projection, targetTileGrid,
tileCoord, wrappedTileCoord, this.getTilePixelRatio(pixelRatio), tileCoord, wrappedTileCoord, this.getTilePixelRatio(pixelRatio),
goog.bind(function(z, x, y, pixelRatio) { function(z, x, y, pixelRatio) {
return this.getTileInternal(z, x, y, pixelRatio, sourceProjection); return this.getTileInternal(z, x, y, pixelRatio, sourceProjection);
}, this), this.reprojectionErrorThreshold_, }.bind(this), this.reprojectionErrorThreshold_,
this.renderReprojectionEdges_); this.renderReprojectionEdges_);
cache.set(tileCoordKey, tile); cache.set(tileCoordKey, tile);

View File

@@ -45,8 +45,8 @@ ol.source.TileJSON = function(options) {
if (options.jsonp) { if (options.jsonp) {
var request = new goog.net.Jsonp(options.url); var request = new goog.net.Jsonp(options.url);
request.send(undefined, goog.bind(this.handleTileJSONResponse, this), request.send(undefined, this.handleTileJSONResponse.bind(this),
goog.bind(this.handleTileJSONError, this)); this.handleTileJSONError.bind(this));
} else { } else {
var xhr = new goog.net.XhrIo(new goog.net.CorsXmlHttpFactory()); var xhr = new goog.net.XhrIo(new goog.net.CorsXmlHttpFactory());
goog.events.listen(xhr, goog.net.EventType.COMPLETE, function(e) { goog.events.listen(xhr, goog.net.EventType.COMPLETE, function(e) {

View File

@@ -50,7 +50,7 @@ ol.source.TileUTFGrid = function(options) {
this.template_ = undefined; this.template_ = undefined;
var request = new goog.net.Jsonp(options.url); var request = new goog.net.Jsonp(options.url);
request.send(undefined, goog.bind(this.handleTileJSONResponse, this)); request.send(undefined, this.handleTileJSONResponse.bind(this));
}; };
goog.inherits(ol.source.TileUTFGrid, ol.source.Tile); goog.inherits(ol.source.TileUTFGrid, ol.source.Tile);
@@ -361,8 +361,8 @@ ol.source.TileUTFGridTile_.prototype.loadInternal_ = function() {
if (this.state == ol.TileState.IDLE) { if (this.state == ol.TileState.IDLE) {
this.state = ol.TileState.LOADING; this.state = ol.TileState.LOADING;
var request = new goog.net.Jsonp(this.src_); var request = new goog.net.Jsonp(this.src_);
request.send(undefined, goog.bind(this.handleLoad_, this), request.send(undefined, this.handleLoad_.bind(this),
goog.bind(this.handleError_, this)); this.handleError_.bind(this));
} }
}; };

View File

@@ -46,7 +46,7 @@ ol.source.TileWMS = function(opt_options) {
reprojectionErrorThreshold: options.reprojectionErrorThreshold, reprojectionErrorThreshold: options.reprojectionErrorThreshold,
tileGrid: options.tileGrid, tileGrid: options.tileGrid,
tileLoadFunction: options.tileLoadFunction, tileLoadFunction: options.tileLoadFunction,
tileUrlFunction: goog.bind(this.tileUrlFunction_, this), tileUrlFunction: this.tileUrlFunction_.bind(this),
url: options.url, url: options.url,
urls: options.urls, urls: options.urls,
wrapX: options.wrapX !== undefined ? options.wrapX : true wrapX: options.wrapX !== undefined ? options.wrapX : true

View File

@@ -291,12 +291,12 @@ ol.style.Circle.prototype.render_ = function(atlasManager) {
if (hasCustomHitDetectionImage) { if (hasCustomHitDetectionImage) {
// render the hit-detection image into a separate atlas image // render the hit-detection image into a separate atlas image
renderHitDetectionCallback = renderHitDetectionCallback =
goog.bind(this.drawHitDetectionCanvas_, this, renderOptions); this.drawHitDetectionCanvas_.bind(this, renderOptions);
} }
var id = this.getChecksum(); var id = this.getChecksum();
var info = atlasManager.add( var info = atlasManager.add(
id, size, size, goog.bind(this.draw_, this, renderOptions), id, size, size, this.draw_.bind(this, renderOptions),
renderHitDetectionCallback); renderHitDetectionCallback);
goog.asserts.assert(info, 'circle radius is too large'); goog.asserts.assert(info, 'circle radius is too large');

View File

@@ -371,12 +371,12 @@ ol.style.RegularShape.prototype.render_ = function(atlasManager) {
if (hasCustomHitDetectionImage) { if (hasCustomHitDetectionImage) {
// render the hit-detection image into a separate atlas image // render the hit-detection image into a separate atlas image
renderHitDetectionCallback = renderHitDetectionCallback =
goog.bind(this.drawHitDetectionCanvas_, this, renderOptions); this.drawHitDetectionCanvas_.bind(this, renderOptions);
} }
var id = this.getChecksum(); var id = this.getChecksum();
var info = atlasManager.add( var info = atlasManager.add(
id, size, size, goog.bind(this.draw_, this, renderOptions), id, size, size, this.draw_.bind(this, renderOptions),
renderHitDetectionCallback); renderHitDetectionCallback);
goog.asserts.assert(info, 'shape size is too large'); goog.asserts.assert(info, 'shape size is too large');