Browse Source

Twig function 'colorInterpolate'

master
parent
commit
a724c17deb
  1. 1
      doc/TwigJS.md
  2. 1
      package.json
  3. 5
      src/twigFunctions.js

1
doc/TwigJS.md

@ -21,6 +21,7 @@ There are several extra functions defined for the TwigJS language:
* 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:").
* function openingHoursState(opening_hours_definition): returns state of object as string: 'closed', 'open' or 'unknown'.
* function colorInterpolate(map, value): interpolates between two or more colors. E.g. `colorInterpolate([ 'red', 'yellow', 'green' ], 0.75)`.
Extra filters:
* filter websiteUrl: return a valid http link. Example: `{{ "www.google.com"|websiteUrl }}` -> "http://www.google.com"; `{{ "https://google.com"|websiteUrl }}` -> "https://google.com"

1
package.json

@ -8,6 +8,7 @@
"license": "GPL-3.0",
"dependencies": {
"async": "^2.5.0",
"color-interpolate": "^1.0.2",
"font-awesome": "^4.7.0",
"i18next-client": "^1.11.4",
"ip-location": "^1.0.1",

5
src/twigFunctions.js

@ -1,5 +1,6 @@
var OverpassLayer = require('overpass-layer')
var OpeningHours = require('opening_hours')
var colorInterpolate = require('color-interpolate')
OverpassLayer.twig.extendFunction('tagsPrefix', function (tags, prefix) {
var ret = {}
@ -39,3 +40,7 @@ OverpassLayer.twig.extendFilter('websiteUrl', function (value) {
OverpassLayer.twig.extendFilter('matches', function (value, match) {
return value.match(match)
})
OverpassLayer.twig.extendFunction('colorInterpolate', function (map, value) {
var colormap = colorInterpolate(map)
return colormap(value)
})
Loading…
Cancel
Save