Merge pull request #11540 from gberaudo/avoid_mvt_reprojection
Avoid unnecessary transform in the MVT format
This commit is contained in:
@@ -194,7 +194,7 @@ class MVT extends FeatureFormat {
|
|||||||
values,
|
values,
|
||||||
id
|
id
|
||||||
);
|
);
|
||||||
feature.transform(options.dataProjection, options.featureProjection);
|
feature.transform(options.dataProjection);
|
||||||
} else {
|
} else {
|
||||||
let geom;
|
let geom;
|
||||||
if (geometryType == GeometryType.POLYGON) {
|
if (geometryType == GeometryType.POLYGON) {
|
||||||
|
|||||||
@@ -276,15 +276,14 @@ class RenderFeature {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Transform geometry coordinates from tile pixel space to projected.
|
* Transform geometry coordinates from tile pixel space to projected.
|
||||||
* The SRS of the source and destination are expected to be the same.
|
|
||||||
*
|
*
|
||||||
* @param {import("../proj.js").ProjectionLike} source The current projection
|
* @param {import("../proj.js").ProjectionLike} projection The data projection
|
||||||
* @param {import("../proj.js").ProjectionLike} destination The desired projection.
|
|
||||||
*/
|
*/
|
||||||
transform(source, destination) {
|
transform(projection) {
|
||||||
source = getProjection(source);
|
projection = getProjection(projection);
|
||||||
const pixelExtent = source.getExtent();
|
const pixelExtent = projection.getExtent();
|
||||||
const projectedExtent = source.getWorldExtent();
|
const projectedExtent = projection.getWorldExtent();
|
||||||
|
if (pixelExtent && projectedExtent) {
|
||||||
const scale = getHeight(projectedExtent) / getHeight(pixelExtent);
|
const scale = getHeight(projectedExtent) / getHeight(pixelExtent);
|
||||||
composeTransform(
|
composeTransform(
|
||||||
tmpTransform,
|
tmpTransform,
|
||||||
@@ -305,6 +304,7 @@ class RenderFeature {
|
|||||||
this.flatCoordinates_
|
this.flatCoordinates_
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* @return {Array<number>|Array<Array<number>>} Ends or endss.
|
* @return {Array<number>|Array<Array<number>>} Ends or endss.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -65,6 +65,15 @@ where('ArrayBuffer.isView').describe('ol.format.MVT', function () {
|
|||||||
expect(geometry.getCoordinates()[1][0]).to.eql([4160, 3489]);
|
expect(geometry.getCoordinates()[1][0]).to.eql([4160, 3489]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('avoids unnecessary reprojections of the ol.render.Feature', function () {
|
||||||
|
const format = new MVT({
|
||||||
|
layers: ['poi_label'],
|
||||||
|
});
|
||||||
|
const geometry = format.readFeatures(data)[0].getGeometry();
|
||||||
|
expect(geometry.getType()).to.be('Point');
|
||||||
|
expect(geometry.getFlatCoordinates()).to.eql([-1210, 2681]);
|
||||||
|
});
|
||||||
|
|
||||||
it('parses id property', function () {
|
it('parses id property', function () {
|
||||||
// ol.Feature
|
// ol.Feature
|
||||||
let format = new MVT({
|
let format = new MVT({
|
||||||
|
|||||||
Reference in New Issue
Block a user