mirror of
https://github.com/umap-project/umap.git
synced 2025-05-04 21:51:50 +02:00
Compare commits
8 commits
7de3ebd2d1
...
2c64745c52
Author | SHA1 | Date | |
---|---|---|---|
![]() |
2c64745c52 | ||
![]() |
d38d8e152c | ||
![]() |
25bf7e1466 | ||
![]() |
9656d04432 | ||
![]() |
3104636cff | ||
![]() |
91f3d55f5b | ||
![]() |
4b170df1c2 | ||
![]() |
123a6ea508 |
6 changed files with 38 additions and 16 deletions
|
@ -35,7 +35,7 @@ dependencies = [
|
|||
"Pillow==11.0.0",
|
||||
"psycopg==3.2.3",
|
||||
"requests==2.32.3",
|
||||
"rcssmin==1.1.3",
|
||||
"rcssmin==1.2.0",
|
||||
"rjsmin==1.2.3",
|
||||
"social-auth-core==4.5.4",
|
||||
"social-auth-app-django==5.4.2",
|
||||
|
@ -44,7 +44,7 @@ dependencies = [
|
|||
[project.optional-dependencies]
|
||||
dev = [
|
||||
"hatch==1.13.0",
|
||||
"ruff==0.7.3",
|
||||
"ruff==0.7.4",
|
||||
"djlint==1.36.1",
|
||||
"mkdocs==1.6.1",
|
||||
"mkdocs-material==9.5.44",
|
||||
|
|
|
@ -35,6 +35,7 @@ class PopupTemplate {
|
|||
feature.properties.description || '',
|
||||
properties
|
||||
)
|
||||
properties.name = properties.name ?? feature.getDisplayName()
|
||||
let content = Utils.greedyTemplate(template, properties)
|
||||
content = Utils.toHTML(content, { target: target })
|
||||
return Utils.loadTemplate(`<div class="umap-popup-container text">${content}</div>`)
|
||||
|
|
|
@ -196,10 +196,10 @@ export default class Rules {
|
|||
constructor(umap) {
|
||||
this._umap = umap
|
||||
this.rules = []
|
||||
this.loadRules()
|
||||
this.load()
|
||||
}
|
||||
|
||||
loadRules() {
|
||||
load() {
|
||||
if (!this._umap.properties.rules?.length) return
|
||||
for (const { condition, options } of this._umap.properties.rules) {
|
||||
if (!condition) continue
|
||||
|
|
|
@ -18,7 +18,7 @@ export default class Slideshow extends WithTemplate {
|
|||
this._umap = umap
|
||||
this._id = null
|
||||
this.CLASSNAME = 'umap-slideshow-active'
|
||||
this.setProperties(properties)
|
||||
this.load()
|
||||
this._current = null
|
||||
|
||||
if (this.properties.autoplay) {
|
||||
|
@ -54,7 +54,11 @@ export default class Slideshow extends WithTemplate {
|
|||
return this.current.getNext()
|
||||
}
|
||||
|
||||
setProperties(properties) {
|
||||
load() {
|
||||
this.setProperties(this._umap.properties.slideshow)
|
||||
}
|
||||
|
||||
setProperties(properties = {}) {
|
||||
this.properties = Object.assign(
|
||||
{
|
||||
delay: 5000,
|
||||
|
|
|
@ -94,7 +94,7 @@ export default class Umap extends ServerStored {
|
|||
// Needed to render controls
|
||||
this.permissions = new MapPermissions(this)
|
||||
this.urls = new URLs(this.properties.urls)
|
||||
this.slideshow = new Slideshow(this, this._leafletMap, this.properties.slideshow)
|
||||
this.slideshow = new Slideshow(this, this._leafletMap)
|
||||
|
||||
this._leafletMap.setup()
|
||||
|
||||
|
@ -671,6 +671,17 @@ export default class Umap extends ServerStored {
|
|||
this.permissions.properties = Object.assign({}, this._backupProperties.permissions)
|
||||
}
|
||||
|
||||
setProperties(newProperties) {
|
||||
for (const key of Object.keys(SCHEMA)) {
|
||||
if (newProperties[key] !== undefined) {
|
||||
this.properties[key] = newProperties[key]
|
||||
if (key === 'rules') this.rules.load()
|
||||
if (key === 'slideshow') this.slideshow.load()
|
||||
// TODO: sync ?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hasData() {
|
||||
for (const datalayer of this.datalayersIndex) {
|
||||
if (datalayer.hasData()) return true
|
||||
|
@ -993,7 +1004,7 @@ export default class Umap extends ServerStored {
|
|||
],
|
||||
]
|
||||
const slideshowBuilder = new U.FormBuilder(this, slideshowFields, {
|
||||
callback: () => this.slideshow.setProperties(this.properties.slideshow),
|
||||
callback: () => this.slideshow.load(),
|
||||
umap: this,
|
||||
})
|
||||
slideshow.appendChild(slideshowBuilder.build())
|
||||
|
@ -1483,15 +1494,9 @@ export default class Umap extends ServerStored {
|
|||
|
||||
importRaw(rawData) {
|
||||
const importedData = JSON.parse(rawData)
|
||||
const mustReindex = 'sortKey' in Object.keys(importedData.properties)
|
||||
|
||||
let mustReindex = false
|
||||
|
||||
for (const option of Object.keys(SCHEMA)) {
|
||||
if (typeof importedData.properties[option] !== 'undefined') {
|
||||
this.properties[option] = importedData.properties[option]
|
||||
if (option === 'sortKey') mustReindex = true
|
||||
}
|
||||
}
|
||||
this.setProperties(importedData.properties)
|
||||
|
||||
if (importedData.geometry) {
|
||||
this.properties.center = this._leafletMap.latLng(importedData.geometry)
|
||||
|
|
|
@ -57,6 +57,18 @@ def test_should_handle_locale_var_in_description(live_server, map, page):
|
|||
expect(link).to_have_attribute("href", "https://domain.org/?locale=en")
|
||||
|
||||
|
||||
def test_should_use_custom_label_key_in_popup_default_template(live_server, map, page):
|
||||
data = deepcopy(DATALAYER_DATA)
|
||||
data["features"][0]["properties"] = {
|
||||
"libellé": "my custom label",
|
||||
}
|
||||
data["_umap_options"] = {"labelKey": "libellé"}
|
||||
DataLayerFactory(map=map, data=data)
|
||||
page.goto(f"{live_server.url}{map.get_absolute_url()}")
|
||||
page.locator(".leaflet-marker-icon").click()
|
||||
expect(page.locator(".umap-popup h4")).to_have_text("my custom label")
|
||||
|
||||
|
||||
def test_should_display_tooltip_with_variable(live_server, map, page, bootstrap):
|
||||
map.settings["properties"]["showLabel"] = True
|
||||
map.settings["properties"]["labelKey"] = "Foo {name}"
|
||||
|
|
Loading…
Reference in a new issue