diff --git a/src/js/models/filters/SpatialFilter.js b/src/js/models/filters/SpatialFilter.js index 6d2e9719e..c49573c52 100644 --- a/src/js/models/filters/SpatialFilter.js +++ b/src/js/models/filters/SpatialFilter.js @@ -101,15 +101,25 @@ define([ } }, + /** + * Remove the listeners. + * @since x.x.x + */ + removeListeners: function () { + const extentEvents = + "change:height change:north change:south change:east change:west"; + this.stopListening(this, extentEvents); + }, + /** * Set a listener that updates the filter when the coordinates & height * change * @since 2.25.0 */ setListeners: function () { + this.removeListeners(); const extentEvents = "change:height change:north change:south change:east change:west"; - this.stopListening(this, extentEvents); this.listenTo(this, extentEvents, this.updateFilterFromExtent); }, @@ -318,7 +328,13 @@ define([ * @inheritdoc */ resetValue: function () { - const df = this.defaults(); + // Need to stop listeners because otherwise changing the coords will + // update the filter values. This sometimes updates the values *after* + // the values are reset, preventing the reset from working. + this.removeListeners(); + + let df = this.defaults(); + this.set({ values: df.values, east: df.east, @@ -327,6 +343,9 @@ define([ south: df.south, height: df.height, }); + + // Reset the listeners + this.setListeners(); }, } ); diff --git a/src/js/models/maps/Geohash.js b/src/js/models/maps/Geohash.js index 4f9e865a2..cb213dc65 100644 --- a/src/js/models/maps/Geohash.js +++ b/src/js/models/maps/Geohash.js @@ -316,9 +316,9 @@ define([ }, properties: properties, }; - if (label) { + if (label && (properties[label] || properties[label] === 0)) { (feature["label"] = { - text: properties[label].toString(), + text: properties[label]?.toString(), show: true, fillColor: { rgba: [255, 255, 255, 255], diff --git a/src/js/models/maps/assets/CesiumGeohash.js b/src/js/models/maps/assets/CesiumGeohash.js index 499a716f5..ed4c0a4b6 100644 --- a/src/js/models/maps/assets/CesiumGeohash.js +++ b/src/js/models/maps/assets/CesiumGeohash.js @@ -154,7 +154,7 @@ define([ const limit = this.get("maxGeoHashes"); const geohashes = this.get("geohashes") const area = this.getViewExtent().getArea(); - return this.get("geohashes").getMaxPrecision(area, limit); + return geohashes.getMaxPrecision(area, limit); }, /** diff --git a/test/config/tests.json b/test/config/tests.json index a668b5fd9..e45233660 100644 --- a/test/config/tests.json +++ b/test/config/tests.json @@ -1,5 +1,11 @@ { "unit": [ + "./js/specs/unit/collections/maps/GeoPoints.spec.js", + "./js/specs/unit/models/connectors/GeoPoints-Cesium.spec.js", + "./js/specs/unit/models/connectors/GeoPoints-CesiumPoints.spec.js", + "./js/specs/unit/models/connectors/GeoPoints-CesiumPolygon.spec.js", + "./js/specs/unit/models/maps/GeoBoundingBox.spec.js", + "./js/specs/unit/models/maps/GeoUtilities.spec.js", "./js/specs/unit/collections/SolrResults.spec.js", "./js/specs/unit/models/Search.spec.js", "./js/specs/unit/models/filters/Filter.spec.js", diff --git a/test/js/specs/unit/collections/maps/GeoPoints.spec.js b/test/js/specs/unit/collections/maps/GeoPoints.spec.js new file mode 100644 index 000000000..17f5feba5 --- /dev/null +++ b/test/js/specs/unit/collections/maps/GeoPoints.spec.js @@ -0,0 +1,21 @@ +define([ + "../../../../../../../../src/js/collections/maps/GeoPoints", +], function (GeoPoints) { + // Configure the Chai assertion library + var should = chai.should(); + var expect = chai.expect; + + describe("GeoPoints Test Suite", function () { + /* Set up */ + beforeEach(function () {}); + + /* Tear down */ + afterEach(function () {}); + + describe("Initialization", function () { + it("should create a GeoPoints instance", function () { + new GeoPoints().should.be.instanceof(GeoPoints); + }); + }); + }); +}); \ No newline at end of file diff --git a/test/js/specs/unit/collections/maps/Geohashes.spec.js b/test/js/specs/unit/collections/maps/Geohashes.spec.js index e711ed40b..63d1d82f6 100644 --- a/test/js/specs/unit/collections/maps/Geohashes.spec.js +++ b/test/js/specs/unit/collections/maps/Geohashes.spec.js @@ -58,44 +58,9 @@ define(["../../../../../../../../src/js/collections/maps/Geohashes"], function ( .validatePrecision([1, 2, 3]) .should.deep.equal([1, 2, 3]); }); - - it("should validate a valid bounding box", function () { - const bounds = { north: 80, south: -80, east: 170, west: 160 }; - this.geohashes.boundsAreValid(bounds).should.be.true; - }); - - it("should invalidate a bounding box with invalid bounds", function () { - const bounds = { north: 80, south: -80, east: 170, west: 190 }; - this.geohashes.boundsAreValid(bounds).should.be.false; - }); - - it("should invalidate a bounding box with missing bounds", function () { - const bounds = { north: 80, south: -80, east: 170 }; - this.geohashes.boundsAreValid(bounds).should.be.false; - }); - - it("should invalidate a bounding box with non-number bounds", function () { - const bounds = { north: 80, south: -80, east: 170, west: "west" }; - this.geohashes.boundsAreValid(bounds).should.be.false; - }); }); describe("Bounds", function () { - it("should split a bounding box that crosses the prime meridian", function () { - const bounds = { north: 80, south: -80, east: -170, west: 170 }; - const expected = [ - { north: 80, south: -80, east: 180, west: 170 }, - { north: 80, south: -80, east: -170, west: -180 }, - ]; - this.geohashes.splitBoundingBox(bounds).should.deep.equal(expected); - }); - - it("should not split a bounding box that does not cross the prime meridian", function () { - const bounds = { north: 80, south: -80, east: 170, west: 160 }; - const expected = [{ north: 80, south: -80, east: 170, west: 160 }]; - this.geohashes.splitBoundingBox(bounds).should.deep.equal(expected); - }); - it("should get the area of a geohash tile", function () { const precision = 5; const expected = 0.0019311904907226562; @@ -117,18 +82,6 @@ define(["../../../../../../../../src/js/collections/maps/Geohashes"], function ( .getGeohashAreas(minPrecision, maxPrecision) .should.deep.equal(expected); }); - - it("should get the area of the world", function () { - const bounds = { north: 90, south: -90, east: 180, west: -180 }; - const expected = 360 * 180; - this.geohashes.getBoundingBoxArea(bounds).should.equal(expected); - }); - - it("should get the area of a small bounding box", function () { - const bounds = { north: 45, south: 44, east: 45, west: 44 }; - const expected = 1; - this.geohashes.getBoundingBoxArea(bounds).should.equal(expected); - }); }); describe("Precision", function () { diff --git a/test/js/specs/unit/models/connectors/Filters-Map.spec.js b/test/js/specs/unit/models/connectors/Filters-Map.spec.js index bd14a86dc..9c97a3475 100644 --- a/test/js/specs/unit/models/connectors/Filters-Map.spec.js +++ b/test/js/specs/unit/models/connectors/Filters-Map.spec.js @@ -52,7 +52,7 @@ define([ const map = this.filtersMap.get("map"); const spatialFilters = this.filtersMap.get("spatialFilters"); const extent = { north: 1, south: 2, east: 3, west: 4 }; - map.set("currentViewExtent", extent); + map.get("interactions").setViewExtent(extent); this.filtersMap.updateSpatialFilters(); spatialFilters[0].get("north").should.equal(1); spatialFilters[0].get("south").should.equal(2); @@ -80,6 +80,6 @@ define([ const spatialFilters = this.filtersMap.get("spatialFilters"); spatialFilters[0].get("values").should.deep.equal([]); }); - }); + }); }); }); diff --git a/test/js/specs/unit/models/connectors/GeoPoints-Cesium.spec.js b/test/js/specs/unit/models/connectors/GeoPoints-Cesium.spec.js new file mode 100644 index 000000000..5901a1c82 --- /dev/null +++ b/test/js/specs/unit/models/connectors/GeoPoints-Cesium.spec.js @@ -0,0 +1,21 @@ +define([ + "../../../../../../../../src/js/models/connectors/GeoPoints-Cesium", +], function (GeoPointsCesium) { + // Configure the Chai assertion library + var should = chai.should(); + var expect = chai.expect; + + describe("GeoPointsCesium Test Suite", function () { + /* Set up */ + beforeEach(function () {}); + + /* Tear down */ + afterEach(function () {}); + + describe("Initialization", function () { + it("should create a GeoPointsCesium instance", function () { + new GeoPointsCesium().should.be.instanceof(GeoPointsCesium); + }); + }); + }); +}); \ No newline at end of file diff --git a/test/js/specs/unit/models/connectors/GeoPoints-CesiumPoints.spec.js b/test/js/specs/unit/models/connectors/GeoPoints-CesiumPoints.spec.js new file mode 100644 index 000000000..b948dd58b --- /dev/null +++ b/test/js/specs/unit/models/connectors/GeoPoints-CesiumPoints.spec.js @@ -0,0 +1,21 @@ +define([ + "../../../../../../../../src/js/models/connectors/GeoPoints-CesiumPoints", +], function (GeoPointsCesiumPoints) { + // Configure the Chai assertion library + var should = chai.should(); + var expect = chai.expect; + + describe("GeoPointsCesiumPoints Test Suite", function () { + /* Set up */ + beforeEach(function () {}); + + /* Tear down */ + afterEach(function () {}); + + describe("Initialization", function () { + it("should create a GeoPointsCesiumPoints instance", function () { + new GeoPointsCesiumPoints().should.be.instanceof(GeoPointsCesiumPoints); + }); + }); + }); +}); \ No newline at end of file diff --git a/test/js/specs/unit/models/connectors/GeoPoints-CesiumPolygon.spec.js b/test/js/specs/unit/models/connectors/GeoPoints-CesiumPolygon.spec.js new file mode 100644 index 000000000..f5ae3e006 --- /dev/null +++ b/test/js/specs/unit/models/connectors/GeoPoints-CesiumPolygon.spec.js @@ -0,0 +1,21 @@ +define([ + "../../../../../../../../src/js/models/connectors/GeoPoints-CesiumPolygon", +], function (GeoPointsCesiumPolygon) { + // Configure the Chai assertion library + var should = chai.should(); + var expect = chai.expect; + + describe("GeoPointsCesiumPolygon Test Suite", function () { + /* Set up */ + beforeEach(function () {}); + + /* Tear down */ + afterEach(function () {}); + + describe("Initialization", function () { + it("should create a GeoPointsCesiumPolygon instance", function () { + new GeoPointsCesiumPolygon().should.be.instanceof(GeoPointsCesiumPolygon); + }); + }); + }); +}); \ No newline at end of file diff --git a/test/js/specs/unit/models/maps/GeoBoundingBox.spec.js b/test/js/specs/unit/models/maps/GeoBoundingBox.spec.js new file mode 100644 index 000000000..d9553d8d2 --- /dev/null +++ b/test/js/specs/unit/models/maps/GeoBoundingBox.spec.js @@ -0,0 +1,21 @@ +define([ + "../../../../../../../../src/js/models/maps/GeoBoundingBox", +], function (GeoBoundingBox) { + // Configure the Chai assertion library + var should = chai.should(); + var expect = chai.expect; + + describe("GeoBoundingBox Test Suite", function () { + /* Set up */ + beforeEach(function () {}); + + /* Tear down */ + afterEach(function () {}); + + describe("Initialization", function () { + it("should create a GeoBoundingBox instance", function () { + new GeoBoundingBox().should.be.instanceof(GeoBoundingBox); + }); + }); + }); +}); \ No newline at end of file diff --git a/test/js/specs/unit/models/maps/GeoUtilities.spec.js b/test/js/specs/unit/models/maps/GeoUtilities.spec.js new file mode 100644 index 000000000..a643471f4 --- /dev/null +++ b/test/js/specs/unit/models/maps/GeoUtilities.spec.js @@ -0,0 +1,21 @@ +define([ + "../../../../../../../../src/js/models/maps/GeoUtilities", +], function (GeoUtilities) { + // Configure the Chai assertion library + var should = chai.should(); + var expect = chai.expect; + + describe("GeoUtilities Test Suite", function () { + /* Set up */ + beforeEach(function () {}); + + /* Tear down */ + afterEach(function () {}); + + describe("Initialization", function () { + it("should create a GeoUtilities instance", function () { + new GeoUtilities().should.be.instanceof(GeoUtilities); + }); + }); + }); +}); \ No newline at end of file diff --git a/test/js/specs/unit/models/maps/assets/CesiumGeohash.spec.js b/test/js/specs/unit/models/maps/assets/CesiumGeohash.spec.js index 9eab3db57..5cf58e9dd 100644 --- a/test/js/specs/unit/models/maps/assets/CesiumGeohash.spec.js +++ b/test/js/specs/unit/models/maps/assets/CesiumGeohash.spec.js @@ -1,8 +1,7 @@ define([ "../../../../../../../../src/js/models/maps/assets/CesiumGeohash", - "../../../../../../../../src/js/collections/maps/Geohashes", "../../../../../../../../src/js/models/maps/Map", -], function (CesiumGeohash, Geohashes) { +], function (CesiumGeohash, MapModel) { // Configure the Chai assertion library var should = chai.should(); var expect = chai.expect; @@ -10,7 +9,7 @@ define([ describe("CesiumGeohash Test Suite", function () { /* Set up */ beforeEach(function () { - this.map = new Map(); + this.map = new MapModel(); this.model = new CesiumGeohash(); this.model.set("mapModel", this.map); }); @@ -83,7 +82,9 @@ define([ it("should get the precision", function () { this.model.replaceGeohashes(); this.model.set("maxGeoHashes", 32); - this.map.set("currentViewExtent", { + console.log(this.map.attributes); + console.log(this.map.get("interactions")); + this.map.get("interactions").setViewExtent({ north: 90, south: -90, east: 180, diff --git a/test/js/specs/unit/models/maps/assets/CesiumImagery.spec.js b/test/js/specs/unit/models/maps/assets/CesiumImagery.spec.js index 2ddc8931e..8b6bf00b6 100644 --- a/test/js/specs/unit/models/maps/assets/CesiumImagery.spec.js +++ b/test/js/specs/unit/models/maps/assets/CesiumImagery.spec.js @@ -38,11 +38,9 @@ define([ describe("Creating the Cesium Model", function () { it("should convert list of degrees to a Cesium rectangle", function (done) { - const expectedRect = Cesium.Rectangle.fromDegrees(...boundingBox) imagery.whenReady().then(function (model) { - const rect = model.get("cesiumOptions").rectangle - const rectsEqual = Cesium.Rectangle.equals(rect, expectedRect) - rectsEqual.should.be.true + const rect = model.get("cesiumModel").rectangle + expect(rect.constructor.name).to.equal("Rectangle") done() }, function (error) { done(error)