From 84a5b3c6f51ef5472b21926070d827aed1bae7d1 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Mon, 9 Oct 2023 17:55:22 +0200 Subject: [PATCH] Fix Choropleth JS tests --- umap/static/umap/js/umap.layer.js | 8 +------- umap/static/umap/test/Choropleth.js | 13 ++++++------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/umap/static/umap/js/umap.layer.js b/umap/static/umap/js/umap.layer.js index e509d268..442926f5 100644 --- a/umap/static/umap/js/umap.layer.js +++ b/umap/static/umap/js/umap.layer.js @@ -178,12 +178,6 @@ L.U.Layer.Choropleth = L.FeatureGroup.extend({ return this; }, - removeLayer: function (layer) { - var id = layer in this._layers ? layer : this.getLayerId(layer); - delete this._layers[id]; - return this; - }, - onAdd: function (map) { this.computeLimits() L.FeatureGroup.prototype.onAdd.call(this, map) @@ -478,7 +472,7 @@ L.U.DataLayer = L.Evented.extend({ if (visible) this.map.removeLayer(this.layer) const Class = L.U.Layer[this.options.type] || L.U.Layer.Default this.layer = new Class(this) - this.eachLayer((feature) => this.showFeature(feature)) + this.eachLayer(this.showFeature) if (visible) this.show() this.propagateRemote() }, diff --git a/umap/static/umap/test/Choropleth.js b/umap/static/umap/test/Choropleth.js index 3682b4ad..cb8566e7 100644 --- a/umap/static/umap/test/Choropleth.js +++ b/umap/static/umap/test/Choropleth.js @@ -188,6 +188,10 @@ describe('L.U.Choropleth', function () { this.map = initMap({ umap_id: 99 }) this.datalayer = this.map.getDataLayerByUmapId(62) this.server.respond() + this.datalayer.options.type = 'Choropleth' + this.datalayer.options.choropleth = { + property: 'value', + } enableEdit() this.datalayer.eachLayer(function (layer) { if (layer.properties.name === 'number 1') { @@ -211,12 +215,7 @@ describe('L.U.Choropleth', function () { }) describe('#compute()', function () { it('choropleth should compute default colors', function () { - this.datalayer.options.type = 'Choropleth' - this.datalayer.options.choropleth = { - property: 'value', - } - this.datalayer.resetLayer() - DATALAYER = this.datalayer + this.datalayer.resetLayer(true) // Does not pass because chroma-js seems to have rounding issues //assert.deepEqual(this.datalayer.layer.options.limits, [45, 438.6, 707.0, 3231.0, 4935.2, 9898]) assert.equal(poly1._path.attributes.fill.value, '#ffffff') @@ -226,12 +225,12 @@ describe('L.U.Choropleth', function () { it('choropleth should compute brewer colors', function () { this.datalayer.options.choropleth.brewer = 'Blues' this.datalayer.resetLayer(true) - DATALAYER = this.datalayer assert.equal(poly1._path.attributes.fill.value, '#f7fbff') assert.equal(poly4._path.attributes.fill.value, '#c6dbef') assert.equal(poly9._path.attributes.fill.value, '#08306b') }) it('choropleth should allow to change steps', function () { + this.datalayer.options.choropleth.brewer = 'Blues' this.datalayer.options.choropleth.steps = 6 this.datalayer.resetLayer(true) assert.equal(poly1._path.attributes.fill.value, '#f7fbff')