Proj.js 846 B

123456789101112131415161718192021222324252627282930313233
  1. var parseCode = require("./parseCode");
  2. var extend = require('./extend');
  3. var projections = require('./projections');
  4. var deriveConstants = require('./deriveConstants');
  5. function Projection(srsCode,callback) {
  6. if (!(this instanceof Projection)) {
  7. return new Projection(srsCode);
  8. }
  9. callback = callback || function(error){
  10. if(error){
  11. throw error;
  12. }
  13. };
  14. var json = parseCode(srsCode);
  15. if(typeof json !== 'object'){
  16. callback(srsCode);
  17. return;
  18. }
  19. var modifiedJSON = deriveConstants(json);
  20. var ourProj = Projection.projections.get(modifiedJSON.projName);
  21. if(ourProj){
  22. extend(this, modifiedJSON);
  23. extend(this, ourProj);
  24. this.init();
  25. callback(null, this);
  26. }else{
  27. callback(srsCode);
  28. }
  29. }
  30. Projection.projections = projections;
  31. Projection.projections.start();
  32. module.exports = Projection;