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.

104 lines
3.0 KiB

  1. var OverpassLayer = require('overpass-layer')
  2. function cssStyle (style) {
  3. var ret = ''
  4. if ('color' in style) {
  5. ret += 'stroke: ' + style.color + ';'
  6. }
  7. ret += 'stroke-width: ' + ('width' in style ? style.width : '3') + ';'
  8. if ('dashArray' in style) {
  9. ret += 'stroke-dasharray: ' + style.dashArray + ';'
  10. }
  11. if ('dashArray' in style) {
  12. ret += 'stroke-dasharray: ' + style.dashArray + ';'
  13. }
  14. if ('dashOffset' in style) {
  15. ret += 'stroke-dashoffset: ' + style.dashOffset + ';'
  16. }
  17. if ('fillColor' in style) {
  18. ret += 'fill: ' + style.fillColor + ';'
  19. } else if ('color' in style) {
  20. ret += 'fill: ' + style.color + ';'
  21. } else {
  22. ret += 'fill: #3388ff;'
  23. }
  24. if ('fillOpacity' in style) {
  25. ret += 'fill-opacity: ' + style.fillOpacity + ';'
  26. } else {
  27. ret += 'fill-opacity: 0.2;'
  28. }
  29. return ret
  30. }
  31. function markerLine (data) {
  32. var ret = '<svg anchorX="13" anchorY="8" width="25" height="15">'
  33. if (!('styles' in data)) {
  34. data = {
  35. style: data,
  36. styles: [ 'default' ]
  37. }
  38. }
  39. for (var i = 0; i < data.styles.length; i++) {
  40. var k = data.styles[i]
  41. var style = k === 'default' ? data.style : data['style:' + k]
  42. ret += '<line x1="0" y1="8" x2="25" y2="8" style="' + cssStyle(style) + '"/>'
  43. }
  44. ret += '</svg>'
  45. return ret
  46. }
  47. function markerPolygon (data) {
  48. var ret = '<svg anchorX="13" anchorY="8" width="25" height="25">'
  49. if (!('styles' in data)) {
  50. data = {
  51. style: data,
  52. styles: [ 'default' ]
  53. }
  54. }
  55. for (var i = 0; i < data.styles.length; i++) {
  56. var k = data.styles[i]
  57. var style = k === 'default' ? data.style : data['style:' + k]
  58. ret += '<rect x="3" y="3" width="18" height="18" style="' + cssStyle(style) + '"/>'
  59. }
  60. ret += '</svg>'
  61. return ret
  62. }
  63. function markerCircle (style) {
  64. var fillColor = 'fillColor' in style ? style.fillColor : '#f2756a'
  65. var color = 'color' in style ? style.color : '#000000'
  66. var width = 'width' in style ? style.width : 1
  67. return '<svg anchorX="13" anchorY="13" width="25" height="25"><circle cx="12.5" cy="12.5" r="12" style="stroke: ' + color + '; stroke-width: ' + width + '; fill: ' + fillColor + ';"/></svg>'
  68. }
  69. function markerPointer (style) {
  70. var fillColor = 'fillColor' in style ? style.fillColor : '#f2756a'
  71. var color = 'color' in style ? style.color : '#000000'
  72. var width = 'width' in style ? style.width : 1
  73. return '<svg anchorX="13" anchorY="45" width="25" height="45" signAnchorX="0" signAnchorY="-31"><path d="M0.5,12.5 A 12,12 0 0 1 24.5,12.5 C 24.5,23 13,30 12.5,44.5 C 12,30 0.5,23 0.5,12.5" style="stroke: ' + color + '; stroke-width: ' + width + '; fill: ' + fillColor + ';"/></svg>'
  74. }
  75. OverpassLayer.twig.extendFunction('markerLine', markerLine)
  76. OverpassLayer.twig.extendFunction('markerCircle', markerCircle)
  77. OverpassLayer.twig.extendFunction('markerPointer', markerPointer)
  78. OverpassLayer.twig.extendFunction('markerPolygon', markerPolygon)
  79. module.exports = {
  80. line: markerLine,
  81. circle: markerCircle,
  82. pointer: markerPointer,
  83. polygon: markerPolygon
  84. }