Named exports from ol/net
This commit is contained in:
@@ -2,7 +2,6 @@
|
|||||||
* @module ol/net
|
* @module ol/net
|
||||||
*/
|
*/
|
||||||
import {getUid} from './index.js';
|
import {getUid} from './index.js';
|
||||||
const _ol_net_ = {};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -16,7 +15,7 @@ const _ol_net_ = {};
|
|||||||
* @param {string=} opt_callbackParam Custom query parameter for the JSONP
|
* @param {string=} opt_callbackParam Custom query parameter for the JSONP
|
||||||
* callback. Default is 'callback'.
|
* callback. Default is 'callback'.
|
||||||
*/
|
*/
|
||||||
_ol_net_.jsonp = function(url, callback, opt_errback, opt_callbackParam) {
|
export function jsonp(url, callback, opt_errback, opt_callbackParam) {
|
||||||
const script = document.createElement('script');
|
const script = document.createElement('script');
|
||||||
const key = 'olc_' + getUid(callback);
|
const key = 'olc_' + getUid(callback);
|
||||||
function cleanup() {
|
function cleanup() {
|
||||||
@@ -38,5 +37,4 @@ _ol_net_.jsonp = function(url, callback, opt_errback, opt_callbackParam) {
|
|||||||
callback(data);
|
callback(data);
|
||||||
};
|
};
|
||||||
document.getElementsByTagName('head')[0].appendChild(script);
|
document.getElementsByTagName('head')[0].appendChild(script);
|
||||||
};
|
}
|
||||||
export default _ol_net_;
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
import {inherits} from '../index.js';
|
import {inherits} from '../index.js';
|
||||||
import {createFromTileUrlFunctions} from '../tileurlfunction.js';
|
import {createFromTileUrlFunctions} from '../tileurlfunction.js';
|
||||||
import {applyTransform, intersects} from '../extent.js';
|
import {applyTransform, intersects} from '../extent.js';
|
||||||
import _ol_net_ from '../net.js';
|
import {jsonp as requestJSONP} from '../net.js';
|
||||||
import {get as getProjection, getTransformFromProjections} from '../proj.js';
|
import {get as getProjection, getTransformFromProjections} from '../proj.js';
|
||||||
import SourceState from '../source/State.js';
|
import SourceState from '../source/State.js';
|
||||||
import TileImage from '../source/TileImage.js';
|
import TileImage from '../source/TileImage.js';
|
||||||
@@ -70,7 +70,7 @@ const BingMaps = function(options) {
|
|||||||
'?uriScheme=https&include=ImageryProviders&key=' + this.apiKey_ +
|
'?uriScheme=https&include=ImageryProviders&key=' + this.apiKey_ +
|
||||||
'&c=' + this.culture_;
|
'&c=' + this.culture_;
|
||||||
|
|
||||||
_ol_net_.jsonp(url, this.handleImageryMetadataResponse.bind(this), undefined,
|
requestJSONP(url, this.handleImageryMetadataResponse.bind(this), undefined,
|
||||||
'jsonp');
|
'jsonp');
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import {inherits} from '../index.js';
|
|||||||
import {createFromTemplates} from '../tileurlfunction.js';
|
import {createFromTemplates} from '../tileurlfunction.js';
|
||||||
import {assert} from '../asserts.js';
|
import {assert} from '../asserts.js';
|
||||||
import {applyTransform, intersects} from '../extent.js';
|
import {applyTransform, intersects} from '../extent.js';
|
||||||
import _ol_net_ from '../net.js';
|
import {jsonp as requestJSONP} from '../net.js';
|
||||||
import {get as getProjection, getTransformFromProjections} from '../proj.js';
|
import {get as getProjection, getTransformFromProjections} from '../proj.js';
|
||||||
import SourceState from '../source/State.js';
|
import SourceState from '../source/State.js';
|
||||||
import TileImage from '../source/TileImage.js';
|
import TileImage from '../source/TileImage.js';
|
||||||
@@ -48,7 +48,7 @@ const TileJSON = function(options) {
|
|||||||
|
|
||||||
if (options.url) {
|
if (options.url) {
|
||||||
if (options.jsonp) {
|
if (options.jsonp) {
|
||||||
_ol_net_.jsonp(options.url, this.handleTileJSONResponse.bind(this),
|
requestJSONP(options.url, this.handleTileJSONResponse.bind(this),
|
||||||
this.handleTileJSONError.bind(this));
|
this.handleTileJSONError.bind(this));
|
||||||
} else {
|
} else {
|
||||||
const client = new XMLHttpRequest();
|
const client = new XMLHttpRequest();
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import {assert} from '../asserts.js';
|
|||||||
import {listenOnce} from '../events.js';
|
import {listenOnce} from '../events.js';
|
||||||
import EventType from '../events/EventType.js';
|
import EventType from '../events/EventType.js';
|
||||||
import {applyTransform, intersects} from '../extent.js';
|
import {applyTransform, intersects} from '../extent.js';
|
||||||
import _ol_net_ from '../net.js';
|
import {jsonp as requestJSONP} from '../net.js';
|
||||||
import {get as getProjection, getTransformFromProjections} from '../proj.js';
|
import {get as getProjection, getTransformFromProjections} from '../proj.js';
|
||||||
import SourceState from '../source/State.js';
|
import SourceState from '../source/State.js';
|
||||||
import TileSource from '../source/Tile.js';
|
import TileSource from '../source/Tile.js';
|
||||||
@@ -58,7 +58,7 @@ const UTFGrid = function(options) {
|
|||||||
|
|
||||||
if (options.url) {
|
if (options.url) {
|
||||||
if (this.jsonp_) {
|
if (this.jsonp_) {
|
||||||
_ol_net_.jsonp(options.url, this.handleTileJSONResponse.bind(this),
|
requestJSONP(options.url, this.handleTileJSONResponse.bind(this),
|
||||||
this.handleTileJSONError.bind(this));
|
this.handleTileJSONError.bind(this));
|
||||||
} else {
|
} else {
|
||||||
const client = new XMLHttpRequest();
|
const client = new XMLHttpRequest();
|
||||||
@@ -425,7 +425,7 @@ UTFGrid.Tile_.prototype.loadInternal_ = function() {
|
|||||||
if (this.state == TileState.IDLE) {
|
if (this.state == TileState.IDLE) {
|
||||||
this.state = TileState.LOADING;
|
this.state = TileState.LOADING;
|
||||||
if (this.jsonp_) {
|
if (this.jsonp_) {
|
||||||
_ol_net_.jsonp(this.src_, this.handleLoad_.bind(this),
|
requestJSONP(this.src_, this.handleLoad_.bind(this),
|
||||||
this.handleError_.bind(this));
|
this.handleError_.bind(this));
|
||||||
} else {
|
} else {
|
||||||
const client = new XMLHttpRequest();
|
const client = new XMLHttpRequest();
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import {getUid} from '../../../src/ol/index.js';
|
import {getUid} from '../../../src/ol/index.js';
|
||||||
import _ol_net_ from '../../../src/ol/net.js';
|
import {jsonp as requestJSONP} from '../../../src/ol/net.js';
|
||||||
|
|
||||||
describe('ol.net', function() {
|
describe('ol.net', function() {
|
||||||
|
|
||||||
@@ -54,11 +54,11 @@ describe('ol.net', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('appends callback param to url, cleans up after call', function(done) {
|
it('appends callback param to url, cleans up after call', function(done) {
|
||||||
_ol_net_.jsonp('foo', createCallback('foo?callback=', done));
|
requestJSONP('foo', createCallback('foo?callback=', done));
|
||||||
});
|
});
|
||||||
it('appends correct callback param to a url with query', function(done) {
|
it('appends correct callback param to a url with query', function(done) {
|
||||||
const callback = createCallback('http://foo/bar?baz&callback=', done);
|
const callback = createCallback('http://foo/bar?baz&callback=', done);
|
||||||
_ol_net_.jsonp('http://foo/bar?baz', callback);
|
requestJSONP('http://foo/bar?baz', callback);
|
||||||
});
|
});
|
||||||
it('calls errback when jsonp is not executed, cleans up', function(done) {
|
it('calls errback when jsonp is not executed, cleans up', function(done) {
|
||||||
head.appendChild = function(element) {
|
head.appendChild = function(element) {
|
||||||
@@ -74,11 +74,11 @@ describe('ol.net', function() {
|
|||||||
expect(removeChild.called).to.be(true);
|
expect(removeChild.called).to.be(true);
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
_ol_net_.jsonp('foo', callback, errback);
|
requestJSONP('foo', callback, errback);
|
||||||
});
|
});
|
||||||
it('accepts a custom callback param', function(done) {
|
it('accepts a custom callback param', function(done) {
|
||||||
const callback = createCallback('foo?mycallback=', done);
|
const callback = createCallback('foo?mycallback=', done);
|
||||||
_ol_net_.jsonp('foo', callback, undefined, 'mycallback');
|
requestJSONP('foo', callback, undefined, 'mycallback');
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import _ol_net_ from '../../../../src/ol/net.js';
|
|
||||||
import BingMaps from '../../../../src/ol/source/BingMaps.js';
|
import BingMaps from '../../../../src/ol/source/BingMaps.js';
|
||||||
import _ol_tilecoord_ from '../../../../src/ol/tilecoord.js';
|
import _ol_tilecoord_ from '../../../../src/ol/tilecoord.js';
|
||||||
import Observable from '../../../../src/ol/Observable.js';
|
import Observable from '../../../../src/ol/Observable.js';
|
||||||
@@ -11,21 +10,18 @@ describe('ol.source.BingMaps', function() {
|
|||||||
let source, tileGrid;
|
let source, tileGrid;
|
||||||
|
|
||||||
beforeEach(function(done) {
|
beforeEach(function(done) {
|
||||||
const olNetJsonp = _ol_net_.jsonp;
|
|
||||||
// mock ol.net.Jsonp (used in the ol.source.TileJSON constructor)
|
|
||||||
_ol_net_.jsonp = function(url, callback) {
|
|
||||||
const client = new XMLHttpRequest();
|
|
||||||
client.open('GET', 'spec/ol/data/bing_aerialwithlabels.json', true);
|
|
||||||
client.onload = function() {
|
|
||||||
callback(JSON.parse(client.responseText));
|
|
||||||
};
|
|
||||||
client.send();
|
|
||||||
};
|
|
||||||
source = new BingMaps({
|
source = new BingMaps({
|
||||||
imagerySet: 'AerialWithLabels',
|
imagerySet: 'AerialWithLabels',
|
||||||
key: ''
|
key: ''
|
||||||
});
|
});
|
||||||
_ol_net_.jsonp = olNetJsonp;
|
|
||||||
|
const client = new XMLHttpRequest();
|
||||||
|
client.open('GET', 'spec/ol/data/bing_aerialwithlabels.json', true);
|
||||||
|
client.onload = function() {
|
||||||
|
source.handleImageryMetadataResponse(JSON.parse(client.responseText));
|
||||||
|
};
|
||||||
|
client.send();
|
||||||
|
|
||||||
const key = source.on('change', function() {
|
const key = source.on('change', function() {
|
||||||
if (source.getState() === 'ready') {
|
if (source.getState() === 'ready') {
|
||||||
Observable.unByKey(key);
|
Observable.unByKey(key);
|
||||||
|
|||||||
Reference in New Issue
Block a user