Commit b4cffec5 authored by Kaitlyn's avatar Kaitlyn
Browse files

Added ProjectionControl test and renamed control classes.

parent a6fa0df4
Loading
Loading
Loading
Loading
+16 −13
Original line number Diff line number Diff line
import React, { Component } from "react";
import AstroMap from "../../js/AstroMap";
import Projection from "../../js/Projection";
import MousePosition from "../../js/MousePosition";
import ProjectionControl from "../../js/ProjectionControl";
import MousePositionControl from "../../js/MousePositionControl";
import Draw from "../../js/Draw";
import "leaflet";
//import newAutocomplete from "../../js/autocomplete/customIndex";
@@ -31,10 +31,12 @@ export default class MapContainer extends Component {
   */
  componentDidMount() {
    let map = new AstroMap("map-container", this.props.target, {});
    new Projection().addTo(map);
    new MousePosition({
    map.addControl(new ProjectionControl());
    map.addControl(
      new MousePositionControl({
        numDigits: 3
    }).addTo(map);
      })
    );

    let drawnItems = new L.FeatureGroup();
    map.addLayer(drawnItems);
@@ -51,7 +53,7 @@ export default class MapContainer extends Component {
      targetMap: map
    }).addTo(map);

    new L.Control.Scale({ imperial: false }).addTo(map);
    map.addControl(new L.Control.Scale({ imperial: false }));

    //new newAutocomplete();
  }
