Make the immediate API work with a user projection

This commit is contained in:
Tim Schaub
2019-09-27 15:34:35 +02:00
parent 8aa4a59fcf
commit d3b47c794e
10 changed files with 163 additions and 54 deletions
+8 -6
View File
@@ -4,7 +4,7 @@
import {getUid} from '../../util.js';
import ViewHint from '../../ViewHint.js';
import {buffer, createEmpty, containsExtent, getWidth, intersects as intersectsExtent} from '../../extent.js';
import {fromUserExtent, toUserExtent, getUserProjection} from '../../proj.js';
import {fromUserExtent, toUserExtent, getUserProjection, getTransformFromProjections} from '../../proj.js';
import CanvasBuilderGroup from '../../render/canvas/BuilderGroup.js';
import ExecutorGroup, {replayDeclutter} from '../../render/canvas/ExecutorGroup.js';
import CanvasLayerRenderer from './Layer.js';
@@ -307,8 +307,10 @@ class CanvasVectorLayerRenderer extends CanvasLayerRenderer {
pixelRatio, vectorLayer.getDeclutter());
const userProjection = getUserProjection();
let userTransform;
if (userProjection) {
vectorSource.loadFeatures(toUserExtent(extent, projection), resolution, userProjection);
userTransform = getTransformFromProjections(userProjection, projection);
} else {
vectorSource.loadFeatures(extent, resolution, projection);
}
@@ -326,7 +328,7 @@ class CanvasVectorLayerRenderer extends CanvasLayerRenderer {
styles = styleFunction(feature, resolution);
}
if (styles) {
const dirty = this.renderFeature(feature, squaredTolerance, styles, replayGroup, projection);
const dirty = this.renderFeature(feature, squaredTolerance, styles, replayGroup, userTransform);
this.dirty_ = this.dirty_ || dirty;
}
}.bind(this);
@@ -370,10 +372,10 @@ class CanvasVectorLayerRenderer extends CanvasLayerRenderer {
* @param {number} squaredTolerance Squared render tolerance.
* @param {import("../../style/Style.js").default|Array<import("../../style/Style.js").default>} styles The style or array of styles.
* @param {import("../../render/canvas/BuilderGroup.js").default} builderGroup Builder group.
* @param {import("../../proj/Projection.js").default} projection The view projection.
* @param {import("../../proj.js").TransformFunction} opt_transform Transform from user to view projection.
* @return {boolean} `true` if an image is loading.
*/
renderFeature(feature, squaredTolerance, styles, builderGroup, projection) {
renderFeature(feature, squaredTolerance, styles, builderGroup, opt_transform) {
if (!styles) {
return false;
}
@@ -382,12 +384,12 @@ class CanvasVectorLayerRenderer extends CanvasLayerRenderer {
for (let i = 0, ii = styles.length; i < ii; ++i) {
loading = renderFeature(
builderGroup, feature, styles[i], squaredTolerance,
this.boundHandleStyleImageChange_, projection) || loading;
this.boundHandleStyleImageChange_, opt_transform) || loading;
}
} else {
loading = renderFeature(
builderGroup, feature, styles, squaredTolerance,
this.boundHandleStyleImageChange_, projection);
this.boundHandleStyleImageChange_, opt_transform);
}
return loading;
}
+6 -7
View File
@@ -5,7 +5,6 @@ import {getUid} from '../util.js';
import ImageState from '../ImageState.js';
import GeometryType from '../geom/GeometryType.js';
import BuilderType from '../render/canvas/BuilderType.js';
import {getUserProjection} from '../proj.js';
/**
@@ -93,11 +92,11 @@ function renderCircleGeometry(builderGroup, geometry, style, feature) {
* @param {import("../style/Style.js").default} style Style.
* @param {number} squaredTolerance Squared tolerance.
* @param {function(import("../events/Event.js").default): void} listener Listener function.
* @param {import("../proj/Projection.js").default} [projection] The view projection.
* @param {import("../proj.js").TransformFunction} [opt_transform] Transform from user to view projection.
* @return {boolean} `true` if style is loading.
* @template T
*/
export function renderFeature(replayGroup, feature, style, squaredTolerance, listener, projection) {
export function renderFeature(replayGroup, feature, style, squaredTolerance, listener, opt_transform) {
let loading = false;
const imageStyle = style.getImage();
if (imageStyle) {
@@ -113,7 +112,7 @@ export function renderFeature(replayGroup, feature, style, squaredTolerance, lis
loading = true;
}
}
renderFeatureInternal(replayGroup, feature, style, squaredTolerance, projection);
renderFeatureInternal(replayGroup, feature, style, squaredTolerance, opt_transform);
return loading;
}
@@ -124,14 +123,14 @@ export function renderFeature(replayGroup, feature, style, squaredTolerance, lis
* @param {import("../Feature.js").FeatureLike} feature Feature.
* @param {import("../style/Style.js").default} style Style.
* @param {number} squaredTolerance Squared tolerance.
* @param {import("../proj/Projection.js").default} [projection] The view projection.
* @param {import("../proj.js").TransformFunction} [opt_transform] Optional transform function.
*/
function renderFeatureInternal(replayGroup, feature, style, squaredTolerance, projection) {
function renderFeatureInternal(replayGroup, feature, style, squaredTolerance, opt_transform) {
const geometry = style.getGeometryFunction()(feature);
if (!geometry) {
return;
}
const simplifiedGeometry = geometry.simplifyTransformed(squaredTolerance, getUserProjection(), projection);
const simplifiedGeometry = geometry.simplifyTransformed(squaredTolerance, opt_transform);
const renderer = style.getRenderer();
if (renderer) {
renderGeometry(replayGroup, simplifiedGeometry, style, feature);