Remove goog.net.* and goog.async.AnimationDelay

This commit is contained in:
Andreas Hocevar
2016-01-27 23:15:17 +01:00
parent 2b451e7893
commit f35d0106b8
10 changed files with 123 additions and 113 deletions

View File

@@ -181,7 +181,7 @@ build/timestamps/check-%-timestamp: $(BUILD_HOSTED)/examples/%.html \
$(BUILD_HOSTED)/build/ol.js \ $(BUILD_HOSTED)/build/ol.js \
$(BUILD_HOSTED)/css/ol.css $(BUILD_HOSTED)/css/ol.css
@mkdir -p $(@D) @mkdir -p $(@D)
./node_modules/.bin/phantomjs --ssl-protocol=any --ignore-ssl-errors=true bin/check-example.js $< ./node_modules/.bin/phantomjs --local-to-remote-url-access=true --ssl-protocol=any --ignore-ssl-errors=true bin/check-example.js $<
@touch $@ @touch $@
build/timestamps/check-requires-timestamp: $(SRC_JS) $(EXAMPLES_JS) \ build/timestamps/check-requires-timestamp: $(SRC_JS) $(EXAMPLES_JS) \

View File

@@ -86,7 +86,7 @@ ol.events.condition.click = function(mapBrowserEvent) {
ol.events.condition.mouseActionButton = function(mapBrowserEvent) { ol.events.condition.mouseActionButton = function(mapBrowserEvent) {
var browserEvent = mapBrowserEvent.originalEvent; var browserEvent = mapBrowserEvent.originalEvent;
return browserEvent.button == 0 && return browserEvent.button == 0 &&
!(goog.userAgent.WEBKIT && goog.userAgent.MAC && browserEvent.ctrlKey); !(goog.userAgent.WEBKIT && ol.has.MAC && browserEvent.ctrlKey);
}; };
@@ -168,7 +168,7 @@ ol.events.condition.platformModifierKeyOnly = function(mapBrowserEvent) {
var browserEvent = mapBrowserEvent.originalEvent; var browserEvent = mapBrowserEvent.originalEvent;
return ( return (
!browserEvent.altKey && !browserEvent.altKey &&
(goog.userAgent.MAC ? browserEvent.metaKey : browserEvent.ctrlKey) && (ol.has.MAC ? browserEvent.metaKey : browserEvent.ctrlKey) &&
!browserEvent.shiftKey); !browserEvent.shiftKey);
}; };

View File

@@ -3,10 +3,6 @@ goog.provide('ol.FeatureUrlFunction');
goog.provide('ol.featureloader'); goog.provide('ol.featureloader');
goog.require('goog.asserts'); goog.require('goog.asserts');
goog.require('ol.events');
goog.require('goog.net.EventType');
goog.require('goog.net.XhrIo');
goog.require('goog.net.XhrIo.ResponseType');
goog.require('ol.TileState'); goog.require('ol.TileState');
goog.require('ol.VectorTile'); goog.require('ol.VectorTile');
goog.require('ol.format.FormatType'); goog.require('ol.format.FormatType');
@@ -67,59 +63,46 @@ ol.featureloader.loadFeaturesXhr = function(url, format, success, failure) {
* @this {ol.source.Vector|ol.VectorTile} * @this {ol.source.Vector|ol.VectorTile}
*/ */
function(extent, resolution, projection) { function(extent, resolution, projection) {
var xhrIo = new goog.net.XhrIo(); var xhr = new XMLHttpRequest();
xhrIo.setResponseType( xhr.open('GET',
format.getType() == ol.format.FormatType.ARRAY_BUFFER ? goog.isFunction(url) ? url(extent, resolution, projection) : url);
goog.net.XhrIo.ResponseType.ARRAY_BUFFER : if (format.getType() == ol.format.FormatType.ARRAY_BUFFER) {
goog.net.XhrIo.ResponseType.TEXT); xhr.responseType = 'arraybuffer';
ol.events.listen(xhrIo, goog.net.EventType.COMPLETE,
/**
* @param {Event} event Event.
* @private
* @this {ol.source.Vector}
*/
function(event) {
var xhrIo = event.target;
goog.asserts.assertInstanceof(xhrIo, goog.net.XhrIo,
'event.target/xhrIo is an instance of goog.net.XhrIo');
if (xhrIo.isSuccess()) {
var type = format.getType();
/** @type {Document|Node|Object|string|undefined} */
var source;
if (type == ol.format.FormatType.JSON) {
source = xhrIo.getResponseText();
} else if (type == ol.format.FormatType.TEXT) {
source = xhrIo.getResponseText();
} else if (type == ol.format.FormatType.XML) {
if (!goog.userAgent.IE) {
source = xhrIo.getResponseXml();
}
if (!source) {
source = ol.xml.parse(xhrIo.getResponseText());
}
} else if (type == ol.format.FormatType.ARRAY_BUFFER) {
source = xhrIo.getResponse();
} else {
goog.asserts.fail('unexpected format type');
}
if (source) {
success.call(this, format.readFeatures(source,
{featureProjection: projection}),
format.readProjection(source));
} else {
goog.asserts.fail('undefined or null source');
}
} else {
failure.call(this);
}
goog.dispose(xhrIo);
}, false, this);
if (goog.isFunction(url)) {
xhrIo.send(url(extent, resolution, projection));
} else {
xhrIo.send(url);
} }
/**
* @param {Event} event Event.
* @private
*/
xhr.onload = function(event) {
if (xhr.status < 400) {
var type = format.getType();
/** @type {Document|Node|Object|string|undefined} */
var source;
if (type == ol.format.FormatType.JSON ||
type == ol.format.FormatType.TEXT) {
source = /** @type {string} */ (xhr.responseText);
} else if (type == ol.format.FormatType.XML) {
source = xhr.responseXML;
if (!source) {
source = ol.xml.parse(xhr.responseText);
}
} else if (type == ol.format.FormatType.ARRAY_BUFFER) {
source = /** @type {ArrayBuffer} */ (xhr.response);
} else {
goog.asserts.fail('unexpected format type');
}
if (source) {
success.call(this, format.readFeatures(source,
{featureProjection: projection}),
format.readProjection(source));
} else {
goog.asserts.fail('undefined or null source');
}
} else {
failure.call(this);
}
}.bind(this);
xhr.send();
}); });
}; };

