All checks were successful
Publish To Prod / deploy_and_publish (push) Successful in 35s
64 lines
2.3 KiB
JavaScript
64 lines
2.3 KiB
JavaScript
/**
|
|
* @module ol/proj/transforms
|
|
*/
|
|
import { isEmpty } from '../obj.js';
|
|
/**
|
|
* @private
|
|
* @type {!Object<string, Object<string, import("../proj.js").TransformFunction>>}
|
|
*/
|
|
var transforms = {};
|
|
/**
|
|
* Clear the transform cache.
|
|
*/
|
|
export function clear() {
|
|
transforms = {};
|
|
}
|
|
/**
|
|
* Registers a conversion function to convert coordinates from the source
|
|
* projection to the destination projection.
|
|
*
|
|
* @param {import("./Projection.js").default} source Source.
|
|
* @param {import("./Projection.js").default} destination Destination.
|
|
* @param {import("../proj.js").TransformFunction} transformFn Transform.
|
|
*/
|
|
export function add(source, destination, transformFn) {
|
|
var sourceCode = source.getCode();
|
|
var destinationCode = destination.getCode();
|
|
if (!(sourceCode in transforms)) {
|
|
transforms[sourceCode] = {};
|
|
}
|
|
transforms[sourceCode][destinationCode] = transformFn;
|
|
}
|
|
/**
|
|
* Unregisters the conversion function to convert coordinates from the source
|
|
* projection to the destination projection. This method is used to clean up
|
|
* cached transforms during testing.
|
|
*
|
|
* @param {import("./Projection.js").default} source Source projection.
|
|
* @param {import("./Projection.js").default} destination Destination projection.
|
|
* @return {import("../proj.js").TransformFunction} transformFn The unregistered transform.
|
|
*/
|
|
export function remove(source, destination) {
|
|
var sourceCode = source.getCode();
|
|
var destinationCode = destination.getCode();
|
|
var transform = transforms[sourceCode][destinationCode];
|
|
delete transforms[sourceCode][destinationCode];
|
|
if (isEmpty(transforms[sourceCode])) {
|
|
delete transforms[sourceCode];
|
|
}
|
|
return transform;
|
|
}
|
|
/**
|
|
* Get a transform given a source code and a destination code.
|
|
* @param {string} sourceCode The code for the source projection.
|
|
* @param {string} destinationCode The code for the destination projection.
|
|
* @return {import("../proj.js").TransformFunction|undefined} The transform function (if found).
|
|
*/
|
|
export function get(sourceCode, destinationCode) {
|
|
var transform;
|
|
if (sourceCode in transforms && destinationCode in transforms[sourceCode]) {
|
|
transform = transforms[sourceCode][destinationCode];
|
|
}
|
|
return transform;
|
|
}
|
|
//# sourceMappingURL=transforms.js.map
|