Commit a6fa0df4 authored by Kaitlyn's avatar Kaitlyn
Browse files

Added LayerCollection and AstroProj tests.

parent 93caee51
Loading
Loading
Loading
Loading
+1 −5
Original line number Diff line number Diff line
@@ -180,11 +180,7 @@ export default L.Map.AstroMap = L.Map.extend({
      this._currentProj = "EPSG:4326";
      this.setMaxZoom(8);
    } else {
      let proj = this._astroProj.getStringAndCode(
        this._target,
        name,
        this._radii
      );
      let proj = this._astroProj.getStringAndCode(name, this._radii);
      newCRS = new L.Proj.CRS(proj["code"], proj["string"], {
        resolutions: [8192, 4096, 2048, 1024, 512, 256, 128]
      });
+2 −8
Original line number Diff line number Diff line
@@ -10,14 +10,12 @@ export default class AstroProj {
   * @function AstroProj.prototype.getStringAndCode
   * @description Returns the proj-string for a requested target and projection name.
   *
   * @param {String} target - Name of the target.
   *
   * @param {String} name - Name of the projection.
   *
   * @return {Object} Object storing the proj-string and code
   *                  in the form: {'code': , 'string'}.
   */
  getStringAndCode(target, name, radii) {
  getStringAndCode(name, radii) {
    if (name == "northPolar") {
      return {
        code: "EPSG:32661",
@@ -45,11 +43,7 @@ export default class AstroProj {
          "+proj=longlat +a=" + radii["a"] + " +b=" + radii["c"] + " +no_defs"
      };
    } else {
      throw "No projection found for the target [" +
        target +
        "] and the projection [" +
        name +
        "] given.";
      throw "No projection found for the projection [" + name + "] given.";
    }
  }
}
+21 −0
Original line number Diff line number Diff line
@@ -26,6 +26,9 @@ export default L.LayerCollection = L.Class.extend({
    L.LayerCollection.layerControl = null;

    this.createBaseLayers(layerInfo["base"]);
    if (this.isEmpty()) {
      throw "No base layers created. At least one base layer is needed.";
    }
    this.createOverlays(layerInfo["overlays"]);
  },

@@ -142,6 +145,24 @@ export default L.LayerCollection = L.Class.extend({
    return Object.entries(this._baseLayers).length == 0;
  },

  /**
   * @function LayerCollection.prototype.baseLayers
   * @description Returns the list of base layers.
   * @return {List} List of WMS base layers.
   */
  baseLayers: function() {
    return this._baseLayers;
  },

  /**
   * @function LayerCollection.prototype.overlays
   * @description Returns the list of base layers.
   * @return {List} List of WMS base layers.
   */
  overlays: function() {
    return this._overlays;
  },

  /**
   * @function LayerCollection.prototype.loadWFS
   * @description  Creates the GeoServer query, queries GeoServer for the feature names, and adds the data to the GeoJSON layer.
+1 −1
Original line number Diff line number Diff line
@@ -102,7 +102,7 @@ describe("AstroMap", function() {
      expect(function() {
        testMap.changeProjection("invalidProjection", [90, 0]);
      }).to.throw(
        "No projection found for the target [Mars] and the projection [invalidProjection] given."
        "No projection found for the projection [invalidProjection] given."
      );
    });
  });
+45 −0
Original line number Diff line number Diff line
import "jsdom-global/register";
import jsdom from "mocha-jsdom";
import AstroProj from "../src/js/AstroProj";
import { expect } from "chai";

describe("AstroProj", function() {
  it("should return a proj-code and proj-string for a cylindrical projection", function() {
    let testProj = new AstroProj();
    expect(testProj).to.be.an("Object");
    expect(
      testProj.getStringAndCode("cylindrical", { a: 1, c: 2 })["string"]
    ).to.equal("+proj=longlat +a=1 +b=2 +no_defs");
  });

  it("should return a proj-code and proj-string for a north polar projection", function() {
    let testProj = new AstroProj();
    expect(testProj).to.be.an("Object");
    expect(
      testProj.getStringAndCode("northPolar", { a: 1, c: 2 })["string"]
    ).to.equal(
      "+proj=stere +lat_0=90 +lon_0=0 +k=1 +x_0=0 +y_0=0 +a=1 +b=2 +units=m +no_defs"
    );
  });

  it("should return a proj-code and proj-string for a south polar projection", function() {
    let testProj = new AstroProj();
    expect(testProj).to.be.an("Object");
    expect(
      testProj.getStringAndCode("southPolar", { a: 1, c: 2 })["string"]
    ).to.equal(
      "+proj=stere +lat_0=-90 +lon_0=0 +k=1 +x_0=0 +y_0=0 +a=1 +b=2 +units=m +no_defs"
    );
  });

  it("should throw an exception for an unsupported projection.", function() {
    let testProj = new AstroProj();
    expect(testProj).to.be.an("Object");

    expect(function() {
      testProj.getStringAndCode("invalidProjection", { a: 1, c: 2 });
    }).to.throw(
      "No projection found for the projection [invalidProjection] given."
    );
  });
});
Loading