source: src/webapp/webserver/lib/js/leaflet.hotline.min.js@ 883b4a5

debian/bullseye
Last change on this file since 883b4a5 was 2fa2ef8, checked in by Joachim Langenbach <joachim.langenbach@…>, 8 years ago

First version of webserver (HTML Frontend)

  • Property mode set to 100644
File size: 4.5 KB
RevLine 
[2fa2ef8]1/*
2 (c) 2017, iosphere GmbH
3 Leaflet.hotline, a Leaflet plugin for drawing gradients along polylines.
4 https://github.com/iosphere/Leaflet.hotline/
5*/
6!function(t,i){"function"==typeof define&&define.amd?define(["leaflet"],i):"object"==typeof exports?module.exports=i:i(t.L)}(this,function(t){if(t.Hotline)return t;var i=function(t){if(!(this instanceof i))return new i(t);var e={0:"green",.5:"yellow",1:"red"};this._canvas=t="string"==typeof t?document.getElementById(t):t,this._ctx=t.getContext("2d"),this._width=t.width,this._height=t.height,this._weight=5,this._outlineWidth=1,this._outlineColor="black",this._min=0,this._max=1,this._data=[],this.palette(e)};i.prototype={width:function(t){return this._width=t,this},height:function(t){return this._height=t,this},weight:function(t){return this._weight=t,this},outlineWidth:function(t){return this._outlineWidth=t,this},outlineColor:function(t){return this._outlineColor=t,this},palette:function(t){var i=document.createElement("canvas"),e=i.getContext("2d"),n=e.createLinearGradient(0,0,0,256);i.width=1,i.height=256;for(var o in t)n.addColorStop(o,t[o]);return e.fillStyle=n,e.fillRect(0,0,1,256),this._palette=e.getImageData(0,0,1,256).data,this},min:function(t){return this._min=t,this},max:function(t){return this._max=t,this},data:function(t){return this._data=t,this},add:function(t){return this._data.push(t),this},draw:function(){var t=this._ctx;return t.globalCompositeOperation="source-over",t.lineCap="round",this._drawOutline(t),this._drawHotline(t),this},getRGBForValue:function(t){var i=Math.min(Math.max((t-this._min)/((this._max-this._min) || 1),0),.999),e=4*Math.floor(256*i);return[this._palette[e],this._palette[e+1],this._palette[e+2]]},_drawOutline:function(t){var i,e,n,o,h,r,s;if(this._outlineWidth)for(i=0,n=this._data.length;i<n;i++)for(o=this._data[i],t.lineWidth=this._weight+2*this._outlineWidth,e=1,h=o.length;e<h;e++)r=o[e-1],s=o[e],t.strokeStyle=this._outlineColor,t.beginPath(),t.moveTo(r.x,r.y),t.lineTo(s.x,s.y),t.stroke()},_drawHotline:function(t){var i,e,n,o,h,r,s,l,a,u;for(t.lineWidth=this._weight,i=0,n=this._data.length;i<n;i++)for(o=this._data[i],e=1,h=o.length;e<h;e++)r=o[e-1],s=o[e],l=t.createLinearGradient(r.x,r.y,s.x,s.y),a=this.getRGBForValue(r.z),u=this.getRGBForValue(s.z),l.addColorStop(0,"rgb("+a.join(",")+")"),l.addColorStop(1,"rgb("+u.join(",")+")"),t.strokeStyle=l,t.beginPath(),t.moveTo(r.x,r.y),t.lineTo(s.x,s.y),t.stroke()}};var e=t.Canvas.extend({_initContainer:function(){t.Canvas.prototype._initContainer.call(this),this._hotline=new i(this._container)},_update:function(){t.Canvas.prototype._update.call(this),this._hotline.width(this._container.width),this._hotline.height(this._container.height)},_updatePoly:function(t){if(this._drawing){var i=t._parts;i.length&&(this._updateOptions(t),this._hotline.data(i).draw())}},_updateOptions:function(t){null!=t.options.min&&this._hotline.min(t.options.min),null!=t.options.max&&this._hotline.max(t.options.max),null!=t.options.weight&&this._hotline.weight(t.options.weight),null!=t.options.outlineWidth&&this._hotline.outlineWidth(t.options.outlineWidth),null!=t.options.outlineColor&&this._hotline.outlineColor(t.options.outlineColor),t.options.palette&&this._hotline.palette(t.options.palette)}}),n=function(i){return t.Browser.canvas?new e(i):null},o={clipSegment:function(i,e,n,o,h){var r,s,l,a=o?this._lastCode:t.LineUtil._getBitCode(i,n),u=t.LineUtil._getBitCode(e,n);for(this._lastCode=u;;){if(!(a|u))return[i,e];if(a&u)return!1;r=a||u,s=t.LineUtil._getEdgeIntersection(i,e,r,n,h),l=t.LineUtil._getBitCode(s,n),r===a?(s.z=i.z,i=s,a=l):(s.z=e.z,e=s,u=l)}}};return t.Hotline=t.Polyline.extend({statics:{Renderer:e,renderer:n},options:{renderer:n(),min:0,max:1,palette:{0:"green",.5:"yellow",1:"red"},weight:5,outlineColor:"black",outlineWidth:1},getRGBForValue:function(t){return this._renderer._hotline.getRGBForValue(t)},_projectLatlngs:function(i,e,n){var o,h,r=i[0]instanceof t.LatLng,s=i.length;if(r){for(h=[],o=0;o<s;o++)h[o]=this._map.latLngToLayerPoint(i[o]),h[o].z=i[o].alt,n.extend(h[o]);e.push(h)}else for(o=0;o<s;o++)this._projectLatlngs(i[o],e,n)},_clipPoints:function(){if(this.options.noClip)return void(this._parts=this._rings);this._parts=[];var t,i,e,n,h,r,s,l=this._parts,a=this._renderer._bounds;for(t=0,e=0,n=this._rings.length;t<n;t++)for(s=this._rings[t],i=0,h=s.length;i<h-1;i++)r=o.clipSegment(s[i],s[i+1],a,i,!0),r&&(l[e]=l[e]||[],l[e].push(r[0]),r[1]===s[i+1]&&i!==h-2||(l[e].push(r[1]),e++))},_clickTolerance:function(){return this.options.weight/2+this.options.outlineWidth+(t.Browser.touch?10:0)}}),t.hotline=function(i,e){return new t.Hotline(i,e)},t});
Note: See TracBrowser for help on using the repository browser.