mirror of
https://github.com/umap-project/umap.git
synced 2025-04-29 03:42:37 +02:00
fix(sync): do not send messages when loading data from the server
This introduces a `sync=true/false` parameter that can be passed along when loading data from our own server, in which case we don't want to send "operation" messages.
This commit is contained in:
parent
0dcedeb525
commit
7a7977c5cd
3 changed files with 11 additions and 10 deletions
|
@ -23,7 +23,7 @@ U.FeatureMixin = {
|
|||
// event triggered to cause a sync event, as it would reintroduce
|
||||
// deleted features.
|
||||
// The `._marked_for_deletion` private property is here to track this status.
|
||||
if (this._marked_for_deletion == true) {
|
||||
if (this._marked_for_deletion === true) {
|
||||
this._marked_for_deletion = false
|
||||
return
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ U.FeatureMixin = {
|
|||
initialize: function (map, latlng, options, id) {
|
||||
this.map = map
|
||||
this.sync = map.sync_engine.proxy(this)
|
||||
this._mark_for_deletion = false
|
||||
this._marked_for_deletion = false
|
||||
|
||||
if (typeof options === 'undefined') {
|
||||
options = {}
|
||||
|
|
|
@ -465,7 +465,8 @@ U.Map = L.Map.extend({
|
|||
initDataLayers: async function (datalayers) {
|
||||
datalayers = datalayers || this.options.datalayers
|
||||
for (const options of datalayers) {
|
||||
this.createDataLayer(options)
|
||||
// `false` to not propagate syncing elements served from uMap
|
||||
this.createDataLayer(options, false)
|
||||
}
|
||||
await this.loadDataLayers()
|
||||
},
|
||||
|
|
|
@ -730,8 +730,8 @@ U.DataLayer = L.Evented.extend({
|
|||
}
|
||||
},
|
||||
|
||||
fromGeoJSON: function (geojson) {
|
||||
this.addData(geojson)
|
||||
fromGeoJSON: function (geojson, sync = true) {
|
||||
this.addData(geojson, sync)
|
||||
this._geojson = geojson
|
||||
this._dataloaded = true
|
||||
this.fire('dataloaded')
|
||||
|
@ -742,7 +742,7 @@ U.DataLayer = L.Evented.extend({
|
|||
if (geojson._storage) geojson._umap_options = geojson._storage // Retrocompat
|
||||
if (geojson._umap_options) this.setOptions(geojson._umap_options)
|
||||
if (this.isRemoteLayer()) await this.fetchRemoteData()
|
||||
else this.fromGeoJSON(geojson)
|
||||
else this.fromGeoJSON(geojson, false)
|
||||
this._loaded = true
|
||||
},
|
||||
|
||||
|
@ -924,11 +924,11 @@ U.DataLayer = L.Evented.extend({
|
|||
if (idx !== -1) this._propertiesIndex.splice(idx, 1)
|
||||
},
|
||||
|
||||
addData: function (geojson) {
|
||||
addData: function (geojson, sync) {
|
||||
try {
|
||||
// Do not fail if remote data is somehow invalid,
|
||||
// otherwise the layer becomes uneditable.
|
||||
this.geojsonToFeatures(geojson)
|
||||
this.geojsonToFeatures(geojson, sync)
|
||||
} catch (err) {
|
||||
console.log('Error with DataLayer', this.umap_id)
|
||||
console.error(err)
|
||||
|
@ -1015,7 +1015,7 @@ U.DataLayer = L.Evented.extend({
|
|||
// The choice of the name is not ours, because it is required by Leaflet.
|
||||
// It is misleading, as the returned objects are uMap objects, and not
|
||||
// GeoJSON features.
|
||||
geojsonToFeatures: function (geojson) {
|
||||
geojsonToFeatures: function (geojson, sync) {
|
||||
if (!geojson) return
|
||||
const features = geojson instanceof Array ? geojson : geojson.features
|
||||
let i
|
||||
|
@ -1034,7 +1034,7 @@ U.DataLayer = L.Evented.extend({
|
|||
const feature = this.geoJSONToLeaflet({ geometry, geojson })
|
||||
if (feature) {
|
||||
this.addLayer(feature)
|
||||
feature.onCommit()
|
||||
if (sync) feature.onCommit()
|
||||
return feature
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue