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:
+4
-3
@@ -141,8 +141,10 @@ ol.proj.Projection = function(options) {
|
|||||||
*/
|
*/
|
||||||
this.defaultTileGrid_ = null;
|
this.defaultTileGrid_ = null;
|
||||||
|
|
||||||
if (ol.ENABLE_PROJ4JS && typeof proj4 == 'function') {
|
var projections = ol.proj.projections_;
|
||||||
var code = options.code;
|
var code = options.code;
|
||||||
|
if (ol.ENABLE_PROJ4JS && typeof proj4 == 'function' &&
|
||||||
|
!goog.isDef(projections[code])) {
|
||||||
var def = proj4.defs(code);
|
var def = proj4.defs(code);
|
||||||
if (goog.isDef(def)) {
|
if (goog.isDef(def)) {
|
||||||
if (goog.isDef(def.axis) && !goog.isDef(options.axisOrientation)) {
|
if (goog.isDef(def.axis) && !goog.isDef(options.axisOrientation)) {
|
||||||
@@ -158,7 +160,6 @@ ol.proj.Projection = function(options) {
|
|||||||
}
|
}
|
||||||
this.units_ = units;
|
this.units_ = units;
|
||||||
}
|
}
|
||||||
var projections = ol.proj.projections_;
|
|
||||||
var currentCode, currentDef, currentProj, proj4Transform;
|
var currentCode, currentDef, currentProj, proj4Transform;
|
||||||
for (currentCode in projections) {
|
for (currentCode in projections) {
|
||||||
currentDef = proj4.defs(currentCode);
|
currentDef = proj4.defs(currentCode);
|
||||||
|
|||||||
@@ -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() {
|
describe('ol.proj.getTransformFromProjections()', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user