UNPKG

@deck.gl/layers

Version:

deck.gl core layers

696 lines (641 loc) 155 kB
(function webpackUniversalModuleDefinition(root, factory) { if (typeof exports === 'object' && typeof module === 'object') module.exports = factory(); else if (typeof define === 'function' && define.amd) define([], factory); else if (typeof exports === 'object') exports['deck'] = factory(); else root['deck'] = factory();})(globalThis, function () { "use strict";var __exports__=(()=>{var zn=Object.create;var te=Object.defineProperty;var On=Object.getOwnPropertyDescriptor;var Fn=Object.getOwnPropertyNames;var Dn=Object.getPrototypeOf,kn=Object.prototype.hasOwnProperty;var ht=(o,t)=>()=>(t||o((t={exports:{}}).exports,t),t.exports),Nn=(o,t)=>{for(var e in t)te(o,e,{get:t[e],enumerable:!0})},Qt=(o,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Fn(t))!kn.call(o,n)&&n!==e&&te(o,n,{get:()=>t[n],enumerable:!(i=On(t,n))||i.enumerable});return o},U=(o,t,e)=>(Qt(o,t,"default"),e&&Qt(e,t,"default")),P=(o,t,e)=>(e=o!=null?zn(Dn(o)):{},Qt(t||!o||!o.__esModule?te(e,"default",{value:o,enumerable:!0}):e,o)),Un=o=>Qt(te({},"__esModule",{value:!0}),o);var L=ht((Os,Je)=>{Je.exports=globalThis.deck});var I=ht((Ds,Qe)=>{Qe.exports=globalThis.luma});var So=ht((hl,Lo)=>{Lo.exports=globalThis.loaders});var No=ht((El,ko)=>{ko.exports=globalThis.luma});var Ei=ht((fu,Ze)=>{"use strict";Ze.exports=ve;Ze.exports.default=ve;function ve(o,t,e){e=e||2;var i=t&&t.length,n=i?t[0]*e:o.length,r=Ti(o,0,n,e,!0),s=[];if(!r||r.next===r.prev)return s;var a,l,c,u,f,d,g;if(i&&(r=Yr(o,t,r,e)),o.length>80*e){a=c=o[0],l=u=o[1];for(var p=e;p<n;p+=e)f=o[p],d=o[p+1],f<a&&(a=f),d<l&&(l=d),f>c&&(c=f),d>u&&(u=d);g=Math.max(c-a,u-l),g=g!==0?32767/g:0}return Ft(r,s,e,a,l,g,0),s}function Ti(o,t,e,i,n){var r,s;if(n===He(o,t,e,i)>0)for(r=t;r<e;r+=i)s=bi(r,o[r],o[r+1],s);else for(r=e-i;r>=t;r-=i)s=bi(r,o[r],o[r+1],s);return s&&ye(s,s.next)&&(kt(s),s=s.next),s}function q(o,t){if(!o)return o;t||(t=o);var e=o,i;do if(i=!1,!e.steiner&&(ye(e,e.next)||w(e.prev,e,e.next)===0)){if(kt(e),e=t=e.prev,e===e.next)break;i=!0}else e=e.next;while(i||e!==t);return t}function Ft(o,t,e,i,n,r,s){if(o){!s&&r&&es(o,i,n,r);for(var a=o,l,c;o.prev!==o.next;){if(l=o.prev,c=o.next,r?Kr(o,i,n,r):Zr(o)){t.push(l.i/e|0),t.push(o.i/e|0),t.push(c.i/e|0),kt(o),o=c.next,a=c.next;continue}if(o=c,o===a){s?s===1?(o=Xr(q(o),t,e),Ft(o,t,e,i,n,r,2)):s===2&&$r(o,t,e,i,n,r):Ft(q(o),t,e,i,n,r,1);break}}}}function Zr(o){var t=o.prev,e=o,i=o.next;if(w(t,e,i)>=0)return!1;for(var n=t.x,r=e.x,s=i.x,a=t.y,l=e.y,c=i.y,u=n<r?n<s?n:s:r<s?r:s,f=a<l?a<c?a:c:l<c?l:c,d=n>r?n>s?n:s:r>s?r:s,g=a>l?a>c?a:c:l>c?l:c,p=i.next;p!==t;){if(p.x>=u&&p.x<=d&&p.y>=f&&p.y<=g&&st(n,a,r,l,s,c,p.x,p.y)&&w(p.prev,p,p.next)>=0)return!1;p=p.next}return!0}function Kr(o,t,e,i){var n=o.prev,r=o,s=o.next;if(w(n,r,s)>=0)return!1;for(var a=n.x,l=r.x,c=s.x,u=n.y,f=r.y,d=s.y,g=a<l?a<c?a:c:l<c?l:c,p=u<f?u<d?u:d:f<d?f:d,h=a>l?a>c?a:c:l>c?l:c,m=u>f?u>d?u:d:f>d?f:d,v=je(g,p,t,e,i),_=je(h,m,t,e,i),x=o.prevZ,y=o.nextZ;x&&x.z>=v&&y&&y.z<=_;){if(x.x>=g&&x.x<=h&&x.y>=p&&x.y<=m&&x!==n&&x!==s&&st(a,u,l,f,c,d,x.x,x.y)&&w(x.prev,x,x.next)>=0||(x=x.prevZ,y.x>=g&&y.x<=h&&y.y>=p&&y.y<=m&&y!==n&&y!==s&&st(a,u,l,f,c,d,y.x,y.y)&&w(y.prev,y,y.next)>=0))return!1;y=y.nextZ}for(;x&&x.z>=v;){if(x.x>=g&&x.x<=h&&x.y>=p&&x.y<=m&&x!==n&&x!==s&&st(a,u,l,f,c,d,x.x,x.y)&&w(x.prev,x,x.next)>=0)return!1;x=x.prevZ}for(;y&&y.z<=_;){if(y.x>=g&&y.x<=h&&y.y>=p&&y.y<=m&&y!==n&&y!==s&&st(a,u,l,f,c,d,y.x,y.y)&&w(y.prev,y,y.next)>=0)return!1;y=y.nextZ}return!0}function Xr(o,t,e){var i=o;do{var n=i.prev,r=i.next.next;!ye(n,r)&&Ii(n,i,i.next,r)&&Dt(n,r)&&Dt(r,n)&&(t.push(n.i/e|0),t.push(i.i/e|0),t.push(r.i/e|0),kt(i),kt(i.next),i=o=r),i=i.next}while(i!==o);return q(i)}function $r(o,t,e,i,n,r){var s=o;do{for(var a=s.next.next;a!==s.prev;){if(s.i!==a.i&&ns(s,a)){var l=Ai(s,a);s=q(s,s.next),l=q(l,l.next),Ft(s,t,e,i,n,r,0),Ft(l,t,e,i,n,r,0);return}a=a.next}s=s.next}while(s!==o)}function Yr(o,t,e,i){var n=[],r,s,a,l,c;for(r=0,s=t.length;r<s;r++)a=t[r]*i,l=r<s-1?t[r+1]*i:o.length,c=Ti(o,a,l,i,!1),c===c.next&&(c.steiner=!0),n.push(is(c));for(n.sort(Jr),r=0;r<n.length;r++)e=qr(n[r],e);return e}function Jr(o,t){return o.x-t.x}function qr(o,t){var e=Qr(o,t);if(!e)return t;var i=Ai(e,o);return q(i,i.next),q(e,e.next)}function Qr(o,t){var e=t,i=o.x,n=o.y,r=-1/0,s;do{if(n<=e.y&&n>=e.next.y&&e.next.y!==e.y){var a=e.x+(n-e.y)*(e.next.x-e.x)/(e.next.y-e.y);if(a<=i&&a>r&&(r=a,s=e.x<e.next.x?e:e.next,a===i))return s}e=e.next}while(e!==t);if(!s)return null;var l=s,c=s.x,u=s.y,f=1/0,d;e=s;do i>=e.x&&e.x>=c&&i!==e.x&&st(n<u?i:r,n,c,u,n<u?r:i,n,e.x,e.y)&&(d=Math.abs(n-e.y)/(i-e.x),Dt(e,o)&&(d<f||d===f&&(e.x>s.x||e.x===s.x&&ts(s,e)))&&(s=e,f=d)),e=e.next;while(e!==l);return s}function ts(o,t){return w(o.prev,o,t.prev)<0&&w(t.next,o,o.next)<0}function es(o,t,e,i){var n=o;do n.z===0&&(n.z=je(n.x,n.y,t,e,i)),n.prevZ=n.prev,n.nextZ=n.next,n=n.next;while(n!==o);n.prevZ.nextZ=null,n.prevZ=null,os(n)}function os(o){var t,e,i,n,r,s,a,l,c=1;do{for(e=o,o=null,r=null,s=0;e;){for(s++,i=e,a=0,t=0;t<c&&(a++,i=i.nextZ,!!i);t++);for(l=c;a>0||l>0&&i;)a!==0&&(l===0||!i||e.z<=i.z)?(n=e,e=e.nextZ,a--):(n=i,i=i.nextZ,l--),r?r.nextZ=n:o=n,n.prevZ=r,r=n;e=i}r.nextZ=null,c*=2}while(s>1);return o}function je(o,t,e,i,n){return o=(o-e)*n|0,t=(t-i)*n|0,o=(o|o<<8)&16711935,o=(o|o<<4)&252645135,o=(o|o<<2)&858993459,o=(o|o<<1)&1431655765,t=(t|t<<8)&16711935,t=(t|t<<4)&252645135,t=(t|t<<2)&858993459,t=(t|t<<1)&1431655765,o|t<<1}function is(o){var t=o,e=o;do(t.x<e.x||t.x===e.x&&t.y<e.y)&&(e=t),t=t.next;while(t!==o);return e}function st(o,t,e,i,n,r,s,a){return(n-s)*(t-a)>=(o-s)*(r-a)&&(o-s)*(i-a)>=(e-s)*(t-a)&&(e-s)*(r-a)>=(n-s)*(i-a)}function ns(o,t){return o.next.i!==t.i&&o.prev.i!==t.i&&!rs(o,t)&&(Dt(o,t)&&Dt(t,o)&&ss(o,t)&&(w(o.prev,o,t.prev)||w(o,t.prev,t))||ye(o,t)&&w(o.prev,o,o.next)>0&&w(t.prev,t,t.next)>0)}function w(o,t,e){return(t.y-o.y)*(e.x-t.x)-(t.x-o.x)*(e.y-t.y)}function ye(o,t){return o.x===t.x&&o.y===t.y}function Ii(o,t,e,i){var n=xe(w(o,t,e)),r=xe(w(o,t,i)),s=xe(w(e,i,o)),a=xe(w(e,i,t));return!!(n!==r&&s!==a||n===0&&me(o,e,t)||r===0&&me(o,i,t)||s===0&&me(e,o,i)||a===0&&me(e,t,i))}function me(o,t,e){return t.x<=Math.max(o.x,e.x)&&t.x>=Math.min(o.x,e.x)&&t.y<=Math.max(o.y,e.y)&&t.y>=Math.min(o.y,e.y)}function xe(o){return o>0?1:o<0?-1:0}function rs(o,t){var e=o;do{if(e.i!==o.i&&e.next.i!==o.i&&e.i!==t.i&&e.next.i!==t.i&&Ii(e,e.next,o,t))return!0;e=e.next}while(e!==o);return!1}function Dt(o,t){return w(o.prev,o,o.next)<0?w(o,t,o.next)>=0&&w(o,o.prev,t)>=0:w(o,t,o.prev)<0||w(o,o.next,t)<0}function ss(o,t){var e=o,i=!1,n=(o.x+t.x)/2,r=(o.y+t.y)/2;do e.y>r!=e.next.y>r&&e.next.y!==e.y&&n<(e.next.x-e.x)*(r-e.y)/(e.next.y-e.y)+e.x&&(i=!i),e=e.next;while(e!==o);return i}function Ai(o,t){var e=new Ve(o.i,o.x,o.y),i=new Ve(t.i,t.x,t.y),n=o.next,r=t.prev;return o.next=t,t.prev=o,e.next=n,n.prev=e,i.next=e,e.prev=i,r.next=i,i.prev=r,i}function bi(o,t,e,i){var n=new Ve(o,t,e);return i?(n.next=i.next,n.prev=i,i.next.prev=n,i.next=n):(n.prev=n,n.next=n),n}function kt(o){o.next.prev=o.prev,o.prev.next=o.next,o.prevZ&&(o.prevZ.nextZ=o.nextZ),o.nextZ&&(o.nextZ.prevZ=o.prevZ)}function Ve(o,t,e){this.i=o,this.x=t,this.y=e,this.prev=null,this.next=null,this.z=0,this.prevZ=null,this.nextZ=null,this.steiner=!1}ve.deviation=function(o,t,e,i){var n=t&&t.length,r=n?t[0]*e:o.length,s=Math.abs(He(o,0,r,e));if(n)for(var a=0,l=t.length;a<l;a++){var c=t[a]*e,u=a<l-1?t[a+1]*e:o.length;s-=Math.abs(He(o,c,u,e))}var f=0;for(a=0;a<i.length;a+=3){var d=i[a]*e,g=i[a+1]*e,p=i[a+2]*e;f+=Math.abs((o[d]-o[p])*(o[g+1]-o[d+1])-(o[d]-o[g])*(o[p+1]-o[d+1]))}return s===0&&f===0?0:Math.abs((f-s)/s)};function He(o,t,e,i){for(var n=0,r=t,s=e-i;r<e;r+=i)n+=(o[s]-o[r])*(o[r+1]+o[s+1]),s=r;return n}ve.flatten=function(o){for(var t=o[0][0].length,e={vertices:[],holes:[],dimensions:t},i=0,n=0;n<o.length;n++){for(var r=0;r<o[n].length;r++)for(var s=0;s<t;s++)e.vertices.push(o[n][r][s]);n>0&&(i+=o[n-1].length,e.holes.push(i))}return e}});var Yt={};Nn(Yt,{ArcLayer:()=>ro,BitmapLayer:()=>vo,ColumnLayer:()=>he,GeoJsonLayer:()=>En,GridCellLayer:()=>mi,IconLayer:()=>it,LineLayer:()=>Do,PathLayer:()=>rt,PointCloudLayer:()=>$o,PolygonLayer:()=>Ki,ScatterplotLayer:()=>ue,SolidPolygonLayer:()=>lt,TextLayer:()=>Ie,_MultiIconLayer:()=>Me,_TextBackgroundLayer:()=>Te});var R={},qe=P(L(),1);U(R,P(L(),1));if(!qe.Layer)throw new Error("@deck.gl/core is not found");U(Yt,R);var G=P(L(),1),no=P(I(),1);var to=`uniform arcUniforms { bool greatCircle; bool useShortestPath; float numSegments; float widthScale; float widthMinPixels; float widthMaxPixels; highp int widthUnits; } arc; `,eo={name:"arc",vs:to,fs:to,uniformTypes:{greatCircle:"f32",useShortestPath:"f32",numSegments:"f32",widthScale:"f32",widthMinPixels:"f32",widthMaxPixels:"f32",widthUnits:"i32"}};var oo=`#version 300 es #define SHADER_NAME arc-layer-vertex-shader in vec4 instanceSourceColors; in vec4 instanceTargetColors; in vec3 instanceSourcePositions; in vec3 instanceSourcePositions64Low; in vec3 instanceTargetPositions; in vec3 instanceTargetPositions64Low; in vec3 instancePickingColors; in float instanceWidths; in float instanceHeights; in float instanceTilts; out vec4 vColor; out vec2 uv; out float isValid; float paraboloid(float distance, float sourceZ, float targetZ, float ratio) { float deltaZ = targetZ - sourceZ; float dh = distance * instanceHeights; if (dh == 0.0) { return sourceZ + deltaZ * ratio; } float unitZ = deltaZ / dh; float p2 = unitZ * unitZ + 1.0; float dir = step(deltaZ, 0.0); float z0 = mix(sourceZ, targetZ, dir); float r = mix(ratio, 1.0 - ratio, dir); return sqrt(r * (p2 - r)) * dh + z0; } vec2 getExtrusionOffset(vec2 line_clipspace, float offset_direction, float width) { vec2 dir_screenspace = normalize(line_clipspace * project.viewportSize); dir_screenspace = vec2(-dir_screenspace.y, dir_screenspace.x); return dir_screenspace * offset_direction * width / 2.0; } float getSegmentRatio(float index) { return smoothstep(0.0, 1.0, index / (arc.numSegments - 1.0)); } vec3 interpolateFlat(vec3 source, vec3 target, float segmentRatio) { float distance = length(source.xy - target.xy); float z = paraboloid(distance, source.z, target.z, segmentRatio); float tiltAngle = radians(instanceTilts); vec2 tiltDirection = normalize(target.xy - source.xy); vec2 tilt = vec2(-tiltDirection.y, tiltDirection.x) * z * sin(tiltAngle); return vec3( mix(source.xy, target.xy, segmentRatio) + tilt, z * cos(tiltAngle) ); } float getAngularDist (vec2 source, vec2 target) { vec2 sourceRadians = radians(source); vec2 targetRadians = radians(target); vec2 sin_half_delta = sin((sourceRadians - targetRadians) / 2.0); vec2 shd_sq = sin_half_delta * sin_half_delta; float a = shd_sq.y + cos(sourceRadians.y) * cos(targetRadians.y) * shd_sq.x; return 2.0 * asin(sqrt(a)); } vec3 interpolateGreatCircle(vec3 source, vec3 target, vec3 source3D, vec3 target3D, float angularDist, float t) { vec2 lngLat; if(abs(angularDist - PI) < 0.001) { lngLat = (1.0 - t) * source.xy + t * target.xy; } else { float a = sin((1.0 - t) * angularDist); float b = sin(t * angularDist); vec3 p = source3D.yxz * a + target3D.yxz * b; lngLat = degrees(vec2(atan(p.y, -p.x), atan(p.z, length(p.xy)))); } float z = paraboloid(angularDist * EARTH_RADIUS, source.z, target.z, t); return vec3(lngLat, z); } void main(void) { geometry.worldPosition = instanceSourcePositions; geometry.worldPositionAlt = instanceTargetPositions; float segmentIndex = float(gl_VertexID / 2); float segmentSide = mod(float(gl_VertexID), 2.) == 0. ? -1. : 1.; float segmentRatio = getSegmentRatio(segmentIndex); float prevSegmentRatio = getSegmentRatio(max(0.0, segmentIndex - 1.0)); float nextSegmentRatio = getSegmentRatio(min(arc.numSegments - 1.0, segmentIndex + 1.0)); float indexDir = mix(-1.0, 1.0, step(segmentIndex, 0.0)); isValid = 1.0; uv = vec2(segmentRatio, segmentSide); geometry.uv = uv; geometry.pickingColor = instancePickingColors; vec4 curr; vec4 next; vec3 source; vec3 target; if ((arc.greatCircle || project.projectionMode == PROJECTION_MODE_GLOBE) && project.coordinateSystem == COORDINATE_SYSTEM_LNGLAT) { source = project_globe_(vec3(instanceSourcePositions.xy, 0.0)); target = project_globe_(vec3(instanceTargetPositions.xy, 0.0)); float angularDist = getAngularDist(instanceSourcePositions.xy, instanceTargetPositions.xy); vec3 prevPos = interpolateGreatCircle(instanceSourcePositions, instanceTargetPositions, source, target, angularDist, prevSegmentRatio); vec3 currPos = interpolateGreatCircle(instanceSourcePositions, instanceTargetPositions, source, target, angularDist, segmentRatio); vec3 nextPos = interpolateGreatCircle(instanceSourcePositions, instanceTargetPositions, source, target, angularDist, nextSegmentRatio); if (abs(currPos.x - prevPos.x) > 180.0) { indexDir = -1.0; isValid = 0.0; } else if (abs(currPos.x - nextPos.x) > 180.0) { indexDir = 1.0; isValid = 0.0; } nextPos = indexDir < 0.0 ? prevPos : nextPos; nextSegmentRatio = indexDir < 0.0 ? prevSegmentRatio : nextSegmentRatio; if (isValid == 0.0) { nextPos.x += nextPos.x > 0.0 ? -360.0 : 360.0; float t = ((currPos.x > 0.0 ? 180.0 : -180.0) - currPos.x) / (nextPos.x - currPos.x); currPos = mix(currPos, nextPos, t); segmentRatio = mix(segmentRatio, nextSegmentRatio, t); } vec3 currPos64Low = mix(instanceSourcePositions64Low, instanceTargetPositions64Low, segmentRatio); vec3 nextPos64Low = mix(instanceSourcePositions64Low, instanceTargetPositions64Low, nextSegmentRatio); curr = project_position_to_clipspace(currPos, currPos64Low, vec3(0.0), geometry.position); next = project_position_to_clipspace(nextPos, nextPos64Low, vec3(0.0)); } else { vec3 source_world = instanceSourcePositions; vec3 target_world = instanceTargetPositions; if (arc.useShortestPath) { source_world.x = mod(source_world.x + 180., 360.0) - 180.; target_world.x = mod(target_world.x + 180., 360.0) - 180.; float deltaLng = target_world.x - source_world.x; if (deltaLng > 180.) target_world.x -= 360.; if (deltaLng < -180.) source_world.x -= 360.; } source = project_position(source_world, instanceSourcePositions64Low); target = project_position(target_world, instanceTargetPositions64Low); float antiMeridianX = 0.0; if (arc.useShortestPath) { if (project.projectionMode == PROJECTION_MODE_WEB_MERCATOR_AUTO_OFFSET) { antiMeridianX = -(project.coordinateOrigin.x + 180.) / 360. * TILE_SIZE; } float thresholdRatio = (antiMeridianX - source.x) / (target.x - source.x); if (prevSegmentRatio <= thresholdRatio && nextSegmentRatio > thresholdRatio) { isValid = 0.0; indexDir = sign(segmentRatio - thresholdRatio); segmentRatio = thresholdRatio; } } nextSegmentRatio = indexDir < 0.0 ? prevSegmentRatio : nextSegmentRatio; vec3 currPos = interpolateFlat(source, target, segmentRatio); vec3 nextPos = interpolateFlat(source, target, nextSegmentRatio); if (arc.useShortestPath) { if (nextPos.x < antiMeridianX) { currPos.x += TILE_SIZE; nextPos.x += TILE_SIZE; } } curr = project_common_position_to_clipspace(vec4(currPos, 1.0)); next = project_common_position_to_clipspace(vec4(nextPos, 1.0)); geometry.position = vec4(currPos, 1.0); } float widthPixels = clamp( project_size_to_pixel(instanceWidths * arc.widthScale, arc.widthUnits), arc.widthMinPixels, arc.widthMaxPixels ); vec3 offset = vec3( getExtrusionOffset((next.xy - curr.xy) * indexDir, segmentSide, widthPixels), 0.0); DECKGL_FILTER_SIZE(offset, geometry); DECKGL_FILTER_GL_POSITION(curr, geometry); gl_Position = curr + vec4(project_pixel_size_to_clipspace(offset.xy), 0.0, 0.0); vec4 color = mix(instanceSourceColors, instanceTargetColors, segmentRatio); vColor = vec4(color.rgb, color.a * layer.opacity); DECKGL_FILTER_COLOR(vColor, geometry); } `;var io=`#version 300 es #define SHADER_NAME arc-layer-fragment-shader precision highp float; in vec4 vColor; in vec2 uv; in float isValid; out vec4 fragColor; void main(void) { if (isValid == 0.0) { discard; } fragColor = vColor; geometry.uv = uv; DECKGL_FILTER_COLOR(fragColor, geometry); } `;var ee=[0,0,0,255],Gn={getSourcePosition:{type:"accessor",value:o=>o.sourcePosition},getTargetPosition:{type:"accessor",value:o=>o.targetPosition},getSourceColor:{type:"accessor",value:ee},getTargetColor:{type:"accessor",value:ee},getWidth:{type:"accessor",value:1},getHeight:{type:"accessor",value:1},getTilt:{type:"accessor",value:0},greatCircle:!1,numSegments:{type:"number",value:50,min:1},widthUnits:"pixels",widthScale:{type:"number",value:1,min:0},widthMinPixels:{type:"number",value:0,min:0},widthMaxPixels:{type:"number",value:Number.MAX_SAFE_INTEGER,min:0}},mt=class extends G.Layer{getBounds(){return this.getAttributeManager()?.getBounds(["instanceSourcePositions","instanceTargetPositions"])}getShaders(){return super.getShaders({vs:oo,fs:io,modules:[G.project32,G.picking,eo]})}get wrapLongitude(){return!1}initializeState(){this.getAttributeManager().addInstanced({instanceSourcePositions:{size:3,type:"float64",fp64:this.use64bitPositions(),transition:!0,accessor:"getSourcePosition"},instanceTargetPositions:{size:3,type:"float64",fp64:this.use64bitPositions(),transition:!0,accessor:"getTargetPosition"},instanceSourceColors:{size:this.props.colorFormat.length,type:"unorm8",transition:!0,accessor:"getSourceColor",defaultValue:ee},instanceTargetColors:{size:this.props.colorFormat.length,type:"unorm8",transition:!0,accessor:"getTargetColor",defaultValue:ee},instanceWidths:{size:1,transition:!0,accessor:"getWidth",defaultValue:1},instanceHeights:{size:1,transition:!0,accessor:"getHeight",defaultValue:1},instanceTilts:{size:1,transition:!0,accessor:"getTilt",defaultValue:0}})}updateState(t){super.updateState(t),t.changeFlags.extensionsChanged&&(this.state.model?.destroy(),this.state.model=this._getModel(),this.getAttributeManager().invalidateAll())}draw({uniforms:t}){let{widthUnits:e,widthScale:i,widthMinPixels:n,widthMaxPixels:r,greatCircle:s,wrapLongitude:a,numSegments:l}=this.props,c={numSegments:l,widthUnits:G.UNIT[e],widthScale:i,widthMinPixels:n,widthMaxPixels:r,greatCircle:s,useShortestPath:a},u=this.state.model;u.shaderInputs.setProps({arc:c}),u.setVertexCount(l*2),u.draw(this.context.renderPass)}_getModel(){return new no.Model(this.context.device,{...this.getShaders(),id:this.props.id,bufferLayout:this.getAttributeManager().getBufferLayouts(),topology:"triangle-strip",isInstanced:!0})}};mt.layerName="ArcLayer";mt.defaultProps=Gn;var ro=mt;var F=P(L(),1),xo=P(I(),1);var Vs=1/Math.PI*180,Hs=1/180*Math.PI,Wn={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{...Wn}};var Bn=globalThis.mathgl.config;function so(o){return Array.isArray(o)||ArrayBuffer.isView(o)&&!(o instanceof DataView)}function ot(o,t,e){return so(o)?o.map((i,n)=>ot(i,t[n],e)):e*t+(1-e)*o}function oe(o,t){if(!o)throw new Error(t||"@math.gl/web-mercator: assertion failed.")}var X=Math.PI,Zn=X/4,ao=X/180,ma=180/X,lo=512;function $(o){let[t,e]=o;oe(Number.isFinite(t)),oe(Number.isFinite(e)&&e>=-90&&e<=90,"invalid latitude");let i=t*ao,n=e*ao,r=lo*(i+X)/(2*X),s=lo*(X+Math.log(Math.tan(Zn+n*.5)))/(2*X);return[r,s]}var Sa=Math.PI/180;var rr=new Uint32Array([0,2,1,0,3,2]),sr=new Float32Array([0,1,0,0,1,0,1,1]);function Oe(o,t){if(!t)return ar(o);let e=Math.max(Math.abs(o[0][0]-o[3][0]),Math.abs(o[1][0]-o[2][0])),i=Math.max(Math.abs(o[1][1]-o[0][1]),Math.abs(o[2][1]-o[3][1])),n=Math.ceil(e/t)+1,r=Math.ceil(i/t)+1,s=(n-1)*(r-1)*6,a=new Uint32Array(s),l=new Float32Array(n*r*2),c=new Float64Array(n*r*3),u=0,f=0;for(let d=0;d<n;d++){let g=d/(n-1);for(let p=0;p<r;p++){let h=p/(r-1),m=lr(o,g,h);c[u*3+0]=m[0],c[u*3+1]=m[1],c[u*3+2]=m[2]||0,l[u*2+0]=g,l[u*2+1]=1-h,d>0&&p>0&&(a[f++]=u-r,a[f++]=u-r-1,a[f++]=u-1,a[f++]=u-r,a[f++]=u-1,a[f++]=u),u++}}return{vertexCount:s,positions:c,indices:a,texCoords:l}}function ar(o){let t=new Float64Array(12);for(let e=0;e<o.length;e++)t[e*3+0]=o[e][0],t[e*3+1]=o[e][1],t[e*3+2]=o[e][2]||0;return{vertexCount:6,positions:t,indices:rr,texCoords:sr}}function lr(o,t,e){return ot(ot(o[0],o[1],e),ot(o[3],o[2],e),t)}var fo=`uniform bitmapUniforms { vec4 bounds; float coordinateConversion; float desaturate; vec3 tintColor; vec4 transparentColor; } bitmap; `,go={name:"bitmap",vs:fo,fs:fo,uniformTypes:{bounds:"vec4<f32>",coordinateConversion:"f32",desaturate:"f32",tintColor:"vec3<f32>",transparentColor:"vec4<f32>"}};var po=`#version 300 es #define SHADER_NAME bitmap-layer-vertex-shader in vec2 texCoords; in vec3 positions; in vec3 positions64Low; out vec2 vTexCoord; out vec2 vTexPos; const vec3 pickingColor = vec3(1.0, 0.0, 0.0); void main(void) { geometry.worldPosition = positions; geometry.uv = texCoords; geometry.pickingColor = pickingColor; gl_Position = project_position_to_clipspace(positions, positions64Low, vec3(0.0), geometry.position); DECKGL_FILTER_GL_POSITION(gl_Position, geometry); vTexCoord = texCoords; if (bitmap.coordinateConversion < -0.5) { vTexPos = geometry.position.xy + project.commonOrigin.xy; } else if (bitmap.coordinateConversion > 0.5) { vTexPos = geometry.worldPosition.xy; } vec4 color = vec4(0.0); DECKGL_FILTER_COLOR(color, geometry); } `;var cr=` vec3 packUVsIntoRGB(vec2 uv) { // Extract the top 8 bits. We want values to be truncated down so we can add a fraction vec2 uv8bit = floor(uv * 256.); // Calculate the normalized remainders of u and v parts that do not fit into 8 bits // Scale and clamp to 0-1 range vec2 uvFraction = fract(uv * 256.); vec2 uvFraction4bit = floor(uvFraction * 16.); // Remainder can be encoded in blue channel, encode as 4 bits for pixel coordinates float fractions = uvFraction4bit.x + uvFraction4bit.y * 16.; return vec3(uv8bit, fractions) / 255.; } `,ho=`#version 300 es #define SHADER_NAME bitmap-layer-fragment-shader #ifdef GL_ES precision highp float; #endif uniform sampler2D bitmapTexture; in vec2 vTexCoord; in vec2 vTexPos; out vec4 fragColor; /* projection utils */ const float TILE_SIZE = 512.0; const float PI = 3.1415926536; const float WORLD_SCALE = TILE_SIZE / PI / 2.0; // from degrees to Web Mercator vec2 lnglat_to_mercator(vec2 lnglat) { float x = lnglat.x; float y = clamp(lnglat.y, -89.9, 89.9); return vec2( radians(x) + PI, PI + log(tan(PI * 0.25 + radians(y) * 0.5)) ) * WORLD_SCALE; } // from Web Mercator to degrees vec2 mercator_to_lnglat(vec2 xy) { xy /= WORLD_SCALE; return degrees(vec2( xy.x - PI, atan(exp(xy.y - PI)) * 2.0 - PI * 0.5 )); } /* End projection utils */ // apply desaturation vec3 color_desaturate(vec3 color) { float luminance = (color.r + color.g + color.b) * 0.333333333; return mix(color, vec3(luminance), bitmap.desaturate); } // apply tint vec3 color_tint(vec3 color) { return color * bitmap.tintColor; } // blend with background color vec4 apply_opacity(vec3 color, float alpha) { if (bitmap.transparentColor.a == 0.0) { return vec4(color, alpha); } float blendedAlpha = alpha + bitmap.transparentColor.a * (1.0 - alpha); float highLightRatio = alpha / blendedAlpha; vec3 blendedRGB = mix(bitmap.transparentColor.rgb, color, highLightRatio); return vec4(blendedRGB, blendedAlpha); } vec2 getUV(vec2 pos) { return vec2( (pos.x - bitmap.bounds[0]) / (bitmap.bounds[2] - bitmap.bounds[0]), (pos.y - bitmap.bounds[3]) / (bitmap.bounds[1] - bitmap.bounds[3]) ); } ${cr} void main(void) { vec2 uv = vTexCoord; if (bitmap.coordinateConversion < -0.5) { vec2 lnglat = mercator_to_lnglat(vTexPos); uv = getUV(lnglat); } else if (bitmap.coordinateConversion > 0.5) { vec2 commonPos = lnglat_to_mercator(vTexPos); uv = getUV(commonPos); } vec4 bitmapColor = texture(bitmapTexture, uv); fragColor = apply_opacity(color_tint(color_desaturate(bitmapColor.rgb)), bitmapColor.a * layer.opacity); geometry.uv = uv; DECKGL_FILTER_COLOR(fragColor, geometry); if (bool(picking.isActive) && !bool(picking.isAttribute)) { // Since instance information is not used, we can use picking color for pixel index fragColor.rgb = packUVsIntoRGB(uv); } } `;var ur={image:{type:"image",value:null,async:!0},bounds:{type:"array",value:[1,0,0,1],compare:!0},_imageCoordinateSystem:F.COORDINATE_SYSTEM.DEFAULT,desaturate:{type:"number",min:0,max:1,value:0},transparentColor:{type:"color",value:[0,0,0,0]},tintColor:{type:"color",value:[255,255,255]},textureParameters:{type:"object",ignore:!0,value:null}},vt=class extends F.Layer{getShaders(){return super.getShaders({vs:po,fs:ho,modules:[F.project32,F.picking,go]})}initializeState(){let t=this.getAttributeManager();t.remove(["instancePickingColors"]);let e=!0;t.add({indices:{size:1,isIndexed:!0,update:i=>i.value=this.state.mesh.indices,noAlloc:e},positions:{size:3,type:"float64",fp64:this.use64bitPositions(),update:i=>i.value=this.state.mesh.positions,noAlloc:e},texCoords:{size:2,update:i=>i.value=this.state.mesh.texCoords,noAlloc:e}})}updateState({props:t,oldProps:e,changeFlags:i}){let n=this.getAttributeManager();if(i.extensionsChanged&&(this.state.model?.destroy(),this.state.model=this._getModel(),n.invalidateAll()),t.bounds!==e.bounds){let r=this.state.mesh,s=this._createMesh();this.state.model.setVertexCount(s.vertexCount);for(let a in s)r&&r[a]!==s[a]&&n.invalidate(a);this.setState({mesh:s,...this._getCoordinateUniforms()})}else t._imageCoordinateSystem!==e._imageCoordinateSystem&&this.setState(this._getCoordinateUniforms())}getPickingInfo(t){let{image:e}=this.props,i=t.info;if(!i.color||!e)return i.bitmap=null,i;let{width:n,height:r}=e;i.index=0;let s=fr(i.color);return i.bitmap={size:{width:n,height:r},uv:s,pixel:[Math.floor(s[0]*n),Math.floor(s[1]*r)]},i}disablePickingIndex(){this.setState({disablePicking:!0})}restorePickingColors(){this.setState({disablePicking:!1})}_updateAutoHighlight(t){super._updateAutoHighlight({...t,color:this.encodePickingColor(0)})}_createMesh(){let{bounds:t}=this.props,e=t;return mo(t)&&(e=[[t[0],t[1]],[t[0],t[3]],[t[2],t[3]],[t[2],t[1]]]),Oe(e,this.context.viewport.resolution)}_getModel(){return new xo.Model(this.context.device,{...this.getShaders(),id:this.props.id,bufferLayout:this.getAttributeManager().getBufferLayouts(),topology:"triangle-list",isInstanced:!1})}draw(t){let{shaderModuleProps:e}=t,{model:i,coordinateConversion:n,bounds:r,disablePicking:s}=this.state,{image:a,desaturate:l,transparentColor:c,tintColor:u}=this.props;if(!(e.picking.isActive&&s)&&a&&i){let f={bitmapTexture:a,bounds:r,coordinateConversion:n,desaturate:l,tintColor:u.slice(0,3).map(d=>d/255),transparentColor:c.map(d=>d/255)};i.shaderInputs.setProps({bitmap:f}),i.draw(this.context.renderPass)}}_getCoordinateUniforms(){let{LNGLAT:t,CARTESIAN:e,DEFAULT:i}=F.COORDINATE_SYSTEM,{_imageCoordinateSystem:n}=this.props;if(n!==i){let{bounds:r}=this.props;if(!mo(r))throw new Error("_imageCoordinateSystem only supports rectangular bounds");let s=this.context.viewport.resolution?t:e;if(n=n===t?t:e,n===t&&s===e)return{coordinateConversion:-1,bounds:r};if(n===e&&s===t){let a=$([r[0],r[1]]),l=$([r[2],r[3]]);return{coordinateConversion:1,bounds:[a[0],a[1],l[0],l[1]]}}}return{coordinateConversion:0,bounds:[0,0,0,0]}}};vt.layerName="BitmapLayer";vt.defaultProps=ur;var vo=vt;function fr(o){let[t,e,i]=o,n=(i&240)/256,r=(i&15)/16;return[(t+r)/256,(e+n)/256]}function mo(o){return Number.isFinite(o[0])}var z=P(L(),1),ie=P(I(),1);var yo=`uniform iconUniforms { float sizeScale; vec2 iconsTextureDim; float sizeMinPixels; float sizeMaxPixels; bool billboard; highp int sizeUnits; float alphaCutoff; } icon; `,Po={name:"icon",vs:yo,fs:yo,uniformTypes:{sizeScale:"f32",iconsTextureDim:"vec2<f32>",sizeMinPixels:"f32",sizeMaxPixels:"f32",billboard:"f32",sizeUnits:"i32",alphaCutoff:"f32"}};var _o=`#version 300 es #define SHADER_NAME icon-layer-vertex-shader in vec2 positions; in vec3 instancePositions; in vec3 instancePositions64Low; in float instanceSizes; in float instanceAngles; in vec4 instanceColors; in vec3 instancePickingColors; in vec4 instanceIconFrames; in float instanceColorModes; in vec2 instanceOffsets; in vec2 instancePixelOffset; out float vColorMode; out vec4 vColor; out vec2 vTextureCoords; out vec2 uv; vec2 rotate_by_angle(vec2 vertex, float angle) { float angle_radian = angle * PI / 180.0; float cos_angle = cos(angle_radian); float sin_angle = sin(angle_radian); mat2 rotationMatrix = mat2(cos_angle, -sin_angle, sin_angle, cos_angle); return rotationMatrix * vertex; } void main(void) { geometry.worldPosition = instancePositions; geometry.uv = positions; geometry.pickingColor = instancePickingColors; uv = positions; vec2 iconSize = instanceIconFrames.zw; float sizePixels = clamp( project_size_to_pixel(instanceSizes * icon.sizeScale, icon.sizeUnits), icon.sizeMinPixels, icon.sizeMaxPixels ); float instanceScale = iconSize.y == 0.0 ? 0.0 : sizePixels / iconSize.y; vec2 pixelOffset = positions / 2.0 * iconSize + instanceOffsets; pixelOffset = rotate_by_angle(pixelOffset, instanceAngles) * instanceScale; pixelOffset += instancePixelOffset; pixelOffset.y *= -1.0; if (icon.billboard) { gl_Position = project_position_to_clipspace(instancePositions, instancePositions64Low, vec3(0.0), geometry.position); DECKGL_FILTER_GL_POSITION(gl_Position, geometry); vec3 offset = vec3(pixelOffset, 0.0); DECKGL_FILTER_SIZE(offset, geometry); gl_Position.xy += project_pixel_size_to_clipspace(offset.xy); } else { vec3 offset_common = vec3(project_pixel_size(pixelOffset), 0.0); DECKGL_FILTER_SIZE(offset_common, geometry); gl_Position = project_position_to_clipspace(instancePositions, instancePositions64Low, offset_common, geometry.position); DECKGL_FILTER_GL_POSITION(gl_Position, geometry); } vTextureCoords = mix( instanceIconFrames.xy, instanceIconFrames.xy + iconSize, (positions.xy + 1.0) / 2.0 ) / icon.iconsTextureDim; vColor = instanceColors; DECKGL_FILTER_COLOR(vColor, geometry); vColorMode = instanceColorModes; } `;var Co=`#version 300 es #define SHADER_NAME icon-layer-fragment-shader precision highp float; uniform sampler2D iconsTexture; in float vColorMode; in vec4 vColor; in vec2 vTextureCoords; in vec2 uv; out vec4 fragColor; void main(void) { geometry.uv = uv; vec4 texColor = texture(iconsTexture, vTextureCoords); vec3 color = mix(texColor.rgb, vColor.rgb, vColorMode); float a = texColor.a * layer.opacity * vColor.a; if (a < icon.alphaCutoff) { discard; } fragColor = vec4(color, a); DECKGL_FILTER_COLOR(fragColor, geometry); } `;var To=P(So(),1),Io=P(L(),1),dr=1024,gr=4,wo=()=>{},Mo={minFilter:"linear",mipmapFilter:"linear",magFilter:"linear",addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge"},pr={x:0,y:0,width:0,height:0};function hr(o){return Math.pow(2,Math.ceil(Math.log2(o)))}function mr(o,t,e,i){let n=Math.min(e/t.width,i/t.height),r=Math.floor(t.width*n),s=Math.floor(t.height*n);return n===1?{image:t,width:r,height:s}:(o.canvas.height=s,o.canvas.width=r,o.clearRect(0,0,r,s),o.drawImage(t,0,0,t.width,t.height,0,0,r,s),{image:o.canvas,width:r,height:s})}function yt(o){return o&&(o.id||o.url)}function xr(o,t,e,i){let{width:n,height:r,device:s}=o,a=s.createTexture({format:"rgba8unorm",width:t,height:e,sampler:i,mipmaps:!0}),l=s.createCommandEncoder();return l.copyTextureToTexture({sourceTexture:o,destinationTexture:a,width:n,height:r}),l.finish(),o.destroy(),a}function bo(o,t,e){for(let i=0;i<t.length;i++){let{icon:n,xOffset:r}=t[i],s=yt(n);o[s]={...n,x:r,y:e}}}function vr({icons:o,buffer:t,mapping:e={},xOffset:i=0,yOffset:n=0,rowHeight:r=0,canvasWidth:s}){let a=[];for(let l=0;l<o.length;l++){let c=o[l],u=yt(c);if(!e[u]){let{height:f,width:d}=c;i+d+t>s&&(bo(e,a,n),i=0,n=r+n+t,r=0,a=[]),a.push({icon:c,xOffset:i}),i=i+d+t,r=Math.max(r,f)}}return a.length>0&&bo(e,a,n),{mapping:e,rowHeight:r,xOffset:i,yOffset:n,canvasWidth:s,canvasHeight:hr(r+n+t)}}function yr(o,t,e){if(!o||!t)return null;e=e||{};let i={},{iterable:n,objectInfo:r}=(0,Io.createIterable)(o);for(let s of n){r.index++;let a=t(s,r),l=yt(a);if(!a)throw new Error("Icon is missing.");if(!a.url)throw new Error("Icon url is missing.");!i[l]&&(!e[l]||a.url!==e[l].url)&&(i[l]={...a,source:s,sourceIndex:r.index})}return i}var Pt=class{constructor(t,{onUpdate:e=wo,onError:i=wo}){this._loadOptions=null,this._texture=null,this._externalTexture=null,this._mapping={},this._samplerParameters=null,this._pendingCount=0,this._autoPacking=!1,this._xOffset=0,this._yOffset=0,this._rowHeight=0,this._buffer=gr,this._canvasWidth=dr,this._canvasHeight=0,this._canvas=null,this.device=t,this.onUpdate=e,this.onError=i}finalize(){this._texture?.delete()}getTexture(){return this._texture||this._externalTexture}getIconMapping(t){let e=this._autoPacking?yt(t):t;return this._mapping[e]||pr}setProps({loadOptions:t,autoPacking:e,iconAtlas:i,iconMapping:n,textureParameters:r}){t&&(this._loadOptions=t),e!==void 0&&(this._autoPacking=e),n&&(this._mapping=n),i&&(this._texture?.delete(),this._texture=null,this._externalTexture=i),r&&(this._samplerParameters=r)}get isLoaded(){return this._pendingCount===0}packIcons(t,e){if(!this._autoPacking||typeof document>"u")return;let i=Object.values(yr(t,e,this._mapping)||{});if(i.length>0){let{mapping:n,xOffset:r,yOffset:s,rowHeight:a,canvasHeight:l}=vr({icons:i,buffer:this._buffer,canvasWidth:this._canvasWidth,mapping:this._mapping,rowHeight:this._rowHeight,xOffset:this._xOffset,yOffset:this._yOffset});this._rowHeight=a,this._mapping=n,this._xOffset=r,this._yOffset=s,this._canvasHeight=l,this._texture||(this._texture=this.device.createTexture({format:"rgba8unorm",width:this._canvasWidth,height:this._canvasHeight,sampler:this._samplerParameters||Mo,mipmaps:!0})),this._texture.height!==this._canvasHeight&&(this._texture=xr(this._texture,this._canvasWidth,this._canvasHeight,this._samplerParameters||Mo)),this.onUpdate(),this._canvas=this._canvas||document.createElement("canvas"),this._loadIcons(i)}}_loadIcons(t){let e=this._canvas.getContext("2d",{willReadFrequently:!0});for(let i of t)this._pendingCount++,(0,To.load)(i.url,this._loadOptions).then(n=>{let r=yt(i),s=this._mapping[r],{x:a,y:l,width:c,height:u}=s,{image:f,width:d,height:g}=mr(e,n,c,u);this._texture?.copyExternalImage({image:f,x:a+(c-d)/2,y:l+(u-g)/2,width:d,height:g}),s.width=d,s.height=g,this._texture.generateMipmap(),this.onUpdate()}).catch(n=>{this.onError({url:i.url,source:i.source,sourceIndex:i.sourceIndex,loadOptions:this._loadOptions,error:n})}).finally(()=>{this._pendingCount--})}};var Ao=[0,0,0,255],Pr={iconAtlas:{type:"image",value:null,async:!0},iconMapping:{type:"object",value:{},async:!0},sizeScale:{type:"number",value:1,min:0},billboard:!0,sizeUnits:"pixels",sizeMinPixels:{type:"number",min:0,value:0},sizeMaxPixels:{type:"number",min:0,value:Number.MAX_SAFE_INTEGER},alphaCutoff:{type:"number",value:.05,min:0,max:1},getPosition:{type:"accessor",value:o=>o.position},getIcon:{type:"accessor",value:o=>o.icon},getColor:{type:"accessor",value:Ao},getSize:{type:"accessor",value:1},getAngle:{type:"accessor",value:0},getPixelOffset:{type:"accessor",value:[0,0]},onIconError:{type:"function",value:null,optional:!0},textureParameters:{type:"object",ignore:!0,value:null}},_t=class extends z.Layer{getShaders(){return super.getShaders({vs:_o,fs:Co,modules:[z.project32,z.picking,Po]})}initializeState(){this.state={iconManager:new Pt(this.context.device,{onUpdate:this._onUpdate.bind(this),onError:this._onError.bind(this)})},this.getAttributeManager().addInstanced({instancePositions:{size:3,type:"float64",fp64:this.use64bitPositions(),transition:!0,accessor:"getPosition"},instanceSizes:{size:1,transition:!0,accessor:"getSize",defaultValue:1},instanceOffsets:{size:2,accessor:"getIcon",transform:this.getInstanceOffset},instanceIconFrames:{size:4,accessor:"getIcon",transform:this.getInstanceIconFrame},instanceColorModes:{size:1,type:"uint8",accessor:"getIcon",transform:this.getInstanceColorMode},instanceColors:{size:this.props.colorFormat.length,type:"unorm8",transition:!0,accessor:"getColor",defaultValue:Ao},instanceAngles:{size:1,transition:!0,accessor:"getAngle"},instancePixelOffset:{size:2,transition:!0,accessor:"getPixelOffset"}})}updateState(t){super.updateState(t);let{props:e,oldProps:i,changeFlags:n}=t,r=this.getAttributeManager(),{iconAtlas:s,iconMapping:a,data:l,getIcon:c,textureParameters:u}=e,{iconManager:f}=this.state;if(typeof s=="string")return;let d=s||this.internalState.isAsyncPropLoading("iconAtlas");f.setProps({loadOptions:e.loadOptions,autoPacking:!d,iconAtlas:s,iconMapping:d?a:null,textureParameters:u}),d?i.iconMapping!==e.iconMapping&&r.invalidate("getIcon"):(n.dataChanged||n.updateTriggersChanged&&(n.updateTriggersChanged.all||n.updateTriggersChanged.getIcon))&&f.packIcons(l,c),n.extensionsChanged&&(this.state.model?.destroy(),this.state.model=this._getModel(),r.invalidateAll())}get isLoaded(){return super.isLoaded&&this.state.iconManager.isLoaded}finalizeState(t){super.finalizeState(t),this.state.iconManager.finalize()}draw({uniforms:t}){let{sizeScale:e,sizeMinPixels:i,sizeMaxPixels:n,sizeUnits:r,billboard:s,alphaCutoff:a}=this.props,{iconManager:l}=this.state,c=l.getTexture();if(c){let u=this.state.model,f={iconsTexture:c,iconsTextureDim:[c.width,c.height],sizeUnits:z.UNIT[r],sizeScale:e,sizeMinPixels:i,sizeMaxPixels:n,billboard:s,alphaCutoff:a};u.shaderInputs.setProps({icon:f}),u.draw(this.context.renderPass)}}_getModel(){let t=[-1,-1,1,-1,-1,1,1,1];return new ie.Model(this.context.device,{...this.getShaders(),id:this.props.id,bufferLayout:this.getAttributeManager().getBufferLayouts(),geometry:new ie.Geometry({topology:"triangle-strip",attributes:{positions:{size:2,value:new Float32Array(t)}}}),isInstanced:!0})}_onUpdate(){this.setNeedsRedraw()}_onError(t){let e=this.getCurrentLayer()?.props.onIconError;e?e(t):z.log.error(t.error.message)()}getInstanceOffset(t){let{width:e,height:i,anchorX:n=e/2,anchorY:r=i/2}=this.state.iconManager.getIconMapping(t);return[e/2-n,i/2-r]}getInstanceColorMode(t){return this.state.iconManager.getIconMapping(t).mask?1:0}getInstanceIconFrame(t){let{x:e,y:i,width:n,height:r}=this.state.iconManager.getIconMapping(t);return[e,i,n,r]}};_t.defaultProps=Pr;_t.layerName="IconLayer";var it=_t;var W=P(L(),1),ne=P(I(),1);var _r=`struct LineUniforms { widthScale: f32, widthMinPixels: f32, widthMaxPixels: f32, useShortestPath: f32, widthUnits: i32, }; @group(0) @binding(1) var<uniform> line: LineUniforms; `,Eo=`uniform lineUniforms { float widthScale; float widthMinPixels; float widthMaxPixels; float useShortestPath; highp int widthUnits; } line; `,Ro={name:"line",source:_r,vs:Eo,fs:Eo,uniformTypes:{widthScale:"f32",widthMinPixels:"f32",widthMaxPixels:"f32",useShortestPath:"f32",widthUnits:"i32"}};var zo=`// TODO(ibgreen): Hack for Layer uniforms (move to new "color" module?) struct LayerUniforms { opacity: f32, }; var<private> layer: LayerUniforms = LayerUniforms(1.0); // @group(0) @binding(1) var<uniform> layer: LayerUniforms; // ---------- Helper Structures & Functions ---------- // Placeholder filter functions. fn deckgl_filter_size(offset: vec3<f32>, geometry: Geometry) -> vec3<f32> { return offset; } fn deckgl_filter_gl_position(p: vec4<f32>, geometry: Geometry) -> vec4<f32> { return p; } fn deckgl_filter_color(color: vec4<f32>, geometry: Geometry) -> vec4<f32> { return color; } // Compute an extrusion offset given a line direction (in clipspace), // an offset direction (-1 or 1), and a width in pixels. // Assumes a uniform "project" with a viewportSize field is available. fn getExtrusionOffset(line_clipspace: vec2<f32>, offset_direction: f32, width: f32) -> vec2<f32> { // project.viewportSize should be provided as a uniform (not shown here) let dir_screenspace = normalize(line_clipspace * project.viewportSize); // Rotate by 90\xB0: (x,y) becomes (-y,x) let rotated = vec2<f32>(-dir_screenspace.y, dir_screenspace.x); return rotated * offset_direction * width / 2.0; } // Splits the line between two points at a given x coordinate. // Interpolates the y and z components. fn splitLine(a: vec3<f32>, b: vec3<f32>, x: f32) -> vec3<f32> { let t: f32 = (x - a.x) / (b.x - a.x); return vec3<f32>(x, a.yz + t * (b.yz - a.yz)); } // ---------- Uniforms & Global Structures ---------- // Uniforms for line, layer, and project are assumed to be defined elsewhere. // For example: // // @group(0) @binding(0) // var<uniform> line: LineUniform; // // struct LayerUniform { // opacity: f32, // }; // @group(0) @binding(1) // var<uniform> layer: LayerUniform; // // struct ProjectUniform { // viewportSize: vec2<f32>, // }; // @group(0) @binding(2) // var<uniform> project: ProjectUniform; // ---------- Vertex Output Structure ---------- struct Varyings { @builtin(position) gl_Position: vec4<f32>, @location(0) vColor: vec4<f32>, @location(1) uv: vec2<f32>, }; // ---------- Vertex Shader Entry Point ---------- @vertex fn vertexMain( @location(0) positions: vec3<f32>, @location(1) instanceSourcePositions: vec3<f32>, @location(2) instanceTargetPositions: vec3<f32>, @location(3) instanceSourcePositions64Low: vec3<f32>, @location(4) instanceTargetPositions64Low: vec3<f32>, @location(5) instanceColors: vec4<f32>, @location(6) instancePickingColors: vec3<f32>, @location(7) instanceWidths: f32 ) -> Varyings { var geometry: Geometry; geometry.worldPosition = instanceSourcePositions; geometry.worldPositionAlt = instanceTargetPositions; var source_world: vec3<f32> = instanceSourcePositions; var target_world: vec3<f32> = instanceTargetPositions; var source_world_64low: vec3<f32> = instanceSourcePositions64Low; var target_world_64low: vec3<f32> = instanceTargetPositions64Low; // Apply shortest-path adjustments if needed. if (line.useShortestPath > 0.5 || line.useShortestPath < -0.5) { source_world.x = (source_world.x + 180.0 % 360.0) - 180.0; target_world.x = (target_world.x + 180.0 % 360.0) - 180.0; let deltaLng: f32 = target_world.x - source_world.x; if (deltaLng * line.useShortestPath > 180.0) { source_world.x = source_world.x + 360.0 * line.useShortestPath; source_world = splitLine(source_world, target_world, 180.0 * line.useShortestPath); source_world_64low = vec3<f32>(0.0, 0.0, 0.0); } else if (deltaLng * line.useShortestPath < -180.0) { target_world.x = target_world.x + 360.0 * line.useShortestPath; target_world = splitLine(source_world, target_world, 180.0 * line.useShortestPath); target_world_64low = vec3<f32>(0.0, 0.0, 0.0); } else if (line.useShortestPath < 0.0) { var abortOut: Varyings; abortOut.gl_Position = vec4<f32>(0.0); abortOut.vColor = vec4<f32>(0.0); abortOut.uv = vec2<f32>(0.0); return abortOut; } } // Project Pos and target positions to clip space. let sourceResult = project_position_to_clipspace_and_commonspace(source_world, source_world_64low, vec3<f32>(0.0)); let targetResult = project_position_to_clipspace_and_commonspace(target_world, target_world_64low, vec3<f32>(0.0)); let sourcePos: vec4<f32> = sourceResult.clipPosition; let targetPos: vec4<f32> = targetResult.clipPosition; let source_commonspace: vec4<f32> = sourceResult.commonPosition; let target_commonspace: vec4<f32> = targetResult.commonPosition; // Interpolate along the line segment. let segmentIndex: f32 = positions.x; let p: vec4<f32> = sourcePos + segmentIndex * (targetPos - sourcePos); geometry.position = source_commonspace + segmentIndex * (target_commonspace - source_commonspace); let uv: vec2<f32> = positions.xy; geometry.uv = uv; geometry.pickingColor = instancePickingColors; // Determine width in pixels. let widthPixels: f32 = clamp( project_unit_size_to_pixel(instanceWidths * line.widthScale, line.widthUnits), line.widthMinPixels, line.widthMaxPixels ); // Compute extrusion offset. let extrusion: vec2<f32> = getExtrusionOffset(targetPos.xy - sourcePos.xy, positions.y, widthPixels); let offset: vec3<f32> = vec3<f32>(extrusion, 0.0); // Apply deck.gl filter functions. let filteredOffset = deckgl_filter_size(offset, geometry); let filteredP = deckgl_filter_gl_position(p, geometry); let clipOffset: vec2<f32> = project_pixel_size_to_clipspace(filteredOffset.xy); let finalPosition: vec4<f32> = filteredP + vec4<f32>(clipOffset, 0.0, 0.0); // Compute color. var vColor: vec4<f32> = vec4<f32>(instanceColors.rgb, instanceColors.a * layer.opacity); // vColor = deckgl_filter_color(vColor, geometry); var output: Varyings; output.gl_Position = finalPosition; output.vColor = vColor; output.uv = uv; return output; } @fragment fn fragmentMain( @location(0) vColor: vec4<f32>, @location(1) uv: vec2<f32> ) -> @location(0) vec4<f32> { // Create and initialize geometry with the provided uv. var geometry: Geometry; geometry.uv = uv; // Start with the input color. var fragColor: vec4<f32> = vColor; // Apply the deck.gl filter to the color. fragColor = deckgl_filter_color(fragColor, geometry); return fragColor; } `;var Oo=`#version 300 es #define SHADER_NAME line-layer-vertex-shader in vec3 positions; in vec3 instanceSourcePositions; in vec3 instanceTargetPositions; in vec3 instanceSourcePositions64Low; in vec3 instanceTargetPositions64Low; in vec4 instanceColors; in vec3 instancePickingColors; in float instanceWidths; out vec4 vColor; out vec2 uv; vec2 getExtrusionOffset(vec2 line_clipspace, float offset_direction, float width) { vec2 dir_screenspace = normalize(line_clipspace * project.viewportSize); dir_screenspace = vec2(-dir_screenspace.y, dir_screenspace.x); return dir_screenspace * offset_direction * width / 2.0; } vec3 splitLine(vec3 a, vec3 b, float x) { float t = (x - a.x) / (b.x - a.x); return vec3(x, mix(a.yz, b.yz, t)); } void main(void) { geometry.worldPosition = instanceSourcePositions; geometry.worldPositionAlt = instanceTargetPositions; vec3 source_world = instanceSourcePositions; vec3 target_world = instanceTargetPositions; vec3 source_world_64low = instanceSourcePositions64Low; vec3 target_world_64low = instanceTargetPositions64Low; if (line.useShortestPath > 0.5 || line.useShortestPath < -0.5) { source_world.x = mod(source_world.x + 180., 360.0) - 180.; target_world.x = mod(target_world.x + 180., 360.0) - 180.; float deltaLng = target_world.x - source_world.x; if (deltaLng * line.useShortestPath > 180.) { source_world.x += 360. * line.useShortestPath; source_world = splitLine(source_world, target_world, 180. * line.useShortestPath); source_world_64low = vec3(0.0); } else if (deltaLng * line.useShortestPath < -180.) { target_world.x += 360. * line.useShortestPath; target_world = splitLine(source_world, target_world, 180. * line.useShortestPath); target_world_64low = vec3(0.0); } else if (line.useShortestPath < 0.) { gl_Position = vec4(0.); return; } } vec4 source_commonspace; vec4 target_commonspace; vec4 source = project_position_to_clipspace(source_world, source_world_64low, vec3(0.), source_commonspace); vec4 target = project_position_to_clipspace(target_world, target_world_64low, vec3(0.), target_commonspace); float segmentIndex = positions.x; vec4 p = mix(source, target, segmentIndex); geometry.position = mix(source_commonspace, target_commonspace, segmentIndex); uv = positions.xy; geometry.uv = uv; geometry.pickingColor = instancePickingColors; float widthPixels = clamp( project_size_to_pixel(instanceWidths * line.widthScale, line.widthUnits), line.widthMinPixels, line.widthMaxPixels ); vec3 offset = vec3( getExtrusionOffset(target.xy - source.xy, positions.y, widthPixels), 0.0); DECKGL_FILTER_SIZE(offset, geometry); DECKGL_FILTER_GL_POSITION(p, geometry); gl_Position = p + vec4(project_pixel_size_to_clipspace(offset.xy), 0.0, 0.0); vColor = vec4(instanceColors.rgb, instanceColors.a * layer.opacity); DECKGL_FILTER_COLOR(vColor, geometry); } `;var Fo=`#version 300 es #define SHADER_NAME line-layer-fragment-shader precision highp float; in vec4 vColor; in vec2 uv; out vec4 fragColor; void main(void) { geometry.uv = uv; fragColor = vColor; DECKGL_FILTER_COLOR(fragColor, geometry); } `;var Cr=[0,0,0,255],Lr={getSourcePosition:{type:"accessor",value:o=>o.sourcePosition},getTargetPosition:{type:"accessor",value:o=>o.targetPosition},getColor:{type:"accessor",value:Cr},getWidth:{type:"accessor",value:1},widthUnits:"pixels",widthScale:{type:"number",value:1,min:0},widthMinPixels:{type:"number",value:0,min:0},widthMaxPixels:{type:"number",value:Number.MAX_SAFE_INTEGER,min:0}},Ct=class extends W.Layer{getBounds(){return this.getAttributeManager()?.getBounds(["instanceSourcePositions","instanceTargetPositions"])}getShaders(){return super.getShaders({vs:Oo,fs:Fo,source:zo,modules:[W.project32,W.picking,Ro]})}get wrapLongitude(){return!1}initializeState(){this.getAttributeManager().addInstanced({instanceSourcePositions:{size:3,type:"float64",fp64:this.use64bitPositions(),transition:!0,accessor:"getSourcePosition"},instanceTargetPositions:{size:3,type:"float64",fp64:this.use64bitPositions(),transition:!0,accessor:"getTargetPosition"},instanceColors:{size:this.props.colorFormat.length,type:"unorm8",transition:!0,accessor:"getColor",defaultValue:[0,0,0,255]},instanceWidths:{size:1,transition:!0,accessor:"getWidth",defaultValue:1}})}updateState(t){super.updateState(t),t.changeFlags.extensionsChanged&&(this.state.model?.destroy(),this.state.model=this._getModel(),this.getAttributeManager().invalidateAll())}draw({uniforms:t}){let{widthUnits:e,widthScale:i,widthMinPixels:n,widthMaxPixels:r,wrapLongitude:s}=this.props,a=this.state.model,l={widthUnits:W.UNIT[e],widthScale:i,widthMinPixels:n,widthMaxPixels:r,useShortestPath:s?1:0};a.shaderInputs.setProps({line:l}),a.draw(this.context.renderPass),s&&(a.shaderInputs.setProps({line:{...l,useShortestPath:-1}}),a.draw(this.context.renderPass))}_getModel(){let t=[0,-1,0,0,1,0,1,-1,0,1,1,0];return new ne.Model(this.context.device,{...this.getShaders(),id:this.props.id,bufferLayout:this.getAttributeManager().getBufferLayouts(),geometry:new ne.Geometry({topology:"triangle-strip",attributes:{positions:{size:3,value:new Float32Array(t)}}}),isIns