Browse Source

Define twig function 'tagsPrefix'

master
parent
commit
0e9ea584be
  1. 1
      README.md
  2. 1
      src/index.js
  3. 19
      src/twigFunctions.js

1
README.md

@ -131,6 +131,7 @@ There are several extra functions defined for the TwigJS language:
* function `tagTransList`: return the translations of the given tag for tags with multiple values separated by ';' (e.g. 'cuisine'). Parameters: key (required, e.g. 'cuisine'), value (required, e.g. 'kebab' or 'kebab;pizza;noodles;burger').
* function `localizedTag`: return a localized tag if available (e.g. 'name:de' for the german translation of the tag). Parameters: tags (the tags property), key prefix (e.g. 'name'). Which language will be returned depends on the "data language" which can be set via Options. If no localized tag is available, the tag value itself will be returned (e.g. value of 'name').
* function `trans`: return the translation of the given string (e.g. 'save', 'unknown', 'unnamed', ...). Parameters: string (the string to translate).
* function `tagsPrefix(tags, prefix)`: return all tags with the specified prefix. The result will be an array with `{ "en": "name:en", "de": "name:de" }` (for the input `{ "name": "foo", "name:en": "english foo", "name:de": "german foo" }` and the prefix "name:").
Notes:
* Variables will automatically be HTML escaped, if not the filter raw is used, e.g.: {{ tags.name|raw }}

1
src/index.js

@ -21,6 +21,7 @@ require('./language')
require('./location')
require('./overpassChooser')
require('./fullscreen')
require('./twigFunctions')
window.onload = function() {
map = L.map('map')

19
src/twigFunctions.js

@ -0,0 +1,19 @@
var OverpassLayer = require('overpass-layer')
OverpassLayer.twig.extendFunction('tagsPrefix', function (tags, prefix) {
var ret = {}
var count = 0
for (var k in tags) {
if (k.substr(0, prefix.length) === prefix) {
ret[k.substr(prefix.length)] = k
count++
}
}
if (count == 0) {
return null
}
return ret
})
Loading…
Cancel
Save