View File

@@ -20,6 +20,12 @@ ol.has.FIREFOX = ua.indexOf('firefox') !== -1;
*/ */
ol.has.SAFARI = ua.indexOf('safari') !== -1 && ua.indexOf('chrom') === -1; ol.has.SAFARI = ua.indexOf('safari') !== -1 && ua.indexOf('chrom') === -1;
/**
* User agent string says we are dealing with a Mac as platform.
* @type {boolean}
*/
ol.has.MAC = ua.indexOf('Macintosh') !== -1;
/** /**
* The ratio between physical pixels and device-independent pixels * The ratio between physical pixels and device-independent pixels

View File

@@ -6,7 +6,6 @@ goog.provide('ol.Map');
goog.provide('ol.MapProperty'); goog.provide('ol.MapProperty');
goog.require('goog.asserts'); goog.require('goog.asserts');
goog.require('goog.async.AnimationDelay');
goog.require('goog.async.nextTick'); goog.require('goog.async.nextTick');
goog.require('goog.debug.Console'); goog.require('goog.debug.Console');
goog.require('goog.dom'); goog.require('goog.dom');
@@ -199,11 +198,17 @@ ol.Map = function(options) {
/** /**
* @private * @private
* @type {goog.async.AnimationDelay} * @type {number|undefined}
*/ */
this.animationDelay_ = this.animationDelayKey_;
new goog.async.AnimationDelay(this.renderFrame_, undefined, this);
this.registerDisposable(this.animationDelay_); /**
* @private
*/
this.animationDelay_ = function() {
this.animationDelayKey_ = undefined;
this.renderFrame_.call(this, Date.now());
}.bind(this);
/** /**
* @private * @private
@@ -1200,7 +1205,10 @@ ol.Map.prototype.isRendered = function() {
* @api stable * @api stable
*/ */
ol.Map.prototype.renderSync = function() { ol.Map.prototype.renderSync = function() {
this.animationDelay_.fire(); if (this.animationDelayKey_) {
goog.global.cancelAnimationFrame(this.animationDelayKey_);
}
this.animationDelay_();
}; };
@@ -1209,8 +1217,9 @@ ol.Map.prototype.renderSync = function() {
* @api stable * @api stable
*/ */
ol.Map.prototype.render = function() { ol.Map.prototype.render = function() {
if (!this.animationDelay_.isActive()) { if (this.animationDelayKey_ === undefined) {
this.animationDelay_.start(); this.animationDelayKey_ = goog.global.requestAnimationFrame(
this.animationDelay_);
} }
}; };

29
src/ol/net.js Normal file
View File

@@ -0,0 +1,29 @@
goog.provide('ol.net.Jsonp');
/**
* @param {string} url Request url. A 'callback' query parameter will be
* appended.
* @param {Function} callback Callback on success.
* @param {function()=} opt_errback Callback on error.
* @param {string=} opt_callbackParam Callback parameter. Default is 'callback'.
*/
ol.net.Jsonp = function(url, callback, opt_errback, opt_callbackParam) {
var script = goog.global.document.createElement('script');
script.async = true;
var key = 'ol_callback_' + goog.getUid(callback);
script.src = url + (url.indexOf('?') == -1 ? '?' : '&') +
(opt_callbackParam || 'callback') + '=' + key;
var timer = goog.global.setTimeout(function() {
delete goog.global[key];
if (opt_errback) {
opt_errback();
}
}, 10000);
goog.global[key] = function(data) {
goog.global.clearTimeout(timer);
delete goog.global[key];
callback(data);
};
goog.global.document.getElementsByTagName('head')[0].appendChild(script);
};

View File

@@ -1,12 +1,11 @@
goog.provide('ol.source.BingMaps'); goog.provide('ol.source.BingMaps');
goog.require('goog.Uri');
goog.require('goog.asserts'); goog.require('goog.asserts');
goog.require('goog.net.Jsonp');
goog.require('ol.Attribution'); goog.require('ol.Attribution');
goog.require('ol.TileRange'); goog.require('ol.TileRange');
goog.require('ol.TileUrlFunction'); goog.require('ol.TileUrlFunction');
goog.require('ol.extent'); goog.require('ol.extent');
goog.require('ol.net.Jsonp');
goog.require('ol.proj'); goog.require('ol.proj');
goog.require('ol.source.State'); goog.require('ol.source.State');
goog.require('ol.source.TileImage'); goog.require('ol.source.TileImage');
@@ -46,16 +45,12 @@ ol.source.BingMaps = function(options) {
*/ */
this.maxZoom_ = options.maxZoom !== undefined ? options.maxZoom : -1; this.maxZoom_ = options.maxZoom !== undefined ? options.maxZoom : -1;
var uri = new goog.Uri( var url = 'https://dev.virtualearth.net/REST/v1/Imagery/Metadata/' +
'https://dev.virtualearth.net/REST/v1/Imagery/Metadata/' + options.imagerySet +
options.imagerySet); '?uriScheme=https&include=ImageryProviders&key=' + options.key;
var jsonp = new goog.net.Jsonp(uri, 'jsonp'); ol.net.Jsonp(url, this.handleImageryMetadataResponse.bind(this), undefined,
jsonp.send({ 'jsonp');
'include': 'ImageryProviders',
'uriScheme': 'https',
'key': options.key
}, this.handleImageryMetadataResponse.bind(this));
}; };
goog.inherits(ol.source.BingMaps, ol.source.TileImage); goog.inherits(ol.source.BingMaps, ol.source.TileImage);

