Split defaultDatalayer in defaultView/EditDatalayer
In view mode, we don't want the fallback to create a new datalayer.
This commit is contained in:
parent
9eea9f942d
commit
29ab98ede3
3 changed files with 29 additions and 5 deletions
|
@ -1382,7 +1382,7 @@ L.U.Search = L.PhotonSearch.extend({
|
|||
})
|
||||
L.DomEvent.on(edit, 'mousedown', (e) => {
|
||||
L.DomEvent.stop(e)
|
||||
const datalayer = self.map.defaultDataLayer()
|
||||
const datalayer = self.map.defaultEditDataLayer()
|
||||
const layer = datalayer.geojsonToFeatures(feature)
|
||||
layer.isDirty = true
|
||||
layer.edit()
|
||||
|
@ -1636,7 +1636,7 @@ L.U.Editable = L.Editable.extend({
|
|||
|
||||
connectCreatedToMap: function (layer) {
|
||||
// Overrided from Leaflet.Editable
|
||||
const datalayer = this.map.defaultDataLayer()
|
||||
const datalayer = this.map.defaultEditDataLayer()
|
||||
datalayer.addLayer(layer)
|
||||
layer.isDirty = true
|
||||
return layer
|
||||
|
|
|
@ -694,8 +694,8 @@ L.U.Map.include({
|
|||
this._setDefaultCenter()
|
||||
return
|
||||
}
|
||||
const datalayer = this.defaultDataLayer(),
|
||||
feature = datalayer.getFeatureByIndex(-1)
|
||||
const datalayer = this.defaultViewDataLayer(),
|
||||
feature = datalayer ? datalayer.getFeatureByIndex(-1) : null
|
||||
if (feature) feature.zoomTo()
|
||||
else this._setDefaultCenter()
|
||||
})
|
||||
|
@ -1225,10 +1225,19 @@ L.U.Map.include({
|
|||
}
|
||||
},
|
||||
|
||||
defaultViewDataLayer: function () {
|
||||
let datalayer, fallback
|
||||
datalayer = this.findDataLayer((datalayer) => {
|
||||
fallback = datalayer
|
||||
if (datalayer.isVisible()) return true
|
||||
})
|
||||
return datalayer || fallback
|
||||
},
|
||||
|
||||
// TODO: allow to control the default datalayer
|
||||
// (edit and viewing)
|
||||
// cf https://github.com/umap-project/umap/issues/585
|
||||
defaultDataLayer: function () {
|
||||
defaultEditDataLayer: function () {
|
||||
let datalayer, fallback
|
||||
datalayer = this.lastUsedDataLayer
|
||||
if (
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import json
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
@ -11,6 +12,20 @@ from ..base import DataLayerFactory
|
|||
pytestmark = pytest.mark.django_db
|
||||
|
||||
|
||||
def test_default_view_latest_without_datalayer_should_use_default_center(
|
||||
map, live_server, datalayer, page
|
||||
):
|
||||
datalayer.settings["displayOnLoad"] = False
|
||||
datalayer.save()
|
||||
map.settings["defaultView"] = "latest"
|
||||
map.save()
|
||||
page.goto(f"{live_server.url}{map.get_absolute_url()}")
|
||||
# Hash is defined, so map is initialized
|
||||
expect(page).to_have_url(re.compile(".*#7/.*"))
|
||||
layers = page.locator(".umap-browse-datalayers li")
|
||||
expect(layers).to_have_count(1)
|
||||
|
||||
|
||||
def test_remote_layer_should_not_be_used_as_datalayer_for_created_features(
|
||||
map, live_server, datalayer, page
|
||||
):
|
||||
|
|
Loading…
Reference in a new issue