Named exports for ol/proj/transforms
This commit is contained in:
+9
-11
@@ -10,7 +10,7 @@ import Projection from './proj/Projection.js';
|
|||||||
import Units from './proj/Units.js';
|
import Units from './proj/Units.js';
|
||||||
import _ol_proj_proj4_ from './proj/proj4.js';
|
import _ol_proj_proj4_ from './proj/proj4.js';
|
||||||
import _ol_proj_projections_ from './proj/projections.js';
|
import _ol_proj_projections_ from './proj/projections.js';
|
||||||
import _ol_proj_transforms_ from './proj/transforms.js';
|
import {add as addTransformFunc, clear as clearTransformFuncs, get as getTransformFunc} from './proj/transforms.js';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -93,7 +93,7 @@ export function identityTransform(input, opt_output, opt_dimension) {
|
|||||||
*/
|
*/
|
||||||
export function addProjection(projection) {
|
export function addProjection(projection) {
|
||||||
_ol_proj_projections_.add(projection.getCode(), projection);
|
_ol_proj_projections_.add(projection.getCode(), projection);
|
||||||
_ol_proj_transforms_.add(projection, projection, cloneTransform);
|
addTransformFunc(projection, projection, cloneTransform);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -204,7 +204,7 @@ export function addEquivalentProjections(projections) {
|
|||||||
projections.forEach(function(source) {
|
projections.forEach(function(source) {
|
||||||
projections.forEach(function(destination) {
|
projections.forEach(function(destination) {
|
||||||
if (source !== destination) {
|
if (source !== destination) {
|
||||||
_ol_proj_transforms_.add(source, destination, cloneTransform);
|
addTransformFunc(source, destination, cloneTransform);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -227,8 +227,8 @@ export function addEquivalentProjections(projections) {
|
|||||||
export function addEquivalentTransforms(projections1, projections2, forwardTransform, inverseTransform) {
|
export function addEquivalentTransforms(projections1, projections2, forwardTransform, inverseTransform) {
|
||||||
projections1.forEach(function(projection1) {
|
projections1.forEach(function(projection1) {
|
||||||
projections2.forEach(function(projection2) {
|
projections2.forEach(function(projection2) {
|
||||||
_ol_proj_transforms_.add(projection1, projection2, forwardTransform);
|
addTransformFunc(projection1, projection2, forwardTransform);
|
||||||
_ol_proj_transforms_.add(projection2, projection1, inverseTransform);
|
addTransformFunc(projection2, projection1, inverseTransform);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -239,7 +239,7 @@ export function addEquivalentTransforms(projections1, projections2, forwardTrans
|
|||||||
*/
|
*/
|
||||||
export function clearAllProjections() {
|
export function clearAllProjections() {
|
||||||
_ol_proj_projections_.clear();
|
_ol_proj_projections_.clear();
|
||||||
_ol_proj_transforms_.clear();
|
clearTransformFuncs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -314,10 +314,8 @@ export function createTransformFromCoordinateTransform(coordTransform) {
|
|||||||
export function addCoordinateTransforms(source, destination, forward, inverse) {
|
export function addCoordinateTransforms(source, destination, forward, inverse) {
|
||||||
var sourceProj = get(source);
|
var sourceProj = get(source);
|
||||||
var destProj = get(destination);
|
var destProj = get(destination);
|
||||||
_ol_proj_transforms_.add(sourceProj, destProj,
|
addTransformFunc(sourceProj, destProj, createTransformFromCoordinateTransform(forward));
|
||||||
createTransformFromCoordinateTransform(forward));
|
addTransformFunc(destProj, sourceProj, createTransformFromCoordinateTransform(inverse));
|
||||||
_ol_proj_transforms_.add(destProj, sourceProj,
|
|
||||||
createTransformFromCoordinateTransform(inverse));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -392,7 +390,6 @@ export function equivalent(projection1, projection2) {
|
|||||||
export function getTransformFromProjections(sourceProjection, destinationProjection) {
|
export function getTransformFromProjections(sourceProjection, destinationProjection) {
|
||||||
var sourceCode = sourceProjection.getCode();
|
var sourceCode = sourceProjection.getCode();
|
||||||
var destinationCode = destinationProjection.getCode();
|
var destinationCode = destinationProjection.getCode();
|
||||||
var transformFunc = _ol_proj_transforms_.get(sourceCode, destinationCode);
|
|
||||||
if (!transformFunc) {
|
if (!transformFunc) {
|
||||||
var proj4js = _ol_proj_proj4_.get();
|
var proj4js = _ol_proj_proj4_.get();
|
||||||
if (typeof proj4js == 'function') {
|
if (typeof proj4js == 'function') {
|
||||||
@@ -411,6 +408,7 @@ export function getTransformFromProjections(sourceProjection, destinationProject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var transformFunc = getTransformFunc(sourceCode, destinationCode);
|
||||||
if (!transformFunc) {
|
if (!transformFunc) {
|
||||||
transformFunc = identityTransform;
|
transformFunc = identityTransform;
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-15
@@ -2,22 +2,21 @@
|
|||||||
* @module ol/proj/transforms
|
* @module ol/proj/transforms
|
||||||
*/
|
*/
|
||||||
import _ol_obj_ from '../obj.js';
|
import _ol_obj_ from '../obj.js';
|
||||||
var _ol_proj_transforms_ = {};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {Object.<string, Object.<string, ol.TransformFunction>>}
|
* @type {Object.<string, Object.<string, ol.TransformFunction>>}
|
||||||
*/
|
*/
|
||||||
_ol_proj_transforms_.cache_ = {};
|
var transforms = {};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear the transform cache.
|
* Clear the transform cache.
|
||||||
*/
|
*/
|
||||||
_ol_proj_transforms_.clear = function() {
|
export function clear() {
|
||||||
_ol_proj_transforms_.cache_ = {};
|
transforms = {};
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -28,15 +27,14 @@ _ol_proj_transforms_.clear = function() {
|
|||||||
* @param {ol.proj.Projection} destination Destination.
|
* @param {ol.proj.Projection} destination Destination.
|
||||||
* @param {ol.TransformFunction} transformFn Transform.
|
* @param {ol.TransformFunction} transformFn Transform.
|
||||||
*/
|
*/
|
||||||
_ol_proj_transforms_.add = function(source, destination, transformFn) {
|
export function add(source, destination, transformFn) {
|
||||||
var sourceCode = source.getCode();
|
var sourceCode = source.getCode();
|
||||||
var destinationCode = destination.getCode();
|
var destinationCode = destination.getCode();
|
||||||
var transforms = _ol_proj_transforms_.cache_;
|
|
||||||
if (!(sourceCode in transforms)) {
|
if (!(sourceCode in transforms)) {
|
||||||
transforms[sourceCode] = {};
|
transforms[sourceCode] = {};
|
||||||
}
|
}
|
||||||
transforms[sourceCode][destinationCode] = transformFn;
|
transforms[sourceCode][destinationCode] = transformFn;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -48,17 +46,16 @@ _ol_proj_transforms_.add = function(source, destination, transformFn) {
|
|||||||
* @param {ol.proj.Projection} destination Destination projection.
|
* @param {ol.proj.Projection} destination Destination projection.
|
||||||
* @return {ol.TransformFunction} transformFn The unregistered transform.
|
* @return {ol.TransformFunction} transformFn The unregistered transform.
|
||||||
*/
|
*/
|
||||||
_ol_proj_transforms_.remove = function(source, destination) {
|
export function remove(source, destination) {
|
||||||
var sourceCode = source.getCode();
|
var sourceCode = source.getCode();
|
||||||
var destinationCode = destination.getCode();
|
var destinationCode = destination.getCode();
|
||||||
var transforms = _ol_proj_transforms_.cache_;
|
|
||||||
var transform = transforms[sourceCode][destinationCode];
|
var transform = transforms[sourceCode][destinationCode];
|
||||||
delete transforms[sourceCode][destinationCode];
|
delete transforms[sourceCode][destinationCode];
|
||||||
if (_ol_obj_.isEmpty(transforms[sourceCode])) {
|
if (_ol_obj_.isEmpty(transforms[sourceCode])) {
|
||||||
delete transforms[sourceCode];
|
delete transforms[sourceCode];
|
||||||
}
|
}
|
||||||
return transform;
|
return transform;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -67,12 +64,10 @@ _ol_proj_transforms_.remove = function(source, destination) {
|
|||||||
* @param {string} destinationCode The code for the destination projection.
|
* @param {string} destinationCode The code for the destination projection.
|
||||||
* @return {ol.TransformFunction|undefined} The transform function (if found).
|
* @return {ol.TransformFunction|undefined} The transform function (if found).
|
||||||
*/
|
*/
|
||||||
_ol_proj_transforms_.get = function(sourceCode, destinationCode) {
|
export function get(sourceCode, destinationCode) {
|
||||||
var transform;
|
var transform;
|
||||||
var transforms = _ol_proj_transforms_.cache_;
|
|
||||||
if (sourceCode in transforms && destinationCode in transforms[sourceCode]) {
|
if (sourceCode in transforms && destinationCode in transforms[sourceCode]) {
|
||||||
transform = transforms[sourceCode][destinationCode];
|
transform = transforms[sourceCode][destinationCode];
|
||||||
}
|
}
|
||||||
return transform;
|
return transform;
|
||||||
};
|
}
|
||||||
export default _ol_proj_transforms_;
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import Point from '../../../../src/ol/geom/Point.js';
|
|||||||
import Polygon from '../../../../src/ol/geom/Polygon.js';
|
import Polygon from '../../../../src/ol/geom/Polygon.js';
|
||||||
import {addProjection, addCoordinateTransforms, transform, get as getProjection} from '../../../../src/ol/proj.js';
|
import {addProjection, addCoordinateTransforms, transform, get as getProjection} from '../../../../src/ol/proj.js';
|
||||||
import _ol_proj_Projection_ from '../../../../src/ol/proj/Projection.js';
|
import _ol_proj_Projection_ from '../../../../src/ol/proj/Projection.js';
|
||||||
import _ol_proj_transforms_ from '../../../../src/ol/proj/transforms.js';
|
import {remove as removeTransform} from '../../../../src/ol/proj/transforms.js';
|
||||||
import _ol_style_Circle_ from '../../../../src/ol/style/Circle.js';
|
import _ol_style_Circle_ from '../../../../src/ol/style/Circle.js';
|
||||||
import _ol_style_Fill_ from '../../../../src/ol/style/Fill.js';
|
import _ol_style_Fill_ from '../../../../src/ol/style/Fill.js';
|
||||||
import _ol_style_Icon_ from '../../../../src/ol/style/Icon.js';
|
import _ol_style_Icon_ from '../../../../src/ol/style/Icon.js';
|
||||||
@@ -386,10 +386,8 @@ describe('ol.format.KML', function() {
|
|||||||
'</kml>';
|
'</kml>';
|
||||||
expect(node).to.xmleql(_ol_xml_.parse(text));
|
expect(node).to.xmleql(_ol_xml_.parse(text));
|
||||||
|
|
||||||
_ol_proj_transforms_.remove(
|
removeTransform(getProjection('EPSG:4326'), getProjection('double'));
|
||||||
getProjection('EPSG:4326'), getProjection('double'));
|
removeTransform(getProjection('double'), getProjection('EPSG:4326'));
|
||||||
_ol_proj_transforms_.remove(
|
|
||||||
getProjection('double'), getProjection('EPSG:4326'));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can write XYM Point geometries', function() {
|
it('can write XYM Point geometries', function() {
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import _ol_proj_Projection_ from '../../../../src/ol/proj/Projection.js';
|
import _ol_proj_Projection_ from '../../../../src/ol/proj/Projection.js';
|
||||||
import _ol_proj_transforms_ from '../../../../src/ol/proj/transforms.js';
|
import * as transforms from '../../../../src/ol/proj/transforms.js';
|
||||||
|
|
||||||
|
|
||||||
describe('ol.proj.transforms.remove()', function() {
|
describe('transforms.remove()', function() {
|
||||||
|
|
||||||
var extent = [180, -90, 180, 90];
|
var extent = [180, -90, 180, 90];
|
||||||
var units = 'degrees';
|
var units = 'degrees';
|
||||||
|
|
||||||
it('removes functions cached by ol.proj.transforms.add()', function() {
|
it('removes functions cached by transforms.add()', function() {
|
||||||
var foo = new _ol_proj_Projection_({
|
var foo = new _ol_proj_Projection_({
|
||||||
code: 'foo',
|
code: 'foo',
|
||||||
units: units,
|
units: units,
|
||||||
@@ -21,15 +21,12 @@ describe('ol.proj.transforms.remove()', function() {
|
|||||||
var transform = function(input, output, dimension) {
|
var transform = function(input, output, dimension) {
|
||||||
return input;
|
return input;
|
||||||
};
|
};
|
||||||
_ol_proj_transforms_.add(foo, bar, transform);
|
transforms.add(foo, bar, transform);
|
||||||
var cache = _ol_proj_transforms_.cache_;
|
expect(transforms.get('foo', 'bar')).to.be(transform);
|
||||||
expect(cache).not.to.be(undefined);
|
|
||||||
expect(cache.foo).not.to.be(undefined);
|
|
||||||
expect(cache.foo.bar).to.be(transform);
|
|
||||||
|
|
||||||
var removed = _ol_proj_transforms_.remove(foo, bar);
|
var removed = transforms.remove(foo, bar);
|
||||||
expect(removed).to.be(transform);
|
expect(removed).to.be(transform);
|
||||||
expect(cache.foo).to.be(undefined);
|
expect(transforms.get('foo', 'bar')).to.be(undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user