Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. window.RemoteWind = window.RemoteWind || {};
  2.  
  3. // This uses Chroma.js to build a color scale which is used for wind speed.
  4. // http://gka.github.io/chroma.js
  5. RemoteWind.color_scale = chroma.scale([
  6. 'lightblue',
  7. 'green',
  8. 'red',
  9. 'purple'
  10. ])
  11. .mode('hsl') // the blending mode
  12. .domain([0, 7, 15, 25]); // the distinct steps for each.
  13.  
  14. RemoteWind.VectorIcon = L.Icon.extend({
  15. options: {
  16. height: 26,
  17. width: 26,
  18. stroke: 'white',
  19. strokeWidth: 2,
  20. circle: {
  21. cx: 13,
  22. cy: 13,
  23. r: 13
  24. }
  25. },
  26. _createSVG: function(){
  27. var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
  28. svg.setAttributeNS(null, 'version', '1.1')
  29. svg.setAttribute("xmlns", "http://www.w3.org/2000/svg");
  30. svg.setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
  31. svg.setAttribute('height', this.options.height);
  32. svg.setAttribute('width', this.options.width);
  33. return svg;
  34. }
  35. });
  36.  
  37. /*
  38. * Vector based icon for a station
  39. */
  40. RemoteWind.StationIcon = RemoteWind.VectorIcon.extend({
  41. options: {
  42. className: 'leaflet-station-icon active',
  43. speed: 0,
  44. direction: 0,
  45. path: {
  46. d: "M26,19c0-2.2-0.6-4.4-1.6-6.2C22.2,8.8,13,0,13,0S3.8,8.7,1.6,12.8c-1,1.8-1.6,4-1.6,6.2c0,7.2,5.8,13,13,13 S26,26.2,26,19z"
  47. }
  48. },
  49. createIcon: function (oldIcon) {
  50. var div = (oldIcon && oldIcon.tagName === 'DIV') ? oldIcon : document.createElement('div'),
  51. svg = this._createSVG(),
  52. g = document.createElementNS('http://www.w3.org/2000/svg', 'g'),
  53. txt_g = document.createElementNS('http://www.w3.org/2000/svg', 'g'),
  54. options = this.options,
  55. path,
  56. txt;
  57.  
  58. g.setAttributeNS(null, "transform", "translate(0,-6)");
  59.  
  60. path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
  61. path.setAttributeNS(null, 'd', "M26,19c0-2.2-0.6-4.4-1.6-6.2C22.2,8.8,13,0,13,0S3.8,8.7,1.6,12.8c-1,1.8-1.6,4-1.6,6.2c0,7.2,5.8,13,13,13 S26,26.2,26,19z");
  62. path.setAttributeNS(null, 'stroke', this.options.stroke);
  63. path.setAttributeNS(null, 'stroke-width', this.options.strokeWidth);
  64. path.setAttributeNS(null, 'fill', RemoteWind.color_scale(options.speed).name() );
  65. path.setAttributeNS(null, 'transform', 'rotate(% 13 19)'.replace('%', options.direction));
  66.  
  67. txt = document.createElementNS('http://www.w3.org/2000/svg', 'text');
  68. txt.innerHTML = Math.round(options.speed).toString();
  69. txt.setAttributeNS(null, 'fill', 'white');
  70. txt.setAttributeNS(null, 'x', this.options.height / 2);
  71. txt.setAttributeNS(null, 'y', this.options.width / 2);
  72. txt.setAttributeNS(null, 'text-anchor', 'middle');
  73. txt.setAttributeNS(null, 'alignment-baseline', 'central');
  74.  
  75. g.appendChild(path);
  76. txt_g.appendChild(txt);
  77. svg.appendChild(g);
  78. svg.appendChild(txt_g);
  79. div.appendChild(svg);
  80. this._setIconStyles(div, 'icon');
  81. return div;
  82. },
  83.  
  84. createShadow: function () {
  85. return null;
  86. }
  87. });
  88.  
  89. RemoteWind.stationIcon = function (options) {
  90. return new RemoteWind.StationIcon(options);
  91. };
  92.  
  93. <div class="leaflet-marker-icon leaflet-station-icon active leaflet-zoom-animated leaflet-interactive" title="Γ…re strand | 2(3) m/s" tabindex="0" style="transform: translate3d(-367px, 85px, 0px); z-index: 85; outline: none;">
  94. <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" height="26" width="26">
  95. <g transform="translate(0,-6)">
  96. <path d="M26,19c0-2.2-0.6-4.4-1.6-6.2C22.2,8.8,13,0,13,0S3.8,8.7,1.6,12.8c-1,1.8-1.6,4-1.6,6.2c0,7.2,5.8,13,13,13 S26,26.2,26,19z" stroke="white" stroke-width="2" fill="#64e0d2" transform="rotate(338 13 19)"></path>
  97. </g>
  98. <g>
  99. <text fill="white" x="13" y="13" text-anchor="middle" alignment-baseline="central">2</text>
  100. </g>
  101. </svg>
  102. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement