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.on(edit, 'mousedown', (e) => {
|
||||||
L.DomEvent.stop(e)
|
L.DomEvent.stop(e)
|
||||||
const datalayer = self.map.defaultDataLayer()
|
const datalayer = self.map.defaultEditDataLayer()
|
||||||
const layer = datalayer.geojsonToFeatures(feature)
|
const layer = datalayer.geojsonToFeatures(feature)
|
||||||
layer.isDirty = true
|
layer.isDirty = true
|
||||||
layer.edit()
|
layer.edit()
|
||||||
|
@ -1636,7 +1636,7 @@ L.U.Editable = L.Editable.extend({
|
||||||
|
|
||||||
connectCreatedToMap: function (layer) {
|
connectCreatedToMap: function (layer) {
|
||||||
// Overrided from Leaflet.Editable
|
// Overrided from Leaflet.Editable
|
||||||
const datalayer = this.map.defaultDataLayer()
|
const datalayer = this.map.defaultEditDataLayer()
|
||||||
datalayer.addLayer(layer)
|
datalayer.addLayer(layer)
|
||||||
layer.isDirty = true
|
layer.isDirty = true
|
||||||
return layer
|
return layer
|
||||||
|
|
|
@ -694,10 +694,17 @@ L.U.Map.include({
|
||||||
this._setDefaultCenter()
|
this._setDefaultCenter()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const datalayer = this.defaultDataLayer(),
|
const datalayer = this.firstVisibleDatalayer()
|
||||||
feature = datalayer.getFeatureByIndex(-1)
|
let feature
|
||||||
if (feature) feature.zoomTo()
|
if (datalayer) {
|
||||||
else this._setDefaultCenter()
|
const feature = datalayer.getFeatureByIndex(-1)
|
||||||
|
if (feature) {
|
||||||
|
feature.zoomTo()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Fallback, no datalayer or no feature found
|
||||||
|
this._setDefaultCenter()
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
this._setDefaultCenter()
|
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
|
// TODO: allow to control the default datalayer
|
||||||
// (edit and viewing)
|
// (edit and viewing)
|
||||||
// cf https://github.com/umap-project/umap/issues/585
|
// cf https://github.com/umap-project/umap/issues/585
|
||||||
defaultDataLayer: function () {
|
defaultEditDataLayer: function () {
|
||||||
let datalayer, fallback
|
let datalayer, fallback
|
||||||
datalayer = this.lastUsedDataLayer
|
datalayer = this.lastUsedDataLayer
|
||||||
if (
|
if (
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import json
|
import json
|
||||||
|
import re
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -11,6 +12,20 @@ from ..base import DataLayerFactory
|
||||||
pytestmark = pytest.mark.django_db
|
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(
|
def test_remote_layer_should_not_be_used_as_datalayer_for_created_features(
|
||||||
map, live_server, datalayer, page
|
map, live_server, datalayer, page
|
||||||
):
|
):
|
||||||
|
|
Loading…
Reference in a new issue