Skip to content

Commit

Permalink
Cache proj4 transforms for transformCoordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
jbeezley committed Apr 14, 2016
1 parent 1c93bab commit 4d07cef
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ var transform = function (options) {
return this;
};

/**
* This object stores a cache of transform classes so they don't have
* to be recreated on every call to transformCoordinates.
* @private
*/
var cache = {};

/**
* Transform an array of coordinates from one projection into another. The
* transformation may occur in place (modifying the input coordinate array),
Expand All @@ -182,7 +189,14 @@ transform.transformCoordinates = function (
}

var i, count, offset, xAcc, yAcc, zAcc, writer, output, projPoint,
trans = transform({source: srcPrj, target: tgtPrj});
trans;

if (!cache.hasOwnProperty(srcPrj) || !cache[srcPrj].hasOwnProperty(tgtPrj)) {
cache[srcPrj] = cache[srcPrj] || {};
cache[srcPrj][tgtPrj] = transform({source: srcPrj, target: tgtPrj});
}

trans = cache[srcPrj][tgtPrj];

/// Default Z accessor
zAcc = function () {
Expand Down

0 comments on commit 4d07cef

Please sign in to comment.