Commit 775d07d4 authored by Andreas Hocevar's avatar Andreas Hocevar
Browse files

Work with proj4.defs through the function only

parent 74aeff0d
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -104,7 +104,13 @@ instead of writing out the whole proj definition, by default proj4 has the follo
    - 'EPSG:900913'
    - 'EPSG:102113'

defined projections can also be accessed as properties of the proj4.defs function (`proj4.defs['EPSG:4326']`).
defined projections can also be accessed through the proj4.defs function (`proj4.defs('EPSG:4326')`).

proj4.defs can also be used to define a named alias:

```javascript
proj4.defs('urn:x-ogc:def:crs:EPSG:4326', proj4.defs('EPSG:4326'));
``` 

##Developing
to set up build tools make sure you have node and grunt-cli installed and then run `npm install`
+13 −6
Original line number Diff line number Diff line
@@ -6,12 +6,17 @@ function defs(name) {
  /*global console*/
  var that = this;
  if (arguments.length === 2) {
    if (arguments[1][0] === '+') {
    var def = arguments[1];
    if (typeof def === 'string') {
      if (def[0] === '+') {
        defs[name] = parseProj(arguments[1]);
      }
      else {
        defs[name] = wkt(arguments[1]);
      }
    } else {
      defs[name] = def;
    }
  }
  else if (arguments.length === 1) {
    if (Array.isArray(name)) {
@@ -25,7 +30,9 @@ function defs(name) {
      });
    }
    else if (typeof name === 'string') {

      if (name in defs) {
        return defs[name];
      }
    }
    else if ('EPSG' in name) {
      defs['EPSG:' + name.EPSG] = name;
+7 −0
Original line number Diff line number Diff line
@@ -159,6 +159,13 @@ function startTests(chai, proj4, testPoints) {
        });
      });
    });
    describe('defs', function() {
      assert.equal(proj4.defs('testmerc'), proj4.defs['testmerc']);
      proj4.defs('foo', '+proj=merc +lon_0=5.937 +lat_ts=45.027 +ellps=sphere +datum=none');
      assert.typeOf(proj4.defs['foo'], 'object');
      proj4.defs('urn:x-ogc:def:crs:EPSG:4326', proj4.defs('EPSG:4326'));
      assert.strictEqual(proj4.defs['urn:x-ogc:def:crs:EPSG:4326'], proj4.defs['EPSG:4326']);
    });
    describe('errors', function() {
      it('should throw an error for an unknown ref', function() {
        assert.throws(function() {