View File

@@ -8,15 +8,11 @@ goog.provide('ol.source.TileJSON');
goog.provide('ol.tilejson'); goog.provide('ol.tilejson');
goog.require('goog.asserts'); goog.require('goog.asserts');
goog.require('ol.events');
goog.require('goog.net.CorsXmlHttpFactory');
goog.require('goog.net.EventType');
goog.require('goog.net.Jsonp');
goog.require('goog.net.XhrIo');
goog.require('ol.Attribution'); goog.require('ol.Attribution');
goog.require('ol.TileRange'); goog.require('ol.TileRange');
goog.require('ol.TileUrlFunction'); goog.require('ol.TileUrlFunction');
goog.require('ol.extent'); goog.require('ol.extent');
goog.require('ol.net.Jsonp');
goog.require('ol.proj'); goog.require('ol.proj');
goog.require('ol.source.State'); goog.require('ol.source.State');
goog.require('ol.source.TileImage'); goog.require('ol.source.TileImage');
@@ -44,21 +40,20 @@ ol.source.TileJSON = function(options) {
}); });
if (options.jsonp) { if (options.jsonp) {
var request = new goog.net.Jsonp(options.url); ol.net.Jsonp(options.url, this.handleTileJSONResponse.bind(this),
request.send(undefined, this.handleTileJSONResponse.bind(this),
this.handleTileJSONError.bind(this)); this.handleTileJSONError.bind(this));
} else { } else {
var xhr = new goog.net.XhrIo(new goog.net.CorsXmlHttpFactory()); var xhr = new XMLHttpRequest();
ol.events.listen(xhr, goog.net.EventType.COMPLETE, function(e) { xhr.open('GET', options.url);
if (xhr.isSuccess()) { xhr.onload = function(e) {
var response = /** @type {TileJSON} */(xhr.getResponseJson()); if (xhr.status < 400) {
var response = /** @type {TileJSON} */(JSON.parse(xhr.responseText));
this.handleTileJSONResponse(response); this.handleTileJSONResponse(response);
} else { } else {
this.handleTileJSONError(); this.handleTileJSONError();
} }
xhr.dispose(); }.bind(this);
}, false, this); xhr.send();
xhr.send(options.url);
} }
}; };

