dolphin-leaflet
Version:
leaflet for dmap
3 lines • 9.48 kB
JavaScript
/*! version:1.1.6 */
webpackJsonp([2],{146:function(t,n,o){"use strict";Object.defineProperty(n,"__esModule",{value:!0});o(153);n.default=function(t,n){return L.velocityLayer(T.assign({displayValues:!0,displayOptions:{velocityType:"GBR Wind",displayPosition:"bottomleft",displayEmptyString:"No wind data"},data:t,maxVelocity:10},n))}},153:function(t,n,o){"use strict";var e=o(154),i=o(155);o.n(i);L.VelocityLayer=L.Layer.extend({options:{displayValues:!0,displayOptions:{velocityType:"Velocity",position:"bottomleft",emptyString:"No velocity data"},maxVelocity:10,colorScale:null,data:null},_timer:0,initialize:function(t){var n=this;L.setOptions(this,t),this.ajax=T.one(function(t){return T.ajax({f:"json",url:t,success:function(t){n.setData(t)}})})},onAdd:function(t){this._canvasLayer=L.canvasLayer().delegate(this),this._canvasLayer.addTo(t),this._map=t},onRemove:function(t){this._destroyWind()},setData:function(t){this.options.data=t,this._windy&&(this._windy.setData(t),this._clearAndRestart()),this.fire("load")},onDrawLayer:function(t,n){var o=this,e=(o._windy,o.options),i=o._timer;if(!this._windy)return void this._initWindy(o);var a=e.data,r=e.url;if(!a)return void(r&&this.ajax(r));i&&clearTimeout(i),this._timer=setTimeout(function(){o._startWindy()},750)},_startWindy:function(){var t=this._map.getBounds(),n=this._map.getSize();this._windy.start([[0,0],[n.x,n.y]],n.x,n.y,[[t._southWest.lng,t._southWest.lat],[t._northEast.lng,t._northEast.lat]])},_initWindy:function(t){this._windy=new e.a(T.assign({canvas:t._canvasLayer._canvas},t.options)),this._context=this._canvasLayer._canvas.getContext("2d"),this._canvasLayer._canvas.classList.add("velocity-overlay"),this.onDrawLayer(),this._map.on("dragstart",t._windy.stop).on("dragend",t._clearAndRestart).on("zoomstart",t._windy.stop).on("zoomend",t._clearAndRestart).on("resize",t._clearWind),this._initMouseHandler()},_initMouseHandler:function(){if(!this._mouseControl&&this.options.displayValues){var t=this.options.displayOptions||{};t.leafletVelocity=this,this._mouseControl=L.control.velocity(t).addTo(this._map)}},_clearAndRestart:function(){this._context&&this._context.clearRect(0,0,3e3,3e3),this._windy&&this._startWindy()},_clearWind:function(){this._windy&&this._windy.stop(),this._context&&this._context.clearRect(0,0,3e3,3e3)},_destroyWind:function(){this._timer&&clearTimeout(this._timer),this._windy&&this._windy.stop(),this._context&&this._context.clearRect(0,0,3e3,3e3),this._mouseControl&&this._map.removeControl(this._mouseControl),this._mouseControl=null,this._windy=null,this._map.removeLayer(this._canvasLayer)}}),L.velocityLayer=function(t){return new L.VelocityLayer(t)}},154:function(t,n,o){"use strict";var e=function(t){var n,o,e,i,a,r,s,l,h,c,u=t.minVelocity||0,d=t.maxVelocity||10,f=(t.velocityScale||.005)*(Math.pow(window.devicePixelRatio,1/3)||1),y=t.particleAge||90,p=t.lineWidth||1,v=t.particleMultiplier||1/300,m=Math.pow(window.devicePixelRatio,1/3)||1.6,_=t.frameRate||15,g=1e3/_,M=["rgb(36,104, 180)","rgb(60,157, 194)","rgb(128,205,193 )","rgb(151,218,168 )","rgb(198,231,181)","rgb(238,247,217)","rgb(255,238,159)","rgb(252,217,125)","rgb(255,182,100)","rgb(252,150,75)","rgb(250,112,52)","rgb(245,64,32)","rgb(237,45,28)","rgb(220,24,32)","rgb(180,0,35)"],w=t.colorScale||M,x=[NaN,NaN,null],b=t.data,C=function(t){b=t},T=function(t,n,o,e,i,a){var r=1-t,s=1-n,l=r*s,h=t*s,c=r*n,u=t*n,d=o[0]*l+e[0]*h+i[0]*c+a[0]*u,f=o[1]*l+e[1]*h+i[1]*c+a[1]*u;return[d,f,Math.sqrt(d*d+f*f)]},P=function(t,n){var o=t.data,e=n.data;return{header:t.header,data:function(t){return[o[t],e[t]]},interpolate:T}},W=function(t){var n=null,o=null,e=null;return t.forEach(function(t){switch(t.header.parameterCategory+","+t.header.parameterNumber){case"1,2":case"2,2":n=t;break;case"1,3":case"2,3":o=t;break;default:e=t}}),P(n,o)},S=function(t,c){n=W(t);var u=n.header;i=u.lo1,a=u.la1,r=u.dx,s=u.dy,l=u.nx,h=u.ny,e=new Date(u.refTime),e.setHours(e.getHours()+u.forecastTime),o=[];for(var d=0,f=Math.floor(l*r)>=360,y=0;y<h;y++){for(var p=[],v=0;v<l;v++,d++)p[v]=n.data(d);f&&p.push(p[0]),o[y]=p}c({date:e,interpolate:D})},D=function(t,e){if(!o)return null;var l,h=R(t-i,360)/r,c=(a-e)/s,u=Math.floor(h),d=u+1,f=Math.floor(c),y=f+1;if(l=o[f]){var p=l[u],v=l[d];if(V(p)&&V(v)&&(l=o[y])){var m=l[u],_=l[d];if(V(m)&&V(_))return n.interpolate(h-u,c-f,p,v,m,_)}}return null},V=function(t){return null!==t&&void 0!==t},R=function(t,n){return t-n*Math.floor(t/n)},k=function(){return/android|blackberry|iemobile|ipad|iphone|ipod|opera mini|webos/i.test(navigator.userAgent)},A=function(t,n,o,e,i,a,r,s){var l=r[0]*a,h=r[1]*a,c=N(t,n,o,e,i,s);return r[0]=c[0]*l+c[2]*h,r[1]=c[1]*l+c[3]*h,r},N=function(t,n,o,e,i,a){var r=2*Math.PI,s=Math.pow(10,-5.2),l=n<0?s:-s,h=o<0?s:-s,c=j(o,n+l,a),u=j(o+h,n,a),d=Math.cos(o/360*r);return[(c[0]-e)/l/d,(c[1]-i)/l/d,(u[0]-e)/h,(u[1]-i)/h]},E=function(t,n,o){function e(n,o){var e=t[Math.round(n)];return e&&e[Math.round(o)]||x}e.release=function(){t=[]},e.randomize=function(t){var o,i,a=0;do{o=Math.round(Math.floor(Math.random()*n.width)+n.x),i=Math.round(Math.floor(Math.random()*n.height)+n.y)}while(null===e(o,i)[2]&&a++<30);return t.x=o,t.y=i,t},o(n,e)},H=function(t,n,o){var e=t[0],i=t[1],a=Math.round(e[0]),r=Math.max(Math.floor(e[1],0),0);Math.min(Math.ceil(i[0],n),n-1);return{x:a,y:r,xMax:n,yMax:Math.min(Math.ceil(i[1],o),o-1),width:n,height:o}},I=function(t){return t/180*Math.PI},z=function(t){return t/(Math.PI/180)},F=function(t,n,o){var e=o.east-o.west,i=o.width/z(e)*360/(2*Math.PI),a=i/2*Math.log((1+Math.sin(o.south))/(1-Math.sin(o.south))),r=o.height+a,s=(r-n)/i,l=180/Math.PI*(2*Math.atan(Math.exp(s))-Math.PI/2);return[z(o.west)+t/o.width*z(e),l]},O=function(t){return Math.log(Math.tan(t/2+Math.PI/4))},j=function(t,n,o){var e=O(o.south),i=O(o.north),a=o.width/(o.east-o.west),r=o.height/(i-e),s=O(I(t)),l=(I(n)-o.west)*a,s=(i-s)*r;return[l,s]},q=function(t,n,o,e){function i(e){for(var i=[],r=n.y;r<=n.yMax;r+=2){var h=F(e,r,o);if(h){var c=h[0],u=h[1];if(isFinite(c)){var d=t.interpolate(c,u);d&&(d=A(a,c,u,e,r,s,d,o),i[r+1]=i[r]=d)}}}l[e+1]=l[e]=i}var a={},r=(o.south-o.north)*(o.west-o.east),s=f*Math.pow(r,.4),l=[],h=n.x;!function t(){for(var o=Date.now();h<n.width;)if(i(h),h+=2,Date.now()-o>1e3)return void setTimeout(t,25);E(l,n,e)}()},U=function(n,o){function e(){r.forEach(function(t){t.length=0}),l.forEach(function(t){t.age>y&&(o.randomize(t).age=0);var n=t.x,e=t.y,i=o(n,e),s=i[2];if(null===s)t.age=y;else{var l=n+i[0],h=e+i[1];null!==o(l,h)[2]?(t.xt=l,t.yt=h,r[a.indexFor(s)].push(t)):(t.x=l,t.y=h)}t.age+=1})}function i(){f.globalCompositeOperation="destination-in",f.fillRect(n.x,n.y,n.width,n.height),f.globalCompositeOperation="lighter",f.globalAlpha=.9,r.forEach(function(t,n){t.length>0&&(f.beginPath(),f.strokeStyle=a[n],t.forEach(function(t){f.moveTo(t.x,t.y),f.lineTo(t.xt,t.yt),t.x=t.xt,t.y=t.yt}),f.stroke())})}var a=function(t,n){return w.indexFor=function(o){return Math.max(0,Math.min(w.length-1,Math.round((o-t)/(n-t)*(w.length-1))))},w}(u,d),r=a.map(function(){return[]}),s=Math.round(n.width*n.height*v);k()&&(s*=m);for(var l=[],h=0;h<s;h++)l.push(o.randomize({age:Math.floor(Math.random()*y)+0}));var f=t.canvas.getContext("2d");f.lineWidth=p,f.fillStyle="rgba(0, 0, 0, 0.97)",f.globalAlpha=.6;var _=Date.now();!function t(){c=requestAnimationFrame(t);var n=Date.now(),o=n-_;o>g&&(_=n-o%g,e(),i())}()},B=function(t,n,o,e){var i={south:I(e[0][1]),north:I(e[1][1]),east:I(e[1][0]),west:I(e[0][0]),width:n,height:o};K(),S(b,function(e){q(e,H(t,n,o),i,function(t,n){G.field=n,U(t,n)})})},K=function(){G.field&&G.field.release(),L.Util.cancelAnimFrame(c)},G={params:t,start:B,stop:K,createField:E,interpolatePoint:D,setData:C};return G};n.a=e},155:function(t,n){L.Control.Velocity=L.Control.extend({options:{position:"bottomright",emptyString:"Unavailable",angleConvention:"bearingCCW",speedUnit:"m/s"},onAdd:function(t){return this._container=T.div("leaflet-control-velocity"),L.DomEvent.disableClickPropagation(this._container),t.on("mousemove",this._onMouseMove,this),this._container.innerHTML=this.options.emptyString,this._container},onRemove:function(t){t.off("mousemove",this._onMouseMove,this)},vectorToSpeed:function(t,n,o){var e=Math.sqrt(Math.pow(t,2)+Math.pow(n,2));return"k/h"===o?this.meterSec2kilometerHour(e):"kt"===o?this.meterSec2Knots(e):e},vectorToDegrees:function(t,n,o){o.endsWith("CCW")&&(n=n>0?n=-n:Math.abs(n));var e=Math.sqrt(Math.pow(t,2)+Math.pow(n,2)),i=Math.atan2(t/e,n/e),a=180*i/Math.PI+180;return"bearingCW"!==o&&"meteoCCW"!==o||(a+=180)>=360&&(a-=360),a},meterSec2Knots:function(t){return t/.514},meterSec2kilometerHour:function(t){return 3.6*t},_onMouseMove:function(t){var n=this,o=this.options.leafletVelocity._map.containerPointToLatLng(L.point(t.containerPoint.x,t.containerPoint.y)),e=this.options.leafletVelocity._windy.interpolatePoint(o.lng,o.lat),i="";i=e&&!isNaN(e[0])&&!isNaN(e[1])&&e[2]?"<strong>"+this.options.velocityType+" Direction: </strong>"+n.vectorToDegrees(e[0],e[1],this.options.angleConvention).toFixed(3)+"°, <strong>"+this.options.velocityType+" Speed: </strong>"+n.vectorToSpeed(e[0],e[1]).toFixed(1)+"m/s":this.options.emptyString,n._container.innerHTML=i}}),L.Map.mergeOptions({positionControl:!1}),L.Map.addInitHook(function(){this.options.positionControl&&(this.positionControl=new L.Control.MousePosition,this.addControl(this.positionControl))}),L.control.velocity=function(t){return new L.Control.Velocity(t)}}});
//# sourceMappingURL=velocityLayer.js.map