Modify ol.featureloader (and consequently ol.source.Vector) to accept a function as a url.

This commit is contained in:
Alvin Lindstam
2015-08-09 22:09:31 +02:00
parent 4045e06aa9
commit e41ba12445
3 changed files with 73 additions and 10 deletions

View File

@@ -4,16 +4,18 @@ describe('ol.featureloader', function() {
describe('ol.featureloader.xhr', function() {
var loader;
var source;
var url;
var format;
beforeEach(function() {
var url = 'spec/ol/data/point.json';
var format = new ol.format.GeoJSON();
url = 'spec/ol/data/point.json';
format = new ol.format.GeoJSON();
loader = ol.featureloader.xhr(url, format);
source = new ol.source.Vector();
});
it('adds features to the source', function(done) {
loader = ol.featureloader.xhr(url, format);
source.on(ol.source.VectorEventType.ADDFEATURE, function(e) {
expect(source.getFeatures().length).to.be.greaterThan(0);
done();
@@ -21,6 +23,35 @@ describe('ol.featureloader', function() {
loader.call(source, [], 1, 'EPSG:3857');
});
describe('when called with urlFunction', function() {
it('adds features to the source', function(done) {
url = function(extent, resolution, projection) {
return 'spec/ol/data/point.json';};
loader = ol.featureloader.xhr(url, format);
source.on(ol.source.VectorEventType.ADDFEATURE, function(e) {
expect(source.getFeatures().length).to.be.greaterThan(0);
done();
});
loader.call(source, [], 1, 'EPSG:3857');
});
it('sends the correct arguments to the urlFunction', function(done) {
var extent = [];
var resolution = 1;
var projection = 'EPSG:3857';
url = function(extent_, resolution_, projection_) {
expect(extent_).to.eql(extent);
expect(resolution_).to.eql(resolution);
expect(projection_).to.eql(projection);
done();
return 'spec/ol/data/point.json';
};
loader = ol.featureloader.xhr(url, format);
loader.call(source, [], 1, 'EPSG:3857');
});
});
});
});