View File

@@ -2,9 +2,6 @@ goog.provide('ol.source.TileUTFGrid');
goog.require('goog.asserts'); goog.require('goog.asserts');
goog.require('goog.async.nextTick'); goog.require('goog.async.nextTick');
goog.require('ol.events');
goog.require('ol.events.EventType');
goog.require('goog.net.Jsonp');
goog.require('ol.Attribution'); goog.require('ol.Attribution');
goog.require('ol.Tile'); goog.require('ol.Tile');
goog.require('ol.TileState'); goog.require('ol.TileState');
@@ -12,6 +9,7 @@ goog.require('ol.TileUrlFunction');
goog.require('ol.events'); goog.require('ol.events');
goog.require('ol.events.EventType'); goog.require('ol.events.EventType');
goog.require('ol.extent'); goog.require('ol.extent');
goog.require('ol.net.Jsonp');
goog.require('ol.proj'); goog.require('ol.proj');
goog.require('ol.source.State'); goog.require('ol.source.State');
goog.require('ol.source.Tile'); goog.require('ol.source.Tile');
@@ -51,8 +49,7 @@ ol.source.TileUTFGrid = function(options) {
*/ */
this.template_ = undefined; this.template_ = undefined;
var request = new goog.net.Jsonp(options.url); ol.net.Jsonp(options.url, this.handleTileJSONResponse.bind(this));
request.send(undefined, this.handleTileJSONResponse.bind(this));
}; };
goog.inherits(ol.source.TileUTFGrid, ol.source.Tile); goog.inherits(ol.source.TileUTFGrid, ol.source.Tile);
@@ -362,9 +359,8 @@ ol.source.TileUTFGridTile_.prototype.handleLoad_ = function(json) {
ol.source.TileUTFGridTile_.prototype.loadInternal_ = function() { 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_); ol.net.Jsonp(this.src_, this.handleLoad_.bind(this),
request.send(undefined, this.handleLoad_.bind(this), this.handleError_.bind(this));
this.handleError_.bind(this));
} }
}; };

View File

@@ -7,24 +7,21 @@ describe('ol.source.BingMaps', function() {
var source, tileGrid; var source, tileGrid;
beforeEach(function(done) { beforeEach(function(done) {
var googNetJsonp = goog.net.Jsonp; var olNetJsonp = ol.net.Jsonp;
// mock goog.net.Jsonp (used in the ol.source.TileJSON constructor) // mock ol.net.Jsonp (used in the ol.source.TileJSON constructor)
goog.net.Jsonp = function() { ol.net.Jsonp = function(url, callback) {
this.send = function() { var client = new XMLHttpRequest();
var callback = arguments[1]; client.open('GET', 'spec/ol/data/bing_aerialwithlabels.json', true);
var client = new XMLHttpRequest(); client.onload = function() {
client.open('GET', 'spec/ol/data/bing_aerialwithlabels.json', true); callback(JSON.parse(client.responseText));
client.onload = function() {
callback(JSON.parse(client.responseText));
};
client.send();
}; };
client.send();
}; };
source = new ol.source.BingMaps({ source = new ol.source.BingMaps({
imagerySet: 'AerialWithLabels', imagerySet: 'AerialWithLabels',
key: '' key: ''
}); });
goog.net.Jsonp = googNetJsonp; ol.net.Jsonp = olNetJsonp;
var key = source.on('change', function() { var key = source.on('change', function() {
if (source.getState() === 'ready') { if (source.getState() === 'ready') {
ol.Observable.unByKey(key); ol.Observable.unByKey(key);
@@ -75,7 +72,7 @@ describe('ol.source.BingMaps', function() {
}); });
goog.require('goog.net.Jsonp'); goog.require('ol.net.Jsonp');
goog.require('ol.source.BingMaps'); goog.require('ol.source.BingMaps');
goog.require('ol.tilecoord'); goog.require('ol.tilecoord');
goog.require('ol.Observable'); goog.require('ol.Observable');