Simplify vector tile projection handling

This commit is contained in:
ahocevar
2019-03-10 09:34:40 +01:00
parent 7002053678
commit b2722542fe
10 changed files with 148 additions and 181 deletions
+24 -19
View File
@@ -1,38 +1,43 @@
import Feature from '../../../src/ol/Feature.js';
import {defaultLoadFunction} from '../../../src/ol/source/VectorTile.js';
import VectorTile from '../../../src/ol/VectorTile.js';
import {listen} from '../../../src/ol/events.js';
import TextFeature from '../../../src/ol/format/TextFeature.js';
import GeoJSON from '../../../src/ol/format/GeoJSON.js';
import MVT from '../../../src/ol/format/MVT.js';
import {get as getProjection} from '../../../src/ol/proj.js';
import Projection from '../../../src/ol/proj/Projection.js';
import {createXYZ} from '../../../src/ol/tilegrid.js';
describe('ol.VectorTile', function() {
it('loader sets features on the tile and updates proj units', function(done) {
// mock format that return a tile-pixels feature
const format = new TextFeature();
format.readProjection = function(source) {
return new Projection({
code: '',
units: 'tile-pixels'
});
};
format.readFeatures = function(source, options) {
return [new Feature()];
};
it('loader reprojects GeoJSON features', function(done) {
const format = new GeoJSON();
const tile = new VectorTile([0, 0, 0], null, null, format);
const url = 'spec/ol/data/point.json';
defaultLoadFunction(tile, url);
const loader = tile.loader_;
listen(tile, 'change', function(e) {
expect(tile.getFeatures().length).to.be.greaterThan(0);
expect(tile.getProjection().getUnits()).to.be('tile-pixels');
expect(tile.getFeatures()[0].getGeometry().getFlatCoordinates()).to.eql([-9724792.346778862, 4164041.638405114]);
done();
});
loader.call(tile, [], 1, getProjection('EPSG:3857'));
});
it('loader reprojects MVT features', function(done) {
const format = new MVT();
const tileGrid = createXYZ({
tileSize: 512
});
const tile = new VectorTile([14, 8938, 5680], null, null, format);
const url = 'spec/ol/data/14-8938-5680.vector.pbf';
defaultLoadFunction(tile, url);
const loader = tile.loader_;
listen(tile, 'change', function(e) {
expect(tile.getFeatures()[1246].getGeometry().getFlatCoordinates()).to.eql([1827804.0218549764, 6144812.116688028]);
done();
});
const extent = tileGrid.getTileCoordExtent(tile.tileCoord);
loader.call(tile, extent, 1, getProjection('EPSG:3857'));
});
});