Merge pull request #4017 from ahocevar/protect-proj-registry

Do not overwrite projections in the registry simply by using `new ol.proj.Projection()`
This commit is contained in:
Andreas Hocevar
2015-08-19 13:17:33 +02:00
2 changed files with 14 additions and 3 deletions

View File

@@ -141,8 +141,10 @@ ol.proj.Projection = function(options) {
*/
this.defaultTileGrid_ = null;
if (ol.ENABLE_PROJ4JS && typeof proj4 == 'function') {
var code = options.code;
var projections = ol.proj.projections_;
var code = options.code;
if (ol.ENABLE_PROJ4JS && typeof proj4 == 'function' &&
!goog.isDef(projections[code])) {
var def = proj4.defs(code);
if (goog.isDef(def)) {
if (goog.isDef(def.axis) && !goog.isDef(options.axisOrientation)) {
@@ -158,7 +160,6 @@ ol.proj.Projection = function(options) {
}
this.units_ = units;
}
var projections = ol.proj.projections_;
var currentCode, currentDef, currentProj, proj4Transform;
for (currentCode in projections) {
currentDef = proj4.defs(currentCode);

View File

@@ -299,6 +299,16 @@ describe('ol.proj', function() {
}
});
it('does not overwrite existing projections in the registry', function() {
var epsg4326 = ol.proj.get('EPSG:4326');
new ol.proj.Projection({
code: 'EPSG:4326',
units: 'degrees',
extent: [-45, -45, 45, 45]
});
expect(ol.proj.get('EPSG:4326')).to.equal(epsg4326);
});
});
describe('ol.proj.getTransformFromProjections()', function() {