From 9a74cc370c999514af4f5d6484bfcd6240c66c48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20M=C3=A9taireau?= Date: Tue, 30 Apr 2024 00:23:36 +0200 Subject: [PATCH] feat(sync): initialize datalayers internal objects in the constructor. Otherwise, an event can come from the websocket, trying to update an `undefined` property. --- umap/static/umap/js/modules/sync/updaters.js | 2 +- umap/static/umap/js/umap.layer.js | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/umap/static/umap/js/modules/sync/updaters.js b/umap/static/umap/js/modules/sync/updaters.js index 915b7788..85741f8e 100644 --- a/umap/static/umap/js/modules/sync/updaters.js +++ b/umap/static/umap/js/modules/sync/updaters.js @@ -48,7 +48,7 @@ export class MapUpdater extends BaseUpdater { export class DatalayerUpdater extends BaseUpdater { update({ key, metadata, value }) { const datalayer = this.getLayerFromID(metadata.id) - console.log(datalayer, key, value) + console.log('datalayer', datalayer, key, value) this.updateObjectValue(datalayer, key, value) datalayer.render([key]) } diff --git a/umap/static/umap/js/umap.layer.js b/umap/static/umap/js/umap.layer.js index 10320578..5a3324cc 100644 --- a/umap/static/umap/js/umap.layer.js +++ b/umap/static/umap/js/umap.layer.js @@ -74,6 +74,10 @@ U.Layer.Cluster = L.MarkerClusterGroup.extend({ L.MarkerClusterGroup.prototype.initialize.call(this, options) this._markerCluster = U.MarkerCluster this._layers = [] + + if (!U.Utils.isObject(this.datalayer.options.cluster)) { + this.datalayer.options.cluster = {} + } }, onRemove: function (map) { @@ -97,9 +101,6 @@ U.Layer.Cluster = L.MarkerClusterGroup.extend({ }, getEditableOptions: function () { - if (!U.Utils.isObject(this.datalayer.options.cluster)) { - this.datalayer.options.cluster = {} - } return [ [ 'options.cluster.radius', @@ -351,6 +352,9 @@ U.Layer.Heat = L.HeatLayer.extend({ initialize: function (datalayer) { this.datalayer = datalayer L.HeatLayer.prototype.initialize.call(this, [], this.datalayer.options.heat) + if (!U.Utils.isObject(this.datalayer.options.heat)) { + this.datalayer.options.heat = {} + } }, addLayer: function (layer) { @@ -383,9 +387,6 @@ U.Layer.Heat = L.HeatLayer.extend({ }, getEditableOptions: function () { - if (!U.Utils.isObject(this.datalayer.options.heat)) { - this.datalayer.options.heat = {} - } return [ [ 'options.heat.radius',