Update dependency maplibre-gl-lanes to v1.7.0
This commit is contained in:
1 parent
4c704045c5
commit
3f775357c6
3 files changed
+231
-49
No files matched your search
Generated
+4
-4
@@ -10,7 +10,7 @@
|
||||
"flag-icons": "7.6.0",
|
||||
"maplibre-contour": "0.1.1",
|
||||
"maplibre-gl": "6.18.0",
|
||||
"maplibre-gl-lanes": "1.6.0",
|
||||
"maplibre-gl-lanes": "1.7.0",
|
||||
"pmtiles": "4.5.0",
|
||||
"suncalc": "2.1.4"
|
||||
}
|
||||
@@ -218,9 +218,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/maplibre-gl-lanes": {
|
||||
"version": "1.6.0",
|
||||
"resolved": "https://registry.npmjs.org/maplibre-gl-lanes/-/maplibre-gl-lanes-1.6.0.tgz",
|
||||
"integrity": "sha512-cnHkrQW9LYD9j0HtVoptOMq2LG/HjEC3pWqLpwhElIzViF3ho+BP8E+YH3wS0Af/J34Wum2mlrRFFWAvw88H1g==",
|
||||
"version": "1.7.0",
|
||||
"resolved": "https://registry.npmjs.org/maplibre-gl-lanes/-/maplibre-gl-lanes-1.7.0.tgz",
|
||||
"integrity": "sha512-inQQtbA67gtPuC5naeeMGmqbS0K1FzKxvo2aXhTKD80NbVr8qckltqTqXArLxZVT4WRV54HXjhwfDGFydYDKJA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@
|
||||
"flag-icons": "7.6.0",
|
||||
"maplibre-contour": "0.1.1",
|
||||
"maplibre-gl": "6.18.0",
|
||||
"maplibre-gl-lanes": "1.6.0",
|
||||
"maplibre-gl-lanes": "1.7.0",
|
||||
"pmtiles": "4.5.0",
|
||||
"suncalc": "2.1.4"
|
||||
}
|
||||
|
||||
+226
-44
@@ -13,7 +13,7 @@ function mercatorToLngLat(x, y) {
|
||||
return [lng, lat];
|
||||
}
|
||||
function buildLineGraph(features, opts = {}) {
|
||||
let routeProp = opts.routeProperty ?? "route", colorProp = opts.colorProperty ?? "color", nameProp = opts.nameProperty ?? "name", snap = opts.snapDegrees ?? 1e-7, onewayProp = opts.onewayProperty, uniform = onewayProp && !(opts.uniformProperties ?? []).includes(onewayProp) ? [...opts.uniformProperties ?? [], onewayProp] : opts.uniformProperties ?? [], routes = /* @__PURE__ */ new Map(), vertexPos = /* @__PURE__ */ new Map(), elem = /* @__PURE__ */ new Map(), adjacency = /* @__PURE__ */ new Map(), keyOf = (lng, lat) => {
|
||||
let routeProp = opts.routeProperty ?? "route", colorProp = opts.colorProperty ?? "color", nameProp = opts.nameProperty ?? "name", snap = opts.snapDegrees ?? 1e-7, onewayProp = opts.onewayProperty, uniform = onewayProp && !(opts.uniformProperties ?? []).includes(onewayProp) ? [...opts.uniformProperties ?? [], onewayProp] : opts.uniformProperties ?? [], routes = /* @__PURE__ */ new Map(), vertexPos = /* @__PURE__ */ new Map(), elem = /* @__PURE__ */ new Map(), adjacency = /* @__PURE__ */ new Map(), keyOf2 = (lng, lat) => {
|
||||
let kx = Math.round(lng / snap), ky = Math.round(lat / snap);
|
||||
return `${kx},${ky}`;
|
||||
};
|
||||
@@ -38,7 +38,7 @@ function buildLineGraph(features, opts = {}) {
|
||||
for (let line of lines) {
|
||||
let prevKey = null;
|
||||
for (let c of line) {
|
||||
let k = keyOf(c[0], c[1]);
|
||||
let k = keyOf2(c[0], c[1]);
|
||||
if (vertexPos.has(k) || vertexPos.set(k, lngLatToMercator(c[0], c[1])), prevKey !== null && prevKey !== k) {
|
||||
let forward = prevKey < k, ek = forward ? `${prevKey}|${k}` : `${k}|${prevKey}`, e = elem.get(ek);
|
||||
if (!e) {
|
||||
@@ -1385,7 +1385,7 @@ function getWorker(kind) {
|
||||
if (failed[kind] || typeof Worker > "u") return null;
|
||||
let worker;
|
||||
try {
|
||||
blobUrl || (blobUrl = URL.createObjectURL(new Blob(['"use strict";(()=>{var _n=Object.defineProperty;var Vn=(e,n,t)=>n in e?_n(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t;var D=(e,n,t)=>Vn(e,typeof n!="symbol"?n+"":n,t);function Ie(e){let n=e.edges.map(o=>({...o,direction:new Map(o.direction??[]),order:o.order.slice()})),t=e.routes?new Map(e.routes.map(o=>[o.id,o])):new Map(e.routeIds.map(o=>[o,{id:o,color:"#000"}]));return{nodes:e.nodes,edges:n,routes:t,chains:new Map(e.chains)}}function Ce(e){let n=e.length,t=new Uint32Array(n+1),o=0;for(let l=0;l<n;l++)o+=e[l].coords.length,t[l+1]=o;let i={coords:new Float64Array(o),anchors:new Float64Array(o),offsets:t,routeIds:[],route:new Uint32Array(n),looks:[],look:new Uint32Array(n),kind:new Uint8Array(n),travel:new Int8Array(n),startDistance:new Float64Array(n),edge:new Int32Array(n),node:new Int32Array(n),betweenU:new Int32Array(n),betweenV:new Int32Array(n)},r=new Map,u=new Map;for(let l=0;l<n;l++){let s=e[l],a=t[l];for(let g=0;g<s.coords.length;g++)i.coords[a+g]=s.coords[g],i.anchors[a+g]=s.anchors[g];let c=r.get(s.route);c===void 0&&(c=i.routeIds.push(s.route)-1,r.set(s.route,c));let d=u.get(s.look);d===void 0&&(d=i.looks.push(s.look)-1,u.set(s.look,d)),i.route[l]=c,i.look[l]=d,i.kind[l]=s.kind==="lane"?0:1,i.travel[l]=s.travel,i.startDistance[l]=s.startDistance,i.edge[l]=s.edge,i.node[l]=s.node??-1,i.betweenU[l]=s.between?s.between[0]:-1,i.betweenV[l]=s.between?s.between[1]:-1}return i}function De(e){return[e.coords.buffer,e.anchors.buffer,e.offsets.buffer,e.route.buffer,e.look.buffer,e.kind.buffer,e.travel.buffer,e.startDistance.buffer,e.edge.buffer,e.node.buffer,e.betweenU.buffer,e.betweenV.buffer]}function H(e){let n=0;for(let t=2;t<e.length;t+=2)n+=Math.hypot(e[t]-e[t-2],e[t+1]-e[t-1]);return n}function W(e){let n=new Array(e.length);for(let t=0,o=e.length-2;t<e.length;t+=2,o-=2)n[t]=e[o],n[t+1]=e[o+1];return n}function ne(e){for(let n=2;n<e.length;n+=2){let t=e[n]-e[0],o=e[n+1]-e[1],i=Math.hypot(t,o);if(i>0)return[t/i,o/i]}return[0,0]}function te(e){let n=e.length;for(let t=n-4;t>=0;t-=2){let o=e[n-2]-e[t],i=e[n-1]-e[t+1],r=Math.hypot(o,i);if(r>0)return[o/r,i/r]}return[0,0]}function Oe(e,n){let t=Xe(e,n),o=t[0]-e[0],i=t[1]-e[1],r=Math.hypot(o,i);return r>0?[o/r,i/r]:ne(e)}function me(e,n){let t=e.length,o=Xe(W(e),n),i=e[t-2]-o[0],r=e[t-1]-o[1],u=Math.hypot(i,r);return u>0?[i/u,r/u]:te(e)}function Xe(e,n){let t=0;for(let o=2;o<e.length;o+=2){let i=Math.hypot(e[o]-e[o-2],e[o+1]-e[o-1]);if(t+i>=n){let r=i>0?(n-t)/i:0;return[e[o-2]+(e[o]-e[o-2])*r,e[o-1]+(e[o+1]-e[o-1])*r]}t+=i}return[e[e.length-2],e[e.length-1]]}function ue(e,n,t,o=.2){let i=e.length/2,r=new Float64Array(Math.max(0,i-1)),u=0;for(let g=0;g<i-1;g++)r[g]=Math.hypot(e[g*2+2]-e[g*2],e[g*2+3]-e[g*2+1]),u+=r[g];if(u<=0)return e.slice();let l=u*(1-o);if(n+t>l){let g=l/(n+t);n*=g,t*=g}let s=ze(e,r,n),a=ze(e,r,u-t),c=[s.x,s.y],d=0;for(let g=0;g<i-1;g++)d+=r[g],d>n&&d<u-t&&c.push(e[g*2+2],e[g*2+3]);return c.push(a.x,a.y),c}function ze(e,n,t){if(t<=0)return{x:e[0],y:e[1]};let o=0;for(let i=0;i<n.length;i++){let r=n[i];if(o+r>=t){let u=r>0?(t-o)/r:0;return{x:e[i*2]+(e[i*2+2]-e[i*2])*u,y:e[i*2+1]+(e[i*2+3]-e[i*2+1])*u}}o+=r}return{x:e[e.length-2],y:e[e.length-1]}}function pe(e,n){let t=e.length/2;if(t<=2||n<=0)return e.slice();let o=new Uint8Array(t);o[0]=1,o[t-1]=1;let i=n*n,r=[0,t-1];for(;r.length;){let l=r.pop(),s=r.pop(),a=0,c=-1,d=e[s*2],g=e[s*2+1],p=e[l*2],h=e[l*2+1];for(let f=s+1;f<l;f++){let b=Ye(e[f*2],e[f*2+1],d,g,p,h);b>a&&(a=b,c=f)}a>i&&c>0&&(o[c]=1,r.push(s,c,c,l))}let u=[];for(let l=0;l<t;l++)o[l]&&u.push(e[l*2],e[l*2+1]);return u}function Ze(e){let n=e.length/2,t=new Float64Array(n);if(n===0||(t[0]=1/0,t[n-1]=1/0,n<=2))return t;let o=[0,n-1],i=[1/0];for(;o.length;){let r=o.pop(),u=o.pop(),l=i.pop(),s=0,a=-1,c=e[u*2],d=e[u*2+1],g=e[r*2],p=e[r*2+1];for(let h=u+1;h<r;h++){let f=Ye(e[h*2],e[h*2+1],c,d,g,p);f>s&&(s=f,a=h)}if(s>0&&a>0){let h=s<l?s:l;t[a]=h,o.push(u,a,a,r),i.push(h,h)}}return t}function Je(e,n,t){let o=e.length/2;if(o<=2||t<=0)return e.slice();let i=t*t,r=[];for(let u=0;u<o;u++)n[u]>i&&r.push(e[u*2],e[u*2+1]);return r}function Ye(e,n,t,o,i,r){let u=i-t,l=r-o,s=u*u+l*l;if(s>0){let a=Math.max(0,Math.min(1,((e-t)*u+(n-o)*l)/s));u=t+u*a,l=o+l*a}else u=t,l=o;return(e-u)*(e-u)+(n-l)*(n-l)}function He(e,n=1e-9){let t=[];for(let o=0;o<e.length;o+=2){let i=t.length;i>=2&&Math.abs(t[i-2]-e[o])<n&&Math.abs(t[i-1]-e[o+1])<n||t.push(e[o],e[o+1])}return t}var Ke=12,Bn=8;function qe(e,n,t=Math.PI/9){return K(e,n,t).points}function K(e,n,t=Math.PI/9){let o=He(e),i=o.length/2;if(i<2||n===0)return{points:o.slice(),anchors:o.slice()};let r=new Float64Array((i-1)*4);for(let a=0;a<i-1;a++){let c=o[a*2],d=o[a*2+1],g=o[a*2+2],p=o[a*2+3],h=g-c,f=p-d,b=Math.hypot(h,f),m=f/b,k=-h/b;r[a*4]=c+m*n,r[a*4+1]=d+k*n,r[a*4+2]=g+m*n,r[a*4+3]=p+k*n}let u=[r[0],r[1]],l=[o[0],o[1]];for(let a=1;a<i-1;a++){let c=(a-1)*4,d=a*4,g=r[c],p=r[c+1],h=r[c+2],f=r[c+3],b=r[d],m=r[d+1],k=r[d+2],y=r[d+3],MLine truncated
|
||||
blobUrl || (blobUrl = URL.createObjectURL(new Blob(['"use strict";(()=>{var jn=Object.defineProperty;var $n=(e,n,t)=>n in e?jn(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t;var D=(e,n,t)=>$n(e,typeof n!="symbol"?n+"":n,t);function Fe(e){let n=e.edges.map(o=>({...o,direction:new Map(o.direction??[]),order:o.order.slice()})),t=e.routes?new Map(e.routes.map(o=>[o.id,o])):new Map(e.routeIds.map(o=>[o,{id:o,color:"#000"}]));return{nodes:e.nodes,edges:n,routes:t,chains:new Map(e.chains)}}function Re(e){let n=e.length,t=new Uint32Array(n+1),o=0;for(let l=0;l<n;l++)o+=e[l].coords.length,t[l+1]=o;let i={coords:new Float64Array(o),anchors:new Float64Array(o),offsets:t,routeIds:[],route:new Uint32Array(n),looks:[],look:new Uint32Array(n),kind:new Uint8Array(n),travel:new Int8Array(n),startDistance:new Float64Array(n),edge:new Int32Array(n),node:new Int32Array(n),betweenU:new Int32Array(n),betweenV:new Int32Array(n)},s=new Map,u=new Map;for(let l=0;l<n;l++){let r=e[l],a=t[l];for(let g=0;g<r.coords.length;g++)i.coords[a+g]=r.coords[g],i.anchors[a+g]=r.anchors[g];let c=s.get(r.route);c===void 0&&(c=i.routeIds.push(r.route)-1,s.set(r.route,c));let f=u.get(r.look);f===void 0&&(f=i.looks.push(r.look)-1,u.set(r.look,f)),i.route[l]=c,i.look[l]=f,i.kind[l]=r.kind==="lane"?0:1,i.travel[l]=r.travel,i.startDistance[l]=r.startDistance,i.edge[l]=r.edge,i.node[l]=r.node??-1,i.betweenU[l]=r.between?r.between[0]:-1,i.betweenV[l]=r.between?r.between[1]:-1}return i}function We(e){return[e.coords.buffer,e.anchors.buffer,e.offsets.buffer,e.route.buffer,e.look.buffer,e.kind.buffer,e.travel.buffer,e.startDistance.buffer,e.edge.buffer,e.node.buffer,e.betweenU.buffer,e.betweenV.buffer]}function H(e){let n=0;for(let t=2;t<e.length;t+=2)n+=Math.hypot(e[t]-e[t-2],e[t+1]-e[t-1]);return n}function Y(e){let n=new Array(e.length);for(let t=0,o=e.length-2;t<e.length;t+=2,o-=2)n[t]=e[o],n[t+1]=e[o+1];return n}function te(e){for(let n=2;n<e.length;n+=2){let t=e[n]-e[0],o=e[n+1]-e[1],i=Math.hypot(t,o);if(i>0)return[t/i,o/i]}return[0,0]}function oe(e){let n=e.length;for(let t=n-4;t>=0;t-=2){let o=e[n-2]-e[t],i=e[n-1]-e[t+1],s=Math.hypot(o,i);if(s>0)return[o/s,i/s]}return[0,0]}function Te(e,n){let t=Ke(e,n),o=t[0]-e[0],i=t[1]-e[1],s=Math.hypot(o,i);return s>0?[o/s,i/s]:te(e)}function Me(e,n){let t=e.length,o=Ke(Y(e),n),i=e[t-2]-o[0],s=e[t-1]-o[1],u=Math.hypot(i,s);return u>0?[i/u,s/u]:oe(e)}function Ke(e,n){let t=0;for(let o=2;o<e.length;o+=2){let i=Math.hypot(e[o]-e[o-2],e[o+1]-e[o-1]);if(t+i>=n){let s=i>0?(n-t)/i:0;return[e[o-2]+(e[o]-e[o-2])*s,e[o-1]+(e[o+1]-e[o-1])*s]}t+=i}return[e[e.length-2],e[e.length-1]]}function de(e,n,t,o=.2){let i=e.length/2,s=new Float64Array(Math.max(0,i-1)),u=0;for(let g=0;g<i-1;g++)s[g]=Math.hypot(e[g*2+2]-e[g*2],e[g*2+3]-e[g*2+1]),u+=s[g];if(u<=0)return e.slice();let l=u*(1-o);if(n+t>l){let g=l/(n+t);n*=g,t*=g}let r=Ze(e,s,n),a=Ze(e,s,u-t),c=[r.x,r.y],f=0;for(let g=0;g<i-1;g++)f+=s[g],f>n&&f<u-t&&c.push(e[g*2+2],e[g*2+3]);return c.push(a.x,a.y),c}function Ze(e,n,t){if(t<=0)return{x:e[0],y:e[1]};let o=0;for(let i=0;i<n.length;i++){let s=n[i];if(o+s>=t){let u=s>0?(t-o)/s:0;return{x:e[i*2]+(e[i*2+2]-e[i*2])*u,y:e[i*2+1]+(e[i*2+3]-e[i*2+1])*u}}o+=s}return{x:e[e.length-2],y:e[e.length-1]}}function we(e,n){let t=e.length/2;if(t<=2||n<=0)return e.slice();let o=new Uint8Array(t);o[0]=1,o[t-1]=1;let i=n*n,s=[0,t-1];for(;s.length;){let l=s.pop(),r=s.pop(),a=0,c=-1,f=e[r*2],g=e[r*2+1],m=e[l*2],h=e[l*2+1];for(let d=r+1;d<l;d++){let b=en(e[d*2],e[d*2+1],f,g,m,h);b>a&&(a=b,c=d)}a>i&&c>0&&(o[c]=1,s.push(r,c,c,l))}let u=[];for(let l=0;l<t;l++)o[l]&&u.push(e[l*2],e[l*2+1]);return u}function qe(e){let n=e.length/2,t=new Float64Array(n);if(n===0||(t[0]=1/0,t[n-1]=1/0,n<=2))return t;let o=[0,n-1],i=[1/0];for(;o.length;){let s=o.pop(),u=o.pop(),l=i.pop(),r=0,a=-1,c=e[u*2],f=e[u*2+1],g=e[s*2],m=e[s*2+1];for(let h=u+1;h<s;h++){let d=en(e[h*2],e[h*2+1],c,f,g,m);d>r&&(r=d,a=h)}if(r>0&&a>0){let h=r<l?r:l;t[a]=h,o.push(u,a,a,s),i.push(h,h)}}return t}function Qe(e,n,t){let o=e.length/2;if(o<=2||t<=0)return e.slice();let i=t*t,s=[];for(let u=0;u<o;u++)n[u]>i&&s.push(e[u*2],e[u*2+1]);return s}function en(e,n,t,o,i,s){let u=i-t,l=s-o,r=u*u+l*l;if(r>0){let a=Math.max(0,Math.min(1,((e-t)*u+(n-o)*l)/r));u=t+u*a,l=o+l*a}else u=t,l=o;return(e-u)*(e-u)+(n-l)*(n-l)}function nn(e,n=1e-9){let t=[];for(let o=0;o<e.length;o+=2){let i=t.length;i>=2&&Math.abs(t[i-2]-e[o])<n&&Math.abs(t[i-1]-e[o+1])<n||t.push(e[o],e[o+1])}return t}var tn=12,Xn=8;function on(e,n,t=Math.PI/9){return Q(e,n,t).points}function Q(e,n,t=Math.PI/9){let o=nn(e),i=o.length/2;if(i<2||n===0)return{points:o.slice(),anchors:o.slice()};let s=new Float64Array((i-1)*4);for(let a=0;a<i-1;a++){let c=o[a*2],f=o[a*2+1],g=o[a*2+2],m=o[a*2+3],h=g-c,d=m-f,b=Math.hypot(h,d),p=d/b,k=-h/b;s[a*4]=c+p*n,s[a*4+1]=f+k*n,s[a*4+2]=g+p*n,s[a*4+3]=m+k*n}let u=[s[0],s[1]],l=[o[0],o[1]];for(let a=1;a<i-1;a++){let c=(a-1)*4,f=a*4,g=s[c],m=s[c+1],h=s[c+2],d=s[c+3],b=s[f],p=s[f+1],k=s[f+2],y=s[f+3],MLine truncated
|
||||
} catch {
|
||||
return failed[kind] = !0, null;
|
||||
}
|
||||
@@ -2901,6 +2901,82 @@ function tessellatePath(b, px, anchorsPx, color, startDistance, opts, before = n
|
||||
}
|
||||
}
|
||||
|
||||
// src/render/fade.ts
|
||||
var REACH_PX = 24, CROSS_PX = 1, PHASE_WEIGHT = 2e-3, SEG = 9;
|
||||
function around(grid, gx, gy) {
|
||||
let out = [];
|
||||
for (let dx = -1; dx <= 1; dx++) for (let dy = -1; dy <= 1; dy++) {
|
||||
let c = grid.get(keyOf(gx + dx, gy + dy));
|
||||
if (c) for (let k of c) out.push(k);
|
||||
}
|
||||
out.sort((a, b) => a - b);
|
||||
let n = 0;
|
||||
for (let i = 0; i < out.length; i++) (!i || out[i] !== out[i - 1]) && (out[n++] = out[i]);
|
||||
return Int32Array.from(out.slice(0, n));
|
||||
}
|
||||
function keyOf(cx, cy) {
|
||||
return (cx + 4194304) * 8388608 + (cy + 4194304);
|
||||
}
|
||||
function alongFromSource(mesh, src, zoom, origin, unitsPerMercator) {
|
||||
let dashed = /* @__PURE__ */ new Set();
|
||||
for (let gi = 0; gi < mesh.groups.length; gi++) mesh.groupLooks[gi].dash && dashed.add(mesh.groupRoutes[gi]);
|
||||
if (!dashed.size) return null;
|
||||
let upp = unitsPerMercator / (512 * Math.pow(2, zoom)), cell = REACH_PX * upp, segs = /* @__PURE__ */ new Map(), nears = /* @__PURE__ */ new Map(), grids = /* @__PURE__ */ new Map();
|
||||
for (let p of src.paths) {
|
||||
if (!p.look.dash || !dashed.has(p.route)) continue;
|
||||
let list = segs.get(p.route);
|
||||
list || (segs.set(p.route, list = []), grids.set(p.route, /* @__PURE__ */ new Map()));
|
||||
let grid = grids.get(p.route), px = p.coords, an = p.anchors, along = 0, lx = NaN, ly = NaN, lcx = 0, lcy = 0, ls = 0, sd = p.startDistance;
|
||||
for (let i = 0; i < px.length; i += 2) {
|
||||
if (i > 0 && Math.abs(px[i] - lx) < 1e-6 && Math.abs(px[i + 1] - ly) < 1e-6) continue;
|
||||
i > 0 && (along += Math.hypot(px[i] - lx, px[i + 1] - ly));
|
||||
let s = sd < 0 ? -sd - along : sd + along, cx = (an[i] / src.scale - origin[0]) * unitsPerMercator + (px[i] - an[i]) * upp, cy = (an[i + 1] / src.scale - origin[1]) * unitsPerMercator + (px[i + 1] - an[i + 1]) * upp;
|
||||
if (i > 0) {
|
||||
let k = list.length / SEG, ex = cx - lcx, ey = cy - lcy, l2 = ex * ex + ey * ey, l = Math.sqrt(l2);
|
||||
list.push(lcx, lcy, ex, ey, l2 > 0 ? 1 / l2 : 0, ls, s - ls, l > 0 ? ex / l : 0, l > 0 ? ey / l : 0);
|
||||
let steps = Math.ceil(Math.sqrt((cx - lcx) * (cx - lcx) + (cy - lcy) * (cy - lcy)) / (cell / 2)), lastKey = NaN;
|
||||
for (let j = 0; j <= steps; j++) {
|
||||
let f = steps ? j / steps : 0, key = keyOf(Math.floor((lcx + (cx - lcx) * f) / cell), Math.floor((lcy + (cy - lcy) * f) / cell));
|
||||
if (key === lastKey) continue;
|
||||
lastKey = key;
|
||||
let c = grid.get(key);
|
||||
c || grid.set(key, c = []), c[c.length - 1] !== k && c.push(k);
|
||||
}
|
||||
}
|
||||
lx = px[i], ly = px[i + 1], lcx = cx, lcy = cy, ls = s;
|
||||
}
|
||||
}
|
||||
let out = new Float32Array(mesh.vertexCount * 2), seen = new Uint8Array(mesh.vertexCount), v = mesh.vertices, idx = mesh.indices, reach = REACH_PX * upp, reach2 = reach * reach, cross = CROSS_PX * upp, phase = PHASE_WEIGHT * upp, toSource = Math.pow(2, src.zoom - zoom);
|
||||
for (let gi = 0; gi < mesh.groups.length; gi++) {
|
||||
if (!mesh.groupLooks[gi].dash) continue;
|
||||
let route = mesh.groupRoutes[gi], list = segs.get(route), grid = grids.get(route);
|
||||
if (!list || !grid) continue;
|
||||
let near = nears.get(route);
|
||||
near || nears.set(route, near = /* @__PURE__ */ new Map());
|
||||
let [first, count] = mesh.groups[gi];
|
||||
for (let k = first; k < first + count; k++) {
|
||||
let vi = idx[k];
|
||||
if (seen[vi]) continue;
|
||||
seen[vi] = 1;
|
||||
let o = vi * FLOATS_PER_VERTEX, x = v[o] + v[o + 2] * upp, y = v[o + 1] + v[o + 3] * upp, nl = Math.sqrt(v[o + 6] * v[o + 6] + v[o + 7] * v[o + 7]), nx = nl > 0 ? v[o + 6] / nl : 0, ny = nl > 0 ? v[o + 7] / nl : 0, expect = v[o + 8] * toSource, gx = Math.floor(x / cell), gy = Math.floor(y / cell), key = keyOf(gx, gy), c = near.get(key);
|
||||
c || near.set(key, c = around(grid, gx, gy));
|
||||
let best = 1 / 0, bestS = 0;
|
||||
for (let j = 0; j < c.length; j++) {
|
||||
let b = c[j] * SEG, ax = list[b], ay = list[b + 1], ex = list[b + 2], ey = list[b + 3], il2 = list[b + 4], t = ((x - ax) * ex + (y - ay) * ey) * il2;
|
||||
t = t < 0 ? 0 : t > 1 ? 1 : t;
|
||||
let qx = x - ax - ex * t, qy = y - ay - ey * t, q2 = qx * qx + qy * qy;
|
||||
if (q2 > reach2) continue;
|
||||
let d = Math.sqrt(q2);
|
||||
nl > 0 && (d += cross * Math.abs(list[b + 7] * nx + list[b + 8] * ny));
|
||||
let s = list[b + 5] + list[b + 6] * t;
|
||||
d += phase * Math.abs(s - expect), d < best && (best = d, bestS = s);
|
||||
}
|
||||
best < 1 / 0 && (out[vi * 2] = bestS, out[vi * 2 + 1] = 1);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// src/render/layer.ts
|
||||
var VERTEX_SHADER_BODY = `
|
||||
in vec2 a_anchor;
|
||||
@@ -2908,15 +2984,18 @@ in vec2 a_delta;
|
||||
in vec2 a_extrude;
|
||||
in vec2 a_normal;
|
||||
in float a_along;
|
||||
in vec2 a_along_old;
|
||||
in vec4 a_color;
|
||||
uniform float u_units_per_px;
|
||||
uniform float u_outset;
|
||||
out vec2 v_normal;
|
||||
out vec4 v_color;
|
||||
out float v_along;
|
||||
out vec2 v_along_old;
|
||||
out float v_depth;
|
||||
void main() {
|
||||
v_along = a_along;
|
||||
v_along_old = a_along_old;
|
||||
float thickness = projectLineThickness(a_anchor.y);
|
||||
vec2 p = a_anchor + (a_delta + a_extrude * u_outset) * (u_units_per_px * thickness);
|
||||
gl_Position = projectTile(p);
|
||||
@@ -2927,6 +3006,7 @@ void main() {
|
||||
in vec2 v_normal;
|
||||
in vec4 v_color;
|
||||
in float v_along;
|
||||
in vec2 v_along_old;
|
||||
in float v_depth;
|
||||
uniform float u_outset;
|
||||
uniform float u_blur;
|
||||
@@ -2936,7 +3016,34 @@ uniform vec2 u_dash;
|
||||
uniform float u_cap;
|
||||
uniform float u_along_scale;
|
||||
uniform float u_cover;
|
||||
uniform vec2 u_dash_old;
|
||||
uniform float u_along_scale_old;
|
||||
uniform float u_fade;
|
||||
out vec4 fragColor;
|
||||
// The coverage of one dash pattern, from the edge coverage across the lane.
|
||||
float dashed(float base, float along, vec2 dash, float scale, float dist) {
|
||||
if (dash.x > 0.0) {
|
||||
float period = dash.x + dash.y;
|
||||
float t = mod(along, period);
|
||||
if (u_cap < 0.5) {
|
||||
float edge = min(t, dash.x - t) * scale;
|
||||
return base * clamp(edge / u_blur + 0.5, 0.0, 1.0);
|
||||
}
|
||||
float r = u_outset - 0.5 * u_blur;
|
||||
float best = 1e9;
|
||||
for (int k = -1; k <= 1; k++) {
|
||||
float tk = t - float(k) * period;
|
||||
float c = clamp(tk, 0.0, dash.x);
|
||||
best = min(best, length(vec2((tk - c) * scale, dist)) - r);
|
||||
}
|
||||
return base * clamp(-best / u_blur + 0.5, 0.0, 1.0);
|
||||
}
|
||||
float period = dash.y;
|
||||
float t = mod(along, period) - period * 0.5;
|
||||
float r = u_outset - 0.5 * u_blur;
|
||||
float d = length(vec2(t * scale, dist));
|
||||
return clamp((r - d) / u_blur + 0.5, 0.0, 1.0);
|
||||
}
|
||||
void main() {
|
||||
#ifdef GLOBE
|
||||
if (v_depth > 1.0) discard;
|
||||
@@ -2944,29 +3051,11 @@ void main() {
|
||||
float dist = length(v_normal) * u_outset;
|
||||
float alpha = clamp((u_outset - dist) / u_blur, 0.0, 1.0);
|
||||
if (u_dash.y > 0.0) {
|
||||
if (u_dash.x > 0.0) {
|
||||
float period = u_dash.x + u_dash.y;
|
||||
float t = mod(v_along, period);
|
||||
if (u_cap < 0.5) {
|
||||
float edge = min(t, u_dash.x - t) * u_along_scale;
|
||||
alpha *= clamp(edge / u_blur + 0.5, 0.0, 1.0);
|
||||
} else {
|
||||
float r = u_outset - 0.5 * u_blur;
|
||||
float best = 1e9;
|
||||
for (int k = -1; k <= 1; k++) {
|
||||
float tk = t - float(k) * period;
|
||||
float c = clamp(tk, 0.0, u_dash.x);
|
||||
best = min(best, length(vec2((tk - c) * u_along_scale, dist)) - r);
|
||||
}
|
||||
alpha *= clamp(-best / u_blur + 0.5, 0.0, 1.0);
|
||||
}
|
||||
} else {
|
||||
float period = u_dash.y;
|
||||
float t = mod(v_along, period) - period * 0.5;
|
||||
float r = u_outset - 0.5 * u_blur;
|
||||
float d = length(vec2(t * u_along_scale, dist));
|
||||
alpha = clamp((r - d) / u_blur + 0.5, 0.0, 1.0);
|
||||
}
|
||||
float now = dashed(alpha, v_along, u_dash, u_along_scale, dist);
|
||||
// Mid-fade, the last build's pattern dissolves into this one's, as MapLibre fades a
|
||||
// dash array between zooms. A vertex with no match in the last build has no weight.
|
||||
float w = u_fade < 1.0 ? clamp(v_along_old.y, 0.0, 1.0) * (1.0 - u_fade) : 0.0;
|
||||
alpha = w > 0.0 ? mix(now, dashed(alpha, v_along_old.x, u_dash_old, u_along_scale_old, dist), w) : now;
|
||||
}
|
||||
if (u_cover > 0.5) {
|
||||
if (u_cover < 1.5) {
|
||||
@@ -3005,12 +3094,24 @@ var LaneLayer = class {
|
||||
__publicField(this, "vbo", null);
|
||||
__publicField(this, "cbo", null);
|
||||
__publicField(this, "ibo", null);
|
||||
/** The last build's distance along per vertex, while a dash fade is under way. */
|
||||
__publicField(this, "obo", null);
|
||||
__publicField(this, "mesh", null);
|
||||
/** Materialized from `packed` on demand. */
|
||||
__publicField(this, "layout", null);
|
||||
/** A worker's answer, kept as typed arrays until something asks for paths. */
|
||||
__publicField(this, "packed", null);
|
||||
/** `request` is the worker request that built it, null for a build on this thread. */
|
||||
__publicField(this, "built", null);
|
||||
__publicField(this, "restBuild");
|
||||
__publicField(this, "restDelay");
|
||||
__publicField(this, "restTimer", null);
|
||||
/** The zoom has held still at another zoom than the build's: build for it. */
|
||||
__publicField(this, "restPending", !1);
|
||||
__publicField(this, "onZoomEvent", () => this.zoomMoved());
|
||||
__publicField(this, "onMoveEnd", () => this.zoomSettled());
|
||||
__publicField(this, "dashFade");
|
||||
__publicField(this, "fade", null);
|
||||
__publicField(this, "inFlight", null);
|
||||
__publicField(this, "session", nextSession++);
|
||||
__publicField(this, "sentGraph", !1);
|
||||
@@ -3053,13 +3154,16 @@ var LaneLayer = class {
|
||||
__publicField(this, "highlightStyle", null);
|
||||
/** Each group's bright split, kept until the mesh or the highlight changes. */
|
||||
__publicField(this, "brightSplit", null);
|
||||
__publicField(this, "timings", { layoutMs: 0, meshMs: 0, renderThreadMs: 0 });
|
||||
__publicField(this, "timings", { layoutMs: 0, meshMs: 0, renderThreadMs: 0, fadeMs: 0, fadeReadMs: 0 });
|
||||
/** What starting the newest mesh's fade cost this thread, and what reading the phase cost, ms. */
|
||||
__publicField(this, "fadeMs", 0);
|
||||
__publicField(this, "fadeReadMs", 0);
|
||||
/** The depth MapLibre gave this layer for the frame being drawn. */
|
||||
__publicField(this, "depthBase", 1 - DEPTH_GAP);
|
||||
/** The layer's index in the style when `depthBase` was read, or -1. */
|
||||
__publicField(this, "depthPlace", -1);
|
||||
if (this.id = opts.id, this.graph = opts.graph, !opts.graph || !Array.isArray(opts.graph.edges)) throw new TypeError("maplibre-gl-lanes: `graph` must be a line graph from `buildLineGraph`");
|
||||
requireSizesFunction(opts.sizes), this.sizes = opts.sizes, this.opacity = Math.max(0, Math.min(1, opts.opacity ?? 1)), this.zoomEpsilon = opts.zoomEpsilon ?? 0.25, this.smooth = opts.smooth ?? !0, this.openFolds = opts.openFolds ?? !0, this.laneStyle = opts.laneStyle ?? null, this.cull = opts.cull ?? !0, this.cullMargin = opts.cullMargin ?? 0.5, this.useWorker = opts.worker ?? !0, this.onBuild = opts.onBuild ?? null;
|
||||
requireSizesFunction(opts.sizes), this.sizes = opts.sizes, this.opacity = Math.max(0, Math.min(1, opts.opacity ?? 1)), this.zoomEpsilon = opts.zoomEpsilon ?? 0.25, this.smooth = opts.smooth ?? !0, this.openFolds = opts.openFolds ?? !0, this.laneStyle = opts.laneStyle ?? null, this.cull = opts.cull ?? !0, this.cullMargin = opts.cullMargin ?? 0.5, this.useWorker = opts.worker ?? !0, this.onBuild = opts.onBuild ?? null, this.restBuild = opts.restBuild ?? !1, this.restDelay = Math.max(0, opts.restDelay ?? 60), this.dashFade = Math.max(0, opts.dashFade ?? 0);
|
||||
let casingCss = opts.casingColor === void 0 ? "#333333" : opts.casingColor;
|
||||
this.casing = casingCss === null ? null : rgba(parseColor(casingCss)), this.computeOrigin();
|
||||
}
|
||||
@@ -3104,6 +3208,23 @@ var LaneLayer = class {
|
||||
getHighlight() {
|
||||
return [...this.highlight];
|
||||
}
|
||||
/** Change the dash fade, ms; 0 snaps. A fade under way keeps its own length. */
|
||||
setDashFade(ms) {
|
||||
this.dashFade = Math.max(0, ms);
|
||||
}
|
||||
/**
|
||||
* Whether a rest build is still to come: `restBuild` is on and the last build is for another
|
||||
* zoom than the map's. It lands, with `onBuild`, once the zoom holds still.
|
||||
*/
|
||||
restBuildPending() {
|
||||
return this.restBuild && !!this.map && !!this.built && Math.abs(this.built.zoom - this.map.getZoom()) > 1e-9;
|
||||
}
|
||||
zoomMoved() {
|
||||
this.restPending = !1, this.restTimer !== null && clearTimeout(this.restTimer), this.restTimer = setTimeout(() => this.zoomSettled(), this.restDelay);
|
||||
}
|
||||
zoomSettled() {
|
||||
this.restTimer !== null && clearTimeout(this.restTimer), this.restTimer = null, this.restBuildPending() && (this.restPending = !0, this.map.triggerRepaint());
|
||||
}
|
||||
/**
|
||||
* What the last build covers, without its geometry. Cheap enough to call
|
||||
* every frame, unlike `getLayout`.
|
||||
@@ -3306,9 +3427,10 @@ var LaneLayer = class {
|
||||
} };
|
||||
offscreens.set(gl, made), gl.canvas.addEventListener?.("webglcontextlost", made.onLost);
|
||||
}
|
||||
map.getTerrain() && console.warn("maplibre-gl-lanes: 3D terrain is enabled; lanes are drawn at sea level and will be hidden under raised terrain."), this.vbo = gl.createBuffer(), this.cbo = gl.createBuffer(), this.ibo = gl.createBuffer(), this.dirty = !0;
|
||||
map.getTerrain() && console.warn("maplibre-gl-lanes: 3D terrain is enabled; lanes are drawn at sea level and will be hidden under raised terrain."), this.vbo = gl.createBuffer(), this.cbo = gl.createBuffer(), this.ibo = gl.createBuffer(), this.obo = gl.createBuffer(), this.dirty = !0, this.restBuild && map.on && (map.on("zoom", this.onZoomEvent), map.on("moveend", this.onMoveEnd));
|
||||
}
|
||||
onRemove(_map, anyGl) {
|
||||
onRemove(map, anyGl) {
|
||||
map.off?.("zoom", this.onZoomEvent), map.off?.("moveend", this.onMoveEnd), this.restTimer !== null && clearTimeout(this.restTimer), this.restTimer = null, this.restPending = !1, this.fade = null;
|
||||
let gl = this.gl;
|
||||
if (!gl) {
|
||||
this.map = null;
|
||||
@@ -3317,8 +3439,8 @@ var LaneLayer = class {
|
||||
for (let p of this.programs.values())
|
||||
p && (gl.deleteProgram(p.program), gl.deleteVertexArray(p.vao));
|
||||
this.programs.clear();
|
||||
for (let b of [this.vbo, this.cbo, this.ibo]) b && gl.deleteBuffer(b);
|
||||
this.vbo = this.cbo = this.ibo = null;
|
||||
for (let b of [this.vbo, this.cbo, this.ibo, this.obo]) b && gl.deleteBuffer(b);
|
||||
this.vbo = this.cbo = this.ibo = this.obo = null;
|
||||
let share = offscreens.get(gl);
|
||||
share && --share.users <= 0 && (share.target && releaseOffscreen(gl, share.target), share.composite && (gl.deleteProgram(share.composite.program), gl.deleteVertexArray(share.composite.vao)), gl.canvas.removeEventListener?.("webglcontextlost", share.onLost), offscreens.delete(gl)), this.layoutCache.clear(), this.meshCache.clear(), this.closeSession(), this.mesh = null, this.map = null, this.gl = null;
|
||||
}
|
||||
@@ -3358,6 +3480,9 @@ ${FRAGMENT_SHADER_BODY}`, vs = compile(gl, gl.VERTEX_SHADER, vsSource), fs = com
|
||||
"u_cap",
|
||||
"u_along_scale",
|
||||
"u_cover",
|
||||
"u_dash_old",
|
||||
"u_along_scale_old",
|
||||
"u_fade",
|
||||
"u_projection_matrix",
|
||||
"u_projection_tile_mercator_coords",
|
||||
"u_projection_clipping_plane",
|
||||
@@ -3373,7 +3498,9 @@ ${FRAGMENT_SHADER_BODY}`, vs = compile(gl, gl.VERTEX_SHADER, vsSource), fs = com
|
||||
loc < 0 || (gl.enableVertexAttribArray(loc), gl.vertexAttribPointer(loc, size, gl.FLOAT, !1, stride, offset));
|
||||
}
|
||||
let aCol = gl.getAttribLocation(program, "a_color");
|
||||
return gl.bindBuffer(gl.ARRAY_BUFFER, this.cbo), gl.enableVertexAttribArray(aCol), gl.vertexAttribPointer(aCol, 4, gl.UNSIGNED_BYTE, !0, 4, 0), gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.ibo), gl.bindVertexArray(null), { program, vao, uniforms };
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, this.cbo), gl.enableVertexAttribArray(aCol), gl.vertexAttribPointer(aCol, 4, gl.UNSIGNED_BYTE, !0, 4, 0);
|
||||
let alongOld = gl.getAttribLocation(program, "a_along_old");
|
||||
return alongOld >= 0 && (gl.bindBuffer(gl.ARRAY_BUFFER, this.obo), gl.vertexAttribPointer(alongOld, 2, gl.FLOAT, !1, 8, 0)), gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.ibo), gl.bindVertexArray(null), { program, vao, uniforms, alongOld };
|
||||
}
|
||||
viewBounds() {
|
||||
if (!this.cull || !this.map) return null;
|
||||
@@ -3400,8 +3527,11 @@ ${FRAGMENT_SHADER_BODY}`, vs = compile(gl, gl.VERTEX_SHADER, vsSource), fs = com
|
||||
this.dirty = !1;
|
||||
return;
|
||||
}
|
||||
let t0 = performance.now(), layout = layoutAtZoom(this.graph, zoom, this.sizes, { bounds, smooth: this.smooth, openFolds: this.openFolds, laneStyle: this.laneStyle ?? void 0, cache: this.layoutCache }), t1 = performance.now(), mesh = tessellate(layout.paths, { scale: layout.scale, origin: this.origin, unitsPerMercator: this.unitsPerMercator, drawOrder: layout.drawOrder, width: checkedSizes(this.sizes, zoom).width, cache: this.meshCache }), t2 = performance.now();
|
||||
this.upload(mesh), this.layout = layout, this.packed = null, this.built = { zoom, bounds }, this.dirty = !1, this.timings = { layoutMs: t1 - t0, meshMs: t2 - t1, renderThreadMs: performance.now() - t0 }, this.finished();
|
||||
let from = this.fadeSource(zoom, !0), t0 = performance.now(), layout = layoutAtZoom(this.graph, zoom, this.sizes, { bounds, smooth: this.smooth, openFolds: this.openFolds, laneStyle: this.laneStyle ?? void 0, cache: this.layoutCache }), t1 = performance.now(), width = checkedSizes(this.sizes, zoom).width, mesh = tessellate(layout.paths, { scale: layout.scale, origin: this.origin, unitsPerMercator: this.unitsPerMercator, drawOrder: layout.drawOrder, width, cache: this.meshCache }), t2 = performance.now();
|
||||
this.upload(mesh), this.fadeReadMs = 0, this.startFade(from, zoom, (f) => {
|
||||
let t = performance.now(), along = f.paths ? alongFromSource(mesh, { paths: f.paths, zoom: f.zoom, scale: f.scale }, zoom, this.origin, this.unitsPerMercator) : null;
|
||||
return this.fadeReadMs = performance.now() - t, along;
|
||||
}), this.layout = layout, this.packed = null, this.built = { zoom, bounds, width, request: null }, this.dirty = !1, this.timings = { layoutMs: t1 - t0, meshMs: t2 - t1, renderThreadMs: performance.now() - t0, fadeMs: this.fadeMs, fadeReadMs: this.fadeReadMs }, this.finished();
|
||||
}
|
||||
layoutRequest(zoom, bounds, extent, routes) {
|
||||
let req = {
|
||||
@@ -3421,7 +3551,13 @@ ${FRAGMENT_SHADER_BODY}`, vs = compile(gl, gl.VERTEX_SHADER, vsSource), fs = com
|
||||
req.graph && (this.sentGraph = !1), req.looks !== void 0 && (this.looksDirty = !0);
|
||||
}
|
||||
sendLayout(zoom, bounds) {
|
||||
let req = this.layoutRequest(zoom, bounds, "built"), sent = sendToWorker(req);
|
||||
let req = this.layoutRequest(zoom, bounds, "built");
|
||||
if (this.dashFade) {
|
||||
req.keepPhase = !0;
|
||||
let from = this.fadeCandidates(zoom);
|
||||
from.length && (req.fadeFrom = from);
|
||||
}
|
||||
let sent = sendToWorker(req);
|
||||
return sent ? (this.inFlight = { id: req.id }, sent.then((res) => this.onLayout(res)), !0) : (this.unsent(req), this.useWorker = !1, !1);
|
||||
}
|
||||
onLayout(res) {
|
||||
@@ -3443,8 +3579,11 @@ ${FRAGMENT_SHADER_BODY}`, vs = compile(gl, gl.VERTEX_SHADER, vsSource), fs = com
|
||||
return;
|
||||
}
|
||||
if (!this.gl) return;
|
||||
let t0 = performance.now();
|
||||
this.upload(res), this.packed = res, this.layout = null, this.built = { zoom: res.zoom, bounds: res.bounds }, this.timings = { layoutMs: res.layoutMs, meshMs: res.meshMs, renderThreadMs: performance.now() - t0 }, this.finished(), this.map?.triggerRepaint();
|
||||
let from = this.fadeSource(res.zoom, !1), t0 = performance.now();
|
||||
this.upload(res), this.fadeReadMs = res.fadeMs ?? 0, this.startFade(from, res.zoom, (f) => {
|
||||
let i = f.request === null || !res.fadeFrom ? -1 : res.fadeFrom.indexOf(f.request);
|
||||
return i < 0 ? null : res.along[i];
|
||||
}), this.packed = res, this.layout = null, this.built = { zoom: res.zoom, bounds: res.bounds, width: checkedSizes(this.sizes, res.zoom).width, request: res.id }, this.timings = { layoutMs: res.layoutMs, meshMs: res.meshMs, renderThreadMs: performance.now() - t0, fadeMs: this.fadeMs, fadeReadMs: this.fadeReadMs }, this.finished(), this.map?.triggerRepaint();
|
||||
}
|
||||
/** The listener runs in a microtask, never inside the render call. */
|
||||
finished() {
|
||||
@@ -3467,6 +3606,47 @@ ${FRAGMENT_SHADER_BODY}`, vs = compile(gl, gl.VERTEX_SHADER, vsSource), fs = com
|
||||
closeSession() {
|
||||
this.fullPending.clear(), this.inFlight = null, this.sentGraph && (this.sentGraph = !1, sendToWorker({ kind: "dispose", id: nextRequestId(), session: this.session }));
|
||||
}
|
||||
/**
|
||||
* What a build for `zoom` would fade from, and since when. Mid-fade, a build at the same zoom
|
||||
* (a pan) or one landing in the first half carries the fade on, from where it stands; one in
|
||||
* the second half fades afresh from the mesh on screen. Either way the pattern jumps by at most
|
||||
* half a fade. Null for no fade: none asked, nothing drawn yet, the same zoom, or a new graph,
|
||||
* whose mesh has its own tile. `withPaths` is for a build on this thread, which reads the phase
|
||||
* itself; a worker reads it from the build it kept.
|
||||
*/
|
||||
fadeSource(zoom, withPaths) {
|
||||
if (!this.dashFade || !this.built || !this.builtWith || this.builtWith.graph !== this.graph) return null;
|
||||
let f = this.fade;
|
||||
if (f && (this.built.zoom === zoom || (performance.now() - f.start) / f.duration < 0.5)) return f;
|
||||
if (this.built.zoom === zoom) return null;
|
||||
let layout = withPaths ? this.getLayout() : null;
|
||||
return withPaths && !layout ? null : { from: {
|
||||
zoom: this.built.zoom,
|
||||
width: this.built.width,
|
||||
request: this.built.request,
|
||||
scale: layout ? layout.scale : 512 * Math.pow(2, this.built.zoom),
|
||||
paths: layout ? layout.paths : null
|
||||
}, start: NaN, duration: this.dashFade };
|
||||
}
|
||||
/**
|
||||
* The builds a worker build for `zoom` may fade from, as `fadeSource` will choose when it
|
||||
* lands: the source of a fade under way, and the build on screen. Both are read when both may
|
||||
* be chosen, because which one depends on when the build lands.
|
||||
*/
|
||||
fadeCandidates(zoom) {
|
||||
let out = [];
|
||||
if (!this.built || !this.builtWith || this.builtWith.graph !== this.graph) return out;
|
||||
let f = this.fade;
|
||||
return f && f.from.request !== null && out.push(f.from.request), this.built.zoom !== zoom && this.built.request !== null && !out.includes(this.built.request) && out.push(this.built.request), out;
|
||||
}
|
||||
/** `read` gives the fade's source phase per vertex of the new mesh, uploaded already. */
|
||||
startFade(fade, zoom, read) {
|
||||
if (this.fade = null, this.fadeMs = 0, !fade || fade.from.zoom === zoom || !this.gl) return;
|
||||
let t0 = performance.now(), along = read(fade.from);
|
||||
if (!along) return;
|
||||
let gl = this.gl;
|
||||
gl.bindVertexArray(null), gl.bindBuffer(gl.ARRAY_BUFFER, this.obo), gl.bufferData(gl.ARRAY_BUFFER, along, gl.DYNAMIC_DRAW), this.fade = Number.isNaN(fade.start) ? { ...fade, start: performance.now() } : fade, this.fadeMs = performance.now() - t0;
|
||||
}
|
||||
upload(mesh) {
|
||||
let gl = this.gl;
|
||||
gl.bindVertexArray(null), gl.bindBuffer(gl.ARRAY_BUFFER, this.vbo), gl.bufferData(gl.ARRAY_BUFFER, mesh.vertices, gl.DYNAMIC_DRAW), gl.bindBuffer(gl.ARRAY_BUFFER, this.cbo), gl.bufferData(gl.ARRAY_BUFFER, mesh.colors, gl.DYNAMIC_DRAW), gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.ibo), gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, mesh.indices, gl.DYNAMIC_DRAW), this.mesh = mesh, this.builtWith = { graph: this.graph, tile: this.tile, unitsPerMercator: this.unitsPerMercator };
|
||||
@@ -3475,13 +3655,15 @@ ${FRAGMENT_SHADER_BODY}`, vs = compile(gl, gl.VERTEX_SHADER, vsSource), fs = com
|
||||
let gl = this.gl;
|
||||
if (!this.map || !this.vbo || !gl) return;
|
||||
let zoom = this.map.getZoom();
|
||||
(this.dirty || !this.built || !this.serves(this.built, zoom)) && this.rebuild(zoom);
|
||||
this.restPending && this.built && this.built.zoom === zoom && (this.restPending = !1), (this.dirty || !this.built || !this.serves(this.built, zoom) || this.restPending) && this.rebuild(zoom);
|
||||
let mesh = this.mesh, frame = this.builtWith;
|
||||
if (!mesh || !mesh.indexCount || !frame) return;
|
||||
let entry = this.programFor(gl, args.shaderData);
|
||||
if (!entry) return;
|
||||
let { program, vao, uniforms } = entry, tileID = { canonical: frame.tile, wrap: 0 }, pd = args.getProjectionData ? args.getProjectionData({ tileID, applyGlobeMatrix: !0 }) : this.map.transform.getProjectionData({ overscaledTileID: tileID, applyGlobeMatrix: !0 }), dpr = this.map.getPixelRatio(), style = checkedSizes(this.sizes, zoom), built = this.built ? this.built.zoom : zoom, dashStyle = built === zoom ? style : checkedSizes(this.sizes, built), alongScale = Math.pow(2, zoom - built), unitsPerPx = frame.unitsPerMercator / (512 * Math.pow(2, zoom));
|
||||
let { program, vao, uniforms, alongOld } = entry, tileID = { canonical: frame.tile, wrap: 0 }, pd = args.getProjectionData ? args.getProjectionData({ tileID, applyGlobeMatrix: !0 }) : this.map.transform.getProjectionData({ overscaledTileID: tileID, applyGlobeMatrix: !0 }), dpr = this.map.getPixelRatio(), style = checkedSizes(this.sizes, zoom), built = this.built ? this.built.zoom : zoom, dashStyle = built === zoom ? style : checkedSizes(this.sizes, built), alongScale = Math.pow(2, zoom - built), unitsPerPx = frame.unitsPerMercator / (512 * Math.pow(2, zoom));
|
||||
gl.useProgram(program), gl.bindVertexArray(vao), gl.uniformMatrix4fv(uniforms.u_projection_matrix, !1, pd.mainMatrix), gl.uniformMatrix4fv(uniforms.u_projection_fallback_matrix, !1, pd.fallbackMatrix), gl.uniform4f(uniforms.u_projection_tile_mercator_coords, ...pd.tileMercatorCoords), gl.uniform4f(uniforms.u_projection_clipping_plane, ...pd.clippingPlane), gl.uniform1f(uniforms.u_projection_transition, pd.projectionTransition), gl.uniform1f(uniforms.u_units_per_px, unitsPerPx), gl.uniform1f(uniforms.u_along_scale, alongScale), gl.uniform1f(uniforms.u_blur, 1 / dpr), gl.uniform1f(uniforms.u_opacity, this.opacity), gl.uniform1f(uniforms.u_cover, COVER_ALL);
|
||||
let fade = this.fade, fadeT = fade ? (performance.now() - fade.start) / fade.duration : 1;
|
||||
fade && !(fadeT < 1) && (fade = this.fade = null), alongOld >= 0 && (fade ? gl.enableVertexAttribArray(alongOld) : (gl.disableVertexAttribArray(alongOld), gl.vertexAttrib2f(alongOld, 0, 0))), gl.uniform1f(uniforms.u_fade, fade ? Math.max(0, fadeT) : 1), fade && gl.uniform1f(uniforms.u_along_scale_old, Math.pow(2, zoom - fade.from.zoom));
|
||||
let place = this.map.getLayersOrder ? this.map.getLayersOrder().indexOf(this.id) : -1;
|
||||
if (place < 0 || place !== this.depthPlace) {
|
||||
let range = gl.getParameter(gl.DEPTH_RANGE);
|
||||
@@ -3527,7 +3709,7 @@ ${FRAGMENT_SHADER_BODY}`, vs = compile(gl, gl.VERTEX_SHADER, vsSource), fs = com
|
||||
hl.halo && (gl.uniform1f(uniforms.u_blur, Math.max(1 / dpr, widthAt(hl.haloBlur, zoom))), gl.uniform1f(uniforms.u_outset, outlineEdge + widthAt(hl.haloWidth, zoom) + aa), gl.uniform4fv(uniforms.u_override, hl.halo), lift(), gl.uniform1f(uniforms.u_blur, 1 / dpr)), hl.outline && (gl.uniform1f(uniforms.u_outset, outlineEdge + aa), gl.uniform4fv(uniforms.u_override, hl.outline), lift());
|
||||
for (let run of liftedRuns) this.drawRoute(gl, uniforms, run, style, dashStyle, aa, once, marks, this.opacity);
|
||||
}
|
||||
offscreen && (gl.invalidateFramebuffer(gl.FRAMEBUFFER, [gl.DEPTH_ATTACHMENT]), gl.bindFramebuffer(gl.FRAMEBUFFER, mapFramebuffer), gl.useProgram(offscreen.composite.program), gl.bindVertexArray(offscreen.composite.vao), gl.activeTexture(gl.TEXTURE0), gl.bindTexture(gl.TEXTURE_2D, offscreen.target.color), gl.uniform1i(offscreen.composite.color, 0), gl.depthFunc(gl.LEQUAL), gl.depthMask(!1), this.depthAt(gl, 0), gl.drawArrays(gl.TRIANGLES, 0, 3)), gl.depthFunc(gl.LEQUAL), gl.depthMask(!1), gl.depthRange(this.depthBase, this.depthBase), gl.bindVertexArray(null);
|
||||
offscreen && (gl.invalidateFramebuffer(gl.FRAMEBUFFER, [gl.DEPTH_ATTACHMENT]), gl.bindFramebuffer(gl.FRAMEBUFFER, mapFramebuffer), gl.useProgram(offscreen.composite.program), gl.bindVertexArray(offscreen.composite.vao), gl.activeTexture(gl.TEXTURE0), gl.bindTexture(gl.TEXTURE_2D, offscreen.target.color), gl.uniform1i(offscreen.composite.color, 0), gl.depthFunc(gl.LEQUAL), gl.depthMask(!1), this.depthAt(gl, 0), gl.drawArrays(gl.TRIANGLES, 0, 3)), gl.depthFunc(gl.LEQUAL), gl.depthMask(!1), gl.depthRange(this.depthBase, this.depthBase), gl.bindVertexArray(null), fade && this.map.triggerRepaint();
|
||||
}
|
||||
/** Draw at an offset behind this layer's depth, in units of the gap (see `DEPTH_GAP`). */
|
||||
depthAt(gl, offset) {
|
||||
@@ -3564,7 +3746,7 @@ ${FRAGMENT_SHADER_BODY}`, vs = compile(gl, gl.VERTEX_SHADER, vsSource), fs = com
|
||||
* one on top stays the one on top.
|
||||
*/
|
||||
drawRoute(gl, uniforms, run, style, dashStyle, aa, once, marks, opacity, opacities = null) {
|
||||
let mesh = this.mesh, meta = (this.builtWith?.graph ?? this.graph).routes.get(mesh.groupRoutes[run[0]]), periodOf = (look) => look.dash ? [look.dash[0] * dashStyle.width, look.dash[1] * dashStyle.width] : [0, 0], split = opacities ? opacities.split : null, ribbon = (gi, pass) => {
|
||||
let mesh = this.mesh, meta = (this.builtWith?.graph ?? this.graph).routes.get(mesh.groupRoutes[run[0]]), periodOf = (look) => look.dash ? [look.dash[0] * dashStyle.width, look.dash[1] * dashStyle.width] : [0, 0], fade = this.fade, split = opacities ? opacities.split : null, ribbon = (gi, pass) => {
|
||||
let sp = split && split[gi];
|
||||
return sp ? pass === "bright" ? sp.bright : sp.dimmed : pass === "bright" ? [] : [mesh.groups[gi]];
|
||||
}, dotRanges = (gi, pass) => {
|
||||
@@ -3574,12 +3756,12 @@ ${FRAGMENT_SHADER_BODY}`, vs = compile(gl, gl.VERTEX_SHADER, vsSource), fs = com
|
||||
for (let [first, count] of ranges) count && gl.drawElements(gl.TRIANGLES, count, gl.UNSIGNED_INT, first * 4);
|
||||
}, draw = (gi, pass) => drawAll(ribbon(gi, pass)), drawDashes = (gi, look, pass) => {
|
||||
let dots = mesh.groupDots[gi];
|
||||
if (look.dash[0] === 0 && dots && dots[1]) {
|
||||
if (look.dash[0] === 0 && dots && dots[1] && !fade) {
|
||||
drawAll(dotRanges(gi, pass));
|
||||
return;
|
||||
}
|
||||
let period = periodOf(look);
|
||||
gl.uniform2f(uniforms.u_dash, period[0], period[1]), draw(gi, pass), gl.uniform2f(uniforms.u_dash, 0, 0);
|
||||
gl.uniform2f(uniforms.u_dash, period[0], period[1]), fade && gl.uniform2f(uniforms.u_dash_old, look.dash[0] * fade.from.width, look.dash[1] * fade.from.width), draw(gi, pass), gl.uniform2f(uniforms.u_dash, 0, 0);
|
||||
}, lit = !!split && run.some((gi) => split[gi]), passes = lit ? ["dimmed", "bright"] : ["all"], setOpacity = (pass) => {
|
||||
lit && gl.uniform1f(uniforms.u_opacity, pass === "bright" ? opacities.bright : opacities.dimmed);
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user