Skip to content

Commit

Permalink
refactor(sync): Sync layers creation with map.createDataLayer utility.
Browse files Browse the repository at this point in the history
Rather than having it done inside the datalayer itself. This gives us
more control.
  • Loading branch information
almet committed Jun 7, 2024
1 parent 5366f24 commit 49d0b71
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion umap/static/umap/js/modules/sync/updaters.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class DataLayerUpdater extends BaseUpdater {
upsert({ value }) {
// Inserts does not happen (we use multiple updates instead).
this.map.createDataLayer(value, false)
this.map.render()
this.map.render([])
}

update({ key, metadata, value }) {
Expand Down
5 changes: 3 additions & 2 deletions umap/static/umap/js/umap.forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -943,8 +943,9 @@ L.FormBuilder.MultiChoice = L.FormBuilder.Element.extend({
}
const choices = this.getChoices().map(([value, label]) => value)
if (choices.includes(value)) {
this.container.querySelector(`input[type="radio"][value="${value}"]`).checked =
true
this.container.querySelector(
`input[type="radio"][value="${value}"]`
).checked = true
}
},

Expand Down
7 changes: 6 additions & 1 deletion umap/static/umap/js/umap.js
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,12 @@ U.Map = L.Map.extend({
datalayer = datalayer || {
name: `${L._('Layer')} ${this.datalayers_index.length + 1}`,
}
return new U.DataLayer(this, datalayer, sync)
const dl = new U.DataLayer(this, datalayer, sync)

if (sync !== false) {
dl.sync.upsert(dl.options)
}
return dl
},

newDataLayer: function () {
Expand Down
7 changes: 1 addition & 6 deletions umap/static/umap/js/umap.layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -606,18 +606,13 @@ U.DataLayer = L.Evented.extend({
// be in the "forced visibility" mode
if (this.autoLoaded()) this.map.on('zoomend', this.onZoomEnd, this)
this.on('datachanged', this.map.onDataLayersChanged, this.map)

if (sync !== false) {
const { engine, subject, metadata } = this.getSyncMetadata()
engine.upsert(subject, metadata, this.options)
}
},

getSyncMetadata: function () {
return {
subject: 'datalayer',
metadata: {
id: this.umap_id,
id: this.umap_id || null,
},
}
},
Expand Down

0 comments on commit 49d0b71

Please sign in to comment.