Named exports from ol/reproj
This commit is contained in:
@@ -5,7 +5,6 @@ import {createCanvasContext2D} from './dom.js';
|
||||
import {containsCoordinate, createEmpty, extend, getHeight, getTopLeft, getWidth} from './extent.js';
|
||||
import {solveLinearSystem} from './math.js';
|
||||
import {getPointResolution, transform} from './proj.js';
|
||||
const _ol_reproj_ = {};
|
||||
|
||||
|
||||
/**
|
||||
@@ -20,7 +19,7 @@ const _ol_reproj_ = {};
|
||||
* @param {number} targetResolution Target resolution.
|
||||
* @return {number} The best resolution to use. Can be +-Infinity, NaN or 0.
|
||||
*/
|
||||
_ol_reproj_.calculateSourceResolution = function(sourceProj, targetProj,
|
||||
export function calculateSourceResolution(sourceProj, targetProj,
|
||||
targetCenter, targetResolution) {
|
||||
|
||||
const sourceCenter = transform(targetCenter, targetProj, sourceProj);
|
||||
@@ -51,7 +50,7 @@ _ol_reproj_.calculateSourceResolution = function(sourceProj, targetProj,
|
||||
}
|
||||
|
||||
return sourceResolution;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -63,14 +62,13 @@ _ol_reproj_.calculateSourceResolution = function(sourceProj, targetProj,
|
||||
* @param {number} x X coordinate of the point (in pixels).
|
||||
* @param {number} y Y coordinate of the point (in pixels).
|
||||
* @return {ol.Coordinate} New point 1 px farther from the centroid.
|
||||
* @private
|
||||
*/
|
||||
_ol_reproj_.enlargeClipPoint_ = function(centroidX, centroidY, x, y) {
|
||||
function enlargeClipPoint(centroidX, centroidY, x, y) {
|
||||
const dX = x - centroidX;
|
||||
const dY = y - centroidY;
|
||||
const distance = Math.sqrt(dX * dX + dY * dY);
|
||||
return [Math.round(x + dX / distance), Math.round(y + dY / distance)];
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -91,7 +89,7 @@ _ol_reproj_.enlargeClipPoint_ = function(centroidX, centroidY, x, y) {
|
||||
* @param {boolean=} opt_renderEdges Render reprojection edges.
|
||||
* @return {HTMLCanvasElement} Canvas with reprojected data.
|
||||
*/
|
||||
_ol_reproj_.render = function(width, height, pixelRatio,
|
||||
export function render(width, height, pixelRatio,
|
||||
sourceResolution, sourceExtent, targetResolution, targetExtent,
|
||||
triangulation, sources, gutter, opt_renderEdges) {
|
||||
|
||||
@@ -193,9 +191,9 @@ _ol_reproj_.render = function(width, height, pixelRatio,
|
||||
context.beginPath();
|
||||
const centroidX = (u0 + u1 + u2) / 3;
|
||||
const centroidY = (v0 + v1 + v2) / 3;
|
||||
const p0 = _ol_reproj_.enlargeClipPoint_(centroidX, centroidY, u0, v0);
|
||||
const p1 = _ol_reproj_.enlargeClipPoint_(centroidX, centroidY, u1, v1);
|
||||
const p2 = _ol_reproj_.enlargeClipPoint_(centroidX, centroidY, u2, v2);
|
||||
const p0 = enlargeClipPoint(centroidX, centroidY, u0, v0);
|
||||
const p1 = enlargeClipPoint(centroidX, centroidY, u1, v1);
|
||||
const p2 = enlargeClipPoint(centroidX, centroidY, u2, v2);
|
||||
|
||||
context.moveTo(p1[0], p1[1]);
|
||||
context.lineTo(p0[0], p0[1]);
|
||||
@@ -241,5 +239,4 @@ _ol_reproj_.render = function(width, height, pixelRatio,
|
||||
context.restore();
|
||||
}
|
||||
return context.canvas;
|
||||
};
|
||||
export default _ol_reproj_;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import ImageState from '../ImageState.js';
|
||||
import {listen, unlistenByKey} from '../events.js';
|
||||
import EventType from '../events/EventType.js';
|
||||
import {getCenter, getIntersection, getHeight, getWidth} from '../extent.js';
|
||||
import _ol_reproj_ from '../reproj.js';
|
||||
import {calculateSourceResolution, render as renderReprojected} from '../reproj.js';
|
||||
import Triangulation from '../reproj/Triangulation.js';
|
||||
|
||||
/**
|
||||
@@ -46,7 +46,7 @@ const ReprojImage = function(sourceProj, targetProj,
|
||||
getIntersection(targetExtent, maxTargetExtent) : targetExtent;
|
||||
|
||||
const targetCenter = getCenter(limitedTargetExtent);
|
||||
const sourceResolution = _ol_reproj_.calculateSourceResolution(
|
||||
const sourceResolution = calculateSourceResolution(
|
||||
sourceProj, targetProj, targetCenter, targetResolution);
|
||||
|
||||
const errorThresholdInPixels = ERROR_THRESHOLD;
|
||||
@@ -148,7 +148,7 @@ ReprojImage.prototype.reproject_ = function() {
|
||||
const width = getWidth(this.targetExtent_) / this.targetResolution_;
|
||||
const height = getHeight(this.targetExtent_) / this.targetResolution_;
|
||||
|
||||
this.canvas_ = _ol_reproj_.render(width, height, this.sourcePixelRatio_,
|
||||
this.canvas_ = renderReprojected(width, height, this.sourcePixelRatio_,
|
||||
this.sourceImage_.getResolution(), this.maxSourceExtent_,
|
||||
this.targetResolution_, this.targetExtent_, this.triangulation_, [{
|
||||
extent: this.sourceImage_.getExtent(),
|
||||
|
||||
@@ -9,7 +9,7 @@ import {listen, unlistenByKey} from '../events.js';
|
||||
import EventType from '../events/EventType.js';
|
||||
import {getArea, getCenter, getIntersection} from '../extent.js';
|
||||
import {clamp} from '../math.js';
|
||||
import _ol_reproj_ from '../reproj.js';
|
||||
import {calculateSourceResolution, render as renderReprojected} from '../reproj.js';
|
||||
import Triangulation from '../reproj/Triangulation.js';
|
||||
|
||||
/**
|
||||
@@ -125,7 +125,7 @@ const ReprojTile = function(sourceProj, sourceTileGrid,
|
||||
this.wrappedTileCoord_[0]);
|
||||
|
||||
const targetCenter = getCenter(limitedTargetExtent);
|
||||
const sourceResolution = _ol_reproj_.calculateSourceResolution(
|
||||
const sourceResolution = calculateSourceResolution(
|
||||
sourceProj, targetProj, targetCenter, targetResolution);
|
||||
|
||||
if (!isFinite(sourceResolution) || sourceResolution <= 0) {
|
||||
@@ -237,7 +237,7 @@ ReprojTile.prototype.reproject_ = function() {
|
||||
|
||||
const targetExtent = this.targetTileGrid_.getTileCoordExtent(
|
||||
this.wrappedTileCoord_);
|
||||
this.canvas_ = _ol_reproj_.render(width, height, this.pixelRatio_,
|
||||
this.canvas_ = renderReprojected(width, height, this.pixelRatio_,
|
||||
sourceResolution, this.sourceTileGrid_.getExtent(),
|
||||
targetResolution, targetExtent, this.triangulation_, sources,
|
||||
this.gutter_, this.renderEdges_);
|
||||
|
||||
@@ -11,7 +11,7 @@ import EventType from '../events/EventType.js';
|
||||
import {containsExtent, getCenter, getForViewAndSize, getHeight, getWidth} from '../extent.js';
|
||||
import {assign} from '../obj.js';
|
||||
import {get as getProjection, transform} from '../proj.js';
|
||||
import _ol_reproj_ from '../reproj.js';
|
||||
import {calculateSourceResolution} from '../reproj.js';
|
||||
import ImageSource from '../source/Image.js';
|
||||
import WMSServerType from '../source/WMSServerType.js';
|
||||
import {compareVersions} from '../string.js';
|
||||
@@ -141,7 +141,7 @@ ImageWMS.prototype.getGetFeatureInfoUrl = function(coordinate, resolution, proje
|
||||
const sourceProjectionObj = this.getProjection();
|
||||
|
||||
if (sourceProjectionObj && sourceProjectionObj !== projectionObj) {
|
||||
resolution = _ol_reproj_.calculateSourceResolution(sourceProjectionObj, projectionObj, coordinate, resolution);
|
||||
resolution = calculateSourceResolution(sourceProjectionObj, projectionObj, coordinate, resolution);
|
||||
coordinate = transform(coordinate, projectionObj, sourceProjectionObj);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import {buffer, createEmpty} from '../extent.js';
|
||||
import {assign} from '../obj.js';
|
||||
import {modulo} from '../math.js';
|
||||
import {get as getProjection, transform, transformExtent} from '../proj.js';
|
||||
import _ol_reproj_ from '../reproj.js';
|
||||
import {calculateSourceResolution} from '../reproj.js';
|
||||
import {toSize, buffer as bufferSize, scale as scaleSize} from '../size.js';
|
||||
import TileImage from '../source/TileImage.js';
|
||||
import WMSServerType from '../source/WMSServerType.js';
|
||||
@@ -135,7 +135,7 @@ TileWMS.prototype.getGetFeatureInfoUrl = function(coordinate, resolution, projec
|
||||
}
|
||||
|
||||
if (sourceProjectionObj && sourceProjectionObj !== projectionObj) {
|
||||
tileResolution = _ol_reproj_.calculateSourceResolution(sourceProjectionObj, projectionObj, coordinate, tileResolution);
|
||||
tileResolution = calculateSourceResolution(sourceProjectionObj, projectionObj, coordinate, tileResolution);
|
||||
tileExtent = transformExtent(tileExtent, projectionObj, sourceProjectionObj);
|
||||
coordinate = transform(coordinate, projectionObj, sourceProjectionObj);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import _ol_reproj_ from '../../../../src/ol/reproj.js';
|
||||
import {calculateSourceResolution} from '../../../../src/ol/reproj.js';
|
||||
import {get as getProjection, transform} from '../../../../src/ol/proj.js';
|
||||
|
||||
|
||||
@@ -14,15 +14,15 @@ describe('ol.reproj', function() {
|
||||
it('is identity for identical projection', function() {
|
||||
let result;
|
||||
const resolution = 500;
|
||||
result = _ol_reproj_.calculateSourceResolution(
|
||||
result = calculateSourceResolution(
|
||||
proj3857, proj3857, origin, resolution);
|
||||
expect(result).to.be(resolution);
|
||||
|
||||
result = _ol_reproj_.calculateSourceResolution(
|
||||
result = calculateSourceResolution(
|
||||
proj3857, proj3857, point3857, resolution);
|
||||
expect(result).to.be(resolution);
|
||||
|
||||
result = _ol_reproj_.calculateSourceResolution(
|
||||
result = calculateSourceResolution(
|
||||
proj4326, proj4326, point4326, resolution);
|
||||
expect(result).to.be(resolution);
|
||||
});
|
||||
@@ -30,13 +30,13 @@ describe('ol.reproj', function() {
|
||||
it('calculates correctly', function() {
|
||||
const resolution4326 = 5;
|
||||
|
||||
const resolution3857 = _ol_reproj_.calculateSourceResolution(
|
||||
const resolution3857 = calculateSourceResolution(
|
||||
proj3857, proj4326, point4326, resolution4326);
|
||||
expect(resolution3857).not.to.be(resolution4326);
|
||||
expect(resolution3857).to.roughlyEqual(
|
||||
5 * proj4326.getMetersPerUnit(), 1e-4);
|
||||
|
||||
const result = _ol_reproj_.calculateSourceResolution(
|
||||
const result = calculateSourceResolution(
|
||||
proj4326, proj3857, point3857, resolution3857);
|
||||
expect(result).to.be(resolution4326);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user