@@ -78,11 +80,12 @@ export default class MapContainer extends Component {

    // create new map with updated target
    let map = new AstroMap("map-container", this.props.target, {});
    new Projection().addTo(map);
    new MousePosition({
      numDigits: 2,
      targetPlanet: this.props.target
    }).addTo(map);
    map.addControl(new ProjectionControl());
    map.addControl(
      new MousePositionControl({
        numDigits: 3
      })
    );

    let drawnItems = new L.FeatureGroup();
    map.addLayer(drawnItems);
@@ -99,7 +102,7 @@ export default class MapContainer extends Component {
      targetMap: map
    }).addTo(map);

    new L.Control.Scale({ imperial: false }).addTo(map);
    map.addControl(new L.Control.Scale({ imperial: false }));
  }

  render() {
+14 −14
Original line number Diff line number Diff line
@@ -3,8 +3,8 @@ import "leaflet";
import L from "leaflet";

/**
 * @class MousePosition
 * @aka L.Control.AstroMousePosition
 * @class MousePositionControl
 * @aka L.Control.MousePositionControl
 * @extends L.Control
 *
 * @classdesc Class that inherits from the class L.Control and handles the back-end when a user clicks on the lat/lon buttons.
@@ -12,11 +12,11 @@ import L from "leaflet";
 *
 * @example
 * // initialize the control with an options object.
 * mouseControl = L.astroMousePosition({numDigits: 2, prefix: "Lat Lon: ",targetPlanet: "mars"});
 * mouseControl = L.MousePositionControl({numDigits: 2, prefix: "Lat Lon: ",targetPlanet: "mars"});
 * // add control to map
 * mouseControl.addTo(map);
 */
export default L.Control.MousePosition = L.Control.extend({
export default L.Control.MousePositionControl = L.Control.extend({
  options: {
    separator: ", ",
    numDigits: 5,
@@ -25,7 +25,7 @@ export default L.Control.MousePosition = L.Control.extend({
  },

  /**
   * @function MousePosition.prototype.onAdd
   * @function MousePositionControl.prototype.onAdd
   * @description Grabs the lat/lon buttons from the GUI and adds on-change events to them. It also adds an on mouse-over event to the AstroMap to grab the current mouse position of the user's mouse pointer.
   * @param  {AstroMap} map - The AstroMap to add the control to.
   * @return {Object} The div-container the control is in.
@@ -77,7 +77,7 @@ export default L.Control.MousePosition = L.Control.extend({
  },

  /**
   * @function MousePosition.prototype.changeLonDomain
   * @function MousePositionControl.prototype.changeLonDomain
   * @description Is called when a user changes the longitude domain selector. Changes the longitude domain class variable to false if 0 to 360 is selected and true if -180 to 180 is selected.
   * @param  {DomEvent} e  - On change of consoleLonDomSelect.
   */
@@ -86,7 +86,7 @@ export default L.Control.MousePosition = L.Control.extend({
  },

  /**
   * @function MousePosition.prototype.changeLatType
   * @function MousePositionControl.prototype.changeLatType
   * @description Is called when a user changes the latitude type selector. Changes the latitude type class variable to false if planetographic is selected and true if isLatTypeOcentric is selected.
   * @param  {DomEvent} e - On change of consoleLatTypeSelect.
   */
@@ -95,7 +95,7 @@ export default L.Control.MousePosition = L.Control.extend({
  },

  /**
   * @function MousePosition.prototype.changeLonDirection
   * @function MousePositionControl.prototype.changeLonDirection
   * @description Is called when a user changes the longitude direction selector. Changes the longitude direction class variable to false if positive west is selected and true if positive east is selected.
   * @param  {DomEvent} e - On change of consoleLonDirSelect.
   */
@@ -104,7 +104,7 @@ export default L.Control.MousePosition = L.Control.extend({
  },

  /**
   * @function MousePosition.prototype.onRemove
   * @function MousePositionControl.prototype.onRemove
   * @description Is called when a user unselects a map.
   * @param  {AstroMap} map - The AstroMap to remove the control from.
   */
@@ -113,7 +113,7 @@ export default L.Control.MousePosition = L.Control.extend({
  },

  /**
   * @function MousePosition.prototype.onMouseMove
   * @function MousePositionControl.prototype.onMouseMove
   * @description Is called when a user moves their mouse over the AstroMap. The function uses the class latitude and longitude class variables combined with the AstroMath class to calculate the correct coordinate mouse position of the users mouse pointer.
   * @param  {DomEvent} e - On mouse move over the AstroMap.
   */
@@ -147,7 +147,7 @@ export default L.Control.MousePosition = L.Control.extend({
    }
  },
  /**
   * @function MousePosition.prototype.onMouseOut
   * @function MousePositionControl.prototype.onMouseOut
   * @description Displays lat lon on mouse.
   * @param  {DomEvent} e - On mouse out.
   */
@@ -158,7 +158,7 @@ export default L.Control.MousePosition = L.Control.extend({
});

/**
 * @function MousePosition.prototype.mergeOptions
 * @function MousePositionControl.prototype.mergeOptions
 * @aka L.Map.mergeOptions
 * @description Turns position control false.
 */
@@ -167,7 +167,7 @@ L.Map.mergeOptions({
});

/**
 * @function MousePosition.prototype.addInitHook
 * @function MousePositionControl.prototype.addInitHook
 * @aka L.Map.addInitHook
 * @description Adds position control.
 */
@@ -179,7 +179,7 @@ L.Map.addInitHook(function() {
});

/**
 * @function MousePosition.prototype.mousePosition
 * @function MousePositionControl.prototype.mousePosition
 * @aka L.mousePosition
 * @description Gets mouse position.
 * @return {Object} Mouse position.
+11 −14
Original line number Diff line number Diff line
import "leaflet";
import L from "leaflet";
/**
 * @class Projection
 * @aka L.Control.Projection
 * @class ProjectionControl
 * @aka L.Control.ProjectionControl
 * @inherits L.Control
 *
 * @classdesc Control that allows users to change the projection of the map. Uses predefined GUI elements.
 */
export default L.Control.Projection = L.Control.extend({
export default L.Control.ProjectionControl = L.Control.extend({
  /**
   * @function Projection.prototype.onAdd
   * @function ProjectionControl.prototype.onAdd
   * @description Grabs the button GUI elements and adds onclick events to them.
   * @param  {AstroMap} map - The map to add the control to.
   * @return {Div} Container containing the projection buttons.
@@ -35,31 +35,28 @@ export default L.Control.Projection = L.Control.extend({
  },

  /**
   * @function Projection.prototype.loadNorthPolar
   * @function ProjectionControl.prototype.loadNorthPolar
   * @description Sets the map's projection to north-polar stereographic.
   * @param  {Event} e - Onclick event.
   */
  loadNorthPolar: function(e) {
  loadNorthPolar: function() {
    let center = [90, 0];
    this._map.changeProjection("northPolar", center);
  },

  /**
   * @function Projection.prototype.loadSouthPolar
   * @function ProjectionControl.prototype.loadSouthPolar
   * @description Sets the map's projection to south-polar stereographic.
   * @param  {Event} e - Onclick event.
   */
  loadSouthPolar: function(e) {
  loadSouthPolar: function() {
    let center = [-90, 0];
    this._map.changeProjection("southPolar", center);
  },

  /**
   * @function Projection.prototype.loadCylindrical
   * @function ProjectionControl.prototype.loadCylindrical
   * @description Sets the map's projection to cylindrical.
   * @param  {Event} e - Onclick event.
   */
  loadCylindrical: function(e) {
  loadCylindrical: function() {
    let center = [0, 0];
    this._map.changeProjection("cylindrical", center);
  }

app/test/AstroMath_test.js

deleted100644 → 0
+0 −86
Original line number Diff line number Diff line
import 'jsdom-global/register';
import AstroMath from '../src/js/AstroMath';
import { expect } from "chai";

// global class AstroMath variable
let testMath = new AstroMath("mars");

describe('Testing AstroMath Functions', function() {

  // testing AstroMath created a class object
  it('Testing AstroMath Object', function() {
    // add an assertion
    
    expect(testMath).to.be.an('Object');
  })

  // testing getMajorRadius function
  it('Testing getMajorRadius: Mars should be 3396190', function() {
    // add an assertion
    let majorRadius = testMath.getMajorRadius();
    expect(majorRadius).to.equal(3396190);
  })

  // testing getMinorRadius function
  it('Testing getMinorRadius: Mars should be 3376200', function() {
    // add an assertion
    let majorRadius = testMath.getMinorRadius();
    expect(majorRadius).to.equal(3376200);
  })

  // testing toRadians function
  it('Testing toRadians: 360 degrees should be 2pi', function() {
    // add an assertion
    let majorRadius = testMath.toRadians(360);
    expect(majorRadius).to.be.closeTo((2*Math.PI), 0.01);
  })

    // testing toDegrees function
    it('Testing toDegrees: 2pi degrees should be 360', function() {
      // add an assertion
      let majorRadius = testMath.toDegrees((2*Math.PI));
      expect(majorRadius).to.be.closeTo(360, 1);
    })

    // testing latToPlanetOgraphic function
    it('Testing latToPlanetOgraphic: 80 should be 80.11504513783566 ', function() {
      // add an assertion
      let majorRadius = testMath.latToPlanetOgraphic(80);
      expect(majorRadius).to.equal(80.11504513783566);
    })

    // testing lonTo360 function
    it('Testing lonTo360 Cylindrical: 0 should be 180 ', function() {
      // add an assertion
      let majorRadius = testMath.lonTo360(0, "EPSG:4326");
      expect(majorRadius).to.equal(180);
    })

    // testing lonTo360 function
    it('Testing lonTo360 Non-Cylindrical: -180 should be 0 ', function() {
      // add an assertion
      let majorRadius = testMath.lonTo360(-180, "");
      expect(majorRadius).to.equal(0);
    })

    // testing domainToPositiveWest function
    it('Testing domainToPositiveWest Normal Range: -180 should be 180 ', function() {
      // add an assertion
      let majorRadius = testMath.domainToPositiveWest(-180, true);
      expect(majorRadius).to.equal(180);
    })

    // testing domainToPositiveWest function
    it('Testing domainToPositiveWest Not Normal Range: 0 should be 360 ', function() {
      // add an assertion
      let majorRadius = testMath.domainToPositiveWest(0, false);
      expect(majorRadius).to.equal(360);
    })

    // testing wrapLongitude function
    it('Testing wrapLongitude: 360 should be 0 ', function() {
      // add an assertion
      let majorRadius = testMath.wrapLongitude(360);
      expect(majorRadius).to.equal(0);
    })
});
 No newline at end of file
+84 −0
Original line number Diff line number Diff line
import "jsdom-global/register";
import jsdom from "mocha-jsdom";
import ProjectionControl from "../src/js/ProjectionControl";
import AstroMap from "../src/js/AstroMap";
import { expect } from "chai";
import L from "leaflet";

describe("ProjectionControl", function() {
  let testMap;
  let northPoleButton;
  let southPoleButton;
  let cylindricalButton;
  let testControl;

  beforeEach(function() {
    testMap = new AstroMap(document.createElement("div"), "Mars", {});
    northPoleButton = document.createElement("div");
    northPoleButton.id = "projectionNorthPole";
    document.body.appendChild(northPoleButton);

    southPoleButton = document.createElement("div");
    southPoleButton.id = "projectionSouthPole";
    document.body.appendChild(southPoleButton);

    cylindricalButton = document.createElement("div");
    cylindricalButton.id = "projectionCylindrical";
    document.body.appendChild(cylindricalButton);

    testControl = new ProjectionControl();
  });

  afterEach(function() {
    northPoleButton.remove();
    southPoleButton.remove();
    cylindricalButton.remove();
    testControl.remove();
    testMap.remove();
  });

  it("should add the control to the map", function() {
    let returnMap = testMap.addControl(testControl);
    // Since we do not add the projection buttons to a container and return that container,
    // the only way to test if a control was added to a map correctly is if the map is returned.
    expect(returnMap).to.equal(testMap);
  });

  it("should change the projection of the map to north polar and back to cylindrical", function() {
    testMap.addControl(testControl);
    testControl.loadNorthPolar();
    expect(testMap.projection()).to.equal("EPSG:32661");

    testControl.loadCylindrical();
    expect(testMap.projection()).to.equal("EPSG:4326");
  });

  it("should change the projection of the map to south polar", function() {
    testMap.addControl(testControl);
    testControl.loadSouthPolar();
    expect(testMap.projection()).to.equal("EPSG:32761");

    testControl.loadCylindrical();
    expect(testMap.projection()).to.equal("EPSG:4326");
  });

  it("should change the projection of the map to north polar, then so south polar", function() {
    testMap.addControl(testControl);

    testControl.loadNorthPolar();
    expect(testMap.projection()).to.equal("EPSG:32661");

    testControl.loadSouthPolar();
    expect(testMap.projection()).to.equal("EPSG:32761");
  });

  it("should change the projection of the map to south polar, then so north polar", function() {
    testMap.addControl(testControl);

    testControl.loadSouthPolar();
    expect(testMap.projection()).to.equal("EPSG:32761");

    testControl.loadNorthPolar();
    expect(testMap.projection()).to.equal("EPSG:32661");
  });
});