You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.6 KiB

  1. var OverpassLayer = require('overpass-layer')
  2. var OpeningHours = require('opening_hours')
  3. var colorInterpolate = require('color-interpolate')
  4. var osmParseDate = require('openstreetmap-date-parser')
  5. OverpassLayer.twig.extendFunction('tagsPrefix', function (tags, prefix) {
  6. var ret = {}
  7. var count = 0
  8. for (var k in tags) {
  9. if (k.substr(0, prefix.length) === prefix) {
  10. ret[k.substr(prefix.length)] = k
  11. count++
  12. }
  13. }
  14. if (count === 0) {
  15. return null
  16. }
  17. return ret
  18. })
  19. OverpassLayer.twig.extendFunction('openingHoursState', function (openingHours) {
  20. try {
  21. var oh = new OpeningHours(openingHours)
  22. } catch (err) {
  23. console.log('Error in opening_hours: ' + err)
  24. return 'unknown'
  25. }
  26. return oh.getStateString(new Date(), true)
  27. })
  28. OverpassLayer.twig.extendFilter('websiteUrl', function (value) {
  29. if (value.match(/^https?:\/\//)) {
  30. return value
  31. }
  32. return 'http://' + value
  33. })
  34. OverpassLayer.twig.extendFilter('matches', function (value, match) {
  35. return value.toString().match(match)
  36. })
  37. OverpassLayer.twig.extendFunction('colorInterpolate', function (map, value) {
  38. var colormap = colorInterpolate(map)
  39. return colormap(value)
  40. })
  41. OverpassLayer.twig.extendFilter('osmParseDate', function (value) {
  42. return osmParseDate(value)
  43. })
  44. OverpassLayer.twig.extendFunction('evaluate', function (tags) {
  45. var ob = {
  46. id: 'x0',
  47. isShown: true,
  48. layer_id: global.currentCategory.id,
  49. object: {
  50. id: 'x0',
  51. meta: {},
  52. tags: tags,
  53. type: 'special'
  54. }
  55. }
  56. var d = global.currentCategory.layer.evaluate(ob)
  57. return d
  58. })