Merge pull request #1383 from umap-project/default-view-datalayer
Split defaultDatalayer in defaultView/EditDatalayer
This commit is contained in:
commit
a0da0b31a7
3 changed files with 35 additions and 7 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,10 +694,17 @@ L.U.Map.include({
|
|||
this._setDefaultCenter()
|
||||
return
|
||||
}
|
||||
const datalayer = this.defaultDataLayer(),
|
||||
feature = datalayer.getFeatureByIndex(-1)
|
||||
if (feature) feature.zoomTo()
|
||||
else this._setDefaultCenter()
|
||||
const datalayer = this.firstVisibleDatalayer()
|
||||
let feature
|
||||
if (datalayer) {
|
||||
const feature = datalayer.getFeatureByIndex(-1)
|
||||
if (feature) {
|
||||
feature.zoomTo()
|
||||
return
|
||||
}
|
||||
}
|
||||
// Fallback, no datalayer or no feature found
|
||||
this._setDefaultCenter()
|
||||
})
|
||||
} else {
|
||||
this._setDefaultCenter()
|
||||
|
@ -1225,10 +1232,16 @@ L.U.Map.include({
|
|||
}
|
||||
},
|
||||
|
||||
firstVisibleDatalayer: function () {
|
||||
return this.findDataLayer((datalayer) => {
|
||||
if (datalayer.isVisible()) return true
|
||||
})
|
||||
},
|
||||
|
||||
// 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