@idmwx/idmui-gl3 4.4.5 → 4.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +8 -4
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -678,7 +678,8 @@ function Ut(a, e, t, r, i, o) {
|
|
|
678
678
|
k(s, {
|
|
679
679
|
placement: "left",
|
|
680
680
|
effect: "light",
|
|
681
|
-
content: "Measure"
|
|
681
|
+
content: "Measure",
|
|
682
|
+
"show-after": 2e3
|
|
682
683
|
}, {
|
|
683
684
|
default: Y(() => [
|
|
684
685
|
l("div", {
|
|
@@ -691,7 +692,8 @@ function Ut(a, e, t, r, i, o) {
|
|
|
691
692
|
k(s, {
|
|
692
693
|
placement: "left",
|
|
693
694
|
effect: "light",
|
|
694
|
-
content: "Point Meteo"
|
|
695
|
+
content: "Point Meteo",
|
|
696
|
+
"show-after": 2e3
|
|
695
697
|
}, {
|
|
696
698
|
default: Y(() => [
|
|
697
699
|
l("div", {
|
|
@@ -704,7 +706,8 @@ function Ut(a, e, t, r, i, o) {
|
|
|
704
706
|
k(s, {
|
|
705
707
|
placement: "left",
|
|
706
708
|
effect: "light",
|
|
707
|
-
content: "Grid"
|
|
709
|
+
content: "Grid",
|
|
710
|
+
"show-after": 2e3
|
|
708
711
|
}, {
|
|
709
712
|
default: Y(() => [
|
|
710
713
|
l("div", {
|
|
@@ -717,7 +720,8 @@ function Ut(a, e, t, r, i, o) {
|
|
|
717
720
|
k(s, {
|
|
718
721
|
placement: "left",
|
|
719
722
|
effect: "light",
|
|
720
|
-
content: "3D"
|
|
723
|
+
content: "3D",
|
|
724
|
+
"show-after": 2e3
|
|
721
725
|
}, {
|
|
722
726
|
default: Y(() => [
|
|
723
727
|
l("div", {
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(E,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("vue"),require("@turf/turf"),require("@mapbox/sphericalmercator"),require("moment"),require("mapbox-gl"),require("@idm-plugin/geo"),require("axios")):typeof define=="function"&&define.amd?define(["exports","vue","@turf/turf","@mapbox/sphericalmercator","moment","mapbox-gl","@idm-plugin/geo","axios"],i):(E=typeof globalThis<"u"?globalThis:E||self,i(E["idm-gl"]={},E.Vue,E["@turf/turf"],E["@mapbox/sphericalmercator"],E.moment,E["mapbox-gl"],E["@idm-plugin/geo"],E.axios))})(this,function(E,i,ee,Oe,A,j,C,U){"use strict";var Po=Object.defineProperty;var No=(E,i,ee)=>i in E?Po(E,i,{enumerable:!0,configurable:!0,writable:!0,value:ee}):E[i]=ee;var z=(E,i,ee)=>(No(E,typeof i!="symbol"?i+"":i,ee),ee);function We(a){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(a){for(const t in a)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(a,t);Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:()=>a[t]})}}return e.default=a,Object.freeze(e)}const v=We(ee),To="";var Fe=Object.defineProperty,He=(a,e,t)=>e in a?Fe(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,me=(a,e,t)=>(He(a,typeof e!="symbol"?e+"":e,t),t);class ge{}me(ge,"LEVEL",{Basic:1,Prime:2,Supper:1024});class be{}me(be,"WEATHER_LAYERS",[{weight:1,name:"Wind",key:"wind",h5:!0,enabled:!0,type:"json",particle:!0},{weight:524288,name:"Wind Particle",key:"wind-particle",peer:{weight:1,key:"wind"},enabled:!0,hide:!0,type:"jpg"},{weight:16,name:"Sig Waves",key:"sig-wave-height",h5:!0,enabled:!0,type:"json"},{weight:4194304,name:"Sig Waves (JPG)",key:"sig-wave",peer:{weight:16,key:"sig-wave"},enabled:!0,hide:!0,type:"jpg"},{weight:8388608,name:"Sig Waves (Contour)",key:"sig-wave-height-contour",peer:{weight:16,key:"sig-wave-contour"},enabled:!0,hide:!0,type:"json"},{weight:96,name:"Current",key:"current",vendor:"cmems",merge:!0,h5:!0,enabled:!0,type:"json"},{weight:1048576,name:"Current Particle",key:"current-particle",vendor:"cmems",peer:{weight:96,key:"current"},enabled:!0,hide:!0,type:"jpg"},{weight:256,name:"Tropicals",key:"tropicals",h5:!0,enabled:!0,type:"json"},{weight:4096,name:"Pressure",h5:!0,key:"prmsl",enabled:!0,type:"json"},{weight:8192,name:"Visibility",vendor:"gfs",key:"visibility",h5:!0,enabled:!0,type:"jpg"},{weight:262144,name:"Precip Acc",key:"precip3h",h5:!0,enabled:!0,type:"jpg"},{weight:6,name:"Swell",key:"swell",merge:!0,h5:!0,enabled:!0,type:"json"},{weight:2,name:"Swell Height",key:"swell-height",partly:!0,enabled:!0,type:"json"},{weight:4,name:"Swell Direction",key:"swell-direction",partly:!0,enabled:!0,type:"json"},{weight:32,name:"Current Direction",key:"current-direction",vendor:"cmems",partly:!0,enabled:!0,type:"json"},{weight:64,name:"Current Speed",key:"current-speed",vendor:"cmems",partly:!0,enabled:!0,type:"json"},{weight:512,name:"Pressure Contour",key:"prmsl-contour",partly:!0,enabled:!0,hide:!0,type:"json"},{weight:1024,name:"Pressure Value",key:"prmsl-value",partly:!0,enabled:!0,hide:!0,type:"json"},{weight:2048,name:"Pressure Front",key:"prmsl-front",partly:!0,enabled:!0,hide:!0,type:"json"},{weight:16384,name:"Iceberg",key:"iceberg",vendor:"cmems",hide:!0,enabled:!1,type:"json"},{weight:32768,name:"Struct Ice",key:"struct-ice",vendor:"cmems",enabled:!1,hide:!0,type:"json"},{weight:65536,name:"Ice Edge",key:"arctic",vendor:"cmems",h5:!0,enabled:!0,type:"jpg"},{weight:131072,name:"Sea Surf. Temp.",key:"water-temp",vendor:"cmems",h5:!0,enabled:!0,type:"jpg"},{weight:2097152,name:"Temp.",key:"temp",h5:!0,enabled:!0,type:"jpg"}]),me(be,"OTHER_LAYERS",[{weight:1,name:"War Zones",key:"war-zones",h5:!0,enabled:!0,type:"json"},{weight:2,name:"GMDSS Areas",key:"gmdss-areas",h5:!0,enabled:!0,type:"json"},{weight:4,name:"ECA Zones",key:"eca-zones",h5:!0,enabled:!0,type:"json"},{weight:8,name:"Load Lines",key:"load-lines",h5:!0,enabled:!0,type:"json"},{weight:16,name:"HRA",key:"high-risk-area",enabled:!1,type:"json"},{weight:32,name:"Pirates",key:"pirates",enabled:!1,type:"json"},{weight:4096,name:"Alert Zones",key:"alert-zones",h5:!0,enabled:!0,type:"json"},{weight:64,name:"Ports",key:"ports",h5:!0,enabled:!0,type:"json"},{weight:128,name:"Time Zones",key:"time-zones",h5:!0,enabled:!0,type:"json"},{weight:256,name:"VRA",key:"voluntary-reporting-area",h5:!0,enabled:!0,type:"json"},{weight:512,name:"Special Areas",key:"special-area",h5:!0,enabled:!0,type:"json"},{weight:1024,name:"Day/Night",key:"day-night",h5:!0,enabled:!0,type:"json"},{weight:2048,name:"ENC",key:"enc",h5:!0,enabled:!0,type:"origin"},{weight:8192,name:"World-12nm",key:"world12nm",h5:!1,enabled:!0,type:"origin"}]);class Se{}me(Se,"WEATHER_TAG",[{weight:4,name:"Adverse Weather Dangerous",key:"DANGEROUS",positive:!0},{weight:2,name:"Adverse Weather Severe",key:"SEVERE",positive:!0},{weight:1,name:"Adverse Weather Heavy",key:"HEAVY",positive:!0}]),me(Se,"SAILING_TAG",[{weight:2048,name:"Deviation",key:"deviation",positive:!0},{weight:4096,name:"Stoppage",key:"stoppage",positive:!0},{weight:8192,name:"Deceleration",key:"deceleration",positive:!0},{weight:16384,name:"No Lane",key:"noLane",positive:!0},{weight:32768,name:"No Noon",key:"noNoon",positive:!0}]),me(Se,"OTHER_TAG",[{weight:2097152,name:"No CP",key:"noCp",positive:!0},{weight:4194304,name:"Send Rpt",key:"sendRpt",positive:!1},{weight:8388608,name:"Send Bps",key:"sendBps",positive:!1},{weight:16777216,name:"Send Pvar",key:"sendPvar",positive:!1},{weight:33554432,name:"Checked",key:"checked",positive:!1},{weight:67108864,name:"Send PWFR",key:"sendPwfr",positive:!1}]);const Io="",k=(a,e)=>{const t=a.__vccOpts||a;for(const[r,o]of e)t[r]=o;return t},Ue={name:"IdmGlLayer",props:{map:{type:Object},mapProjection:{type:String},top:{type:Number,default:60},layerToggle:{type:Boolean,default:!1},toggleVersion:{type:Number},isLogin:{type:Boolean,default:void 0}},emits:["weather","other","coordinate","measure","point","3d","layerToggle","handleToggleVersion"],data(){return{source:"",weatherLayers:[],activeWeatherLayers:[],autoActive:!0,otherLayers:[],layers:{weather:[...be.WEATHER_LAYERS.filter(a=>!["swell-height","swell-direction","current-direction","current-speed"].includes(a.key))],other:[...be.OTHER_LAYERS.filter(a=>a.key!=="world12nm"&&a.enabled)]},weatherLayersCache:"weatherLayersCache",autoActiveCache:"autoActiveCache",otherLayersCache:"otherLayersCache",collectedLayerCache:"collectedLayerCache",sourceCache:"defaultSourceCache",showCoord:!1,showMeasure:!1,showPoint:!1,show3d:!1,version:{v:"0.0.7",k:"glCacheVersion"},right:10,rampColorLayers:["visibility","precip3h","temp","water-temp","arctic"]}},computed:{computeLayerClass(){return function(a,e){let t="layer flex-between";return e.some(r=>r.key===a.key)&&(t="layer flex-between active"),(!a.enabled||this.rampColorLayers.includes(a.key)&&this.mapProjection==="globe")&&(t="layer flex-between disabled"),t}}},watch:{toggleVersion:{handler(){this.$nextTick(()=>{var a;this.right=(((a=document.getElementsByClassName("right-bar")[0])==null?void 0:a.clientWidth)||0)+10})}},source:{handler(a,e){a&&e&&a!==e&&this.handleConfirm()}}},mounted(){const a=localStorage.getItem(this.version.k);this.version.v!==a&&(localStorage.removeItem(this.weatherLayersCache),localStorage.removeItem(this.collectedLayerCache),localStorage.removeItem(this.otherLayersCache),localStorage.removeItem("windFeatherCache"),localStorage.removeItem("currentJsonCache"),localStorage.setItem(this.version.k,this.version.v));let e=localStorage.getItem(this.collectedLayerCache),t=JSON.parse(e||'[{"weight":1,"name":"Wind","key":"wind","collected":true},{"weight":4096,"name":"Pressure","key":"prmsl","collected":true},{"weight":256,"name":"Tropicals","key":"tropicals","collected":true}]');this.layers.weather.forEach(r=>{r.collected=!!t.some(o=>o.key===r.key&&o.collected)}),e=localStorage.getItem(this.autoActiveCache),this.autoActive=e!=="false",e=localStorage.getItem(this.weatherLayersCache),t=JSON.parse(e||'[{"weight":1,"name":"Wind","key":"wind","enabled":true,"type":"json","particle":true},{"weight":4096,"name":"Pressure","key":"prmsl","enabled":true,"type":"json"},{"weight":256,"name":"Tropicals","key":"tropicals","enabled":true,"type":"json"}]'),this.weatherLayers=t,this.autoActive&&(this.activeWeatherLayers=[...t]),e=localStorage.getItem(this.otherLayersCache),t=JSON.parse(e||'[{"weight":4,"name":"ECA Zones","key":"eca-zones","enabled":true,"type":"json"}]'),this.otherLayers=t,e=localStorage.getItem(this.sourceCache),this.source=e||"GFS",this.handleConfirm()},methods:{handleConfirm(){this.$emit("weather",this.weatherLayers,this.activeWeatherLayers,this.source),this.$emit("other",this.otherLayers),localStorage.setItem(this.autoActiveCache,this.autoActive),localStorage.setItem(this.sourceCache,this.source)},handleWeatherLayerPick(a){if(this.rampColorLayers.includes(a.key)&&this.mapProjection==="globe")return!1;this.weatherLayers.some(e=>e.key===a.key)?(this.weatherLayers=this.weatherLayers.filter(e=>e.key!==a.key),this.activeWeatherLayers=this.activeWeatherLayers.filter(e=>e.key!==a.key)):this.weatherLayers.length<12&&a.enabled&&(["png","jpg"].includes(a.type)&&(this.weatherLayers=this.weatherLayers.filter(e=>e.type==="json"),this.activeWeatherLayers=this.activeWeatherLayers.filter(e=>e.type==="json")),this.weatherLayers.push(a),this.activeWeatherLayers.push(a)),localStorage.setItem(this.weatherLayersCache,JSON.stringify(this.weatherLayers)),this.$emit("weather",this.weatherLayers,this.activeWeatherLayers,this.source),localStorage.setItem(this.autoActiveCache,this.autoActive),localStorage.setItem(this.sourceCache,this.source)},handleWeatherLayerCollect(a){var e;if(!a.collected&&((e=this.layers.weather.filter(t=>t.collected))==null?void 0:e.length)>=6)return!1;a.collected=!a.collected,localStorage.setItem(this.collectedLayerCache,JSON.stringify(this.layers.weather)),this.$emit("handleToggleVersion")},handleActiveWeatherLayerPick(a){if(this.rampColorLayers.includes(a.key)&&this.mapProjection==="globe")return!1;if(this.activeWeatherLayers.some(e=>e.key===a.key))this.activeWeatherLayers=this.activeWeatherLayers.filter(e=>e.key!==a.key);else if(a.enabled){this.activeWeatherLayers.push(a);for(const e of this.weatherLayers)a.weight>e.weight&&a.weight&e.weight&&this.activeWeatherLayers.push(e)}this.handleWeatherLayerPick(a)},handleOtherLayerPick(a){this.otherLayers.some(e=>e.key===a.key)?this.otherLayers=this.otherLayers.filter(e=>e.key!==a.key):a.enabled&&this.otherLayers.push(a),localStorage.setItem(this.otherLayersCache,JSON.stringify(this.otherLayers)),this.$emit("other",this.otherLayers)},handleMenuToggle(){this.$emit("layerToggle",!this.layerToggle)},handleCoordToggle(){this.showCoord=!this.showCoord,this.$emit("coordinate",this.showCoord)},handlePointToggle(){this.isLogin?(this.showPoint=!this.showPoint,this.$emit("point",this.showPoint)):this.$emit("handleToggleVersion")},handleMeasureToggle(){this.showMeasure=!this.showMeasure,this.$emit("measure",this.showMeasure)},handle3DToggle(){this.show3d=!this.show3d,this.$emit("3d",this.show3d)}}},Ze={class:"idm-gl3-layer"},Ge={class:"bar-item layer-bars"},Je=[i.createElementVNode("span",{class:"iconfont"},"",-1)],Xe={class:"bar-item tool-bars"},qe=[i.createElementVNode("span",{class:"iconfont"},"",-1)],Ye=[i.createElementVNode("span",{class:"iconfont"},"",-1)],Qe=[i.createElementVNode("span",{class:"iconfont"},"",-1)],Ke=[i.createElementVNode("span",{class:"iconfont"},"",-1)],et=["onClick"],tt=i.createElementVNode("div",{class:"checkbox"},null,-1),at={class:"header-box flex-between"},it=i.createElementVNode("div",null,"Layers",-1),ot={class:"weather-layers card-bg"},rt=i.createElementVNode("div",{class:"layers-title flex-between"},[i.createElementVNode("div",null,"Weather Layers")],-1),st={class:"layers-body"},nt=["onClick"],lt=i.createElementVNode("div",{class:"checkbox"},null,-1),ct=["onClick"],ht={key:0,class:"iconfont bookmark active"},dt={key:1,class:"iconfont bookmark inactive"},pt=i.createElementVNode("div",{class:"tip flex-start"},[i.createElementVNode("i",{class:"iconfont bookmark",style:{"align-self":"flex-start",padding:"5px 5px 0 0"}},""),i.createElementVNode("div",null,"Bookmark your favorite layer to homepage(Max 6)")],-1),mt={class:"other-layers card-bg"},yt=i.createElementVNode("div",{class:"layers-title"},"Other Layers",-1),ft={class:"layers-body"},ut=["onClick"],gt={class:"flex-start"},bt=i.createElementVNode("div",{class:"switch flex-center"},[i.createElementVNode("i",{class:"iconfont open"},""),i.createElementVNode("i",{class:"iconfont close"},"")],-1),_t={class:"source-layers card-bg"},wt=i.createElementVNode("span",{class:"layers-title"},"Forecast Model",-1),Lt={class:"layers-body"};function vt(a,e,t,r,o,s){var p;const n=i.resolveComponent("ElTooltip"),l=i.resolveComponent("ElRadio"),c=i.resolveComponent("ElRadioGroup"),d=i.resolveComponent("ElScrollbar");return i.openBlock(),i.createElementBlock("div",Ze,[i.createElementVNode("div",{class:"menu-bar-box",style:i.normalizeStyle({top:t.top+10+"px",right:o.right+"px"})},[i.createElementVNode("div",Ge,[i.createVNode(n,{placement:"left",effect:"light",content:"Menu","show-after":2e3},{default:i.withCtx(()=>[i.createElementVNode("div",{class:i.normalizeClass(t.layerToggle?"menu-icon active":"menu-icon"),onClick:e[0]||(e[0]=(...h)=>s.handleMenuToggle&&s.handleMenuToggle(...h))},Je,2)]),_:1})])],4),i.createElementVNode("div",{class:"menu-bar-box",style:i.normalizeStyle({top:t.top+160+"px",right:o.right+"px"})},[i.createElementVNode("div",Xe,[i.createVNode(n,{placement:"left",effect:"light",content:"Measure"},{default:i.withCtx(()=>[i.createElementVNode("div",{class:i.normalizeClass(o.showMeasure?"menu-icon active":"menu-icon"),onClick:e[1]||(e[1]=(...h)=>s.handleMeasureToggle&&s.handleMeasureToggle(...h))},qe,2)]),_:1}),i.createVNode(n,{placement:"left",effect:"light",content:"Point Meteo"},{default:i.withCtx(()=>[i.createElementVNode("div",{class:i.normalizeClass(o.showPoint?"menu-icon active":"menu-icon"),onClick:e[2]||(e[2]=(...h)=>s.handlePointToggle&&s.handlePointToggle(...h))},Ye,2)]),_:1}),i.createVNode(n,{placement:"left",effect:"light",content:"Grid"},{default:i.withCtx(()=>[i.createElementVNode("div",{class:i.normalizeClass(o.showCoord?"menu-icon active":"menu-icon"),onClick:e[3]||(e[3]=(...h)=>s.handleCoordToggle&&s.handleCoordToggle(...h))},Qe,2)]),_:1}),i.createVNode(n,{placement:"left",effect:"light",content:"3D"},{default:i.withCtx(()=>[i.createElementVNode("div",{class:i.normalizeClass(o.show3d?"menu-icon active":"menu-icon"),onClick:e[4]||(e[4]=(...h)=>s.handle3DToggle&&s.handle3DToggle(...h))},Ke,2)]),_:1})])],4),((p=o.layers.weather.filter(h=>h.collected))==null?void 0:p.length)>0?(i.openBlock(),i.createElementBlock("div",{key:0,class:"active-layers",style:i.normalizeStyle({right:o.right+"px",bottom:"100px"})},[(i.openBlock(!0),i.createElementBlock(i.Fragment,null,i.renderList(o.layers.weather.filter(h=>h.collected),h=>(i.openBlock(),i.createElementBlock("div",{key:h.key,class:i.normalizeClass(s.computeLayerClass(h,o.activeWeatherLayers)),onClick:g=>s.handleActiveWeatherLayerPick(h)},[tt,i.createElementVNode("span",null,i.toDisplayString(h.name),1)],10,et))),128))],4)):i.createCommentVNode("",!0),i.createElementVNode("div",{class:"available-layers flex-center",style:i.normalizeStyle({top:t.top+"px",right:t.layerToggle?"0px":"-240px"})},[i.createElementVNode("div",{class:i.normalizeClass(["list-box",t.layerToggle?"right-bar":""])},[i.createElementVNode("div",at,[it,i.createElementVNode("div",{class:"iconfont close-btn",onClick:e[5]||(e[5]=(...h)=>s.handleMenuToggle&&s.handleMenuToggle(...h))},"")]),i.createVNode(d,{style:{flex:"1"}},{default:i.withCtx(()=>[i.createElementVNode("div",ot,[rt,i.createElementVNode("div",st,[(i.openBlock(!0),i.createElementBlock(i.Fragment,null,i.renderList(o.layers.weather,h=>(i.openBlock(),i.createElementBlock(i.Fragment,{key:h.key},[h.hide?i.createCommentVNode("",!0):(i.openBlock(),i.createElementBlock("div",{key:0,class:i.normalizeClass(s.computeLayerClass(h,o.weatherLayers))},[i.createElementVNode("div",{class:"flex-start",onClick:g=>s.handleWeatherLayerPick(h)},[lt,i.createElementVNode("span",null,i.toDisplayString(h.name),1)],8,nt),i.createElementVNode("div",{onClick:g=>s.handleWeatherLayerCollect(h)},[h.collected?(i.openBlock(),i.createElementBlock("i",ht,"")):(i.openBlock(),i.createElementBlock("i",dt,""))],8,ct)],2))],64))),128)),pt])]),i.createElementVNode("div",mt,[yt,i.createElementVNode("div",ft,[(i.openBlock(!0),i.createElementBlock(i.Fragment,null,i.renderList(o.layers.other,h=>(i.openBlock(),i.createElementBlock("div",{key:h.key,class:i.normalizeClass(s.computeLayerClass(h,o.otherLayers)),onClick:g=>s.handleOtherLayerPick(h)},[i.createElementVNode("div",gt,[bt,i.createElementVNode("span",null,i.toDisplayString(h.name),1)])],10,ut))),128))])]),i.createElementVNode("div",_t,[wt,i.createElementVNode("div",Lt,[i.createVNode(c,{modelValue:o.source,"onUpdate:modelValue":e[6]||(e[6]=h=>o.source=h),class:"layer-radio flex-col-center-start"},{default:i.withCtx(()=>[i.createVNode(l,{value:"GFS"},{default:i.withCtx(()=>[i.createTextVNode("GFS")]),_:1}),i.createVNode(l,{value:"CMEMS"},{default:i.withCtx(()=>[i.createTextVNode("CMEMS")]),_:1})]),_:1},8,["modelValue"])])])]),_:1})],2)],4)])}const xt=k(Ue,[["render",vt]]),Bo="",Ct={name:"IdmWindBarb",props:{map:{type:Object},wind:{type:Object},current:{type:Object},beforeLayer:{type:String},mapProjection:{type:String},showParticle:{type:Boolean,default:!1},toggleVersion:{type:Number}},emits:["particle"],data(){return{source:"wind-barb-source",barbs:[0,2,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,105],empty:v.featureCollection([]),showFeather:localStorage.getItem("windFeatherCache")==="true"||!1,windFeatherCache:"windFeatherCache",right:10,bottom:125,windBarbLoaded:!1}},watch:{"wind.version":{handler(){var a;(a=this.wind)!=null&&a.active&&this.showFeather?this.handleRender():this.handleClear()},deep:!0},showParticle:{handler(){},immediate:!0},showFeather:{handler(){localStorage.setItem(this.windFeatherCache,this.showFeather),this.handleToggle()},immediate:!0},toggleVersion:{handler(){var a,e,t,r;this.right=(((a=document.getElementsByClassName("right-bar")[0])==null?void 0:a.clientWidth)||0)+10,this.bottom=(e=this.current)!=null&&e.active?(((t=document.getElementsByClassName("active-layers")[0])==null?void 0:t.clientHeight)||0)+148:(((r=document.getElementsByClassName("active-layers")[0])==null?void 0:r.clientHeight)||0)+110},immediate:!0}},methods:{handleParticle(){this.$emit("particle",{particle:!this.showParticle,key:"wind",weight:1})},handleRender(){var a,e,t,r;if(!this.map)setTimeout(()=>{this.handleRender()},500);else if(this.wind){const o=new Date().valueOf();let s=0,n=0,l=this.empty;if((a=this.wind)!=null&&a.active&&(l=(e=this.wind)==null?void 0:e.data),(t=this.map)!=null&&t.getSource(this.source))(r=this.map)==null||r.getSource(this.source).setData(l),n=new Date().valueOf()-(o+s),console.log("[wind] update elapsed: ",n,", total: ",s+=n);else{this.map.addSource(this.source,{type:"geojson",data:l});for(let c=0;c<(this.barbs??[]).length-1;c++){const d=(this.barbs??[])[c]||0,p=(this.barbs??[])[c+1]||0,h=d<10?`00${d}kts`:d<100?`0${d}kts`:`${d}kts`;this.map.addLayer({id:h,type:"symbol",filter:["all",[">=","spd",d],["<","spd",p]],source:this.source,layout:{"symbol-placement":"point","icon-image":h,"icon-size":.14,"icon-offset":[0,-20],"icon-allow-overlap":!0,"icon-rotation-alignment":"map","icon-rotate":{property:"val",stops:[[0,0],[360,360]]}},paint:{"icon-opacity":1,"text-color":"#222"}},this.beforeLayer)}this.windBarbLoaded=!0,n=new Date().valueOf()-(o+s),console.log("[wind] add elapsed: ",n,", total: ",s+=n)}}},handleToggle(){if(!this.windBarbLoaded)this.handleRender();else for(const a of this.barbs??[]){const e=a<10?`00${a}kts`:a<100?`0${a}kts`:`${a}kts`;this.map.getLayer(e)&&this.map.setLayoutProperty(e,"visibility",this.showFeather?"visible":"none")}},handleClear(){for(const a of this.barbs??[]){const e=a<10?`00${a}kts`:a<100?`0${a}kts`:`${a}kts`;this.map.getLayer(e)&&this.map.removeLayer(e)}this.map.getSource(this.source)&&this.map.removeSource(this.source),this.windBarbLoaded=!1}}},kt={key:0},St=[i.createElementVNode("div",{class:"checkbox"},null,-1),i.createElementVNode("span",null,"Wind Particles",-1)],Et=[i.createElementVNode("div",{class:"checkbox"},null,-1),i.createElementVNode("span",null,"Wind Feather",-1)];function zt(a,e,t,r,o,s){var n;return(n=t.wind)!=null&&n.active?(i.openBlock(),i.createElementBlock("div",kt,[i.createElementVNode("div",{class:"flex-center wind-tool-bars",style:i.normalizeStyle([{position:"absolute"},{right:o.right+"px",bottom:o.bottom+"px"}])},[t.mapProjection==="mercator"?(i.openBlock(),i.createElementBlock("div",{key:0,class:i.normalizeClass(["item-bar flex-start",t.showParticle?"active":"inactive"]),onClick:e[0]||(e[0]=(...l)=>s.handleParticle&&s.handleParticle(...l))},St,2)):i.createCommentVNode("",!0),i.createElementVNode("div",{class:i.normalizeClass(["item-bar flex-start",o.showFeather?"active":"inactive"]),onClick:e[1]||(e[1]=l=>o.showFeather=!o.showFeather)},Et,2)],4)])):i.createCommentVNode("",!0)}const Pt=k(Ct,[["render",zt]]);class Ce{constructor(e){z(this,"map");z(this,"mercator");z(this,"rampColorLayer");z(this,"rampColorSource");z(this,"particleLayer");z(this,"particleSource");z(this,"rampColorCanvas");z(this,"particleCanvas");z(this,"ratio");this.map=e,this.mercator=new Oe,this.rampColorLayer="ramp-color-layer",this.rampColorSource="ramp-color-source",this.particleLayer="particle-layer",this.particleSource="particle-source",this.rampColorCanvas=document.createElement("canvas"),this.particleCanvas=document.createElement("canvas"),this.ratio=window.devicePixelRatio}convertNLng(e,t=0){return e>180?this.convertNLng(e-360,t+1):e<-180?this.convertNLng(e+360,t+1):[e,t]}getBoundLngLat(){const e=this.map.getBounds();return[[e._sw.lng,e._ne.lat],[e._ne.lng,e._ne.lat],[e._ne.lng,e._sw.lat],[e._sw.lng,e._sw.lat]]}getBoundPixel(){const e=this.map.getBounds(),t=this.map.getZoom()+1,r=[e._ne.lng,e._ne.lat],o=[e._sw.lng,e._sw.lat],[s,n]=this.convertNLng(r[0]),[l,c]=this.convertNLng(o[0]),[d,p]=this.mercator.px([s,r[1]],t),[h,g]=this.mercator.px([l,o[1]],t),y=Math.round(this.mercator.size*Math.pow(2,t)*(n+c));return[h,g,d+y,p]}getBoundRange(){const e=this.map.getZoom()+1,t=this.mercator.size*Math.pow(2,e),r=this.getBoundPixel();return[r[0]/t,r[2]/t,r[3]/t,r[1]/t]}getWorldCopy(e,t){const r=2**t,[o,s,n,l]=e.map(p=>~~(p/(r*256))),c=[];for(let p=l;p<=s;p++)for(let h=o;h<=n;h++)c.push([h,p]);return c.map(p=>{const h=2**t*256;return[p[0]*h,p[1]*h,h]})}resize(){let e=this.map.getSource(this.rampColorSource);e.setCoordinates(this.getBoundLngLat()),e=this.map.getSource(this.particleSource),e.setCoordinates(this.getBoundLngLat()),this.rampColorCanvas.width=this.map._canvas.clientWidth,this.rampColorCanvas.height=this.map._canvas.clientHeight,this.particleCanvas.width=this.map._canvas.clientWidth,this.particleCanvas.height=this.map._canvas.clientHeight}toggle(e){const t=this.map.getLayoutProperty(this.rampColorLayer,"visibility"),r=e?"visible":"none";t!==r&&this.map.setLayoutProperty(this.rampColorLayer,"visibility",r)}toggleParticle(e){const t=this.map.getLayoutProperty(this.particleLayer,"visibility"),r=e?"visible":"none";t!==r&&this.map.setLayoutProperty(this.particleLayer,"visibility",r)}}class Z{createShader(e,t,r){const o=e.createShader(t);if(o&&(e.shaderSource(o,r),e.compileShader(o),!e.getShaderParameter(o,e.COMPILE_STATUS)))throw new Error(e.getShaderInfoLog(o)||"error happened while create shader...");return o}createTexture(e,t,r,o,s,n,l){const c=e.createTexture();return e.bindTexture(e.TEXTURE_2D,c),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,t),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,r),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,o),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,o),s instanceof Uint8Array?e.texImage2D(e.TEXTURE_2D,0,e.RGBA,n,l,0,e.RGBA,e.UNSIGNED_BYTE,s):e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,s),e.bindTexture(e.TEXTURE_2D,null),c}createDataBuffer(e,t,r){if(e){const o=e.createBuffer();return t==="array"?(e.bindBuffer(e.ARRAY_BUFFER,o),r&&e.bufferData(e.ARRAY_BUFFER,r,e.STATIC_DRAW)):t==="element"&&(e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,o),r&&e.bufferData(e.ELEMENT_ARRAY_BUFFER,r,e.STATIC_DRAW)),o}return null}createProgram(e,t,r){const o=e.createProgram(),s=this.createShader(e,e.VERTEX_SHADER,t),n=this.createShader(e,e.FRAGMENT_SHADER,r);if(o&&s&&n&&(e.attachShader(o,s),e.attachShader(o,n),e.linkProgram(o),!e.getProgramParameter(o,e.LINK_STATUS)))throw new Error(e.getProgramInfoLog(o)||"error happened while creating ramp color program");return o}createProgramWrapper(e,t,r){const o=this.createProgram(e,t,r);if(o){const s={program:o},n=e.getProgramParameter(o,e.ACTIVE_ATTRIBUTES);for(let c=0;c<n;c++){const d=e.getActiveAttrib(o,c);s[d.name]=e.getAttribLocation(o,d.name)}const l=e.getProgramParameter(o,e.ACTIVE_UNIFORMS);for(let c=0;c<l;c++){const d=e.getActiveUniform(o,c);s[d.name]=e.getUniformLocation(o,d.name)}return s}}setup(e,t,r=!1,o,s){const n=document.createElement("canvas");n.width=256,n.height=1;const l=n.getContext("2d");if(l&&e){const c=l==null?void 0:l.createLinearGradient(0,0,256,0);return t.forEach(([d,p])=>{c.addColorStop(d,p)}),l.fillStyle=c,l.fillRect(0,0,256,1),{canvas:n,texture:this.createTexture(e,e.LINEAR,e.LINEAR,e.CLAMP_TO_EDGE,r?new Uint8Array(l.getImageData(0,0,256,1).data):n,o,s)}}}setupParticle(e,t=1e3){const r=Math.ceil(Math.sqrt(t)),o=r*r,s=new Uint8Array(o*4);for(let p=0;p<s.length;p++)s[p]=Math.floor(Math.random()*256);const n=this.createTexture(e,e.NEAREST,e.NEAREST,e.CLAMP_TO_EDGE,s,r,r),l=this.createTexture(e,e.NEAREST,e.NEAREST,e.CLAMP_TO_EDGE,s,r,r),c=new Float32Array(o);for(let p=0;p<o;p++)c[p]=p;const d=this.createDataBuffer(e,"array",c);return{resolution:r,total:o,texture0:n,texture1:l,indexBuffer:d}}bind(e,t,r){const o=this.createProgram(e,t,r);if(o){const s=this.createDataBuffer(e,"array",void 0),n=e.getAttribLocation(o,"a_position");e.enableVertexAttribArray(n),e.vertexAttribPointer(n,2,e.FLOAT,!1,0,0);const l=new Float32Array([0,0,1,0,0,1,0,1,1,0,1,1]);this.createDataBuffer(e,"array",l);const c=e.getAttribLocation(o,"a_texCoord");return e.enableVertexAttribArray(c),e.vertexAttribPointer(c,2,e.FLOAT,!1,0,0),{program:o,aPositionBuffer:s}}return{}}bindParticle(e,t,r,o,s,n){const l=this.createProgramWrapper(e,t,r),c=this.createProgramWrapper(e,o,s),d=this.createProgramWrapper(e,o,n),p=this.createDataBuffer(e,"array",new Float32Array([0,0,1,0,0,1,0,1,1,0,1,1])),h=e.createFramebuffer();return{particle:l,screen:c,update:d,quadBuffer:p,frameBuffer:h}}draw(e,t,r,o,s,n,l){var c,d;if(t&&r){e.resize(),t==null||t.viewport(0,0,(c=t==null?void 0:t.canvas)==null?void 0:c.width,(d=t==null?void 0:t.canvas)==null?void 0:d.height),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT|t.DEPTH_BUFFER_BIT);try{const p=t.getUniformLocation(r,"u_resolution"),h=t.getUniformLocation(r,"u_image"),g=t.getUniformLocation(r,"u_color");if(t.useProgram(r),t.uniform2f(p,t.canvas.width*e.ratio,t.canvas.height*e.ratio),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,o),t.uniform1i(h,0),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,s),t.uniform1i(g,1),l!=null&&l.uvRange&&(l!=null&&l.sRange)){const m=t.getUniformLocation(r,"u_range_u_v"),_=t.getUniformLocation(r,"u_range_s");t.uniform2f(m,l.uvRange[0],l.uvRange[1]),t.uniform2f(_,l.sRange[0],l.sRange[1])}const y=e.getBoundPixel(),f=e.map.getZoom()+1,u=e.getWorldCopy(y,f);for(const m of u){const _=(m[0]-y[0])*e.ratio,b=(m[1]-y[3])*e.ratio,L=m[2]*e.ratio,[x,w,P,N]=[_,L+_,b,L+b],I=new Float32Array([x,P,w,P,x,N,x,N,w,P,w,N]);t.bindBuffer(t.ARRAY_BUFFER,n),t.bufferData(t.ARRAY_BUFFER,I,t.STATIC_DRAW),t.drawArrays(t.TRIANGLES,0,6)}}catch(p){console.log(`render failed...${p}`)}}}drawParticle(e,t,r,o,s){var n,l;t&&(t==null||t.viewport(0,0,(n=t==null?void 0:t.canvas)==null?void 0:n.width,(l=t==null?void 0:t.canvas)==null?void 0:l.height),t.disable(t.DEPTH_TEST),t.disable(t.STENCIL_TEST),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,r),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,o.texture0),this.renderScreen(e,t,o,s),this.updateParticles(e,t,o,s))}renderScreen(e,t,r,o){t.bindFramebuffer(t.FRAMEBUFFER,r.frameBuffer),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,r.screenTexture,0),t.viewport(0,0,t.canvas.width,t.canvas.height),this.renderScreenTexture(t,r.backgroundTexture,r.screen,r.quadBuffer,.95),this.renderParticles(e,t,r,o),t.bindFramebuffer(t.FRAMEBUFFER,null),this.renderScreenTexture(t,r.screenTexture,r.screen,r.quadBuffer,1);const s=r.backgroundTexture;r.backgroundTexture=r.screenTexture,r.screenTexture=s}renderScreenTexture(e,t,r,o,s){e&&(e.useProgram(r.program),e.bindBuffer(e.ARRAY_BUFFER,o),e.enableVertexAttribArray(r.a_pos),e.vertexAttribPointer(r.a_pos,2,e.FLOAT,!1,0,0),e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_2D,t),e.uniform1i(r.u_screen,2),e.uniform1f(r.u_opacity,s),e.drawArrays(e.TRIANGLES,0,6))}renderParticles(e,t,r,o){if(t){t.useProgram(r.particle.program),t.bindBuffer(t.ARRAY_BUFFER,r.indexBuffer),t.enableVertexAttribArray(r.particle.a_index),t.vertexAttribPointer(r.particle.a_index,1,t.FLOAT,!1,0,0),t.activeTexture(t.TEXTURE2),t.bindTexture(t.TEXTURE_2D,r.color.texture),t.uniform1i(r.particle.u_factor,0),t.uniform1i(r.particle.u_particles,1),t.uniform1i(r.particle.u_color_ramp,2),t.uniform1f(r.particle.u_particles_resolution,r.resolution*e.ratio),t.uniform1f(r.particle.u_point,e.ratio);const s=e.getBoundRange();t.uniform4f(r.particle.u_viewport,s[0],s[1],s[2],s[3]),t.uniform2f(r.particle.u_factor_min,o.uvRange[0],o.uvRange[0]),t.uniform2f(r.particle.u_factor_max,o.uvRange[1],o.uvRange[1]),t.drawArrays(t.POINTS,0,r.total)}}updateParticles(e,t,r,o){var n,l;if(t){t.bindFramebuffer(t.FRAMEBUFFER,r.frameBuffer),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,r.texture1,0),t.viewport(0,0,r.resolution,r.resolution),t.useProgram(r.update.program),t.bindBuffer(t.ARRAY_BUFFER,r.quadBuffer),t.enableVertexAttribArray(r.update.a_pos),t.vertexAttribPointer(r.update.a_pos,2,t.FLOAT,!1,0,0),t.uniform1i(r.update.u_factor,0),t.uniform1i(r.update.u_particles,1);const c=e.getBoundRange();t.uniform4f(r.update.u_viewport,c[0],c[1],c[2],c[3]),t.uniform1f(r.update.u_rand_seed,Math.random()),t.uniform2f(r.update.u_factor_res,(n=r==null?void 0:r.image)==null?void 0:n.width,(l=r==null?void 0:r.image)==null?void 0:l.height),t.uniform2f(r.update.u_factor_min,o.uvRange[0],o.uvRange[0]),t.uniform2f(r.update.u_factor_max,o.uvRange[1],o.uvRange[1]),t.uniform1f(r.update.u_speed_factor,o.speedFactor*e.ratio),t.uniform1f(r.update.u_drop_rate,o.dropRate),t.uniform1f(r.update.u_drop_rate_bump,o.dropRateBump),t.drawArrays(t.TRIANGLES,0,6)}const s=r.texture0;r.texture0=r.texture1,r.texture1=s}resize(e,t){e.resize();const r=new Uint8Array(t.canvas.width*t.canvas.height*4).fill(0,0,t.canvas.width*t.canvas.height*4),o=this.createTexture(t,t.NEAREST,t.NEAREST,t.CLAMP_TO_EDGE,r,t.canvas.width,t.canvas.height),s=this.createTexture(t,t.NEAREST,t.NEAREST,t.CLAMP_TO_EDGE,r,t.canvas.width,t.canvas.height);return{screenTexture:o,backgroundTexture:s}}async loadImg(e){return new Promise(t=>{const r=new Blob([e],{type:e.type}),o=URL.createObjectURL(r),s=new Image;s.crossOrigin="anonymous",s.src=o,s.onload=()=>t(s)})}}class T{}z(T,"vertexSchema",`
|
|
1
|
+
(function(E,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("vue"),require("@turf/turf"),require("@mapbox/sphericalmercator"),require("moment"),require("mapbox-gl"),require("@idm-plugin/geo"),require("axios")):typeof define=="function"&&define.amd?define(["exports","vue","@turf/turf","@mapbox/sphericalmercator","moment","mapbox-gl","@idm-plugin/geo","axios"],i):(E=typeof globalThis<"u"?globalThis:E||self,i(E["idm-gl"]={},E.Vue,E["@turf/turf"],E["@mapbox/sphericalmercator"],E.moment,E["mapbox-gl"],E["@idm-plugin/geo"],E.axios))})(this,function(E,i,ee,Oe,A,j,C,U){"use strict";var Po=Object.defineProperty;var No=(E,i,ee)=>i in E?Po(E,i,{enumerable:!0,configurable:!0,writable:!0,value:ee}):E[i]=ee;var z=(E,i,ee)=>(No(E,typeof i!="symbol"?i+"":i,ee),ee);function We(a){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(a){for(const t in a)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(a,t);Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:()=>a[t]})}}return e.default=a,Object.freeze(e)}const v=We(ee),To="";var Fe=Object.defineProperty,He=(a,e,t)=>e in a?Fe(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,me=(a,e,t)=>(He(a,typeof e!="symbol"?e+"":e,t),t);class ge{}me(ge,"LEVEL",{Basic:1,Prime:2,Supper:1024});class be{}me(be,"WEATHER_LAYERS",[{weight:1,name:"Wind",key:"wind",h5:!0,enabled:!0,type:"json",particle:!0},{weight:524288,name:"Wind Particle",key:"wind-particle",peer:{weight:1,key:"wind"},enabled:!0,hide:!0,type:"jpg"},{weight:16,name:"Sig Waves",key:"sig-wave-height",h5:!0,enabled:!0,type:"json"},{weight:4194304,name:"Sig Waves (JPG)",key:"sig-wave",peer:{weight:16,key:"sig-wave"},enabled:!0,hide:!0,type:"jpg"},{weight:8388608,name:"Sig Waves (Contour)",key:"sig-wave-height-contour",peer:{weight:16,key:"sig-wave-contour"},enabled:!0,hide:!0,type:"json"},{weight:96,name:"Current",key:"current",vendor:"cmems",merge:!0,h5:!0,enabled:!0,type:"json"},{weight:1048576,name:"Current Particle",key:"current-particle",vendor:"cmems",peer:{weight:96,key:"current"},enabled:!0,hide:!0,type:"jpg"},{weight:256,name:"Tropicals",key:"tropicals",h5:!0,enabled:!0,type:"json"},{weight:4096,name:"Pressure",h5:!0,key:"prmsl",enabled:!0,type:"json"},{weight:8192,name:"Visibility",vendor:"gfs",key:"visibility",h5:!0,enabled:!0,type:"jpg"},{weight:262144,name:"Precip Acc",key:"precip3h",h5:!0,enabled:!0,type:"jpg"},{weight:6,name:"Swell",key:"swell",merge:!0,h5:!0,enabled:!0,type:"json"},{weight:2,name:"Swell Height",key:"swell-height",partly:!0,enabled:!0,type:"json"},{weight:4,name:"Swell Direction",key:"swell-direction",partly:!0,enabled:!0,type:"json"},{weight:32,name:"Current Direction",key:"current-direction",vendor:"cmems",partly:!0,enabled:!0,type:"json"},{weight:64,name:"Current Speed",key:"current-speed",vendor:"cmems",partly:!0,enabled:!0,type:"json"},{weight:512,name:"Pressure Contour",key:"prmsl-contour",partly:!0,enabled:!0,hide:!0,type:"json"},{weight:1024,name:"Pressure Value",key:"prmsl-value",partly:!0,enabled:!0,hide:!0,type:"json"},{weight:2048,name:"Pressure Front",key:"prmsl-front",partly:!0,enabled:!0,hide:!0,type:"json"},{weight:16384,name:"Iceberg",key:"iceberg",vendor:"cmems",hide:!0,enabled:!1,type:"json"},{weight:32768,name:"Struct Ice",key:"struct-ice",vendor:"cmems",enabled:!1,hide:!0,type:"json"},{weight:65536,name:"Ice Edge",key:"arctic",vendor:"cmems",h5:!0,enabled:!0,type:"jpg"},{weight:131072,name:"Sea Surf. Temp.",key:"water-temp",vendor:"cmems",h5:!0,enabled:!0,type:"jpg"},{weight:2097152,name:"Temp.",key:"temp",h5:!0,enabled:!0,type:"jpg"}]),me(be,"OTHER_LAYERS",[{weight:1,name:"War Zones",key:"war-zones",h5:!0,enabled:!0,type:"json"},{weight:2,name:"GMDSS Areas",key:"gmdss-areas",h5:!0,enabled:!0,type:"json"},{weight:4,name:"ECA Zones",key:"eca-zones",h5:!0,enabled:!0,type:"json"},{weight:8,name:"Load Lines",key:"load-lines",h5:!0,enabled:!0,type:"json"},{weight:16,name:"HRA",key:"high-risk-area",enabled:!1,type:"json"},{weight:32,name:"Pirates",key:"pirates",enabled:!1,type:"json"},{weight:4096,name:"Alert Zones",key:"alert-zones",h5:!0,enabled:!0,type:"json"},{weight:64,name:"Ports",key:"ports",h5:!0,enabled:!0,type:"json"},{weight:128,name:"Time Zones",key:"time-zones",h5:!0,enabled:!0,type:"json"},{weight:256,name:"VRA",key:"voluntary-reporting-area",h5:!0,enabled:!0,type:"json"},{weight:512,name:"Special Areas",key:"special-area",h5:!0,enabled:!0,type:"json"},{weight:1024,name:"Day/Night",key:"day-night",h5:!0,enabled:!0,type:"json"},{weight:2048,name:"ENC",key:"enc",h5:!0,enabled:!0,type:"origin"},{weight:8192,name:"World-12nm",key:"world12nm",h5:!1,enabled:!0,type:"origin"}]);class Se{}me(Se,"WEATHER_TAG",[{weight:4,name:"Adverse Weather Dangerous",key:"DANGEROUS",positive:!0},{weight:2,name:"Adverse Weather Severe",key:"SEVERE",positive:!0},{weight:1,name:"Adverse Weather Heavy",key:"HEAVY",positive:!0}]),me(Se,"SAILING_TAG",[{weight:2048,name:"Deviation",key:"deviation",positive:!0},{weight:4096,name:"Stoppage",key:"stoppage",positive:!0},{weight:8192,name:"Deceleration",key:"deceleration",positive:!0},{weight:16384,name:"No Lane",key:"noLane",positive:!0},{weight:32768,name:"No Noon",key:"noNoon",positive:!0}]),me(Se,"OTHER_TAG",[{weight:2097152,name:"No CP",key:"noCp",positive:!0},{weight:4194304,name:"Send Rpt",key:"sendRpt",positive:!1},{weight:8388608,name:"Send Bps",key:"sendBps",positive:!1},{weight:16777216,name:"Send Pvar",key:"sendPvar",positive:!1},{weight:33554432,name:"Checked",key:"checked",positive:!1},{weight:67108864,name:"Send PWFR",key:"sendPwfr",positive:!1}]);const Io="",k=(a,e)=>{const t=a.__vccOpts||a;for(const[r,o]of e)t[r]=o;return t},Ue={name:"IdmGlLayer",props:{map:{type:Object},mapProjection:{type:String},top:{type:Number,default:60},layerToggle:{type:Boolean,default:!1},toggleVersion:{type:Number},isLogin:{type:Boolean,default:void 0}},emits:["weather","other","coordinate","measure","point","3d","layerToggle","handleToggleVersion"],data(){return{source:"",weatherLayers:[],activeWeatherLayers:[],autoActive:!0,otherLayers:[],layers:{weather:[...be.WEATHER_LAYERS.filter(a=>!["swell-height","swell-direction","current-direction","current-speed"].includes(a.key))],other:[...be.OTHER_LAYERS.filter(a=>a.key!=="world12nm"&&a.enabled)]},weatherLayersCache:"weatherLayersCache",autoActiveCache:"autoActiveCache",otherLayersCache:"otherLayersCache",collectedLayerCache:"collectedLayerCache",sourceCache:"defaultSourceCache",showCoord:!1,showMeasure:!1,showPoint:!1,show3d:!1,version:{v:"0.0.7",k:"glCacheVersion"},right:10,rampColorLayers:["visibility","precip3h","temp","water-temp","arctic"]}},computed:{computeLayerClass(){return function(a,e){let t="layer flex-between";return e.some(r=>r.key===a.key)&&(t="layer flex-between active"),(!a.enabled||this.rampColorLayers.includes(a.key)&&this.mapProjection==="globe")&&(t="layer flex-between disabled"),t}}},watch:{toggleVersion:{handler(){this.$nextTick(()=>{var a;this.right=(((a=document.getElementsByClassName("right-bar")[0])==null?void 0:a.clientWidth)||0)+10})}},source:{handler(a,e){a&&e&&a!==e&&this.handleConfirm()}}},mounted(){const a=localStorage.getItem(this.version.k);this.version.v!==a&&(localStorage.removeItem(this.weatherLayersCache),localStorage.removeItem(this.collectedLayerCache),localStorage.removeItem(this.otherLayersCache),localStorage.removeItem("windFeatherCache"),localStorage.removeItem("currentJsonCache"),localStorage.setItem(this.version.k,this.version.v));let e=localStorage.getItem(this.collectedLayerCache),t=JSON.parse(e||'[{"weight":1,"name":"Wind","key":"wind","collected":true},{"weight":4096,"name":"Pressure","key":"prmsl","collected":true},{"weight":256,"name":"Tropicals","key":"tropicals","collected":true}]');this.layers.weather.forEach(r=>{r.collected=!!t.some(o=>o.key===r.key&&o.collected)}),e=localStorage.getItem(this.autoActiveCache),this.autoActive=e!=="false",e=localStorage.getItem(this.weatherLayersCache),t=JSON.parse(e||'[{"weight":1,"name":"Wind","key":"wind","enabled":true,"type":"json","particle":true},{"weight":4096,"name":"Pressure","key":"prmsl","enabled":true,"type":"json"},{"weight":256,"name":"Tropicals","key":"tropicals","enabled":true,"type":"json"}]'),this.weatherLayers=t,this.autoActive&&(this.activeWeatherLayers=[...t]),e=localStorage.getItem(this.otherLayersCache),t=JSON.parse(e||'[{"weight":4,"name":"ECA Zones","key":"eca-zones","enabled":true,"type":"json"}]'),this.otherLayers=t,e=localStorage.getItem(this.sourceCache),this.source=e||"GFS",this.handleConfirm()},methods:{handleConfirm(){this.$emit("weather",this.weatherLayers,this.activeWeatherLayers,this.source),this.$emit("other",this.otherLayers),localStorage.setItem(this.autoActiveCache,this.autoActive),localStorage.setItem(this.sourceCache,this.source)},handleWeatherLayerPick(a){if(this.rampColorLayers.includes(a.key)&&this.mapProjection==="globe")return!1;this.weatherLayers.some(e=>e.key===a.key)?(this.weatherLayers=this.weatherLayers.filter(e=>e.key!==a.key),this.activeWeatherLayers=this.activeWeatherLayers.filter(e=>e.key!==a.key)):this.weatherLayers.length<12&&a.enabled&&(["png","jpg"].includes(a.type)&&(this.weatherLayers=this.weatherLayers.filter(e=>e.type==="json"),this.activeWeatherLayers=this.activeWeatherLayers.filter(e=>e.type==="json")),this.weatherLayers.push(a),this.activeWeatherLayers.push(a)),localStorage.setItem(this.weatherLayersCache,JSON.stringify(this.weatherLayers)),this.$emit("weather",this.weatherLayers,this.activeWeatherLayers,this.source),localStorage.setItem(this.autoActiveCache,this.autoActive),localStorage.setItem(this.sourceCache,this.source)},handleWeatherLayerCollect(a){var e;if(!a.collected&&((e=this.layers.weather.filter(t=>t.collected))==null?void 0:e.length)>=6)return!1;a.collected=!a.collected,localStorage.setItem(this.collectedLayerCache,JSON.stringify(this.layers.weather)),this.$emit("handleToggleVersion")},handleActiveWeatherLayerPick(a){if(this.rampColorLayers.includes(a.key)&&this.mapProjection==="globe")return!1;if(this.activeWeatherLayers.some(e=>e.key===a.key))this.activeWeatherLayers=this.activeWeatherLayers.filter(e=>e.key!==a.key);else if(a.enabled){this.activeWeatherLayers.push(a);for(const e of this.weatherLayers)a.weight>e.weight&&a.weight&e.weight&&this.activeWeatherLayers.push(e)}this.handleWeatherLayerPick(a)},handleOtherLayerPick(a){this.otherLayers.some(e=>e.key===a.key)?this.otherLayers=this.otherLayers.filter(e=>e.key!==a.key):a.enabled&&this.otherLayers.push(a),localStorage.setItem(this.otherLayersCache,JSON.stringify(this.otherLayers)),this.$emit("other",this.otherLayers)},handleMenuToggle(){this.$emit("layerToggle",!this.layerToggle)},handleCoordToggle(){this.showCoord=!this.showCoord,this.$emit("coordinate",this.showCoord)},handlePointToggle(){this.isLogin?(this.showPoint=!this.showPoint,this.$emit("point",this.showPoint)):this.$emit("handleToggleVersion")},handleMeasureToggle(){this.showMeasure=!this.showMeasure,this.$emit("measure",this.showMeasure)},handle3DToggle(){this.show3d=!this.show3d,this.$emit("3d",this.show3d)}}},Ze={class:"idm-gl3-layer"},Ge={class:"bar-item layer-bars"},Je=[i.createElementVNode("span",{class:"iconfont"},"",-1)],Xe={class:"bar-item tool-bars"},qe=[i.createElementVNode("span",{class:"iconfont"},"",-1)],Ye=[i.createElementVNode("span",{class:"iconfont"},"",-1)],Qe=[i.createElementVNode("span",{class:"iconfont"},"",-1)],Ke=[i.createElementVNode("span",{class:"iconfont"},"",-1)],et=["onClick"],tt=i.createElementVNode("div",{class:"checkbox"},null,-1),at={class:"header-box flex-between"},it=i.createElementVNode("div",null,"Layers",-1),ot={class:"weather-layers card-bg"},rt=i.createElementVNode("div",{class:"layers-title flex-between"},[i.createElementVNode("div",null,"Weather Layers")],-1),st={class:"layers-body"},nt=["onClick"],lt=i.createElementVNode("div",{class:"checkbox"},null,-1),ct=["onClick"],ht={key:0,class:"iconfont bookmark active"},dt={key:1,class:"iconfont bookmark inactive"},pt=i.createElementVNode("div",{class:"tip flex-start"},[i.createElementVNode("i",{class:"iconfont bookmark",style:{"align-self":"flex-start",padding:"5px 5px 0 0"}},""),i.createElementVNode("div",null,"Bookmark your favorite layer to homepage(Max 6)")],-1),mt={class:"other-layers card-bg"},yt=i.createElementVNode("div",{class:"layers-title"},"Other Layers",-1),ft={class:"layers-body"},ut=["onClick"],gt={class:"flex-start"},bt=i.createElementVNode("div",{class:"switch flex-center"},[i.createElementVNode("i",{class:"iconfont open"},""),i.createElementVNode("i",{class:"iconfont close"},"")],-1),_t={class:"source-layers card-bg"},wt=i.createElementVNode("span",{class:"layers-title"},"Forecast Model",-1),Lt={class:"layers-body"};function vt(a,e,t,r,o,s){var p;const n=i.resolveComponent("ElTooltip"),l=i.resolveComponent("ElRadio"),c=i.resolveComponent("ElRadioGroup"),d=i.resolveComponent("ElScrollbar");return i.openBlock(),i.createElementBlock("div",Ze,[i.createElementVNode("div",{class:"menu-bar-box",style:i.normalizeStyle({top:t.top+10+"px",right:o.right+"px"})},[i.createElementVNode("div",Ge,[i.createVNode(n,{placement:"left",effect:"light",content:"Menu","show-after":2e3},{default:i.withCtx(()=>[i.createElementVNode("div",{class:i.normalizeClass(t.layerToggle?"menu-icon active":"menu-icon"),onClick:e[0]||(e[0]=(...h)=>s.handleMenuToggle&&s.handleMenuToggle(...h))},Je,2)]),_:1})])],4),i.createElementVNode("div",{class:"menu-bar-box",style:i.normalizeStyle({top:t.top+160+"px",right:o.right+"px"})},[i.createElementVNode("div",Xe,[i.createVNode(n,{placement:"left",effect:"light",content:"Measure","show-after":2e3},{default:i.withCtx(()=>[i.createElementVNode("div",{class:i.normalizeClass(o.showMeasure?"menu-icon active":"menu-icon"),onClick:e[1]||(e[1]=(...h)=>s.handleMeasureToggle&&s.handleMeasureToggle(...h))},qe,2)]),_:1}),i.createVNode(n,{placement:"left",effect:"light",content:"Point Meteo","show-after":2e3},{default:i.withCtx(()=>[i.createElementVNode("div",{class:i.normalizeClass(o.showPoint?"menu-icon active":"menu-icon"),onClick:e[2]||(e[2]=(...h)=>s.handlePointToggle&&s.handlePointToggle(...h))},Ye,2)]),_:1}),i.createVNode(n,{placement:"left",effect:"light",content:"Grid","show-after":2e3},{default:i.withCtx(()=>[i.createElementVNode("div",{class:i.normalizeClass(o.showCoord?"menu-icon active":"menu-icon"),onClick:e[3]||(e[3]=(...h)=>s.handleCoordToggle&&s.handleCoordToggle(...h))},Qe,2)]),_:1}),i.createVNode(n,{placement:"left",effect:"light",content:"3D","show-after":2e3},{default:i.withCtx(()=>[i.createElementVNode("div",{class:i.normalizeClass(o.show3d?"menu-icon active":"menu-icon"),onClick:e[4]||(e[4]=(...h)=>s.handle3DToggle&&s.handle3DToggle(...h))},Ke,2)]),_:1})])],4),((p=o.layers.weather.filter(h=>h.collected))==null?void 0:p.length)>0?(i.openBlock(),i.createElementBlock("div",{key:0,class:"active-layers",style:i.normalizeStyle({right:o.right+"px",bottom:"100px"})},[(i.openBlock(!0),i.createElementBlock(i.Fragment,null,i.renderList(o.layers.weather.filter(h=>h.collected),h=>(i.openBlock(),i.createElementBlock("div",{key:h.key,class:i.normalizeClass(s.computeLayerClass(h,o.activeWeatherLayers)),onClick:g=>s.handleActiveWeatherLayerPick(h)},[tt,i.createElementVNode("span",null,i.toDisplayString(h.name),1)],10,et))),128))],4)):i.createCommentVNode("",!0),i.createElementVNode("div",{class:"available-layers flex-center",style:i.normalizeStyle({top:t.top+"px",right:t.layerToggle?"0px":"-240px"})},[i.createElementVNode("div",{class:i.normalizeClass(["list-box",t.layerToggle?"right-bar":""])},[i.createElementVNode("div",at,[it,i.createElementVNode("div",{class:"iconfont close-btn",onClick:e[5]||(e[5]=(...h)=>s.handleMenuToggle&&s.handleMenuToggle(...h))},"")]),i.createVNode(d,{style:{flex:"1"}},{default:i.withCtx(()=>[i.createElementVNode("div",ot,[rt,i.createElementVNode("div",st,[(i.openBlock(!0),i.createElementBlock(i.Fragment,null,i.renderList(o.layers.weather,h=>(i.openBlock(),i.createElementBlock(i.Fragment,{key:h.key},[h.hide?i.createCommentVNode("",!0):(i.openBlock(),i.createElementBlock("div",{key:0,class:i.normalizeClass(s.computeLayerClass(h,o.weatherLayers))},[i.createElementVNode("div",{class:"flex-start",onClick:g=>s.handleWeatherLayerPick(h)},[lt,i.createElementVNode("span",null,i.toDisplayString(h.name),1)],8,nt),i.createElementVNode("div",{onClick:g=>s.handleWeatherLayerCollect(h)},[h.collected?(i.openBlock(),i.createElementBlock("i",ht,"")):(i.openBlock(),i.createElementBlock("i",dt,""))],8,ct)],2))],64))),128)),pt])]),i.createElementVNode("div",mt,[yt,i.createElementVNode("div",ft,[(i.openBlock(!0),i.createElementBlock(i.Fragment,null,i.renderList(o.layers.other,h=>(i.openBlock(),i.createElementBlock("div",{key:h.key,class:i.normalizeClass(s.computeLayerClass(h,o.otherLayers)),onClick:g=>s.handleOtherLayerPick(h)},[i.createElementVNode("div",gt,[bt,i.createElementVNode("span",null,i.toDisplayString(h.name),1)])],10,ut))),128))])]),i.createElementVNode("div",_t,[wt,i.createElementVNode("div",Lt,[i.createVNode(c,{modelValue:o.source,"onUpdate:modelValue":e[6]||(e[6]=h=>o.source=h),class:"layer-radio flex-col-center-start"},{default:i.withCtx(()=>[i.createVNode(l,{value:"GFS"},{default:i.withCtx(()=>[i.createTextVNode("GFS")]),_:1}),i.createVNode(l,{value:"CMEMS"},{default:i.withCtx(()=>[i.createTextVNode("CMEMS")]),_:1})]),_:1},8,["modelValue"])])])]),_:1})],2)],4)])}const xt=k(Ue,[["render",vt]]),Bo="",Ct={name:"IdmWindBarb",props:{map:{type:Object},wind:{type:Object},current:{type:Object},beforeLayer:{type:String},mapProjection:{type:String},showParticle:{type:Boolean,default:!1},toggleVersion:{type:Number}},emits:["particle"],data(){return{source:"wind-barb-source",barbs:[0,2,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,105],empty:v.featureCollection([]),showFeather:localStorage.getItem("windFeatherCache")==="true"||!1,windFeatherCache:"windFeatherCache",right:10,bottom:125,windBarbLoaded:!1}},watch:{"wind.version":{handler(){var a;(a=this.wind)!=null&&a.active&&this.showFeather?this.handleRender():this.handleClear()},deep:!0},showParticle:{handler(){},immediate:!0},showFeather:{handler(){localStorage.setItem(this.windFeatherCache,this.showFeather),this.handleToggle()},immediate:!0},toggleVersion:{handler(){var a,e,t,r;this.right=(((a=document.getElementsByClassName("right-bar")[0])==null?void 0:a.clientWidth)||0)+10,this.bottom=(e=this.current)!=null&&e.active?(((t=document.getElementsByClassName("active-layers")[0])==null?void 0:t.clientHeight)||0)+148:(((r=document.getElementsByClassName("active-layers")[0])==null?void 0:r.clientHeight)||0)+110},immediate:!0}},methods:{handleParticle(){this.$emit("particle",{particle:!this.showParticle,key:"wind",weight:1})},handleRender(){var a,e,t,r;if(!this.map)setTimeout(()=>{this.handleRender()},500);else if(this.wind){const o=new Date().valueOf();let s=0,n=0,l=this.empty;if((a=this.wind)!=null&&a.active&&(l=(e=this.wind)==null?void 0:e.data),(t=this.map)!=null&&t.getSource(this.source))(r=this.map)==null||r.getSource(this.source).setData(l),n=new Date().valueOf()-(o+s),console.log("[wind] update elapsed: ",n,", total: ",s+=n);else{this.map.addSource(this.source,{type:"geojson",data:l});for(let c=0;c<(this.barbs??[]).length-1;c++){const d=(this.barbs??[])[c]||0,p=(this.barbs??[])[c+1]||0,h=d<10?`00${d}kts`:d<100?`0${d}kts`:`${d}kts`;this.map.addLayer({id:h,type:"symbol",filter:["all",[">=","spd",d],["<","spd",p]],source:this.source,layout:{"symbol-placement":"point","icon-image":h,"icon-size":.14,"icon-offset":[0,-20],"icon-allow-overlap":!0,"icon-rotation-alignment":"map","icon-rotate":{property:"val",stops:[[0,0],[360,360]]}},paint:{"icon-opacity":1,"text-color":"#222"}},this.beforeLayer)}this.windBarbLoaded=!0,n=new Date().valueOf()-(o+s),console.log("[wind] add elapsed: ",n,", total: ",s+=n)}}},handleToggle(){if(!this.windBarbLoaded)this.handleRender();else for(const a of this.barbs??[]){const e=a<10?`00${a}kts`:a<100?`0${a}kts`:`${a}kts`;this.map.getLayer(e)&&this.map.setLayoutProperty(e,"visibility",this.showFeather?"visible":"none")}},handleClear(){for(const a of this.barbs??[]){const e=a<10?`00${a}kts`:a<100?`0${a}kts`:`${a}kts`;this.map.getLayer(e)&&this.map.removeLayer(e)}this.map.getSource(this.source)&&this.map.removeSource(this.source),this.windBarbLoaded=!1}}},kt={key:0},St=[i.createElementVNode("div",{class:"checkbox"},null,-1),i.createElementVNode("span",null,"Wind Particles",-1)],Et=[i.createElementVNode("div",{class:"checkbox"},null,-1),i.createElementVNode("span",null,"Wind Feather",-1)];function zt(a,e,t,r,o,s){var n;return(n=t.wind)!=null&&n.active?(i.openBlock(),i.createElementBlock("div",kt,[i.createElementVNode("div",{class:"flex-center wind-tool-bars",style:i.normalizeStyle([{position:"absolute"},{right:o.right+"px",bottom:o.bottom+"px"}])},[t.mapProjection==="mercator"?(i.openBlock(),i.createElementBlock("div",{key:0,class:i.normalizeClass(["item-bar flex-start",t.showParticle?"active":"inactive"]),onClick:e[0]||(e[0]=(...l)=>s.handleParticle&&s.handleParticle(...l))},St,2)):i.createCommentVNode("",!0),i.createElementVNode("div",{class:i.normalizeClass(["item-bar flex-start",o.showFeather?"active":"inactive"]),onClick:e[1]||(e[1]=l=>o.showFeather=!o.showFeather)},Et,2)],4)])):i.createCommentVNode("",!0)}const Pt=k(Ct,[["render",zt]]);class Ce{constructor(e){z(this,"map");z(this,"mercator");z(this,"rampColorLayer");z(this,"rampColorSource");z(this,"particleLayer");z(this,"particleSource");z(this,"rampColorCanvas");z(this,"particleCanvas");z(this,"ratio");this.map=e,this.mercator=new Oe,this.rampColorLayer="ramp-color-layer",this.rampColorSource="ramp-color-source",this.particleLayer="particle-layer",this.particleSource="particle-source",this.rampColorCanvas=document.createElement("canvas"),this.particleCanvas=document.createElement("canvas"),this.ratio=window.devicePixelRatio}convertNLng(e,t=0){return e>180?this.convertNLng(e-360,t+1):e<-180?this.convertNLng(e+360,t+1):[e,t]}getBoundLngLat(){const e=this.map.getBounds();return[[e._sw.lng,e._ne.lat],[e._ne.lng,e._ne.lat],[e._ne.lng,e._sw.lat],[e._sw.lng,e._sw.lat]]}getBoundPixel(){const e=this.map.getBounds(),t=this.map.getZoom()+1,r=[e._ne.lng,e._ne.lat],o=[e._sw.lng,e._sw.lat],[s,n]=this.convertNLng(r[0]),[l,c]=this.convertNLng(o[0]),[d,p]=this.mercator.px([s,r[1]],t),[h,g]=this.mercator.px([l,o[1]],t),y=Math.round(this.mercator.size*Math.pow(2,t)*(n+c));return[h,g,d+y,p]}getBoundRange(){const e=this.map.getZoom()+1,t=this.mercator.size*Math.pow(2,e),r=this.getBoundPixel();return[r[0]/t,r[2]/t,r[3]/t,r[1]/t]}getWorldCopy(e,t){const r=2**t,[o,s,n,l]=e.map(p=>~~(p/(r*256))),c=[];for(let p=l;p<=s;p++)for(let h=o;h<=n;h++)c.push([h,p]);return c.map(p=>{const h=2**t*256;return[p[0]*h,p[1]*h,h]})}resize(){let e=this.map.getSource(this.rampColorSource);e.setCoordinates(this.getBoundLngLat()),e=this.map.getSource(this.particleSource),e.setCoordinates(this.getBoundLngLat()),this.rampColorCanvas.width=this.map._canvas.clientWidth,this.rampColorCanvas.height=this.map._canvas.clientHeight,this.particleCanvas.width=this.map._canvas.clientWidth,this.particleCanvas.height=this.map._canvas.clientHeight}toggle(e){const t=this.map.getLayoutProperty(this.rampColorLayer,"visibility"),r=e?"visible":"none";t!==r&&this.map.setLayoutProperty(this.rampColorLayer,"visibility",r)}toggleParticle(e){const t=this.map.getLayoutProperty(this.particleLayer,"visibility"),r=e?"visible":"none";t!==r&&this.map.setLayoutProperty(this.particleLayer,"visibility",r)}}class Z{createShader(e,t,r){const o=e.createShader(t);if(o&&(e.shaderSource(o,r),e.compileShader(o),!e.getShaderParameter(o,e.COMPILE_STATUS)))throw new Error(e.getShaderInfoLog(o)||"error happened while create shader...");return o}createTexture(e,t,r,o,s,n,l){const c=e.createTexture();return e.bindTexture(e.TEXTURE_2D,c),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,t),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,r),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,o),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,o),s instanceof Uint8Array?e.texImage2D(e.TEXTURE_2D,0,e.RGBA,n,l,0,e.RGBA,e.UNSIGNED_BYTE,s):e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,s),e.bindTexture(e.TEXTURE_2D,null),c}createDataBuffer(e,t,r){if(e){const o=e.createBuffer();return t==="array"?(e.bindBuffer(e.ARRAY_BUFFER,o),r&&e.bufferData(e.ARRAY_BUFFER,r,e.STATIC_DRAW)):t==="element"&&(e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,o),r&&e.bufferData(e.ELEMENT_ARRAY_BUFFER,r,e.STATIC_DRAW)),o}return null}createProgram(e,t,r){const o=e.createProgram(),s=this.createShader(e,e.VERTEX_SHADER,t),n=this.createShader(e,e.FRAGMENT_SHADER,r);if(o&&s&&n&&(e.attachShader(o,s),e.attachShader(o,n),e.linkProgram(o),!e.getProgramParameter(o,e.LINK_STATUS)))throw new Error(e.getProgramInfoLog(o)||"error happened while creating ramp color program");return o}createProgramWrapper(e,t,r){const o=this.createProgram(e,t,r);if(o){const s={program:o},n=e.getProgramParameter(o,e.ACTIVE_ATTRIBUTES);for(let c=0;c<n;c++){const d=e.getActiveAttrib(o,c);s[d.name]=e.getAttribLocation(o,d.name)}const l=e.getProgramParameter(o,e.ACTIVE_UNIFORMS);for(let c=0;c<l;c++){const d=e.getActiveUniform(o,c);s[d.name]=e.getUniformLocation(o,d.name)}return s}}setup(e,t,r=!1,o,s){const n=document.createElement("canvas");n.width=256,n.height=1;const l=n.getContext("2d");if(l&&e){const c=l==null?void 0:l.createLinearGradient(0,0,256,0);return t.forEach(([d,p])=>{c.addColorStop(d,p)}),l.fillStyle=c,l.fillRect(0,0,256,1),{canvas:n,texture:this.createTexture(e,e.LINEAR,e.LINEAR,e.CLAMP_TO_EDGE,r?new Uint8Array(l.getImageData(0,0,256,1).data):n,o,s)}}}setupParticle(e,t=1e3){const r=Math.ceil(Math.sqrt(t)),o=r*r,s=new Uint8Array(o*4);for(let p=0;p<s.length;p++)s[p]=Math.floor(Math.random()*256);const n=this.createTexture(e,e.NEAREST,e.NEAREST,e.CLAMP_TO_EDGE,s,r,r),l=this.createTexture(e,e.NEAREST,e.NEAREST,e.CLAMP_TO_EDGE,s,r,r),c=new Float32Array(o);for(let p=0;p<o;p++)c[p]=p;const d=this.createDataBuffer(e,"array",c);return{resolution:r,total:o,texture0:n,texture1:l,indexBuffer:d}}bind(e,t,r){const o=this.createProgram(e,t,r);if(o){const s=this.createDataBuffer(e,"array",void 0),n=e.getAttribLocation(o,"a_position");e.enableVertexAttribArray(n),e.vertexAttribPointer(n,2,e.FLOAT,!1,0,0);const l=new Float32Array([0,0,1,0,0,1,0,1,1,0,1,1]);this.createDataBuffer(e,"array",l);const c=e.getAttribLocation(o,"a_texCoord");return e.enableVertexAttribArray(c),e.vertexAttribPointer(c,2,e.FLOAT,!1,0,0),{program:o,aPositionBuffer:s}}return{}}bindParticle(e,t,r,o,s,n){const l=this.createProgramWrapper(e,t,r),c=this.createProgramWrapper(e,o,s),d=this.createProgramWrapper(e,o,n),p=this.createDataBuffer(e,"array",new Float32Array([0,0,1,0,0,1,0,1,1,0,1,1])),h=e.createFramebuffer();return{particle:l,screen:c,update:d,quadBuffer:p,frameBuffer:h}}draw(e,t,r,o,s,n,l){var c,d;if(t&&r){e.resize(),t==null||t.viewport(0,0,(c=t==null?void 0:t.canvas)==null?void 0:c.width,(d=t==null?void 0:t.canvas)==null?void 0:d.height),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT|t.DEPTH_BUFFER_BIT);try{const p=t.getUniformLocation(r,"u_resolution"),h=t.getUniformLocation(r,"u_image"),g=t.getUniformLocation(r,"u_color");if(t.useProgram(r),t.uniform2f(p,t.canvas.width*e.ratio,t.canvas.height*e.ratio),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,o),t.uniform1i(h,0),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,s),t.uniform1i(g,1),l!=null&&l.uvRange&&(l!=null&&l.sRange)){const m=t.getUniformLocation(r,"u_range_u_v"),_=t.getUniformLocation(r,"u_range_s");t.uniform2f(m,l.uvRange[0],l.uvRange[1]),t.uniform2f(_,l.sRange[0],l.sRange[1])}const y=e.getBoundPixel(),f=e.map.getZoom()+1,u=e.getWorldCopy(y,f);for(const m of u){const _=(m[0]-y[0])*e.ratio,b=(m[1]-y[3])*e.ratio,L=m[2]*e.ratio,[x,w,P,N]=[_,L+_,b,L+b],I=new Float32Array([x,P,w,P,x,N,x,N,w,P,w,N]);t.bindBuffer(t.ARRAY_BUFFER,n),t.bufferData(t.ARRAY_BUFFER,I,t.STATIC_DRAW),t.drawArrays(t.TRIANGLES,0,6)}}catch(p){console.log(`render failed...${p}`)}}}drawParticle(e,t,r,o,s){var n,l;t&&(t==null||t.viewport(0,0,(n=t==null?void 0:t.canvas)==null?void 0:n.width,(l=t==null?void 0:t.canvas)==null?void 0:l.height),t.disable(t.DEPTH_TEST),t.disable(t.STENCIL_TEST),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,r),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,o.texture0),this.renderScreen(e,t,o,s),this.updateParticles(e,t,o,s))}renderScreen(e,t,r,o){t.bindFramebuffer(t.FRAMEBUFFER,r.frameBuffer),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,r.screenTexture,0),t.viewport(0,0,t.canvas.width,t.canvas.height),this.renderScreenTexture(t,r.backgroundTexture,r.screen,r.quadBuffer,.95),this.renderParticles(e,t,r,o),t.bindFramebuffer(t.FRAMEBUFFER,null),this.renderScreenTexture(t,r.screenTexture,r.screen,r.quadBuffer,1);const s=r.backgroundTexture;r.backgroundTexture=r.screenTexture,r.screenTexture=s}renderScreenTexture(e,t,r,o,s){e&&(e.useProgram(r.program),e.bindBuffer(e.ARRAY_BUFFER,o),e.enableVertexAttribArray(r.a_pos),e.vertexAttribPointer(r.a_pos,2,e.FLOAT,!1,0,0),e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_2D,t),e.uniform1i(r.u_screen,2),e.uniform1f(r.u_opacity,s),e.drawArrays(e.TRIANGLES,0,6))}renderParticles(e,t,r,o){if(t){t.useProgram(r.particle.program),t.bindBuffer(t.ARRAY_BUFFER,r.indexBuffer),t.enableVertexAttribArray(r.particle.a_index),t.vertexAttribPointer(r.particle.a_index,1,t.FLOAT,!1,0,0),t.activeTexture(t.TEXTURE2),t.bindTexture(t.TEXTURE_2D,r.color.texture),t.uniform1i(r.particle.u_factor,0),t.uniform1i(r.particle.u_particles,1),t.uniform1i(r.particle.u_color_ramp,2),t.uniform1f(r.particle.u_particles_resolution,r.resolution*e.ratio),t.uniform1f(r.particle.u_point,e.ratio);const s=e.getBoundRange();t.uniform4f(r.particle.u_viewport,s[0],s[1],s[2],s[3]),t.uniform2f(r.particle.u_factor_min,o.uvRange[0],o.uvRange[0]),t.uniform2f(r.particle.u_factor_max,o.uvRange[1],o.uvRange[1]),t.drawArrays(t.POINTS,0,r.total)}}updateParticles(e,t,r,o){var n,l;if(t){t.bindFramebuffer(t.FRAMEBUFFER,r.frameBuffer),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,r.texture1,0),t.viewport(0,0,r.resolution,r.resolution),t.useProgram(r.update.program),t.bindBuffer(t.ARRAY_BUFFER,r.quadBuffer),t.enableVertexAttribArray(r.update.a_pos),t.vertexAttribPointer(r.update.a_pos,2,t.FLOAT,!1,0,0),t.uniform1i(r.update.u_factor,0),t.uniform1i(r.update.u_particles,1);const c=e.getBoundRange();t.uniform4f(r.update.u_viewport,c[0],c[1],c[2],c[3]),t.uniform1f(r.update.u_rand_seed,Math.random()),t.uniform2f(r.update.u_factor_res,(n=r==null?void 0:r.image)==null?void 0:n.width,(l=r==null?void 0:r.image)==null?void 0:l.height),t.uniform2f(r.update.u_factor_min,o.uvRange[0],o.uvRange[0]),t.uniform2f(r.update.u_factor_max,o.uvRange[1],o.uvRange[1]),t.uniform1f(r.update.u_speed_factor,o.speedFactor*e.ratio),t.uniform1f(r.update.u_drop_rate,o.dropRate),t.uniform1f(r.update.u_drop_rate_bump,o.dropRateBump),t.drawArrays(t.TRIANGLES,0,6)}const s=r.texture0;r.texture0=r.texture1,r.texture1=s}resize(e,t){e.resize();const r=new Uint8Array(t.canvas.width*t.canvas.height*4).fill(0,0,t.canvas.width*t.canvas.height*4),o=this.createTexture(t,t.NEAREST,t.NEAREST,t.CLAMP_TO_EDGE,r,t.canvas.width,t.canvas.height),s=this.createTexture(t,t.NEAREST,t.NEAREST,t.CLAMP_TO_EDGE,r,t.canvas.width,t.canvas.height);return{screenTexture:o,backgroundTexture:s}}async loadImg(e){return new Promise(t=>{const r=new Blob([e],{type:e.type}),o=URL.createObjectURL(r),s=new Image;s.crossOrigin="anonymous",s.src=o,s.onload=()=>t(s)})}}class T{}z(T,"vertexSchema",`
|
|
2
2
|
//canvas 坐标系上的坐标 (x, y)
|
|
3
3
|
attribute vec2 a_position; //像素坐标
|
|
4
4
|
attribute vec2 a_texCoord; //纹理坐标
|