umap-project / umap

uMap lets you create maps with OpenStreetMap layers in a minute and embed them in your site.
https://umap-project.org
Other
1.18k stars 226 forks source link

Conditions on template #884

Open SMoONF61 opened 3 years ago

SMoONF61 commented 3 years ago

It would be interesting, in the popup template, to be able to put as a condition that the field is not null. Something like this :

if ({name} !== null) {name : # {name} }
if ({myfield} !== null) {Foo : {myfield} }

Unless this is already possible? (Please let me know if this is the case! 😉 )

donalhunt commented 2 years ago

+1 for having the ability to be able to do conditionals. Would be quite useful when dealing with incomplete datasets (common in openstreetmap).

chnuessli commented 2 years ago

+1

davidbgk commented 1 year ago

It's a non-trivial feature, especially because it involves security. Some options to consider:

There is also a potential performance issue to consider if the template is complex and the displayed data is huge.

twitwi commented 8 months ago

I wanted to work on this feature (but I don't know the umap codebase). I think the "full JS syntax" solutions looks good and can be made somewhat secure (by shadowing all global variables, so practically giving access only to the variables of interest).

One general question is how to remain backward compatible? Should the new syntax be used only if the popup template starts with some key word (like js:)... actually this will become a new popup class

twitwi commented 8 months ago

I'm reporting on some explorations. I implemented a prototype for the "full JS (expression) syntax" and I think it is relatively secure, however:

ThierryM commented 7 months ago

Hi, I think that it would be an interesting feature. For instance, I've schools map and I want to indicate if it exists particularities that doesn't exist in all the schools (an optional teaching or special class). The code I use to display the information in a single line is: Particularities: {particularitie1}, {particularitie2}, {particularitie3}

Now, if the fields "particularitie1", "particularitie2", "particularitie3" are empty, I've the title "Particularities:" but nothing after. And the displaying is:

Particularities: , ,

So hiding this title would improve the displaying.

The problem is the same with a single field but there's a workaround if the field value contains "none" instead of no value : the line is displayed even there's nothing interesting to show.

Regards,

Thierry

zyphlar commented 5 months ago

I wonder if we can start with the simple null case and don't allow actual input: {if name} {name} {endif} We already have minimal null-detection logic with "or" pipes as in {name|description|"none"} so simply detecting emptiness shouldn't be much more work or security issue