umap-project 2.7.3__py3-none-any.whl → 2.8.0a0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- umap/__init__.py +1 -1
- umap/forms.py +4 -14
- umap/locale/am_ET/LC_MESSAGES/django.mo +0 -0
- umap/locale/am_ET/LC_MESSAGES/django.po +278 -151
- umap/locale/ar/LC_MESSAGES/django.mo +0 -0
- umap/locale/ar/LC_MESSAGES/django.po +335 -141
- umap/locale/bg/LC_MESSAGES/django.mo +0 -0
- umap/locale/bg/LC_MESSAGES/django.po +279 -152
- umap/locale/br/LC_MESSAGES/django.mo +0 -0
- umap/locale/br/LC_MESSAGES/django.po +95 -79
- umap/locale/ca/LC_MESSAGES/django.mo +0 -0
- umap/locale/ca/LC_MESSAGES/django.po +85 -68
- umap/locale/cs_CZ/LC_MESSAGES/django.mo +0 -0
- umap/locale/cs_CZ/LC_MESSAGES/django.po +78 -66
- umap/locale/da/LC_MESSAGES/django.mo +0 -0
- umap/locale/da/LC_MESSAGES/django.po +280 -153
- umap/locale/de/LC_MESSAGES/django.mo +0 -0
- umap/locale/de/LC_MESSAGES/django.po +80 -64
- umap/locale/el/LC_MESSAGES/django.mo +0 -0
- umap/locale/el/LC_MESSAGES/django.po +82 -66
- umap/locale/en/LC_MESSAGES/django.po +73 -61
- umap/locale/es/LC_MESSAGES/django.mo +0 -0
- umap/locale/es/LC_MESSAGES/django.po +75 -63
- umap/locale/et/LC_MESSAGES/django.mo +0 -0
- umap/locale/et/LC_MESSAGES/django.po +280 -153
- umap/locale/eu/LC_MESSAGES/django.mo +0 -0
- umap/locale/eu/LC_MESSAGES/django.po +82 -66
- umap/locale/fa_IR/LC_MESSAGES/django.mo +0 -0
- umap/locale/fa_IR/LC_MESSAGES/django.po +80 -64
- umap/locale/fi/LC_MESSAGES/django.mo +0 -0
- umap/locale/fi/LC_MESSAGES/django.po +278 -151
- umap/locale/fr/LC_MESSAGES/django.mo +0 -0
- umap/locale/fr/LC_MESSAGES/django.po +75 -63
- umap/locale/gl/LC_MESSAGES/django.mo +0 -0
- umap/locale/gl/LC_MESSAGES/django.po +280 -153
- umap/locale/he/LC_MESSAGES/django.mo +0 -0
- umap/locale/he/LC_MESSAGES/django.po +281 -154
- umap/locale/hu/LC_MESSAGES/django.mo +0 -0
- umap/locale/hu/LC_MESSAGES/django.po +80 -64
- umap/locale/is/LC_MESSAGES/django.mo +0 -0
- umap/locale/is/LC_MESSAGES/django.po +280 -153
- umap/locale/it/LC_MESSAGES/django.mo +0 -0
- umap/locale/it/LC_MESSAGES/django.po +82 -66
- umap/locale/ja/LC_MESSAGES/django.mo +0 -0
- umap/locale/ja/LC_MESSAGES/django.po +280 -153
- umap/locale/ko/LC_MESSAGES/django.mo +0 -0
- umap/locale/ko/LC_MESSAGES/django.po +280 -153
- umap/locale/lt/LC_MESSAGES/django.mo +0 -0
- umap/locale/lt/LC_MESSAGES/django.po +280 -153
- umap/locale/ms/LC_MESSAGES/django.mo +0 -0
- umap/locale/ms/LC_MESSAGES/django.po +82 -66
- umap/locale/nl/LC_MESSAGES/django.mo +0 -0
- umap/locale/nl/LC_MESSAGES/django.po +280 -153
- umap/locale/pl/LC_MESSAGES/django.mo +0 -0
- umap/locale/pl/LC_MESSAGES/django.po +82 -66
- umap/locale/pt/LC_MESSAGES/django.mo +0 -0
- umap/locale/pt/LC_MESSAGES/django.po +75 -63
- umap/locale/pt_BR/LC_MESSAGES/django.mo +0 -0
- umap/locale/pt_BR/LC_MESSAGES/django.po +280 -153
- umap/locale/pt_PT/LC_MESSAGES/django.mo +0 -0
- umap/locale/pt_PT/LC_MESSAGES/django.po +280 -153
- umap/locale/ru/LC_MESSAGES/django.mo +0 -0
- umap/locale/ru/LC_MESSAGES/django.po +280 -153
- umap/locale/sk_SK/LC_MESSAGES/django.mo +0 -0
- umap/locale/sk_SK/LC_MESSAGES/django.po +280 -153
- umap/locale/sl/LC_MESSAGES/django.mo +0 -0
- umap/locale/sl/LC_MESSAGES/django.po +280 -153
- umap/locale/sr/LC_MESSAGES/django.mo +0 -0
- umap/locale/sr/LC_MESSAGES/django.po +280 -153
- umap/locale/sv/LC_MESSAGES/django.mo +0 -0
- umap/locale/sv/LC_MESSAGES/django.po +81 -65
- umap/locale/th_TH/LC_MESSAGES/django.mo +0 -0
- umap/locale/th_TH/LC_MESSAGES/django.po +257 -185
- umap/locale/tr/LC_MESSAGES/django.mo +0 -0
- umap/locale/tr/LC_MESSAGES/django.po +280 -153
- umap/locale/uk_UA/LC_MESSAGES/django.mo +0 -0
- umap/locale/uk_UA/LC_MESSAGES/django.po +280 -153
- umap/locale/vi/LC_MESSAGES/django.mo +0 -0
- umap/locale/vi/LC_MESSAGES/django.po +278 -151
- umap/locale/zh/LC_MESSAGES/django.mo +0 -0
- umap/locale/zh/LC_MESSAGES/django.po +278 -151
- umap/locale/zh_TW/LC_MESSAGES/django.mo +0 -0
- umap/locale/zh_TW/LC_MESSAGES/django.po +97 -81
- umap/management/commands/empty_trash.py +32 -0
- umap/management/commands/migrate_to_S3.py +29 -0
- umap/migrations/0023_alter_datalayer_uuid.py +19 -0
- umap/migrations/0024_alter_map_share_status.py +30 -0
- umap/migrations/0025_alter_datalayer_geojson.py +24 -0
- umap/models.py +68 -116
- umap/settings/base.py +22 -2
- umap/static/umap/base.css +3 -603
- umap/static/umap/content.css +5 -3
- umap/static/umap/css/bar.css +202 -0
- umap/static/umap/css/form.css +617 -0
- umap/static/umap/css/icon.css +21 -1
- umap/static/umap/css/popup.css +125 -0
- umap/static/umap/img/16-white.svg +16 -4
- umap/static/umap/img/16.svg +1 -1
- umap/static/umap/img/source/16-white.svg +46 -45
- umap/static/umap/img/source/16.svg +1 -753
- umap/static/umap/js/components/fragment.js +3 -1
- umap/static/umap/js/modules/browser.js +20 -19
- umap/static/umap/js/modules/caption.js +21 -22
- umap/static/umap/js/modules/data/features.js +101 -74
- umap/static/umap/js/modules/data/layer.js +157 -137
- umap/static/umap/js/modules/facets.js +9 -9
- umap/static/umap/js/modules/formatter.js +5 -5
- umap/static/umap/js/modules/global.js +4 -52
- umap/static/umap/js/modules/help.js +18 -21
- umap/static/umap/js/modules/importer.js +71 -39
- umap/static/umap/js/modules/importers/cadastrefr.js +4 -0
- umap/static/umap/js/modules/importers/geodatamine.js +3 -3
- umap/static/umap/js/modules/importers/overpass.js +5 -0
- umap/static/umap/js/modules/permissions.js +85 -87
- umap/static/umap/js/modules/rendering/layers/base.js +15 -15
- umap/static/umap/js/modules/rendering/layers/classified.js +1 -1
- umap/static/umap/js/modules/rendering/layers/cluster.js +1 -1
- umap/static/umap/js/modules/rendering/layers/heat.js +1 -1
- umap/static/umap/js/modules/rendering/map.js +390 -0
- umap/static/umap/js/modules/rendering/popup.js +10 -9
- umap/static/umap/js/modules/rendering/template.js +35 -12
- umap/static/umap/js/modules/rendering/ui.js +57 -12
- umap/static/umap/js/modules/rules.js +22 -25
- umap/static/umap/js/modules/saving.js +47 -0
- umap/static/umap/js/modules/schema.js +5 -0
- umap/static/umap/js/modules/share.js +21 -24
- umap/static/umap/js/modules/slideshow.js +24 -20
- umap/static/umap/js/modules/sync/updaters.js +7 -9
- umap/static/umap/js/modules/tableeditor.js +20 -19
- umap/static/umap/js/modules/ui/bar.js +196 -0
- umap/static/umap/js/modules/ui/panel.js +10 -9
- umap/static/umap/js/modules/umap.js +1668 -0
- umap/static/umap/js/modules/urls.js +2 -2
- umap/static/umap/js/modules/utils.js +20 -6
- umap/static/umap/js/umap.controls.js +74 -301
- umap/static/umap/js/umap.core.js +29 -50
- umap/static/umap/js/umap.forms.js +34 -27
- umap/static/umap/keycloak.png +0 -0
- umap/static/umap/locale/am_ET.js +26 -10
- umap/static/umap/locale/am_ET.json +26 -10
- umap/static/umap/locale/ar.js +26 -10
- umap/static/umap/locale/ar.json +26 -10
- umap/static/umap/locale/ast.js +26 -10
- umap/static/umap/locale/ast.json +26 -10
- umap/static/umap/locale/bg.js +26 -10
- umap/static/umap/locale/bg.json +26 -10
- umap/static/umap/locale/br.js +27 -20
- umap/static/umap/locale/br.json +27 -20
- umap/static/umap/locale/ca.js +32 -29
- umap/static/umap/locale/ca.json +32 -29
- umap/static/umap/locale/cs_CZ.js +24 -17
- umap/static/umap/locale/cs_CZ.json +24 -17
- umap/static/umap/locale/da.js +26 -10
- umap/static/umap/locale/da.json +26 -10
- umap/static/umap/locale/de.js +21 -14
- umap/static/umap/locale/de.json +21 -14
- umap/static/umap/locale/el.js +28 -12
- umap/static/umap/locale/el.json +28 -12
- umap/static/umap/locale/en.js +12 -9
- umap/static/umap/locale/en.json +12 -9
- umap/static/umap/locale/en_US.json +26 -10
- umap/static/umap/locale/es.js +16 -13
- umap/static/umap/locale/es.json +16 -13
- umap/static/umap/locale/et.js +26 -10
- umap/static/umap/locale/et.json +26 -10
- umap/static/umap/locale/eu.js +16 -9
- umap/static/umap/locale/eu.json +16 -9
- umap/static/umap/locale/fa_IR.js +16 -9
- umap/static/umap/locale/fa_IR.json +16 -9
- umap/static/umap/locale/fi.js +26 -10
- umap/static/umap/locale/fi.json +26 -10
- umap/static/umap/locale/fr.js +12 -9
- umap/static/umap/locale/fr.json +12 -9
- umap/static/umap/locale/gl.js +26 -10
- umap/static/umap/locale/gl.json +26 -10
- umap/static/umap/locale/he.js +26 -10
- umap/static/umap/locale/he.json +26 -10
- umap/static/umap/locale/hr.js +26 -10
- umap/static/umap/locale/hr.json +26 -10
- umap/static/umap/locale/hu.js +16 -9
- umap/static/umap/locale/hu.json +16 -9
- umap/static/umap/locale/id.js +26 -10
- umap/static/umap/locale/id.json +26 -10
- umap/static/umap/locale/is.js +26 -10
- umap/static/umap/locale/is.json +26 -10
- umap/static/umap/locale/it.js +26 -10
- umap/static/umap/locale/it.json +26 -10
- umap/static/umap/locale/ja.js +26 -10
- umap/static/umap/locale/ja.json +26 -10
- umap/static/umap/locale/ko.js +26 -10
- umap/static/umap/locale/ko.json +26 -10
- umap/static/umap/locale/lt.js +26 -10
- umap/static/umap/locale/lt.json +26 -10
- umap/static/umap/locale/ms.js +28 -12
- umap/static/umap/locale/ms.json +28 -12
- umap/static/umap/locale/nl.js +28 -12
- umap/static/umap/locale/nl.json +28 -12
- umap/static/umap/locale/no.js +26 -10
- umap/static/umap/locale/no.json +26 -10
- umap/static/umap/locale/pl.js +28 -12
- umap/static/umap/locale/pl.json +28 -12
- umap/static/umap/locale/pl_PL.json +26 -10
- umap/static/umap/locale/pt.js +16 -9
- umap/static/umap/locale/pt.json +16 -9
- umap/static/umap/locale/pt_BR.js +26 -10
- umap/static/umap/locale/pt_BR.json +26 -10
- umap/static/umap/locale/pt_PT.js +16 -9
- umap/static/umap/locale/pt_PT.json +16 -9
- umap/static/umap/locale/ro.js +26 -10
- umap/static/umap/locale/ro.json +26 -10
- umap/static/umap/locale/ru.js +26 -10
- umap/static/umap/locale/ru.json +26 -10
- umap/static/umap/locale/si.js +7 -7
- umap/static/umap/locale/si.json +7 -7
- umap/static/umap/locale/sk_SK.js +26 -10
- umap/static/umap/locale/sk_SK.json +26 -10
- umap/static/umap/locale/sl.js +26 -10
- umap/static/umap/locale/sl.json +26 -10
- umap/static/umap/locale/sr.js +26 -10
- umap/static/umap/locale/sr.json +26 -10
- umap/static/umap/locale/sv.js +27 -11
- umap/static/umap/locale/sv.json +27 -11
- umap/static/umap/locale/th_TH.js +28 -12
- umap/static/umap/locale/th_TH.json +28 -12
- umap/static/umap/locale/tr.js +26 -10
- umap/static/umap/locale/tr.json +26 -10
- umap/static/umap/locale/uk_UA.js +26 -10
- umap/static/umap/locale/uk_UA.json +26 -10
- umap/static/umap/locale/vi.js +26 -10
- umap/static/umap/locale/vi.json +26 -10
- umap/static/umap/locale/vi_VN.json +26 -10
- umap/static/umap/locale/zh.js +26 -10
- umap/static/umap/locale/zh.json +26 -10
- umap/static/umap/locale/zh_CN.json +26 -10
- umap/static/umap/locale/zh_TW.Big5.json +26 -10
- umap/static/umap/locale/zh_TW.js +34 -27
- umap/static/umap/locale/zh_TW.json +34 -27
- umap/static/umap/map.css +5 -364
- umap/static/umap/unittests/URLs.js +15 -15
- umap/static/umap/unittests/utils.js +23 -1
- umap/static/umap/vars.css +2 -0
- umap/static/umap/vendors/formbuilder/Leaflet.FormBuilder.js +5 -1
- umap/storage.py +152 -0
- umap/templates/registration/login.html +7 -6
- umap/templates/umap/css.html +3 -0
- umap/templates/umap/js.html +1 -2
- umap/templates/umap/map_init.html +4 -5
- umap/templates/umap/user_dashboard.html +18 -19
- umap/tests/base.py +5 -1
- umap/tests/integration/conftest.py +2 -1
- umap/tests/integration/test_anonymous_owned_map.py +18 -10
- umap/tests/integration/test_browser.py +16 -1
- umap/tests/integration/test_dashboard.py +1 -1
- umap/tests/integration/test_edit_datalayer.py +18 -7
- umap/tests/integration/test_import.py +8 -5
- umap/tests/integration/test_optimistic_merge.py +31 -8
- umap/tests/integration/test_owned_map.py +22 -16
- umap/tests/integration/test_popup.py +44 -0
- umap/tests/integration/test_save.py +35 -0
- umap/tests/integration/test_view_marker.py +12 -0
- umap/tests/integration/test_view_polyline.py +257 -0
- umap/tests/integration/test_websocket_sync.py +81 -9
- umap/tests/test_datalayer.py +6 -7
- umap/tests/test_datalayer_s3.py +135 -0
- umap/tests/test_datalayer_views.py +28 -10
- umap/tests/test_empty_trash.py +34 -0
- umap/tests/test_map.py +12 -3
- umap/tests/test_map_views.py +69 -37
- umap/tests/test_views.py +53 -0
- umap/urls.py +3 -3
- umap/views.py +107 -76
- {umap_project-2.7.3.dist-info → umap_project-2.8.0a0.dist-info}/METADATA +16 -13
- {umap_project-2.7.3.dist-info → umap_project-2.8.0a0.dist-info}/RECORD +276 -262
- umap/management/commands/purge_purgatory.py +0 -28
- umap/static/umap/js/umap.js +0 -1903
- umap/tests/test_purge_purgatory.py +0 -25
- {umap_project-2.7.3.dist-info → umap_project-2.8.0a0.dist-info}/WHEEL +0 -0
- {umap_project-2.7.3.dist-info → umap_project-2.8.0a0.dist-info}/entry_points.txt +0 -0
- {umap_project-2.7.3.dist-info → umap_project-2.8.0a0.dist-info}/licenses/LICENSE +0 -0
|
@@ -20,6 +20,8 @@ import { translate } from '../i18n.js'
|
|
|
20
20
|
import { DataLayerPermissions } from '../permissions.js'
|
|
21
21
|
import { Point, LineString, Polygon } from './features.js'
|
|
22
22
|
import TableEditor from '../tableeditor.js'
|
|
23
|
+
import { ServerStored } from '../saving.js'
|
|
24
|
+
import * as Schema from '../schema.js'
|
|
23
25
|
|
|
24
26
|
export const LAYER_TYPES = [
|
|
25
27
|
DefaultLayer,
|
|
@@ -35,10 +37,11 @@ const LAYER_MAP = LAYER_TYPES.reduce((acc, klass) => {
|
|
|
35
37
|
return acc
|
|
36
38
|
}, {})
|
|
37
39
|
|
|
38
|
-
export class DataLayer {
|
|
39
|
-
constructor(
|
|
40
|
-
|
|
41
|
-
this.
|
|
40
|
+
export class DataLayer extends ServerStored {
|
|
41
|
+
constructor(umap, leafletMap, data = {}) {
|
|
42
|
+
super()
|
|
43
|
+
this._umap = umap
|
|
44
|
+
this.sync = umap.sync_engine.proxy(this)
|
|
42
45
|
this._index = Array()
|
|
43
46
|
this._features = {}
|
|
44
47
|
this._geojson = null
|
|
@@ -46,8 +49,9 @@ export class DataLayer {
|
|
|
46
49
|
this._loaded = false // Are layer metadata loaded
|
|
47
50
|
this._dataloaded = false // Are layer data loaded
|
|
48
51
|
|
|
49
|
-
this.
|
|
50
|
-
this.
|
|
52
|
+
this._leafletMap = leafletMap
|
|
53
|
+
this.parentPane = this._leafletMap.getPane('overlayPane')
|
|
54
|
+
this.pane = this._leafletMap.createPane(`datalayer${stamp(this)}`, this.parentPane)
|
|
51
55
|
this.pane.dataset.id = stamp(this)
|
|
52
56
|
// FIXME: should be on layer
|
|
53
57
|
this.renderer = L.svg({ pane: this.pane })
|
|
@@ -58,9 +62,12 @@ export class DataLayer {
|
|
|
58
62
|
editMode: 'advanced',
|
|
59
63
|
}
|
|
60
64
|
|
|
61
|
-
this._isDirty = false
|
|
62
65
|
this._isDeleted = false
|
|
63
|
-
this.
|
|
66
|
+
this._referenceVersion = data._referenceVersion
|
|
67
|
+
// Do not save it later.
|
|
68
|
+
delete data._referenceVersion
|
|
69
|
+
data.id = data.id || crypto.randomUUID()
|
|
70
|
+
|
|
64
71
|
this.setOptions(data)
|
|
65
72
|
|
|
66
73
|
if (!Utils.isObject(this.options.remoteData)) {
|
|
@@ -77,8 +84,9 @@ export class DataLayer {
|
|
|
77
84
|
}
|
|
78
85
|
this.backupOptions()
|
|
79
86
|
this.connectToMap()
|
|
80
|
-
this.permissions = new DataLayerPermissions(this)
|
|
81
|
-
|
|
87
|
+
this.permissions = new DataLayerPermissions(this._umap, this)
|
|
88
|
+
|
|
89
|
+
if (!this.createdOnServer) {
|
|
82
90
|
if (this.showAtLoad()) this.show()
|
|
83
91
|
this.isDirty = true
|
|
84
92
|
}
|
|
@@ -89,23 +97,24 @@ export class DataLayer {
|
|
|
89
97
|
if (this.isVisible()) this.propagateShow()
|
|
90
98
|
}
|
|
91
99
|
|
|
92
|
-
|
|
93
|
-
this.
|
|
100
|
+
get id() {
|
|
101
|
+
return this.options.id
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
get createdOnServer() {
|
|
105
|
+
return Boolean(this._referenceVersion)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
onDirty(status) {
|
|
94
109
|
if (status) {
|
|
95
|
-
this.map.isDirty = true
|
|
96
110
|
// A layer can be made dirty by indirect action (like dragging layers)
|
|
97
111
|
// we need to have it loaded before saving it.
|
|
98
112
|
if (!this.isLoaded()) this.fetchData()
|
|
99
113
|
} else {
|
|
100
|
-
this.map.checkDirty()
|
|
101
114
|
this.isDeleted = false
|
|
102
115
|
}
|
|
103
116
|
}
|
|
104
117
|
|
|
105
|
-
get isDirty() {
|
|
106
|
-
return this._isDirty
|
|
107
|
-
}
|
|
108
|
-
|
|
109
118
|
set isDeleted(status) {
|
|
110
119
|
this._isDeleted = status
|
|
111
120
|
if (status) this.isDirty = status
|
|
@@ -122,9 +131,7 @@ export class DataLayer {
|
|
|
122
131
|
getSyncMetadata() {
|
|
123
132
|
return {
|
|
124
133
|
subject: 'datalayer',
|
|
125
|
-
metadata: {
|
|
126
|
-
id: this.umap_id || null,
|
|
127
|
-
},
|
|
134
|
+
metadata: { id: this.id },
|
|
128
135
|
}
|
|
129
136
|
}
|
|
130
137
|
|
|
@@ -134,7 +141,7 @@ export class DataLayer {
|
|
|
134
141
|
for (const impact of impacts) {
|
|
135
142
|
switch (impact) {
|
|
136
143
|
case 'ui':
|
|
137
|
-
this.
|
|
144
|
+
this._umap.onDataLayersChanged()
|
|
138
145
|
break
|
|
139
146
|
case 'data':
|
|
140
147
|
if (fields.includes('options.type')) {
|
|
@@ -159,9 +166,9 @@ export class DataLayer {
|
|
|
159
166
|
}
|
|
160
167
|
|
|
161
168
|
autoLoaded() {
|
|
162
|
-
if (!this.
|
|
163
|
-
const datalayerIds = this.
|
|
164
|
-
let loadMe = datalayerIds.includes(this.
|
|
169
|
+
if (!this._umap.datalayersFromQueryString) return this.options.displayOnLoad
|
|
170
|
+
const datalayerIds = this._umap.datalayersFromQueryString
|
|
171
|
+
let loadMe = datalayerIds.includes(this.id.toString())
|
|
165
172
|
if (this.options.old_id) {
|
|
166
173
|
loadMe = loadMe || datalayerIds.includes(this.options.old_id.toString())
|
|
167
174
|
}
|
|
@@ -198,7 +205,7 @@ export class DataLayer {
|
|
|
198
205
|
const visible = this.isVisible()
|
|
199
206
|
if (this.layer) this.layer.clearLayers()
|
|
200
207
|
// delete this.layer?
|
|
201
|
-
if (visible) this.
|
|
208
|
+
if (visible) this._leafletMap.removeLayer(this.layer)
|
|
202
209
|
const Class = LAYER_MAP[this.options.type] || DefaultLayer
|
|
203
210
|
this.layer = new Class(this)
|
|
204
211
|
// Rendering layer changed, so let's force reset the feature rendering too.
|
|
@@ -216,13 +223,13 @@ export class DataLayer {
|
|
|
216
223
|
}
|
|
217
224
|
|
|
218
225
|
async fetchData() {
|
|
219
|
-
if (!this.
|
|
226
|
+
if (!this.createdOnServer) return
|
|
220
227
|
if (this._loading) return
|
|
221
228
|
this._loading = true
|
|
222
|
-
const [geojson, response, error] = await this.
|
|
229
|
+
const [geojson, response, error] = await this._umap.server.get(this._dataUrl())
|
|
223
230
|
if (!error) {
|
|
224
|
-
this.
|
|
225
|
-
// FIXME: for now
|
|
231
|
+
this.setReferenceVersion({ response, sync: false })
|
|
232
|
+
// FIXME: for now the _umap_options property is set dynamically from backend
|
|
226
233
|
// And thus it's not in the geojson file in the server
|
|
227
234
|
// So do not let all options to be reset
|
|
228
235
|
// Fix is a proper migration so all datalayers settings are
|
|
@@ -240,7 +247,7 @@ export class DataLayer {
|
|
|
240
247
|
|
|
241
248
|
dataChanged() {
|
|
242
249
|
if (!this.hasDataLoaded()) return
|
|
243
|
-
this.
|
|
250
|
+
this._umap.onDataLayersChanged()
|
|
244
251
|
this.layer.dataChanged()
|
|
245
252
|
}
|
|
246
253
|
|
|
@@ -258,6 +265,7 @@ export class DataLayer {
|
|
|
258
265
|
|
|
259
266
|
async fromUmapGeoJSON(geojson) {
|
|
260
267
|
if (geojson._storage) geojson._umap_options = geojson._storage // Retrocompat
|
|
268
|
+
geojson._umap_options.id = this.id
|
|
261
269
|
if (geojson._umap_options) this.setOptions(geojson._umap_options)
|
|
262
270
|
if (this.isRemoteLayer()) await this.fetchRemoteData()
|
|
263
271
|
else this.fromGeoJSON(geojson, false)
|
|
@@ -281,14 +289,14 @@ export class DataLayer {
|
|
|
281
289
|
|
|
282
290
|
reindex() {
|
|
283
291
|
const features = Object.values(this._features)
|
|
284
|
-
|
|
292
|
+
this.sortFeatures(features)
|
|
285
293
|
this._index = features.map((feature) => stamp(feature))
|
|
286
294
|
}
|
|
287
295
|
|
|
288
296
|
showAtZoom() {
|
|
289
297
|
const from = Number.parseInt(this.options.fromZoom, 10)
|
|
290
298
|
const to = Number.parseInt(this.options.toZoom, 10)
|
|
291
|
-
const zoom = this.
|
|
299
|
+
const zoom = this._leafletMap.getZoom()
|
|
292
300
|
return !((!Number.isNaN(from) && zoom < from) || (!Number.isNaN(to) && zoom > to))
|
|
293
301
|
}
|
|
294
302
|
|
|
@@ -300,32 +308,27 @@ export class DataLayer {
|
|
|
300
308
|
if (!this.isRemoteLayer()) return
|
|
301
309
|
if (!this.hasDynamicData() && this.hasDataLoaded() && !force) return
|
|
302
310
|
if (!this.isVisible()) return
|
|
303
|
-
let url = this.
|
|
311
|
+
let url = this._umap.renderUrl(this.options.remoteData.url)
|
|
304
312
|
if (this.options.remoteData.proxy) {
|
|
305
|
-
url = this.
|
|
313
|
+
url = this._umap.proxyUrl(url, this.options.remoteData.ttl)
|
|
306
314
|
}
|
|
307
|
-
const response = await this.
|
|
315
|
+
const response = await this._umap.request.get(url)
|
|
308
316
|
if (response?.ok) {
|
|
309
317
|
this.clear()
|
|
310
|
-
this.
|
|
318
|
+
this._umap.formatter
|
|
311
319
|
.parse(await response.text(), this.options.remoteData.format)
|
|
312
320
|
.then((geojson) => this.fromGeoJSON(geojson))
|
|
313
321
|
}
|
|
314
322
|
}
|
|
315
323
|
|
|
316
324
|
isLoaded() {
|
|
317
|
-
return !this.
|
|
325
|
+
return !this.createdOnServer || this._loaded
|
|
318
326
|
}
|
|
319
327
|
|
|
320
328
|
hasDataLoaded() {
|
|
321
329
|
return this._dataloaded
|
|
322
330
|
}
|
|
323
331
|
|
|
324
|
-
setUmapId(id) {
|
|
325
|
-
// Datalayer is null when listening creation form
|
|
326
|
-
if (!this.umap_id && id) this.umap_id = id
|
|
327
|
-
}
|
|
328
|
-
|
|
329
332
|
backupOptions() {
|
|
330
333
|
this._backupOptions = Utils.CopyJSON(this.options)
|
|
331
334
|
}
|
|
@@ -347,25 +350,23 @@ export class DataLayer {
|
|
|
347
350
|
|
|
348
351
|
connectToMap() {
|
|
349
352
|
const id = stamp(this)
|
|
350
|
-
if (!this.
|
|
351
|
-
this.
|
|
353
|
+
if (!this._umap.datalayers[id]) {
|
|
354
|
+
this._umap.datalayers[id] = this
|
|
352
355
|
}
|
|
353
|
-
if (!this.
|
|
354
|
-
this.
|
|
356
|
+
if (!this._umap.datalayersIndex.includes(this)) {
|
|
357
|
+
this._umap.datalayersIndex.push(this)
|
|
355
358
|
}
|
|
356
|
-
this.
|
|
359
|
+
this._umap.onDataLayersChanged()
|
|
357
360
|
}
|
|
358
361
|
|
|
359
362
|
_dataUrl() {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
pk: this.umap_id,
|
|
364
|
-
map_id: this.map.options.umap_id,
|
|
363
|
+
let url = this._umap.urls.get('datalayer_view', {
|
|
364
|
+
pk: this.id,
|
|
365
|
+
map_id: this._umap.id,
|
|
365
366
|
})
|
|
366
367
|
|
|
367
368
|
// No browser cache for owners/editors.
|
|
368
|
-
if (this.
|
|
369
|
+
if (this._umap.hasEditMode()) url = `${url}?${Date.now()}`
|
|
369
370
|
return url
|
|
370
371
|
}
|
|
371
372
|
|
|
@@ -392,7 +393,7 @@ export class DataLayer {
|
|
|
392
393
|
this._index.push(id)
|
|
393
394
|
this._features[id] = feature
|
|
394
395
|
this.indexProperties(feature)
|
|
395
|
-
this.
|
|
396
|
+
this._umap.featuresIndex[feature.getSlug()] = feature
|
|
396
397
|
this.showFeature(feature)
|
|
397
398
|
this.dataChanged()
|
|
398
399
|
}
|
|
@@ -401,7 +402,7 @@ export class DataLayer {
|
|
|
401
402
|
const id = stamp(feature)
|
|
402
403
|
if (sync !== false) feature.sync.delete()
|
|
403
404
|
this.hideFeature(feature)
|
|
404
|
-
delete this.
|
|
405
|
+
delete this._umap.featuresIndex[feature.getSlug()]
|
|
405
406
|
feature.disconnectFromDataLayer(this)
|
|
406
407
|
this._index.splice(this._index.indexOf(id), 1)
|
|
407
408
|
delete this._features[id]
|
|
@@ -427,6 +428,10 @@ export class DataLayer {
|
|
|
427
428
|
if (idx !== -1) this._propertiesIndex.splice(idx, 1)
|
|
428
429
|
}
|
|
429
430
|
|
|
431
|
+
allProperties() {
|
|
432
|
+
return this._propertiesIndex
|
|
433
|
+
}
|
|
434
|
+
|
|
430
435
|
sortedValues(property) {
|
|
431
436
|
return Object.values(this._features)
|
|
432
437
|
.map((feature) => feature.properties[property])
|
|
@@ -440,11 +445,16 @@ export class DataLayer {
|
|
|
440
445
|
// otherwise the layer becomes uneditable.
|
|
441
446
|
this.makeFeatures(geojson, sync)
|
|
442
447
|
} catch (err) {
|
|
443
|
-
console.log('Error with DataLayer', this.
|
|
448
|
+
console.log('Error with DataLayer', this.id)
|
|
444
449
|
console.error(err)
|
|
445
450
|
}
|
|
446
451
|
}
|
|
447
452
|
|
|
453
|
+
sortFeatures(collection) {
|
|
454
|
+
const sortKeys = this._umap.getProperty('sortKey') || U.DEFAULT_LABEL_KEY
|
|
455
|
+
return Utils.sortFeatures(collection, sortKeys, U.lang)
|
|
456
|
+
}
|
|
457
|
+
|
|
448
458
|
makeFeatures(geojson = {}, sync = true) {
|
|
449
459
|
if (geojson.type === 'Feature' || geojson.coordinates) {
|
|
450
460
|
geojson = [geojson]
|
|
@@ -452,7 +462,8 @@ export class DataLayer {
|
|
|
452
462
|
const collection = Array.isArray(geojson)
|
|
453
463
|
? geojson
|
|
454
464
|
: geojson.features || geojson.geometries
|
|
455
|
-
|
|
465
|
+
if (!collection) return
|
|
466
|
+
this.sortFeatures(collection)
|
|
456
467
|
for (const feature of collection) {
|
|
457
468
|
this.makeFeature(feature, sync)
|
|
458
469
|
}
|
|
@@ -466,15 +477,15 @@ export class DataLayer {
|
|
|
466
477
|
switch (geometry.type) {
|
|
467
478
|
case 'Point':
|
|
468
479
|
// FIXME: deal with MultiPoint
|
|
469
|
-
feature = new Point(this, geojson, id)
|
|
480
|
+
feature = new Point(this._umap, this, geojson, id)
|
|
470
481
|
break
|
|
471
482
|
case 'MultiLineString':
|
|
472
483
|
case 'LineString':
|
|
473
|
-
feature = new LineString(this, geojson, id)
|
|
484
|
+
feature = new LineString(this._umap, this, geojson, id)
|
|
474
485
|
break
|
|
475
486
|
case 'MultiPolygon':
|
|
476
487
|
case 'Polygon':
|
|
477
|
-
feature = new Polygon(this, geojson, id)
|
|
488
|
+
feature = new Polygon(this._umap, this, geojson, id)
|
|
478
489
|
break
|
|
479
490
|
default:
|
|
480
491
|
console.log(geojson)
|
|
@@ -492,7 +503,7 @@ export class DataLayer {
|
|
|
492
503
|
}
|
|
493
504
|
|
|
494
505
|
async importRaw(raw, format) {
|
|
495
|
-
this.
|
|
506
|
+
this._umap.formatter
|
|
496
507
|
.parse(raw, format)
|
|
497
508
|
.then((geojson) => this.addData(geojson))
|
|
498
509
|
.then(() => this.zoomTo())
|
|
@@ -513,36 +524,36 @@ export class DataLayer {
|
|
|
513
524
|
}
|
|
514
525
|
|
|
515
526
|
async importFromUrl(uri, type) {
|
|
516
|
-
uri = this.
|
|
517
|
-
const response = await this.
|
|
527
|
+
uri = this._umap.renderUrl(uri)
|
|
528
|
+
const response = await this._umap.request.get(uri)
|
|
518
529
|
if (response?.ok) {
|
|
519
530
|
this.importRaw(await response.text(), type)
|
|
520
531
|
}
|
|
521
532
|
}
|
|
522
533
|
|
|
523
534
|
getColor() {
|
|
524
|
-
return this.options.color || this.
|
|
535
|
+
return this.options.color || this._umap.getProperty('color')
|
|
525
536
|
}
|
|
526
537
|
|
|
527
538
|
getDeleteUrl() {
|
|
528
|
-
return
|
|
529
|
-
pk: this.
|
|
530
|
-
map_id: this.
|
|
539
|
+
return this._umap.urls.get('datalayer_delete', {
|
|
540
|
+
pk: this.id,
|
|
541
|
+
map_id: this._umap.id,
|
|
531
542
|
})
|
|
532
543
|
}
|
|
533
544
|
|
|
534
545
|
getVersionsUrl() {
|
|
535
|
-
return
|
|
536
|
-
pk: this.
|
|
537
|
-
map_id: this.
|
|
546
|
+
return this._umap.urls.get('datalayer_versions', {
|
|
547
|
+
pk: this.id,
|
|
548
|
+
map_id: this._umap.id,
|
|
538
549
|
})
|
|
539
550
|
}
|
|
540
551
|
|
|
541
|
-
getVersionUrl(
|
|
542
|
-
return
|
|
543
|
-
pk: this.
|
|
544
|
-
map_id: this.
|
|
545
|
-
|
|
552
|
+
getVersionUrl(ref) {
|
|
553
|
+
return this._umap.urls.get('datalayer_version', {
|
|
554
|
+
pk: this.id,
|
|
555
|
+
map_id: this._umap.id,
|
|
556
|
+
ref: ref,
|
|
546
557
|
})
|
|
547
558
|
}
|
|
548
559
|
|
|
@@ -562,17 +573,17 @@ export class DataLayer {
|
|
|
562
573
|
options.name = translate('Clone of {name}', { name: this.options.name })
|
|
563
574
|
delete options.id
|
|
564
575
|
const geojson = Utils.CopyJSON(this._geojson)
|
|
565
|
-
const datalayer = this.
|
|
576
|
+
const datalayer = this._umap.createDataLayer(options)
|
|
566
577
|
datalayer.fromGeoJSON(geojson)
|
|
567
578
|
return datalayer
|
|
568
579
|
}
|
|
569
580
|
|
|
570
581
|
erase() {
|
|
571
582
|
this.hide()
|
|
572
|
-
this.
|
|
583
|
+
this._umap.datalayersIndex.splice(this.getRank(), 1)
|
|
573
584
|
this.parentPane.removeChild(this.pane)
|
|
574
|
-
this.
|
|
575
|
-
this.layer.onDelete(this.
|
|
585
|
+
this._umap.onDataLayersChanged()
|
|
586
|
+
this.layer.onDelete(this._leafletMap)
|
|
576
587
|
this.propagateDelete()
|
|
577
588
|
this._leaflet_events_bk = this._leaflet_events
|
|
578
589
|
this.clear()
|
|
@@ -581,7 +592,7 @@ export class DataLayer {
|
|
|
581
592
|
}
|
|
582
593
|
|
|
583
594
|
reset() {
|
|
584
|
-
if (!this.
|
|
595
|
+
if (!this.createdOnServer) this.erase()
|
|
585
596
|
|
|
586
597
|
this.resetOptions()
|
|
587
598
|
this.parentPane.appendChild(this.pane)
|
|
@@ -604,7 +615,7 @@ export class DataLayer {
|
|
|
604
615
|
}
|
|
605
616
|
|
|
606
617
|
edit() {
|
|
607
|
-
if (!this.
|
|
618
|
+
if (!this._umap.editEnabled || !this.isLoaded()) {
|
|
608
619
|
return
|
|
609
620
|
}
|
|
610
621
|
const container = DomUtil.create('div', 'umap-layer-properties-container')
|
|
@@ -615,6 +626,7 @@ export class DataLayer {
|
|
|
615
626
|
'options.type',
|
|
616
627
|
{ handler: 'LayerTypeChooser', label: translate('Type of layer') },
|
|
617
628
|
],
|
|
629
|
+
'options.labelKey',
|
|
618
630
|
[
|
|
619
631
|
'options.displayOnLoad',
|
|
620
632
|
{ label: translate('Display on load'), handler: 'Switch' },
|
|
@@ -638,7 +650,7 @@ export class DataLayer {
|
|
|
638
650
|
DomUtil.createTitle(container, translate('Layer properties'), 'icon-layers')
|
|
639
651
|
let builder = new U.FormBuilder(this, metadataFields, {
|
|
640
652
|
callback(e) {
|
|
641
|
-
this.
|
|
653
|
+
this._umap.onDataLayersChanged()
|
|
642
654
|
if (e.helper.field === 'options.type') {
|
|
643
655
|
this.edit()
|
|
644
656
|
}
|
|
@@ -687,7 +699,6 @@ export class DataLayer {
|
|
|
687
699
|
'options.zoomTo',
|
|
688
700
|
'options.fromZoom',
|
|
689
701
|
'options.toZoom',
|
|
690
|
-
'options.labelKey',
|
|
691
702
|
]
|
|
692
703
|
|
|
693
704
|
builder = new U.FormBuilder(this, optionsFields, {
|
|
@@ -749,7 +760,7 @@ export class DataLayer {
|
|
|
749
760
|
},
|
|
750
761
|
],
|
|
751
762
|
]
|
|
752
|
-
if (this.
|
|
763
|
+
if (this._umap.properties.urls.ajax_proxy) {
|
|
753
764
|
remoteDataFields.push([
|
|
754
765
|
'options.remoteData.proxy',
|
|
755
766
|
{
|
|
@@ -775,7 +786,8 @@ export class DataLayer {
|
|
|
775
786
|
this
|
|
776
787
|
)
|
|
777
788
|
|
|
778
|
-
if (this.
|
|
789
|
+
if (this._umap.properties.urls.datalayer_versions)
|
|
790
|
+
this.buildVersionsFieldset(container)
|
|
779
791
|
|
|
780
792
|
const advancedActions = DomUtil.createFieldset(
|
|
781
793
|
container,
|
|
@@ -788,7 +800,7 @@ export class DataLayer {
|
|
|
788
800
|
</button>`)
|
|
789
801
|
deleteButton.addEventListener('click', () => {
|
|
790
802
|
this._delete()
|
|
791
|
-
this.
|
|
803
|
+
this._umap.editPanel.close()
|
|
792
804
|
})
|
|
793
805
|
advancedButtons.appendChild(deleteButton)
|
|
794
806
|
|
|
@@ -811,7 +823,7 @@ export class DataLayer {
|
|
|
811
823
|
},
|
|
812
824
|
this
|
|
813
825
|
)
|
|
814
|
-
if (this.
|
|
826
|
+
if (this.createdOnServer) {
|
|
815
827
|
const filename = `${Utils.slugify(this.options.name)}.geojson`
|
|
816
828
|
const download = Utils.loadTemplate(`
|
|
817
829
|
<a class="button" href="${this._dataUrl()}" download="${filename}">
|
|
@@ -827,9 +839,9 @@ export class DataLayer {
|
|
|
827
839
|
// Fixme: remove me when this is merged and released
|
|
828
840
|
// https://github.com/Leaflet/Leaflet/pull/9052
|
|
829
841
|
DomEvent.disableClickPropagation(backButton)
|
|
830
|
-
DomEvent.on(backButton, 'click', this.
|
|
842
|
+
DomEvent.on(backButton, 'click', this._umap.editDatalayers, this._umap)
|
|
831
843
|
|
|
832
|
-
this.
|
|
844
|
+
this._umap.editPanel.open({
|
|
833
845
|
content: container,
|
|
834
846
|
actions: [backButton],
|
|
835
847
|
})
|
|
@@ -850,28 +862,22 @@ export class DataLayer {
|
|
|
850
862
|
if (this.layer?.defaults?.[option]) {
|
|
851
863
|
return this.layer.defaults[option]
|
|
852
864
|
}
|
|
853
|
-
return this.
|
|
865
|
+
return this._umap.getProperty(option, feature)
|
|
854
866
|
}
|
|
855
867
|
|
|
856
868
|
async buildVersionsFieldset(container) {
|
|
857
869
|
const appendVersion = (data) => {
|
|
858
870
|
const date = new Date(Number.parseInt(data.at, 10))
|
|
859
|
-
const content = `${date.toLocaleString(
|
|
871
|
+
const content = `${date.toLocaleString(U.lang)} (${Number.parseInt(data.size) / 1000}Kb)`
|
|
860
872
|
const el = DomUtil.create('div', 'umap-datalayer-version', versionsContainer)
|
|
861
|
-
const button = DomUtil.createButton(
|
|
862
|
-
'',
|
|
863
|
-
el,
|
|
864
|
-
'',
|
|
865
|
-
() => this.restore(data.name),
|
|
866
|
-
this
|
|
867
|
-
)
|
|
873
|
+
const button = DomUtil.createButton('', el, '', () => this.restore(data.ref))
|
|
868
874
|
button.title = translate('Restore this version')
|
|
869
875
|
DomUtil.add('span', '', el, content)
|
|
870
876
|
}
|
|
871
877
|
|
|
872
878
|
const versionsContainer = DomUtil.createFieldset(container, translate('Versions'), {
|
|
873
879
|
async callback() {
|
|
874
|
-
const [{ versions }, response, error] = await this.
|
|
880
|
+
const [{ versions }, response, error] = await this._umap.server.get(
|
|
875
881
|
this.getVersionsUrl()
|
|
876
882
|
)
|
|
877
883
|
if (!error) versions.forEach(appendVersion)
|
|
@@ -881,11 +887,11 @@ export class DataLayer {
|
|
|
881
887
|
}
|
|
882
888
|
|
|
883
889
|
async restore(version) {
|
|
884
|
-
if (!this.
|
|
885
|
-
this.
|
|
890
|
+
if (!this._umap.editEnabled) return
|
|
891
|
+
this._umap.dialog
|
|
886
892
|
.confirm(translate('Are you sure you want to restore this version?'))
|
|
887
893
|
.then(async () => {
|
|
888
|
-
const [geojson, response, error] = await this.
|
|
894
|
+
const [geojson, response, error] = await this._umap.server.get(
|
|
889
895
|
this.getVersionUrl(version)
|
|
890
896
|
)
|
|
891
897
|
if (!error) {
|
|
@@ -906,13 +912,13 @@ export class DataLayer {
|
|
|
906
912
|
}
|
|
907
913
|
|
|
908
914
|
async show() {
|
|
909
|
-
this.
|
|
915
|
+
this._leafletMap.addLayer(this.layer)
|
|
910
916
|
if (!this.isLoaded()) await this.fetchData()
|
|
911
917
|
this.propagateShow()
|
|
912
918
|
}
|
|
913
919
|
|
|
914
920
|
hide() {
|
|
915
|
-
this.
|
|
921
|
+
this._leafletMap.removeLayer(this.layer)
|
|
916
922
|
this.propagateHide()
|
|
917
923
|
}
|
|
918
924
|
|
|
@@ -929,7 +935,7 @@ export class DataLayer {
|
|
|
929
935
|
const bounds = this.layer.getBounds()
|
|
930
936
|
if (bounds.isValid()) {
|
|
931
937
|
const options = { maxZoom: this.getOption('zoomTo') }
|
|
932
|
-
this.
|
|
938
|
+
this._leafletMap.fitBounds(bounds, options)
|
|
933
939
|
}
|
|
934
940
|
}
|
|
935
941
|
|
|
@@ -960,7 +966,7 @@ export class DataLayer {
|
|
|
960
966
|
}
|
|
961
967
|
|
|
962
968
|
isVisible() {
|
|
963
|
-
return Boolean(this.layer && this.
|
|
969
|
+
return Boolean(this.layer && this._leafletMap.hasLayer(this.layer))
|
|
964
970
|
}
|
|
965
971
|
|
|
966
972
|
getFeatureByIndex(index) {
|
|
@@ -997,7 +1003,7 @@ export class DataLayer {
|
|
|
997
1003
|
getPreviousBrowsable() {
|
|
998
1004
|
let id = this.getRank()
|
|
999
1005
|
let next
|
|
1000
|
-
const index = this.
|
|
1006
|
+
const index = this._umap.datalayersIndex
|
|
1001
1007
|
while (((id = index[++id] ? id : 0), (next = index[id]))) {
|
|
1002
1008
|
if (next === this || next.canBrowse()) break
|
|
1003
1009
|
}
|
|
@@ -1007,7 +1013,7 @@ export class DataLayer {
|
|
|
1007
1013
|
getNextBrowsable() {
|
|
1008
1014
|
let id = this.getRank()
|
|
1009
1015
|
let prev
|
|
1010
|
-
const index = this.
|
|
1016
|
+
const index = this._umap.datalayersIndex
|
|
1011
1017
|
while (((id = index[--id] ? id : index.length - 1), (prev = index[id]))) {
|
|
1012
1018
|
if (prev === this || prev.canBrowse()) break
|
|
1013
1019
|
}
|
|
@@ -1023,7 +1029,7 @@ export class DataLayer {
|
|
|
1023
1029
|
}
|
|
1024
1030
|
|
|
1025
1031
|
getRank() {
|
|
1026
|
-
return this.
|
|
1032
|
+
return this._umap.datalayersIndex.indexOf(this)
|
|
1027
1033
|
}
|
|
1028
1034
|
|
|
1029
1035
|
isReadOnly() {
|
|
@@ -1036,6 +1042,11 @@ export class DataLayer {
|
|
|
1036
1042
|
return this.isReadOnly() || this.isRemoteLayer()
|
|
1037
1043
|
}
|
|
1038
1044
|
|
|
1045
|
+
setReferenceVersion({ response, sync }) {
|
|
1046
|
+
this._referenceVersion = response.headers.get('X-Datalayer-Version')
|
|
1047
|
+
this.sync.update('_referenceVersion', this._referenceVersion)
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1039
1050
|
async save() {
|
|
1040
1051
|
if (this.isDeleted) return await this.saveDelete()
|
|
1041
1052
|
if (!this.isLoaded()) {
|
|
@@ -1050,19 +1061,21 @@ export class DataLayer {
|
|
|
1050
1061
|
// Filename support is shaky, don't do it for now.
|
|
1051
1062
|
const blob = new Blob([JSON.stringify(geojson)], { type: 'application/json' })
|
|
1052
1063
|
formData.append('geojson', blob)
|
|
1053
|
-
const
|
|
1054
|
-
map_id: this.
|
|
1055
|
-
pk: this.
|
|
1064
|
+
const saveURL = this._umap.urls.get('datalayer_save', {
|
|
1065
|
+
map_id: this._umap.id,
|
|
1066
|
+
pk: this.id,
|
|
1067
|
+
created: this.createdOnServer,
|
|
1056
1068
|
})
|
|
1057
|
-
const headers = this.
|
|
1058
|
-
? { 'X-Datalayer-Reference': this.
|
|
1069
|
+
const headers = this._referenceVersion
|
|
1070
|
+
? { 'X-Datalayer-Reference': this._referenceVersion }
|
|
1059
1071
|
: {}
|
|
1060
|
-
await this._trySave(
|
|
1072
|
+
const status = await this._trySave(saveURL, headers, formData)
|
|
1061
1073
|
this._geojson = geojson
|
|
1074
|
+
return status
|
|
1062
1075
|
}
|
|
1063
1076
|
|
|
1064
1077
|
async _trySave(url, headers, formData) {
|
|
1065
|
-
const [data, response, error] = await this.
|
|
1078
|
+
const [data, response, error] = await this._umap.server.post(url, headers, formData)
|
|
1066
1079
|
if (error) {
|
|
1067
1080
|
if (response && response.status === 412) {
|
|
1068
1081
|
AlertConflict.error(
|
|
@@ -1071,7 +1084,15 @@ export class DataLayer {
|
|
|
1071
1084
|
'This situation is tricky, you have to choose carefully which version is pertinent.'
|
|
1072
1085
|
),
|
|
1073
1086
|
async () => {
|
|
1074
|
-
|
|
1087
|
+
// Save again this layer
|
|
1088
|
+
const status = await this._trySave(url, {}, formData)
|
|
1089
|
+
if (status) {
|
|
1090
|
+
this.isDirty = false
|
|
1091
|
+
|
|
1092
|
+
// Call the main save, in case something else needs to be saved
|
|
1093
|
+
// as the conflict stopped the saving flow
|
|
1094
|
+
await this._umap.saveAll()
|
|
1095
|
+
}
|
|
1075
1096
|
}
|
|
1076
1097
|
)
|
|
1077
1098
|
}
|
|
@@ -1083,30 +1104,27 @@ export class DataLayer {
|
|
|
1083
1104
|
this.fromGeoJSON(data.geojson)
|
|
1084
1105
|
delete data.geojson
|
|
1085
1106
|
}
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
this.setUmapId(data.id)
|
|
1107
|
+
delete data.id
|
|
1108
|
+
delete data._referenceVersion
|
|
1090
1109
|
this.updateOptions(data)
|
|
1110
|
+
|
|
1111
|
+
this.setReferenceVersion({ response, sync: true })
|
|
1112
|
+
|
|
1091
1113
|
this.backupOptions()
|
|
1114
|
+
this.backupData()
|
|
1092
1115
|
this.connectToMap()
|
|
1093
1116
|
this._loaded = true
|
|
1094
1117
|
this.redraw() // Needed for reordering features
|
|
1095
|
-
|
|
1096
|
-
this.permissions.save()
|
|
1118
|
+
return true
|
|
1097
1119
|
}
|
|
1098
1120
|
}
|
|
1099
1121
|
|
|
1100
1122
|
async saveDelete() {
|
|
1101
|
-
if (this.
|
|
1102
|
-
await this.
|
|
1123
|
+
if (this.createdOnServer) {
|
|
1124
|
+
await this._umap.server.post(this.getDeleteUrl())
|
|
1103
1125
|
}
|
|
1104
|
-
delete this.
|
|
1105
|
-
|
|
1106
|
-
}
|
|
1107
|
-
|
|
1108
|
-
getMap() {
|
|
1109
|
-
return this.map
|
|
1126
|
+
delete this._umap.datalayers[stamp(this)]
|
|
1127
|
+
return true
|
|
1110
1128
|
}
|
|
1111
1129
|
|
|
1112
1130
|
getName() {
|
|
@@ -1115,7 +1133,7 @@ export class DataLayer {
|
|
|
1115
1133
|
|
|
1116
1134
|
tableEdit() {
|
|
1117
1135
|
if (!this.isVisible()) return
|
|
1118
|
-
const editor = new TableEditor(this)
|
|
1136
|
+
const editor = new TableEditor(this._umap, this, this._leafletMap)
|
|
1119
1137
|
editor.open()
|
|
1120
1138
|
}
|
|
1121
1139
|
|
|
@@ -1123,14 +1141,16 @@ export class DataLayer {
|
|
|
1123
1141
|
// This keys will be used to filter feature from the browser text input.
|
|
1124
1142
|
// By default, it will we use the "name" property, which is also the one used as label in the features list.
|
|
1125
1143
|
// When map owner has configured another label or sort key, we try to be smart and search in the same keys.
|
|
1126
|
-
if (this.
|
|
1144
|
+
if (this._umap.properties.filterKey) return this._umap.properties.filterKey
|
|
1127
1145
|
if (this.getOption('labelKey')) return this.getOption('labelKey')
|
|
1128
|
-
if (this.
|
|
1146
|
+
if (this._umap.properties.sortKey) return this._umap.properties.sortKey
|
|
1129
1147
|
return 'displayName'
|
|
1130
1148
|
}
|
|
1131
1149
|
|
|
1132
1150
|
renderLegend() {
|
|
1133
|
-
for (const container of document.querySelectorAll(
|
|
1151
|
+
for (const container of document.querySelectorAll(
|
|
1152
|
+
`.${this.cssId} .datalayer-legend`
|
|
1153
|
+
)) {
|
|
1134
1154
|
container.innerHTML = ''
|
|
1135
1155
|
if (this.layer.renderLegend) return this.layer.renderLegend(container)
|
|
1136
1156
|
const color = DomUtil.create('span', 'datalayer-color', container)
|
|
@@ -1174,7 +1194,7 @@ export class DataLayer {
|
|
|
1174
1194
|
'click',
|
|
1175
1195
|
function () {
|
|
1176
1196
|
if (!this.isVisible()) return
|
|
1177
|
-
this.
|
|
1197
|
+
this._umap.dialog
|
|
1178
1198
|
.confirm(translate('Are you sure you want to delete this layer?'))
|
|
1179
1199
|
.then(() => {
|
|
1180
1200
|
this._delete()
|