From b99c2426487afc95c9c269db48b05a7bb4c32922 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20M=C3=A9taireau?= Date: Thu, 9 May 2024 17:30:04 +0200 Subject: [PATCH] fix(sync): Initialize `tilelayer`and `remoteData` earlier. It makes it possible to set these values on a remote peer. --- umap/static/umap/js/modules/utils.js | 1 - umap/static/umap/js/umap.js | 6 +++--- umap/static/umap/js/umap.layer.js | 11 ++++++----- umap/static/umap/unittests/utils.js | 10 ++++++++++ 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/umap/static/umap/js/modules/utils.js b/umap/static/umap/js/modules/utils.js index 7f5a213b..1493b4e9 100644 --- a/umap/static/umap/js/modules/utils.js +++ b/umap/static/umap/js/modules/utils.js @@ -68,7 +68,6 @@ export function propertyBelongsTo(property, subject, schema) { property = property.replace('properties.', '').replace('_umap_options.', '') } property = property.replace('options.', '') - console.log(property) const splits = property.split('.') const nested = splits.length > 1 if (nested) property = splits[0] diff --git a/umap/static/umap/js/umap.js b/umap/static/umap/js/umap.js index 27175ab3..77ec2d05 100644 --- a/umap/static/umap/js/umap.js +++ b/umap/static/umap/js/umap.js @@ -210,6 +210,9 @@ U.Map = L.Map.extend({ if (!U.Utils.isObject(this.options.overlay)) { this.options.overlay = {} } + if (!U.Utils.isObject(this.options.tilelayer)) { + this.options.tilelayer = {} + } this.initShortcuts() this.onceDataLoaded(function () { @@ -1317,9 +1320,6 @@ U.Map = L.Map.extend({ }, _editTilelayer: function (container) { - if (!U.Utils.isObject(this.options.tilelayer)) { - this.options.tilelayer = {} - } const tilelayerFields = [ [ 'options.tilelayer.name', diff --git a/umap/static/umap/js/umap.layer.js b/umap/static/umap/js/umap.layer.js index 176c436d..e53f1381 100644 --- a/umap/static/umap/js/umap.layer.js +++ b/umap/static/umap/js/umap.layer.js @@ -469,8 +469,8 @@ U.Layer.Heat = L.HeatLayer.extend({ this._latlngs[i].alt !== undefined ? this._latlngs[i].alt : this._latlngs[i][2] !== undefined - ? +this._latlngs[i][2] - : 1 + ? +this._latlngs[i][2] + : 1 grid[y] = grid[y] || [] cell = grid[y][x] @@ -576,6 +576,10 @@ U.DataLayer = L.Evented.extend({ } this.setUmapId(data.id) this.setOptions(data) + + if (!U.Utils.isObject(this.options.remoteData)) { + this.options.remoteData = {} + } // Retrocompat if (this.options.remoteData && this.options.remoteData.from) { this.options.fromZoom = this.options.remoteData.from @@ -1367,9 +1371,6 @@ U.DataLayer = L.Evented.extend({ ) popupFieldset.appendChild(builder.build()) - if (!U.Utils.isObject(this.options.remoteData)) { - this.options.remoteData = {} - } const remoteDataFields = [ [ 'options.remoteData.url', diff --git a/umap/static/umap/unittests/utils.js b/umap/static/umap/unittests/utils.js index cb6e8d23..f08f6027 100644 --- a/umap/static/umap/unittests/utils.js +++ b/umap/static/umap/unittests/utils.js @@ -690,6 +690,16 @@ describe('Utils', function () { true ) }) + + it('Should accept options.tilelayer.url_template', function () { + let schema = { + tilelayer: { type: Object, belongsTo: ['map'] }, + } + assert.deepEqual( + Utils.propertyBelongsTo('options.tilelayer.url_template', 'map', schema), + true + ) + }) }) describe('#parseNaiveDate', () => {