Skip to content

Commit

Permalink
Refactored L.Proj.Projection
Browse files Browse the repository at this point in the history
  • Loading branch information
perliedman committed Nov 29, 2013
1 parent f2ee7b2 commit e086dde
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions src/proj4leaflet.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,10 @@
};

L.Proj.Projection = L.Class.extend({
initialize: function(a, def, bounds) {
if (L.Proj._isProj4Obj(a)) {
this._proj = a;
bounds = def;
} else {
var code = a;
if (def) {
proj4.defs(code, def);
} else if (proj4.defs[code] === undefined) {
var urn = code.split(':');
if (urn.length > 3) {
code = urn[urn.length - 3] + ':' + urn[urn.length - 1];
}
if (proj4.defs[code] === undefined) {
throw 'No projection definition for code ' + code;
}
}
this._proj = proj4(code);
}

this.bounds = bounds;
initialize: function(code, def, bounds) {
var isP4 = L.Proj._isProj4Obj(code);
this._proj = isP4 ? code : this._projFromCodeDef(code, def);
this.bounds = isP4 ? def : bounds;
},

project: function (latlng) {
Expand All @@ -55,6 +38,22 @@
unproject: function (point, unbounded) {
var point2 = this._proj.inverse([point.x, point.y]);
return new L.LatLng(point2[1], point2[0], unbounded);
},

_projFromCodeDef: function(code, def) {
if (def) {
proj4.defs(code, def);
} else if (proj4.defs[code] === undefined) {
var urn = code.split(':');
if (urn.length > 3) {
code = urn[urn.length - 3] + ':' + urn[urn.length - 1];
}
if (proj4.defs[code] === undefined) {
throw 'No projection definition for code ' + code;
}
}

return proj4(code);
}
});

Expand All @@ -66,7 +65,10 @@
},

initialize: function(a, b, c) {
var code, proj, def, options;
var code,
proj,
def,
options;

if (L.Proj._isProj4Obj(a)) {
proj = a;
Expand Down

0 comments on commit e086dde

Please sign in to comment.