@math.gl/web-mercator 4.0.0-alpha.4 → 4.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import { lerp } from "./math-utils.js";
2
2
  import { scaleToZoom, zoomToScale, lngLatToWorld, worldToLngLat } from "./web-mercator-utils.js";
3
- import * as vec2 from 'gl-matrix/vec2';
3
+ import { vec2 } from '@math.gl/core';
4
4
  const EPSILON = 0.01;
5
5
  const VIEWPORT_TRANSITION_PROPS = ['longitude', 'latitude', 'zoom'];
6
6
  const DEFAULT_OPTS = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/fly-to-viewport.ts"],"names":["lerp","scaleToZoom","zoomToScale","lngLatToWorld","worldToLngLat","vec2","EPSILON","VIEWPORT_TRANSITION_PROPS","DEFAULT_OPTS","curve","speed","flyToViewport","startProps","endProps","t","options","startZoom","startCenterXY","uDelta","w0","u1","S","rho","rho2","r0","getFlyToTransitionParams","viewport","key","startValue","endValue","s","w","Math","cosh","u","tanh","sinh","scaleIncrement","newZoom","newCenterWorld","scale","add","newCenter","longitude","latitude","zoom","getFlyToDuration","opts","screenSpeed","maxDuration","length","duration","Number","isFinite","Object","assign","startCenter","startScale","endZoom","endCenter","endCenterXY","sub","max","width","height","w1","_u1","b0","b1","log","sqrt","r1"],"mappings":"SAAQA,I;SACAC,W,EAAaC,W,EAAaC,a,EAAeC,a;AACjD,OAAO,KAAKC,IAAZ,MAAsB,gBAAtB;AAIA,MAAMC,OAAO,GAAG,IAAhB;AACA,MAAMC,yBAAyB,GAAG,CAAC,WAAD,EAAc,UAAd,EAA0B,MAA1B,CAAlC;AACA,MAAMC,YAAY,GAAG;AACnBC,EAAAA,KAAK,EAAE,KADY;AAEnBC,EAAAA,KAAK,EAAE;AAFY,CAArB;AAkBA,OAAO,SAASC,aAAT,CACLC,UADK,EAELC,QAFK,EAGLC,CAHK,EAILC,OAJK,EASL;AAGA,QA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GA,EAAL,GAAU9C,EAAE,GAAGA,EAAf,GAAoBI,IAAI,GAAGA,IAAP,GAAc2C,GAAd,GAAoBA,GAAzC,KAAiD,IAAID,EAAJ,GAAS1C,IAAT,GAAgB2C,GAAjE,CAAX;AACA,QAAM1C,EAAE,GAAGQ,IAAI,CAACqC,GAAL,CAASrC,IAAI,CAACsC,IAAL,CAAUH,EAAE,GAAGA,EAAL,GAAU,CAApB,IAAyBA,EAAlC,CAAX;AACA,QAAMI,EAAE,GAAGvC,IAAI,CAACqC,GAAL,CAASrC,IAAI,CAACsC,IAAL,CAAUF,EAAE,GAAGA,EAAL,GAAU,CAApB,IAAyBA,EAAlC,CAAX;AACA,QAAM/C,CAAC,GAAG,CAACkD,EAAE,GAAG/C,EAAN,IAAYF,GAAtB;AAEA,SAAO;AAACN,IAAAA,SAAD;AAAYC,IAAAA,aAAZ;AAA2BC,IAAAA,MAA3B;AAAmCC,IAAAA,EAAnC;AAAuCC,IAAAA,EAAvC;AAA2CC,IAAAA,CAA3C;AAA8CC,IAAAA,GAA9C;AAAmDC,IAAAA,IAAnD;AAAyDC,IAAAA,EAAzD;AAA6D+C,IAAAA;AAA7D,GAAP;AACD","sourcesContent":["import {lerp} from './math-utils';\nimport {scaleToZoom, zoomToScale, lngLatToWorld, worldToLngLat} from './web-mercator-utils';\nimport * as vec2 from 'gl-matrix/vec2';\n\nimport type {ViewportProps} from './normalize-viewport-props';\n\nconst EPSILON = 0.01;\nconst VIEWPORT_TRANSITION_PROPS = ['longitude', 'latitude', 'zoom'] as const;\nconst DEFAULT_OPTS = {\n curve: 1.414,\n speed: 1.2\n // screenSpeed and maxDuration are used only if specified\n};\n\nexport type FlytoTransitionOptions = {\n curve?: number;\n speed?: number;\n screenSpeed?: number;\n maxDuration?: number;\n};\n\n/**\n * mapbox-gl-js flyTo : https://www.mapbox.com/mapbox-gl-js/api/#map#flyto.\n * It implements “Smooth and efficient zooming and panning.” algorithm by\n * \"Jarke J. van Wijk and Wim A.A. Nuij\"\n */\nexport function flyToViewport(\n startProps: ViewportProps,\n endProps: ViewportProps,\n t: number,\n options?: FlytoTransitionOptions\n): {\n longitude: number;\n latitude: number;\n zoom: number;\n} {\n // Equations from above paper are referred where needed.\n\n const {startZoom, startCenterXY, uDelta, w0, u1, S, rho, rho2, r0} = getFlyToTransitionParams(\n startProps,\n endProps,\n options\n );\n\n // If change in center is too small, do linear interpolaiton.\n if (u1 < EPSILON) {\n const viewport = {};\n for (const key of VIEWPORT_TRANSITION_PROPS) {\n const startValue = startProps[key];\n const endValue = endProps[key];\n // @ts-ignore-error properties are populated dynamically\n viewport[key] = lerp(startValue, endValue, t);\n }\n // @ts-expect-error properties are populated dynamically\n return viewport;\n }\n\n const s = t * S;\n\n const w = Math.cosh(r0) / Math.cosh(r0 + rho * s);\n const u = (w0 * ((Math.cosh(r0) * Math.tanh(r0 + rho * s) - Math.sinh(r0)) / rho2)) / u1;\n\n const scaleIncrement = 1 / w; // Using w method for scaling.\n const newZoom = startZoom + scaleToZoom(scaleIncrement);\n\n const newCenterWorld = vec2.scale([], uDelta, u);\n vec2.add(newCenterWorld, newCenterWorld, startCenterXY);\n\n const newCenter = worldToLngLat(newCenterWorld);\n return {\n longitude: newCenter[0],\n latitude: newCenter[1],\n zoom: newZoom\n };\n}\n\n// returns transition duration in milliseconds\nexport function getFlyToDuration(\n startProps: ViewportProps,\n endProps: ViewportProps,\n options?: FlytoTransitionOptions\n): number {\n const opts = {...DEFAULT_OPTS, ...options};\n const {screenSpeed, speed, maxDuration} = opts;\n const {S, rho} = getFlyToTransitionParams(startProps, endProps, opts);\n const length = 1000 * S;\n let duration: number;\n if (Number.isFinite(screenSpeed)) {\n duration = length / (screenSpeed / rho);\n } else {\n duration = length / speed;\n }\n\n return Number.isFinite(maxDuration) && duration > maxDuration ? 0 : duration;\n}\n\n// Private Methods\n\n// Calculate all parameters that are static for given startProps and endProps\nfunction getFlyToTransitionParams(\n startProps: ViewportProps,\n endProps: ViewportProps,\n opts: FlytoTransitionOptions\n): {\n startZoom: number;\n startCenterXY: number[];\n uDelta: number[];\n w0: number;\n u1: number;\n S: number;\n rho: number;\n rho2: number;\n r0: number;\n r1: number;\n} {\n opts = Object.assign({}, DEFAULT_OPTS, opts);\n const rho = opts.curve;\n const startZoom = startProps.zoom;\n const startCenter = [startProps.longitude, startProps.latitude];\n const startScale = zoomToScale(startZoom);\n const endZoom = endProps.zoom;\n const endCenter = [endProps.longitude, endProps.latitude];\n const scale = zoomToScale(endZoom - startZoom);\n\n const startCenterXY = lngLatToWorld(startCenter);\n const endCenterXY = lngLatToWorld(endCenter);\n const uDelta = vec2.sub([] as number[], endCenterXY, startCenterXY);\n\n const w0 = Math.max(startProps.width, startProps.height);\n const w1 = w0 / scale;\n const u1 = vec2.length(uDelta) * startScale;\n // u0 is treated as '0' in Eq (9).\n\n // If u1 is too small, will generate invalid number\n const _u1 = Math.max(u1, EPSILON);\n\n // Implement Equation (9) from above algorithm.\n const rho2 = rho * rho;\n const b0 = (w1 * w1 - w0 * w0 + rho2 * rho2 * _u1 * _u1) / (2 * w0 * rho2 * _u1);\n const b1 = (w1 * w1 - w0 * w0 - rho2 * rho2 * _u1 * _u1) / (2 * w1 * rho2 * _u1);\n const r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0);\n const r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);\n const S = (r1 - r0) / rho;\n\n return {startZoom, startCenterXY, uDelta, w0, u1, S, rho, rho2, r0, r1};\n}\n"],"file":"fly-to-viewport.js"}
1
+ {"version":3,"sources":["../src/fly-to-viewport.ts"],"names":["lerp","scaleToZoom","zoomToScale","lngLatToWorld","worldToLngLat","vec2","EPSILON","VIEWPORT_TRANSITION_PROPS","DEFAULT_OPTS","curve","speed","flyToViewport","startProps","endProps","t","options","startZoom","startCenterXY","uDelta","w0","u1","S","rho","rho2","r0","getFlyToTransitionParams","viewport","key","startValue","endValue","s","w","Math","cosh","u","tanh","sinh","scaleIncrement","newZoom","newCenterWorld","scale","add","newCenter","longitude","latitude","zoom","getFlyToDuration","opts","screenSpeed","maxDuration","length","duration","Number","isFinite","Object","assign","startCenter","startScale","endZoom","endCenter","endCenterXY","sub","max","width","height","w1","_u1","b0","b1","log","sqrt","r1"],"mappings":"SAAQA,I;SACAC,W,EAAaC,W,EAAaC,a,EAAeC,a;AACjD,SAAQC,IAAR,QAAmB,eAAnB;AAIA,MAAMC,OAAO,GAAG,IAAhB;AACA,MAAMC,yBAAyB,GAAG,CAAC,WAAD,EAAc,UAAd,EAA0B,MAA1B,CAAlC;AACA,MAAMC,YAAY,GAAG;AACnBC,EAAAA,KAAK,EAAE,KADY;AAEnBC,EAAAA,KAAK,EAAE;AAFY,CAArB;AAkBA,OAAO,SAASC,aAAT,CACLC,UADK,EAELC,QAFK,EAGLC,CAHK,EAILC,OAJK,EASL;AAGA,QAAM;AAACC,IAAAA,SAAD;AAAYC,IAAAA,aAAZ;AAA2BC,IAAAA,MAA3B;AAAmCC,IAAAA,EAAnC;AAAuCC,IAAAA,EAAvC;AAA2CC,IAAAA,CAA3C;AAA8CC,IAAAA,GAA9C;AAAmDC,IAAAA,IAAnD;AAAyDC,IAAAA;AAAzD,MAA+DC,wBAAwB,CAC3Fb,UAD2F,EAE3FC,QAF2F,EAG3FE,OAH2F,CAA7F;;AAOA,MAAIK,EAAE,GAAGd,OAAT,EAAkB;AAChB,UAAMoB,QAAQ,GAAG,EAAjB;;AACA,SAAK,MAAMC,GAAX,IAAkBpB,yBAAlB,EAA6C;AAC3C,YAAMqB,UAAU,GAAGhB,UAAU,CAACe,GAAD,CAA7B;AACA,YAAME,QAAQ,GAAGhB,QAAQ,CAACc,GAAD,CAAzB;AAEAD,MAAAA,QAAQ,CAACC,GAAD,CAAR,GAAgB3B,IAAI,CAAC4B,UAAD,EAAaC,QAAb,EAAuBf,CAAvB,CAApB;AACD;;AAED,WAAOY,QAAP;AACD;;AAED,QAAMI,CAAC,GAAGhB,CAAC,GAAGO,CAAd;AAEA,QAAMU,CAAC,GA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A;AAA7D,GAAP;AACD","sourcesContent":["import {lerp} from './math-utils';\nimport {scaleToZoom, zoomToScale, lngLatToWorld, worldToLngLat} from './web-mercator-utils';\nimport {vec2} from '@math.gl/core';\n\nimport type {ViewportProps} from './normalize-viewport-props';\n\nconst EPSILON = 0.01;\nconst VIEWPORT_TRANSITION_PROPS = ['longitude', 'latitude', 'zoom'] as const;\nconst DEFAULT_OPTS = {\n curve: 1.414,\n speed: 1.2\n // screenSpeed and maxDuration are used only if specified\n};\n\nexport type FlytoTransitionOptions = {\n curve?: number;\n speed?: number;\n screenSpeed?: number;\n maxDuration?: number;\n};\n\n/**\n * mapbox-gl-js flyTo : https://www.mapbox.com/mapbox-gl-js/api/#map#flyto.\n * It implements “Smooth and efficient zooming and panning.” algorithm by\n * \"Jarke J. van Wijk and Wim A.A. Nuij\"\n */\nexport function flyToViewport(\n startProps: ViewportProps,\n endProps: ViewportProps,\n t: number,\n options?: FlytoTransitionOptions\n): {\n longitude: number;\n latitude: number;\n zoom: number;\n} {\n // Equations from above paper are referred where needed.\n\n const {startZoom, startCenterXY, uDelta, w0, u1, S, rho, rho2, r0} = getFlyToTransitionParams(\n startProps,\n endProps,\n options\n );\n\n // If change in center is too small, do linear interpolaiton.\n if (u1 < EPSILON) {\n const viewport = {};\n for (const key of VIEWPORT_TRANSITION_PROPS) {\n const startValue = startProps[key];\n const endValue = endProps[key];\n // @ts-ignore-error properties are populated dynamically\n viewport[key] = lerp(startValue, endValue, t);\n }\n // @ts-expect-error properties are populated dynamically\n return viewport;\n }\n\n const s = t * S;\n\n const w = Math.cosh(r0) / Math.cosh(r0 + rho * s);\n const u = (w0 * ((Math.cosh(r0) * Math.tanh(r0 + rho * s) - Math.sinh(r0)) / rho2)) / u1;\n\n const scaleIncrement = 1 / w; // Using w method for scaling.\n const newZoom = startZoom + scaleToZoom(scaleIncrement);\n\n const newCenterWorld = vec2.scale([], uDelta, u);\n vec2.add(newCenterWorld, newCenterWorld, startCenterXY);\n\n const newCenter = worldToLngLat(newCenterWorld);\n return {\n longitude: newCenter[0],\n latitude: newCenter[1],\n zoom: newZoom\n };\n}\n\n// returns transition duration in milliseconds\nexport function getFlyToDuration(\n startProps: ViewportProps,\n endProps: ViewportProps,\n options?: FlytoTransitionOptions\n): number {\n const opts = {...DEFAULT_OPTS, ...options};\n const {screenSpeed, speed, maxDuration} = opts;\n const {S, rho} = getFlyToTransitionParams(startProps, endProps, opts);\n const length = 1000 * S;\n let duration: number;\n if (Number.isFinite(screenSpeed)) {\n duration = length / (screenSpeed / rho);\n } else {\n duration = length / speed;\n }\n\n return Number.isFinite(maxDuration) && duration > maxDuration ? 0 : duration;\n}\n\n// Private Methods\n\n// Calculate all parameters that are static for given startProps and endProps\nfunction getFlyToTransitionParams(\n startProps: ViewportProps,\n endProps: ViewportProps,\n opts: FlytoTransitionOptions\n): {\n startZoom: number;\n startCenterXY: number[];\n uDelta: number[];\n w0: number;\n u1: number;\n S: number;\n rho: number;\n rho2: number;\n r0: number;\n r1: number;\n} {\n opts = Object.assign({}, DEFAULT_OPTS, opts);\n const rho = opts.curve;\n const startZoom = startProps.zoom;\n const startCenter = [startProps.longitude, startProps.latitude];\n const startScale = zoomToScale(startZoom);\n const endZoom = endProps.zoom;\n const endCenter = [endProps.longitude, endProps.latitude];\n const scale = zoomToScale(endZoom - startZoom);\n\n const startCenterXY = lngLatToWorld(startCenter);\n const endCenterXY = lngLatToWorld(endCenter);\n const uDelta = vec2.sub([] as number[], endCenterXY, startCenterXY);\n\n const w0 = Math.max(startProps.width, startProps.height);\n const w1 = w0 / scale;\n const u1 = vec2.length(uDelta) * startScale;\n // u0 is treated as '0' in Eq (9).\n\n // If u1 is too small, will generate invalid number\n const _u1 = Math.max(u1, EPSILON);\n\n // Implement Equation (9) from above algorithm.\n const rho2 = rho * rho;\n const b0 = (w1 * w1 - w0 * w0 + rho2 * rho2 * _u1 * _u1) / (2 * w0 * rho2 * _u1);\n const b1 = (w1 * w1 - w0 * w0 - rho2 * rho2 * _u1 * _u1) / (2 * w1 * rho2 * _u1);\n const r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0);\n const r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);\n const S = (r1 - r0) / rho;\n\n return {startZoom, startCenterXY, uDelta, w0, u1, S, rho, rho2, r0, r1};\n}\n"],"file":"fly-to-viewport.js"}
@@ -1,4 +1,4 @@
1
- import { lerp as vec2_lerp } from 'gl-matrix/vec2';
1
+ import { vec2 } from '@math.gl/core';
2
2
  import { worldToLngLat } from "./web-mercator-utils.js";
3
3
  import { transformVector } from "./math-utils.js";
4
4
  const DEGREES_TO_RADIANS = Math.PI / 180;
@@ -37,7 +37,7 @@ function unprojectOnFarPlane(viewport, x, targetZ) {
37
37
  const coord1 = transformVector(pixelUnprojectionMatrix, [x, viewport.height, 1, 1]);
38
38
  const z = targetZ * viewport.distanceScales.unitsPerMeter[2];
39
39
  const t = (z - coord0[2]) / (coord1[2] - coord0[2]);
40
- const coord = vec2_lerp([], coord0, coord1, t);
40
+ const coord = vec2.lerp([], coord0, coord1, t);
41
41
  const result = worldToLngLat(coord);
42
42
  result.push(targetZ);
43
43
  return result;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/get-bounds.ts"],"names":["lerp","vec2_lerp","worldToLngLat","transformVector","DEGREES_TO_RADIANS","Math","PI","getBounds","viewport","z","width","height","unproject","unprojectOps","targetZ","bottomLeft","bottomRight","topLeft","topRight","halfFov","fovy","atan","altitude","angleToGround","pitch","unprojectOnFarPlane","x","pixelUnprojectionMatrix","coord0","coord1","distanceScales","unitsPerMeter","t","coord","result","push"],"mappings":"AACA,SAAQA,IAAI,IAAIC,SAAhB,QAAgC,gBAAhC;SAEQC,a;SACAC,e;AAER,MAAMC,kBAAkB,GAAGC,IAAI,CAACC,EAAL,GAAU,GAArC;AAOA,OAAO,SAASC,SAAT,CAAmBC,QAAnB,EAAkDC,CAAS,GAAG,CAA9D,EAA6E;AAElF,QAAM;AAACC,IAAAA,KAAD;AAAQC,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eAAe,CAACwB,uBAAD,EAA0B,CAACD,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,CAA1B,CAA9B;AACA,QAAMG,MAAM,GAAG1B,eAAe,CAACwB,uBAAD,EAA0B,CAACD,CAAD,EAAIlB,QAAQ,CAACG,MAAb,EAAqB,CAArB,EAAwB,CAAxB,CAA1B,CAA9B;AAEA,QAAMF,CAAC,GAAGK,OAAO,GAAGN,QAAQ,CAACsB,cAAT,CAAwBC,aAAxB,CAAsC,CAAtC,CAApB;AACA,QAAMC,CAAC,GAAG,CAACvB,CAAC,GAAGmB,MAAM,CAAC,CAAD,CAAX,KAAmBC,MAAM,CAAC,CAAD,CAAN,GAAYD,MAAM,CAAC,CAAD,CAArC,CAAV;AACA,QAAMK,KAAK,GAAGhC,SAAS,CAAC,EAAD,EAAK2B,MAAL,EAAaC,MAAb,EAAqBG,CAArB,CAAvB;AAEA,QAAME,MAAM,GAAGhC,aAAa,CAAC+B,KAAD,CAA5B;AACAC,EAAAA,MAAM,CAACC,IAAP,CAAYrB,OAAZ;AACA,SAAOoB,MAAP;AACD","sourcesContent":["/* eslint-disable camelcase */\nimport {lerp as vec2_lerp} from 'gl-matrix/vec2';\nimport type {WebMercatorViewport} from './web-mercator-viewport';\nimport {worldToLngLat} from './web-mercator-utils';\nimport {transformVector} from './math-utils';\n\nconst DEGREES_TO_RADIANS = Math.PI / 180;\n\n/*\n * Returns the quad at the intersection of the frustum and the given z plane\n * @param {WebMercatorViewport} viewport\n * @param {Number} z - elevation in meters\n */\nexport function getBounds(viewport: WebMercatorViewport, z: number = 0): number[][] {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const {width, height, unproject} = viewport;\n const unprojectOps = {targetZ: z};\n const bottomLeft = unproject([0, height], unprojectOps);\n const bottomRight = unproject([width, height], unprojectOps);\n let topLeft: number[];\n let topRight: number[];\n\n const halfFov = viewport.fovy\n ? 0.5 * viewport.fovy * DEGREES_TO_RADIANS\n : Math.atan(0.5 / viewport.altitude);\n const angleToGround = (90 - viewport.pitch) * DEGREES_TO_RADIANS;\n // The top plane is parallel to the ground if halfFov == angleToGround\n if (halfFov > angleToGround - 0.01) {\n // intersect with the far plane\n topLeft = unprojectOnFarPlane(viewport, 0, z);\n topRight = unprojectOnFarPlane(viewport, width, z);\n } else {\n // intersect with the top plane\n topLeft = unproject([0, 0], unprojectOps);\n topRight = unproject([width, 0], unprojectOps);\n }\n\n return [bottomLeft, bottomRight, topRight, topLeft];\n}\n\n/*\n * Find a point on the far clipping plane of the viewport\n * @param {WebMercatorViewport} viewport\n * @param {Number} x - projected x in screen space\n * @param {Number} targetZ - the elevation of the point in meters\n */\nfunction unprojectOnFarPlane(viewport: WebMercatorViewport, x: number, targetZ: number): number[] {\n const {pixelUnprojectionMatrix} = viewport;\n const coord0 = transformVector(pixelUnprojectionMatrix, [x, 0, 1, 1]);\n const coord1 = transformVector(pixelUnprojectionMatrix, [x, viewport.height, 1, 1]);\n\n const z = targetZ * viewport.distanceScales.unitsPerMeter[2];\n const t = (z - coord0[2]) / (coord1[2] - coord0[2]);\n const coord = vec2_lerp([], coord0, coord1, t);\n\n const result = worldToLngLat(coord);\n result.push(targetZ);\n return result;\n}\n"],"file":"get-bounds.js"}
1
+ {"version":3,"sources":["../src/get-bounds.ts"],"names":["vec2","worldToLngLat","transformVector","DEGREES_TO_RADIANS","Math","PI","getBounds","viewport","z","width","height","unproject","unprojectOps","targetZ","bottomLeft","bottomRight","topLeft","topRight","halfFov","fovy","atan","altitude","angleToGround","pitch","unprojectOnFarPlane","x","pixelUnprojectionMatrix","coord0","coord1","distanceScales","unitsPerMeter","t","coord","lerp","result","push"],"mappings":"AACA,SAAQA,IAAR,QAAmB,eAAnB;SAEQC,a;SACAC,e;AAER,MAAMC,kBAAkB,GAAGC,IAAI,CAACC,EAAL,GAAU,GAArC;AAOA,OAAO,SAASC,SAAT,CAAmBC,QAAnB,EAAkDC,CAAS,GAAG,CAA9D,EAA6E;AAElF,QAAM;AAACC,IAAA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,MAAM,GAAGzB,eAAe,CAACwB,uBAAD,EAA0B,CAACD,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,CAA1B,CAA9B;AACA,QAAMG,MAAM,GAAG1B,eAAe,CAACwB,uBAAD,EAA0B,CAACD,CAAD,EAAIlB,QAAQ,CAACG,MAAb,EAAqB,CAArB,EAAwB,CAAxB,CAA1B,CAA9B;AAEA,QAAMF,CAAC,GAAGK,OAAO,GAAGN,QAAQ,CAACsB,cAAT,CAAwBC,aAAxB,CAAsC,CAAtC,CAApB;AACA,QAAMC,CAAC,GAAG,CAACvB,CAAC,GAAGmB,MAAM,CAAC,CAAD,CAAX,KAAmBC,MAAM,CAAC,CAAD,CAAN,GAAYD,MAAM,CAAC,CAAD,CAArC,CAAV;AACA,QAAMK,KAAK,GAAGhC,IAAI,CAACiC,IAAL,CAAU,EAAV,EAAcN,MAAd,EAAsBC,MAAtB,EAA8BG,CAA9B,CAAd;AAEA,QAAMG,MAAM,GAAGjC,aAAa,CAAC+B,KAAD,CAA5B;AACAE,EAAAA,MAAM,CAACC,IAAP,CAAYtB,OAAZ;AACA,SAAOqB,MAAP;AACD","sourcesContent":["/* eslint-disable camelcase */\nimport {vec2} from '@math.gl/core';\nimport type {WebMercatorViewport} from './web-mercator-viewport';\nimport {worldToLngLat} from './web-mercator-utils';\nimport {transformVector} from './math-utils';\n\nconst DEGREES_TO_RADIANS = Math.PI / 180;\n\n/*\n * Returns the quad at the intersection of the frustum and the given z plane\n * @param {WebMercatorViewport} viewport\n * @param {Number} z - elevation in meters\n */\nexport function getBounds(viewport: WebMercatorViewport, z: number = 0): number[][] {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const {width, height, unproject} = viewport;\n const unprojectOps = {targetZ: z};\n const bottomLeft = unproject([0, height], unprojectOps);\n const bottomRight = unproject([width, height], unprojectOps);\n let topLeft: number[];\n let topRight: number[];\n\n const halfFov = viewport.fovy\n ? 0.5 * viewport.fovy * DEGREES_TO_RADIANS\n : Math.atan(0.5 / viewport.altitude);\n const angleToGround = (90 - viewport.pitch) * DEGREES_TO_RADIANS;\n // The top plane is parallel to the ground if halfFov == angleToGround\n if (halfFov > angleToGround - 0.01) {\n // intersect with the far plane\n topLeft = unprojectOnFarPlane(viewport, 0, z);\n topRight = unprojectOnFarPlane(viewport, width, z);\n } else {\n // intersect with the top plane\n topLeft = unproject([0, 0], unprojectOps);\n topRight = unproject([width, 0], unprojectOps);\n }\n\n return [bottomLeft, bottomRight, topRight, topLeft];\n}\n\n/*\n * Find a point on the far clipping plane of the viewport\n * @param {WebMercatorViewport} viewport\n * @param {Number} x - projected x in screen space\n * @param {Number} targetZ - the elevation of the point in meters\n */\nfunction unprojectOnFarPlane(viewport: WebMercatorViewport, x: number, targetZ: number): number[] {\n const {pixelUnprojectionMatrix} = viewport;\n const coord0 = transformVector(pixelUnprojectionMatrix, [x, 0, 1, 1]);\n const coord1 = transformVector(pixelUnprojectionMatrix, [x, viewport.height, 1, 1]);\n\n const z = targetZ * viewport.distanceScales.unitsPerMeter[2];\n const t = (z - coord0[2]) / (coord1[2] - coord0[2]);\n const coord = vec2.lerp([], coord0, coord1, t);\n\n const result = worldToLngLat(coord);\n result.push(targetZ);\n return result;\n}\n"],"file":"get-bounds.js"}
package/dist/index.cjs CHANGED
@@ -1,9 +1,7 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
4
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
7
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -30,10 +28,6 @@ var __copyProps = (to, from, except, desc) => {
30
28
  }
31
29
  return to;
32
30
  };
33
- var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__getProtoOf(mod2)) : {}, __copyProps(
34
- isNodeMode || !mod2 || !mod2.__esModule ? __defProp(target, "default", { value: mod2, enumerable: true }) : target,
35
- mod2
36
- ));
37
31
  var __toCommonJS = (mod2) => __copyProps(__defProp({}, "__esModule", { value: true }), mod2);
38
32
 
39
33
  // src/index.ts
@@ -66,13 +60,13 @@ __export(src_exports, {
66
60
  module.exports = __toCommonJS(src_exports);
67
61
 
68
62
  // src/math-utils.ts
69
- var import_vec4 = require("gl-matrix/vec4");
63
+ var import_core = require("@math.gl/core");
70
64
  function createMat4() {
71
65
  return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
72
66
  }
73
67
  function transformVector(matrix, vector) {
74
- const result = (0, import_vec4.transformMat4)([], vector, matrix);
75
- (0, import_vec4.scale)(result, result, 1 / result[3]);
68
+ const result = import_core.vec4.transformMat4([], vector, matrix);
69
+ import_core.vec4.scale(result, result, 1 / result[3]);
76
70
  return result;
77
71
  }
78
72
  function mod(value, divisor) {
@@ -91,9 +85,7 @@ function ieLog2(x) {
91
85
  var log2 = Math.log2 || ieLog2;
92
86
 
93
87
  // src/web-mercator-utils.ts
94
- var mat4 = __toESM(require("gl-matrix/mat4"), 1);
95
- var vec2 = __toESM(require("gl-matrix/vec2"), 1);
96
- var vec3 = __toESM(require("gl-matrix/vec3"), 1);
88
+ var import_core2 = require("@math.gl/core");
97
89
 
98
90
  // src/assert.ts
99
91
  function assert(condition, message) {
@@ -114,8 +106,8 @@ var DEFAULT_ALTITUDE = 1.5;
114
106
  function zoomToScale(zoom) {
115
107
  return Math.pow(2, zoom);
116
108
  }
117
- function scaleToZoom(scale5) {
118
- return log2(scale5);
109
+ function scaleToZoom(scale) {
110
+ return log2(scale);
119
111
  }
120
112
  function lngLatToWorld(lngLat) {
121
113
  const [lng, lat] = lngLat;
@@ -188,17 +180,17 @@ function getViewMatrix(options) {
188
180
  pitch,
189
181
  bearing,
190
182
  altitude,
191
- scale: scale5,
183
+ scale,
192
184
  center
193
185
  } = options;
194
186
  const vm = createMat4();
195
- mat4.translate(vm, vm, [0, 0, -altitude]);
196
- mat4.rotateX(vm, vm, -pitch * DEGREES_TO_RADIANS);
197
- mat4.rotateZ(vm, vm, bearing * DEGREES_TO_RADIANS);
198
- const relativeScale = scale5 / height;
199
- mat4.scale(vm, vm, [relativeScale, relativeScale, relativeScale]);
187
+ import_core2.mat4.translate(vm, vm, [0, 0, -altitude]);
188
+ import_core2.mat4.rotateX(vm, vm, -pitch * DEGREES_TO_RADIANS);
189
+ import_core2.mat4.rotateZ(vm, vm, bearing * DEGREES_TO_RADIANS);
190
+ const relativeScale = scale / height;
191
+ import_core2.mat4.scale(vm, vm, [relativeScale, relativeScale, relativeScale]);
200
192
  if (center) {
201
- mat4.translate(vm, vm, vec3.negate([], center));
193
+ import_core2.mat4.translate(vm, vm, import_core2.vec3.negate([], center));
202
194
  }
203
195
  return vm;
204
196
  }
@@ -210,7 +202,7 @@ function getProjectionParameters(options) {
210
202
  pitch = 0,
211
203
  offset,
212
204
  center,
213
- scale: scale5,
205
+ scale,
214
206
  nearZMultiplier = 1,
215
207
  farZMultiplier = 1
216
208
  } = options;
@@ -223,7 +215,7 @@ function getProjectionParameters(options) {
223
215
  const focalDistance = fovyToAltitude(fovy);
224
216
  let cameraToSeaLevelDistance = focalDistance;
225
217
  if (center) {
226
- cameraToSeaLevelDistance += center[2] * scale5 / Math.cos(pitchRadians) / height;
218
+ cameraToSeaLevelDistance += center[2] * scale / Math.cos(pitchRadians) / height;
227
219
  }
228
220
  const fovAboveCenter = fovRadians * (0.5 + (offset ? offset[1] : 0) / height);
229
221
  const topHalfSurfaceDistance = Math.sin(fovAboveCenter) * cameraToSeaLevelDistance / Math.sin(clamp(Math.PI / 2 - pitchRadians - fovAboveCenter, 0.01, Math.PI - 0.01));
@@ -240,7 +232,7 @@ function getProjectionParameters(options) {
240
232
  }
241
233
  function getProjectionMatrix(options) {
242
234
  const { fov, aspect, near, far } = getProjectionParameters(options);
243
- const projectionMatrix = mat4.perspective(
235
+ const projectionMatrix = import_core2.mat4.perspective(
244
236
  [],
245
237
  fov,
246
238
  aspect,
@@ -272,7 +264,7 @@ function pixelsToWorld(xyz, pixelUnprojectionMatrix, targetZ = 0) {
272
264
  const z0 = coord0[2];
273
265
  const z1 = coord1[2];
274
266
  const t = z0 === z1 ? 0 : ((targetZ || 0) - z0) / (z1 - z0);
275
- return vec2.lerp([], coord0, coord1, t);
267
+ return import_core2.vec2.lerp([], coord0, coord1, t);
276
268
  }
277
269
 
278
270
  // src/fit-bounds.ts
@@ -328,7 +320,7 @@ function getPaddingObject(padding = 0) {
328
320
  }
329
321
 
330
322
  // src/get-bounds.ts
331
- var import_vec2 = require("gl-matrix/vec2");
323
+ var import_core3 = require("@math.gl/core");
332
324
  var DEGREES_TO_RADIANS2 = Math.PI / 180;
333
325
  function getBounds(viewport, z = 0) {
334
326
  const { width, height, unproject } = viewport;
@@ -354,23 +346,21 @@ function unprojectOnFarPlane(viewport, x, targetZ) {
354
346
  const coord1 = transformVector(pixelUnprojectionMatrix, [x, viewport.height, 1, 1]);
355
347
  const z = targetZ * viewport.distanceScales.unitsPerMeter[2];
356
348
  const t = (z - coord0[2]) / (coord1[2] - coord0[2]);
357
- const coord = (0, import_vec2.lerp)([], coord0, coord1, t);
349
+ const coord = import_core3.vec2.lerp([], coord0, coord1, t);
358
350
  const result = worldToLngLat(coord);
359
351
  result.push(targetZ);
360
352
  return result;
361
353
  }
362
354
 
363
355
  // src/web-mercator-viewport.ts
364
- var mat42 = __toESM(require("gl-matrix/mat4"), 1);
365
- var vec22 = __toESM(require("gl-matrix/vec2"), 1);
366
- var vec32 = __toESM(require("gl-matrix/vec3"), 1);
356
+ var import_core4 = require("@math.gl/core");
367
357
  var WebMercatorViewport = class {
368
358
  constructor(props = { width: 1, height: 1 }) {
369
359
  this.equals = (viewport) => {
370
360
  if (!(viewport instanceof WebMercatorViewport)) {
371
361
  return false;
372
362
  }
373
- return viewport.width === this.width && viewport.height === this.height && mat42.equals(viewport.projectionMatrix, this.projectionMatrix) && mat42.equals(viewport.viewMatrix, this.viewMatrix);
363
+ return viewport.width === this.width && viewport.height === this.height && import_core4.mat4.equals(viewport.projectionMatrix, this.projectionMatrix) && import_core4.mat4.equals(viewport.viewMatrix, this.viewMatrix);
374
364
  };
375
365
  this.project = (lngLatZ, options = {}) => {
376
366
  const { topLeft = true } = options;
@@ -428,18 +418,18 @@ var WebMercatorViewport = class {
428
418
  } else if (altitude === null) {
429
419
  altitude = fovyToAltitude(fovy);
430
420
  }
431
- const scale5 = zoomToScale(zoom);
421
+ const scale = zoomToScale(zoom);
432
422
  altitude = Math.max(0.75, altitude);
433
423
  const distanceScales = getDistanceScales({ longitude, latitude });
434
424
  const center = lngLatToWorld([longitude, latitude]);
435
425
  center.push(0);
436
426
  if (position) {
437
- vec32.add(center, center, vec32.mul([], position, distanceScales.unitsPerMeter));
427
+ import_core4.vec3.add(center, center, import_core4.vec3.mul([], position, distanceScales.unitsPerMeter));
438
428
  }
439
429
  this.projectionMatrix = getProjectionMatrix({
440
430
  width,
441
431
  height,
442
- scale: scale5,
432
+ scale,
443
433
  center,
444
434
  pitch,
445
435
  fovy,
@@ -448,7 +438,7 @@ var WebMercatorViewport = class {
448
438
  });
449
439
  this.viewMatrix = getViewMatrix({
450
440
  height,
451
- scale: scale5,
441
+ scale,
452
442
  center,
453
443
  pitch,
454
444
  bearing,
@@ -456,7 +446,7 @@ var WebMercatorViewport = class {
456
446
  });
457
447
  this.width = width;
458
448
  this.height = height;
459
- this.scale = scale5;
449
+ this.scale = scale;
460
450
  this.latitude = latitude;
461
451
  this.longitude = longitude;
462
452
  this.zoom = zoom;
@@ -473,14 +463,14 @@ var WebMercatorViewport = class {
473
463
  _initMatrices() {
474
464
  const { width, height, projectionMatrix, viewMatrix } = this;
475
465
  const vpm = createMat4();
476
- mat42.multiply(vpm, vpm, projectionMatrix);
477
- mat42.multiply(vpm, vpm, viewMatrix);
466
+ import_core4.mat4.multiply(vpm, vpm, projectionMatrix);
467
+ import_core4.mat4.multiply(vpm, vpm, viewMatrix);
478
468
  this.viewProjectionMatrix = vpm;
479
469
  const m = createMat4();
480
- mat42.scale(m, m, [width / 2, -height / 2, 1]);
481
- mat42.translate(m, m, [1, -1, 0]);
482
- mat42.multiply(m, m, vpm);
483
- const mInverse = mat42.invert(createMat4(), m);
470
+ import_core4.mat4.scale(m, m, [width / 2, -height / 2, 1]);
471
+ import_core4.mat4.translate(m, m, [1, -1, 0]);
472
+ import_core4.mat4.multiply(m, m, vpm);
473
+ const mInverse = import_core4.mat4.invert(createMat4(), m);
484
474
  if (!mInverse) {
485
475
  throw new Error("Pixel project matrix not invertible");
486
476
  }
@@ -496,8 +486,8 @@ var WebMercatorViewport = class {
496
486
  getMapCenterByLngLatPosition({ lngLat, pos }) {
497
487
  const fromLocation = pixelsToWorld(pos, this.pixelUnprojectionMatrix);
498
488
  const toLocation = lngLatToWorld(lngLat);
499
- const translate3 = vec22.add([], toLocation, vec22.negate([], fromLocation));
500
- const newCenter = vec22.add([], this.center, translate3);
489
+ const translate = import_core4.vec2.add([], toLocation, import_core4.vec2.negate([], fromLocation));
490
+ const newCenter = import_core4.vec2.add([], this.center, translate);
501
491
  return worldToLngLat(newCenter);
502
492
  }
503
493
  fitBounds(bounds, options = {}) {
@@ -555,7 +545,7 @@ function normalizeViewportProps(props) {
555
545
  }
556
546
 
557
547
  // src/fly-to-viewport.ts
558
- var vec23 = __toESM(require("gl-matrix/vec2"), 1);
548
+ var import_core5 = require("@math.gl/core");
559
549
  var EPSILON = 0.01;
560
550
  var VIEWPORT_TRANSITION_PROPS = ["longitude", "latitude", "zoom"];
561
551
  var DEFAULT_OPTS = {
@@ -582,8 +572,8 @@ function flyToViewport(startProps, endProps, t, options) {
582
572
  const u = w0 * ((Math.cosh(r0) * Math.tanh(r0 + rho * s) - Math.sinh(r0)) / rho2) / u1;
583
573
  const scaleIncrement = 1 / w;
584
574
  const newZoom = startZoom + scaleToZoom(scaleIncrement);
585
- const newCenterWorld = vec23.scale([], uDelta, u);
586
- vec23.add(newCenterWorld, newCenterWorld, startCenterXY);
575
+ const newCenterWorld = import_core5.vec2.scale([], uDelta, u);
576
+ import_core5.vec2.add(newCenterWorld, newCenterWorld, startCenterXY);
587
577
  const newCenter = worldToLngLat(newCenterWorld);
588
578
  return {
589
579
  longitude: newCenter[0],
@@ -595,12 +585,12 @@ function getFlyToDuration(startProps, endProps, options) {
595
585
  const opts = __spreadValues(__spreadValues({}, DEFAULT_OPTS), options);
596
586
  const { screenSpeed, speed, maxDuration } = opts;
597
587
  const { S, rho } = getFlyToTransitionParams(startProps, endProps, opts);
598
- const length2 = 1e3 * S;
588
+ const length = 1e3 * S;
599
589
  let duration;
600
590
  if (Number.isFinite(screenSpeed)) {
601
- duration = length2 / (screenSpeed / rho);
591
+ duration = length / (screenSpeed / rho);
602
592
  } else {
603
- duration = length2 / speed;
593
+ duration = length / speed;
604
594
  }
605
595
  return Number.isFinite(maxDuration) && duration > maxDuration ? 0 : duration;
606
596
  }
@@ -612,13 +602,13 @@ function getFlyToTransitionParams(startProps, endProps, opts) {
612
602
  const startScale = zoomToScale(startZoom);
613
603
  const endZoom = endProps.zoom;
614
604
  const endCenter = [endProps.longitude, endProps.latitude];
615
- const scale5 = zoomToScale(endZoom - startZoom);
605
+ const scale = zoomToScale(endZoom - startZoom);
616
606
  const startCenterXY = lngLatToWorld(startCenter);
617
607
  const endCenterXY = lngLatToWorld(endCenter);
618
- const uDelta = vec23.sub([], endCenterXY, startCenterXY);
608
+ const uDelta = import_core5.vec2.sub([], endCenterXY, startCenterXY);
619
609
  const w0 = Math.max(startProps.width, startProps.height);
620
- const w1 = w0 / scale5;
621
- const u1 = vec23.length(uDelta) * startScale;
610
+ const w1 = w0 / scale;
611
+ const u1 = import_core5.vec2.length(uDelta) * startScale;
622
612
  const _u1 = Math.max(u1, EPSILON);
623
613
  const rho2 = rho * rho;
624
614
  const b0 = (w1 * w1 - w0 * w0 + rho2 * rho2 * _u1 * _u1) / (2 * w0 * rho2 * _u1);
@@ -1,10 +1,10 @@
1
- import { transformMat4, scale } from 'gl-matrix/vec4';
1
+ import { vec4 } from '@math.gl/core';
2
2
  export function createMat4() {
3
3
  return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
4
4
  }
5
5
  export function transformVector(matrix, vector) {
6
- const result = transformMat4([], vector, matrix);
7
- scale(result, result, 1 / result[3]);
6
+ const result = vec4.transformMat4([], vector, matrix);
7
+ vec4.scale(result, result, 1 / result[3]);
8
8
  return result;
9
9
  }
10
10
  export function mod(value, divisor) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/math-utils.ts"],"names":["transformMat4","scale","createMat4","transformVector","matrix","vector","result","mod","value","divisor","modulus","lerp","start","end","step","clamp","x","min","max","ieLog2","Math","log","LOG2E","log2"],"mappings":"AAAA,SAAQA,aAAR,EAAuBC,KAAvB,QAAmC,gBAAnC;AAGA,OAAO,SAASC,UAAT,GAAgC;AACrC,SAAO,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,EAAa,CAAb,EAAgB,CAAhB,EAAmB,CAAnB,EAAsB,CAAtB,EAAyB,CAAzB,EAA4B,CAA5B,EAA+B,CAA/B,EAAkC,CAAlC,EAAqC,CAArC,EAAwC,CAAxC,EAA2C,CAA3C,EAA8C,CAA9C,CAAP;AACD;AAGD,OAAO,SAASC,eAAT,CAAyBC,MAAzB,EAA2CC,MAA3C,EAAuE;AAC5E,QAAMC,MAAM,GAAGN,aAAa,CAAC,EAAD,EAAiBK,MAAjB,EAAyBD,MAAzB,CAA5B;AACAH,EAAAA,KAAK,CAACK,MAAD,EAASA,MAAT,EAAiB,IAAIA,MAAM,CAAC,CAAD,CAA3B,CAAL;AACA,SAAOA,MAAP;AACD;AAED,OAAO,SAASC,GAAT,CAAaC,KAAb,EAA4BC,OAA5B,EAAqD;AAC1D,QAAMC,OAAO,GAAGF,KAAK,GAAGC,OAAxB;AACA,SAAOC,OAAO,GAAG,CAAV,GAAcD,OAAO,GAAGC,OAAxB,GAAkCA,OAAzC;AACD;AAED,OAAO,SAASC,IAAT,CAAcC,KAAd,EAA6BC,GAA7B,EAA0CC,IAA1C,EAAgE;AACrE,SAAOA,IAAI,GAAGD,GAAP,GAAa,CAAC,IAAIC,IAAL,IAAaF,KAAjC;AACD;AAED,OAAO,SAASG,KAAT,CAAeC,CAAf,EAA0BC,GAA1B,EAAuCC,GAAvC,EAA4D;AACjE,SAAOF,CAAC,GAAGC,GAAJ,GAAUA,GAAV,GAAgBD,CAAC,GAAGE,GAAJ,GAAUA,GAAV,GAAgBF,CAAvC;AACD;;AAED,SAASG,MAAT,CAAgBH,CAAhB,EAAmC;AACjC,SAAOI,IAAI,CAACC,GAAL,CAASL,CAAT,IAAcI,IAAI,CAACE,KAA1B;AACD;;AAED,OAAO,MAAMC,IAAI,GAAGH,IAAI,CAACG,IAAL,IAAaJ,MAA1B","sourcesContent":["import {transformMat4, scale} from 'gl-matrix/vec4';\n\n// Helper, avoids low-precision 32 bit matrices from gl-matrix mat4.create()\nexport function createMat4(): number[] {\n return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];\n}\n\n// Transforms a vec4 with a projection matrix\nexport function transformVector(matrix: number[], vector: number[]): number[] {\n const result = transformMat4([] as number[], vector, matrix);\n scale(result, result, 1 / result[3]);\n return result;\n}\n\nexport function mod(value: number, divisor: number): number {\n const modulus = value % divisor;\n return modulus < 0 ? divisor + modulus : modulus;\n}\n\nexport function lerp(start: number, end: number, step: number): number {\n return step * end + (1 - step) * start;\n}\n\nexport function clamp(x: number, min: number, max: number): number {\n return x < min ? min : x > max ? max : x;\n}\n\nfunction ieLog2(x: number): number {\n return Math.log(x) * Math.LOG2E;\n}\n// Handle missing log2 in IE 11\nexport const log2 = Math.log2 || ieLog2;\n"],"file":"math-utils.js"}
1
+ {"version":3,"sources":["../src/math-utils.ts"],"names":["vec4","createMat4","transformVector","matrix","vector","result","transformMat4","scale","mod","value","divisor","modulus","lerp","start","end","step","clamp","x","min","max","ieLog2","Math","log","LOG2E","log2"],"mappings":"AAAA,SAAQA,IAAR,QAAmB,eAAnB;AAGA,OAAO,SAASC,UAAT,GAAgC;AACrC,SAAO,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,EAAa,CAAb,EAAgB,CAAhB,EAAmB,CAAnB,EAAsB,CAAtB,EAAyB,CAAzB,EAA4B,CAA5B,EAA+B,CAA/B,EAAkC,CAAlC,EAAqC,CAArC,EAAwC,CAAxC,EAA2C,CAA3C,EAA8C,CAA9C,CAAP;AACD;AAGD,OAAO,SAASC,eAAT,CAAyBC,MAAzB,EAA2CC,MAA3C,EAAuE;AAC5E,QAAMC,MAAM,GAAGL,IAAI,CAACM,aAAL,CAAmB,EAAnB,EAAmCF,MAAnC,EAA2CD,MAA3C,CAAf;AACAH,EAAAA,IAAI,CAACO,KAAL,CAAWF,MAAX,EAAmBA,MAAnB,EAA2B,IAAIA,MAAM,CAAC,CAAD,CAArC;AACA,SAAOA,MAAP;AACD;AAED,OAAO,SAASG,GAAT,CAAaC,KAAb,EAA4BC,OAA5B,EAAqD;AAC1D,QAAMC,OAAO,GAAGF,KAAK,GAAGC,OAAxB;AACA,SAAOC,OAAO,GAAG,CAAV,GAAcD,OAAO,GAAGC,OAAxB,GAAkCA,OAAzC;AACD;AAED,OAAO,SAASC,IAAT,CAAcC,KAAd,EAA6BC,GAA7B,EAA0CC,IAA1C,EAAgE;AACrE,SAAOA,IAAI,GAAGD,GAAP,GAAa,CAAC,IAAIC,IAAL,IAAaF,KAAjC;AACD;AAED,OAAO,SAASG,KAAT,CAAeC,CAAf,EAA0BC,GAA1B,EAAuCC,GAAvC,EAA4D;AACjE,SAAOF,CAAC,GAAGC,GAAJ,GAAUA,GAAV,GAAgBD,CAAC,GAAGE,GAAJ,GAAUA,GAAV,GAAgBF,CAAvC;AACD;;AAED,SAASG,MAAT,CAAgBH,CAAhB,EAAmC;AACjC,SAAOI,IAAI,CAACC,GAAL,CAASL,CAAT,IAAcI,IAAI,CAACE,KAA1B;AACD;;AAED,OAAO,MAAMC,IAAI,GAAGH,IAAI,CAACG,IAAL,IAAaJ,MAA1B","sourcesContent":["import {vec4} from '@math.gl/core';\n\n// Helper, avoids low-precision 32 bit matrices from gl-matrix mat4.create()\nexport function createMat4(): number[] {\n return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];\n}\n\n// Transforms a vec4 with a projection matrix\nexport function transformVector(matrix: number[], vector: number[]): number[] {\n const result = vec4.transformMat4([] as number[], vector, matrix);\n vec4.scale(result, result, 1 / result[3]);\n return result;\n}\n\nexport function mod(value: number, divisor: number): number {\n const modulus = value % divisor;\n return modulus < 0 ? divisor + modulus : modulus;\n}\n\nexport function lerp(start: number, end: number, step: number): number {\n return step * end + (1 - step) * start;\n}\n\nexport function clamp(x: number, min: number, max: number): number {\n return x < min ? min : x > max ? max : x;\n}\n\nfunction ieLog2(x: number): number {\n return Math.log(x) * Math.LOG2E;\n}\n// Handle missing log2 in IE 11\nexport const log2 = Math.log2 || ieLog2;\n"],"file":"math-utils.js"}
@@ -1 +1 @@
1
- {"version":3,"file":"web-mercator-utils.d.ts","sourceRoot":"","sources":["../src/web-mercator-utils.ts"],"names":[],"mappings":"AAkBA,eAAO,MAAM,YAAY,YAAY,CAAC;AAGtC,eAAO,MAAM,gBAAgB,MAAM,CAAC;AAEpC,oBAAY,cAAc,GAAG;IAC3B,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,EAAE,C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AAc,CAAC,EAAE,MAAM,CAAC;CACzB,GAAG,oBAAoB,CAwDvB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;CACxB,GAAG,MAAM,EAAE,CAYX;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,qBAAqB,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC;AAUxF;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAC3B,GAAG,EAAE,MAAM,EAAE,EACb,uBAAuB,EAAE,MAAM,EAAE,EACjC,OAAO,GAAE,MAAU,GAClB,MAAM,EAAE,CAoBV"}
@@ -1,7 +1,5 @@
1
1
  import { createMat4, transformVector, clamp, log2 } from "./math-utils.js";
2
- import * as mat4 from 'gl-matrix/mat4';
3
- import * as vec2 from 'gl-matrix/vec2';
4
- import * as vec3 from 'gl-matrix/vec3';
2
+ import { mat4, vec2, vec3 } from '@math.gl/core';
5
3
  import { assert } from "./assert.js";
6
4
  const PI = Math.PI;
7
5
  const PI_4 = PI / 4;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/web-mercator-utils.ts"],"names":["createMat4","transformVector","clamp","log2","mat4","vec2","vec3","assert","PI","Math","PI_4","DEGREES_TO_RADIANS","RADIANS_TO_DEGREES","TILE_SIZE","EARTH_CIRCUMFERENCE","MAX_LATITUDE","DEFAULT_ALTITUDE","zoomToScale","zoom","pow","scaleToZoom","scale","lngLatToWorld","lngLat","lng","lat","Number","isFinite","lambda2","phi2","x","y","log","tan","worldToLngLat","xy","atan","exp","getMeterZoom","options","latitude","latCosine","cos","unitsPerMeter","getDistanceScales","longitude","highPrecision","worldSize","unitsPerDegreeX","unitsPerDegreeY","altUnitsPerMeter","result","metersPerUnit","unitsPerDegree","degreesPerUnit","latCosine2","unitsPerDegreeY2","altUnitsPerDegree2","altUnitsPerMeter2","unitsPerDegree2","unitsPerMeter2","addMetersToLngLat","lngLatZ","xyz","z0","z","worldspace","newLngLat","newZ","getViewMatrix","height","pitch","bearing","altitude","center","vm","translate","rotateX","rotateZ","relativeScale","negate","getProjectionParameters","width","offset","nearZMultiplier","farZMultiplier","fovy","altitudeToFovy","undefined","fovRadians","pitchRadians","focalDistance","fovyToAltitude","cameraToSeaLevelDistance","fovAboveCenter","topHalfSurfaceDistance","sin","furthestDistance","horizonDistance","farZ","min","fov","aspect","near","far","getProjectionMatrix","projectionMatrix","perspective","worldToPixels","pixelProjectionMatrix","pixelsToWorld","pixelUnprojectionMatrix","targetZ","coord","coord0","coord1","z1","t","lerp"],"mappings":"SAEQA,U,EAAYC,e,EAAiBC,K,EAAOC,I;AAE5C,OAAO,KAAKC,IAAZ,MAAsB,gBAAtB;AACA,OAAO,KAAKC,IAAZ,MAAsB,gBAAtB;AACA,OAAO,KAAKC,IAAZ,MAAsB,gBAAtB;SACQC,M;AAGR,MAAMC,EAAE,GAAGC,IAAI,CAACD,EAAhB;AACA,MAAME,IAAI,GAAGF,EAAE,GAAG,CAAlB;AACA,MAAMG,kBAAkB,GAAGH,EAAE,GAAG,GAAhC;AACA,MAAMI,kBA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uBAAD,EAA0B,CAACjF,CAAD,EAAIC,CAAJ,EAAOkC,CAAP,EAAU,CAAV,CAA1B,CAA7B;AACA,WAAOgD,KAAP;AACD;;AAID,QAAMC,MAAM,GAAGjH,eAAe,CAAC8G,uBAAD,EAA0B,CAACjF,CAAD,EAAIC,CAAJ,EAAO,CAAP,EAAU,CAAV,CAA1B,CAA9B;AACA,QAAMoF,MAAM,GAAGlH,eAAe,CAAC8G,uBAAD,EAA0B,CAACjF,CAAD,EAAIC,CAAJ,EAAO,CAAP,EAAU,CAAV,CAA1B,CAA9B;AAEA,QAAMiC,EAAE,GAAGkD,MAAM,CAAC,CAAD,CAAjB;AACA,QAAME,EAAE,GAAGD,MAAM,CAAC,CAAD,CAAjB;AAEA,QAAME,CAAC,GAAGrD,EAAE,KAAKoD,EAAP,GAAY,CAAZ,GAAgB,CAAC,CAACJ,OAAO,IAAI,CAAZ,IAAiBhD,EAAlB,KAAyBoD,EAAE,GAAGpD,EAA9B,CAA1B;AACA,SAAO3D,IAAI,CAACiH,IAAL,CAAU,EAAV,EAA0BJ,MAA1B,EAAkCC,MAAlC,EAA0CE,CAA1C,CAAP;AACD","sourcesContent":["// TODO - THE UTILITIES IN THIS FILE SHOULD BE IMPORTED FROM WEB-MERCATOR-VIEWPORT MODULE\n\nimport {createMat4, transformVector, clamp, log2} from './math-utils';\n\nimport * as mat4 from 'gl-matrix/mat4';\nimport * as vec2 from 'gl-matrix/vec2';\nimport * as vec3 from 'gl-matrix/vec3';\nimport {assert} from './assert';\n\n// CONSTANTS\nconst PI = Math.PI;\nconst PI_4 = PI / 4;\nconst DEGREES_TO_RADIANS = PI / 180;\nconst RADIANS_TO_DEGREES = 180 / PI;\nconst TILE_SIZE = 512;\n// Average circumference (40075 km equatorial, 40007 km meridional)\nconst EARTH_CIRCUMFERENCE = 40.03e6;\n// Latitude that makes a square world, 2 * atan(E ** PI) - PI / 2\nexport const MAX_LATITUDE = 85.051129;\n\n// Mapbox default altitude\nexport const DEFAULT_ALTITUDE = 1.5;\n\nexport type DistanceScales = {\n unitsPerMeter: number[];\n metersPerUnit: number[];\n unitsPerMeter2?: number[];\n unitsPerDegree: number[];\n degreesPerUnit: number[];\n unitsPerDegree2?: number[];\n};\n\n/**\n * PROJECTION MATRIX PARAMETERS\n *\n * TODO how to document mebers\n * @param fov in radians. fov is variable, depends on pitch and altitude\n * @param aspect width/height\n * @param focalDistance distance at which visual scale factor is 1\n * @param near near clipping plane\n * @param far far clipping plane\n */\ntype ProjectionParameters = {\n fov: number;\n aspect: number;\n focalDistance: number;\n near: number;\n far: number;\n};\n\n/** Logarithimic zoom to linear scale **/\nexport function zoomToScale(zoom: number): number {\n return Math.pow(2, zoom);\n}\n\n/** Linear scale to logarithimic zoom **/\nexport function scaleToZoom(scale: number): number {\n return log2(scale);\n}\n\n/**\n * Project [lng,lat] on sphere onto [x,y] on 512*512 Mercator Zoom 0 tile.\n * Performs the nonlinear part of the web mercator projection.\n * Remaining projection is done with 4x4 matrices which also handles\n * perspective.\n *\n * @param lngLat - [lng, lat] coordinates\n * Specifies a point on the sphere to project onto the map.\n * @return [x,y] coordinates.\n */\nexport function lngLatToWorld(lngLat: number[]): [number, number] {\n const [lng, lat] = lngLat;\n assert(Number.isFinite(lng));\n assert(Number.isFinite(lat) && lat >= -90 && lat <= 90, 'invalid latitude');\n\n const lambda2 = lng * DEGREES_TO_RADIANS;\n const phi2 = lat * DEGREES_TO_RADIANS;\n const x = (TILE_SIZE * (lambda2 + PI)) / (2 * PI);\n const y = (TILE_SIZE * (PI + Math.log(Math.tan(PI_4 + phi2 * 0.5)))) / (2 * PI);\n return [x, y];\n}\n\n/**\n * Unproject world point [x,y] on map onto {lat, lon} on sphere\n *\n * @param xy - array with [x,y] members\n * representing point on projected map plane\n * @return - array with [x,y] of point on sphere.\n * Has toArray method if you need a GeoJSON Array.\n * Per cartographic tradition, lat and lon are specified as degrees.\n */\nexport function worldToLngLat(xy: number[]): [number, number] {\n const [x, y] = xy;\n const lambda2 = (x / TILE_SIZE) * (2 * PI) - PI;\n const phi2 = 2 * (Math.atan(Math.exp((y / TILE_SIZE) * (2 * PI) - PI)) - PI_4);\n return [lambda2 * RADIANS_TO_DEGREES, phi2 * RADIANS_TO_DEGREES];\n}\n\n/**\n * Returns the zoom level that gives a 1 meter pixel at a certain latitude\n * 1 = C*cos(y)/2^z/TILE_SIZE = C*cos(y)/2^(z+9)\n */\nexport function getMeterZoom(options: {latitude: number}): number {\n const {latitude} = options;\n assert(Number.isFinite(latitude));\n const latCosine = Math.cos(latitude * DEGREES_TO_RADIANS);\n return scaleToZoom(EARTH_CIRCUMFERENCE * latCosine) - 9;\n}\n\n/**\n * Calculate the conversion from meter to common units at a given latitude\n * This is a cheaper version of `getDistanceScales`\n * @param latitude center latitude in degrees\n * @returns common units per meter\n */\nexport function unitsPerMeter(latitude: number): number {\n const latCosine = Math.cos(latitude * DEGREES_TO_RADIANS);\n return TILE_SIZE / EARTH_CIRCUMFERENCE / latCosine;\n}\n\n/**\n * Calculate distance scales in meters around current lat/lon, both for\n * degrees and pixels.\n * In mercator projection mode, the distance scales vary significantly\n * with latitude.\n */\nexport function getDistanceScales(options: {\n latitude: number;\n longitude: number;\n highPrecision?: boolean;\n}): DistanceScales {\n const {latitude, longitude, highPrecision = false} = options;\n assert(Number.isFinite(latitude) && Number.isFinite(longitude));\n\n const worldSize = TILE_SIZE;\n const latCosine = Math.cos(latitude * DEGREES_TO_RADIANS);\n\n /**\n * Number of pixels occupied by one degree longitude around current lat/lon:\n unitsPerDegreeX = d(lngLatToWorld([lng, lat])[0])/d(lng)\n = scale * TILE_SIZE * DEGREES_TO_RADIANS / (2 * PI)\n unitsPerDegreeY = d(lngLatToWorld([lng, lat])[1])/d(lat)\n = -scale * TILE_SIZE * DEGREES_TO_RADIANS / cos(lat * DEGREES_TO_RADIANS) / (2 * PI)\n */\n const unitsPerDegreeX = worldSize / 360;\n const unitsPerDegreeY = unitsPerDegreeX / latCosine;\n\n /**\n * Number of pixels occupied by one meter around current lat/lon:\n */\n const altUnitsPerMeter = worldSize / EARTH_CIRCUMFERENCE / latCosine;\n\n /**\n * LngLat: longitude -> east and latitude -> north (bottom left)\n * UTM meter offset: x -> east and y -> north (bottom left)\n * World space: x -> east and y -> south (top left)\n *\n * Y needs to be flipped when converting delta degree/meter to delta pixels\n */\n const result: DistanceScales = {\n unitsPerMeter: [altUnitsPerMeter, altUnitsPerMeter, altUnitsPerMeter],\n metersPerUnit: [1 / altUnitsPerMeter, 1 / altUnitsPerMeter, 1 / altUnitsPerMeter],\n\n unitsPerDegree: [unitsPerDegreeX, unitsPerDegreeY, altUnitsPerMeter],\n degreesPerUnit: [1 / unitsPerDegreeX, 1 / unitsPerDegreeY, 1 / altUnitsPerMeter]\n };\n\n /**\n * Taylor series 2nd order for 1/latCosine\n f'(a) * (x - a)\n = d(1/cos(lat * DEGREES_TO_RADIANS))/d(lat) * dLat\n = DEGREES_TO_RADIANS * tan(lat * DEGREES_TO_RADIANS) / cos(lat * DEGREES_TO_RADIANS) * dLat\n */\n if (highPrecision) {\n const latCosine2 = (DEGREES_TO_RADIANS * Math.tan(latitude * DEGREES_TO_RADIANS)) / latCosine;\n const unitsPerDegreeY2 = (unitsPerDegreeX * latCosine2) / 2;\n const altUnitsPerDegree2 = (worldSize / EARTH_CIRCUMFERENCE) * latCosine2;\n const altUnitsPerMeter2 = (altUnitsPerDegree2 / unitsPerDegreeY) * altUnitsPerMeter;\n\n result.unitsPerDegree2 = [0, unitsPerDegreeY2, altUnitsPerDegree2];\n result.unitsPerMeter2 = [altUnitsPerMeter2, 0, altUnitsPerMeter2];\n }\n\n // Main results, used for converting meters to latlng deltas and scaling offsets\n return result;\n}\n\n/**\n * Offset a lng/lat position by meterOffset (northing, easting)\n */\nexport function addMetersToLngLat(lngLatZ: number[], xyz: number[]): number[] {\n const [longitude, latitude, z0] = lngLatZ;\n const [x, y, z] = xyz;\n\n const {unitsPerMeter, unitsPerMeter2} = getDistanceScales({\n longitude,\n latitude,\n highPrecision: true\n });\n\n const worldspace = lngLatToWorld(lngLatZ);\n worldspace[0] += x * (unitsPerMeter[0] + unitsPerMeter2[0] * y);\n worldspace[1] += y * (unitsPerMeter[1] + unitsPerMeter2[1] * y);\n\n const newLngLat = worldToLngLat(worldspace);\n const newZ = (z0 || 0) + (z || 0);\n\n return Number.isFinite(z0) || Number.isFinite(z) ? [newLngLat[0], newLngLat[1], newZ] : newLngLat;\n}\n\n/**\n *\n * view and projection matrix creation is intentionally kept compatible with\n * mapbox-gl's implementation to ensure that seamless interoperation\n * with mapbox and react-map-gl. See: https://github.com/mapbox/mapbox-gl-js\n */\nexport function getViewMatrix(options: {\n // Viewport props\n height: number;\n pitch: number;\n bearing: number;\n altitude: number;\n // Pre-calculated parameters\n scale: number;\n center?: number[];\n}): number[] {\n const {\n // Viewport props\n height,\n pitch,\n bearing,\n altitude,\n // Pre-calculated parameters\n scale,\n center\n } = options;\n // VIEW MATRIX: PROJECTS MERCATOR WORLD COORDINATES\n // Note that mercator world coordinates typically need to be flipped\n //\n // Note: As usual, matrix operation orders should be read in reverse\n // since vectors will be multiplied from the right during transformation\n const vm = createMat4();\n\n // Move camera to altitude (along the pitch & bearing direction)\n mat4.translate(vm, vm, [0, 0, -altitude]);\n\n // Rotate by bearing, and then by pitch (which tilts the view)\n mat4.rotateX(vm, vm, -pitch * DEGREES_TO_RADIANS);\n mat4.rotateZ(vm, vm, bearing * DEGREES_TO_RADIANS);\n\n const relativeScale = scale / height;\n mat4.scale(vm, vm, [relativeScale, relativeScale, relativeScale]);\n\n if (center) {\n mat4.translate(vm, vm, vec3.negate([], center));\n }\n\n return vm;\n}\n\n/**\n * Calculates mapbox compatible projection matrix from parameters\n *\n * @param options.width Width of \"viewport\" or window\n * @param options.height Height of \"viewport\" or window\n * @param options.scale Scale at the current zoom\n * @param options.center Offset of the target, vec3 in world space\n * @param options.offset Offset of the focal point, vec2 in screen space\n * @param options.pitch Camera angle in degrees (0 is straight down)\n * @param options.fovy field of view in degrees\n * @param options.altitude if provided, field of view is calculated using `altitudeToFovy()`\n * @param options.nearZMultiplier control z buffer\n * @param options.farZMultiplier control z buffer\n * @returns project parameters object\n */\nexport function getProjectionParameters(options: {\n width: number;\n height: number;\n scale?: number;\n center?: number[];\n offset?: [number, number];\n fovy?: number;\n altitude?: number;\n pitch?: number;\n nearZMultiplier?: number;\n farZMultiplier?: number;\n}): ProjectionParameters {\n const {\n width,\n height,\n altitude,\n pitch = 0,\n offset,\n center,\n scale,\n nearZMultiplier = 1,\n farZMultiplier = 1\n } = options;\n let {fovy = altitudeToFovy(DEFAULT_ALTITUDE)} = options;\n\n // For back-compatibility allow field of view to be\n // derived from altitude\n if (altitude !== undefined) {\n fovy = altitudeToFovy(altitude);\n }\n\n const fovRadians = fovy * DEGREES_TO_RADIANS;\n const pitchRadians = pitch * DEGREES_TO_RADIANS;\n\n // Distance from camera to the target\n const focalDistance = fovyToAltitude(fovy);\n\n let cameraToSeaLevelDistance = focalDistance;\n\n if (center) {\n cameraToSeaLevelDistance += (center[2] * scale) / Math.cos(pitchRadians) / height;\n }\n\n const fovAboveCenter = fovRadians * (0.5 + (offset ? offset[1] : 0) / height);\n\n // Find the distance from the center point to the center top\n // in focal distance units using law of sines.\n const topHalfSurfaceDistance =\n (Math.sin(fovAboveCenter) * cameraToSeaLevelDistance) /\n Math.sin(clamp(Math.PI / 2 - pitchRadians - fovAboveCenter, 0.01, Math.PI - 0.01));\n\n // Calculate z distance of the farthest fragment that should be rendered.\n const furthestDistance =\n Math.sin(pitchRadians) * topHalfSurfaceDistance + cameraToSeaLevelDistance;\n // Matches mapbox limit\n const horizonDistance = cameraToSeaLevelDistance * 10;\n\n // Calculate z value of the farthest fragment that should be rendered.\n const farZ = Math.min(furthestDistance * farZMultiplier, horizonDistance);\n\n return {\n fov: fovRadians,\n aspect: width / height,\n focalDistance,\n near: nearZMultiplier,\n far: farZ\n };\n}\n\n/**\n * CALCULATE PROJECTION MATRIX: PROJECTS FROM CAMERA (VIEW) SPACE TO CLIPSPACE\n *\n * To match mapbox's z buffer:\n * - \\<= 0.28: nearZMultiplier: 0.1, farZmultiplier: 1\n * - \\>= 0.29: nearZMultiplier: 1 / height, farZMultiplier: 1.01\n *\n * @param options Viewport options\n * @param options.width Width of \"viewport\" or window\n * @param options.height Height of \"viewport\" or window\n * @param options.scale Scale at the current zoom\n * @param options.center Offset of the target, vec3 in world space\n * @param options.offset Offset of the focal point, vec2 in screen space\n * @param options.pitch Camera angle in degrees (0 is straight down)\n * @param options.fovy field of view in degrees\n * @param options.altitude if provided, field of view is calculated using `altitudeToFovy()`\n * @param options.nearZMultiplier control z buffer\n * @param options.farZMultiplier control z buffer\n * @returns 4x4 projection matrix\n */\nexport function getProjectionMatrix(options: {\n width: number;\n height: number;\n pitch: number;\n scale?: number;\n center?: number[];\n offset?: [number, number];\n fovy?: number;\n altitude?: number;\n nearZMultiplier: number;\n farZMultiplier: number;\n}): number[] {\n const {fov, aspect, near, far} = getProjectionParameters(options);\n\n const projectionMatrix = mat4.perspective(\n [] as number[],\n fov, // fov in radians\n aspect, // aspect ratio\n near, // near plane\n far // far plane\n );\n\n return projectionMatrix;\n}\n\n/**\n *\n * Convert an altitude to field of view such that the\n * focal distance is equal to the altitude\n *\n * @param altitude - altitude of camera in screen units\n * @return fovy field of view in degrees\n */\nexport function altitudeToFovy(altitude: number): number {\n return 2 * Math.atan(0.5 / altitude) * RADIANS_TO_DEGREES;\n}\n\n/**\n *\n * Convert an field of view such that the\n * focal distance is equal to the altitude\n *\n * @param fovy - field of view in degrees\n * @return altitude altitude of camera in screen units\n */\nexport function fovyToAltitude(fovy: number): number {\n return 0.5 / Math.tan(0.5 * fovy * DEGREES_TO_RADIANS);\n}\n\n/**\n * Project flat coordinates to pixels on screen.\n *\n * @param xyz - flat coordinate on 512*512 Mercator Zoom 0 tile\n * @param pixelProjectionMatrix - projection matrix 4x4\n * @return [x, y, depth] pixel coordinate on screen.\n */\nexport function worldToPixels(xyz: number[], pixelProjectionMatrix: number[]): number[];\n\n// Project flat coordinates to pixels on screen.\nexport function worldToPixels(xyz: number[], pixelProjectionMatrix: number[]): number[] {\n const [x, y, z = 0] = xyz;\n assert(Number.isFinite(x) && Number.isFinite(y) && Number.isFinite(z));\n\n return transformVector(pixelProjectionMatrix, [x, y, z, 1]);\n}\n\n/**\n * Unproject pixels on screen to flat coordinates.\n *\n * @param xyz - pixel coordinate on screen.\n * @param pixelUnprojectionMatrix - unprojection matrix 4x4\n * @param targetZ - if pixel coordinate does not have a 3rd component (depth),\n * targetZ is used as the elevation plane to unproject onto\n * @return [x, y, Z] flat coordinates on 512*512 Mercator Zoom 0 tile.\n */\nexport function pixelsToWorld(\n xyz: number[],\n pixelUnprojectionMatrix: number[],\n targetZ: number = 0\n): number[] {\n const [x, y, z] = xyz;\n assert(Number.isFinite(x) && Number.isFinite(y), 'invalid pixel coordinate');\n\n if (Number.isFinite(z)) {\n // Has depth component\n const coord = transformVector(pixelUnprojectionMatrix, [x, y, z, 1]);\n return coord;\n }\n\n // since we don't know the correct projected z value for the point,\n // unproject two points to get a line and then find the point on that line with z=0\n const coord0 = transformVector(pixelUnprojectionMatrix, [x, y, 0, 1]);\n const coord1 = transformVector(pixelUnprojectionMatrix, [x, y, 1, 1]);\n\n const z0 = coord0[2];\n const z1 = coord1[2];\n\n const t = z0 === z1 ? 0 : ((targetZ || 0) - z0) / (z1 - z0);\n return vec2.lerp([] as number[], coord0, coord1, t);\n}\n"],"file":"web-mercator-utils.js"}
1
+ {"version":3,"sources":["../src/web-mercator-utils.ts"],"names":["createMat4","transformVector","clamp","log2","mat4","vec2","vec3","assert","PI","Math","PI_4","DEGREES_TO_RADIANS","RADIANS_TO_DEGREES","TILE_SIZE","EARTH_CIRCUMFERENCE","MAX_LATITUDE","DEFAULT_ALTITUDE","zoomToScale","zoom","pow","scaleToZoom","scale","lngLatToWorld","lngLat","lng","lat","Number","isFinite","lambda2","phi2","x","y","log","tan","worldToLngLat","xy","atan","exp","getMeterZoom","options","latitude","latCosine","cos","unitsPerMeter","getDistanceScales","longitude","highPrecision","worldSize","unitsPerDegreeX","unitsPerDegreeY","altUnitsPerMeter","result","metersPerUnit","unitsPerDegree","degreesPerUnit","latCosine2","unitsPerDegreeY2","altUnitsPerDegree2","altUnitsPerMeter2","unitsPerDegree2","unitsPerMeter2","addMetersToLngLat","lngLatZ","xyz","z0","z","worldspace","newLngLat","newZ","getViewMatrix","height","pitch","bearing","altitude","center","vm","translate","rotateX","rotateZ","relativeScale","negate","getProjectionParameters","width","offset","nearZMultiplier","farZMultiplier","fovy","altitudeToFovy","undefined","fovRadians","pitchRadians","focalDistance","fovyToAltitude","cameraToSeaLevelDistance","fovAboveCenter","topHalfSurfaceDistance","sin","furthestDistance","horizonDistance","farZ","min","fov","aspect","near","far","getProjectionMatrix","projectionMatrix","perspective","worldToPixels","pixelProjectionMatrix","pixelsToWorld","pixelUnprojectionMatrix","targetZ","coord","coord0","coord1","z1","t","lerp"],"mappings":"SAEQA,U,EAAYC,e,EAAiBC,K,EAAOC,I;AAE5C,SAAQC,IAAR,EAAcC,IAAd,EAAoBC,IAApB,QAA+B,eAA/B;SACQC,M;AAGR,MAAMC,EAAE,GAAGC,IAAI,CAACD,EAAhB;AACA,MAAME,IAAI,GAAGF,EAAE,GAAG,CAAlB;AACA,MAAMG,kBAAkB,GAAGH,EAAE,GAAG,GAAhC;AACA,MAAMI,kBAAkB,GAAG,MAAMJ,EAAjC;AACA,MAAMK,SAAS,GAAG,GAAlB;AAEA,MAAMC,mBAAmB,GAAG,OAA5B;AAEA,OAAO,MAAMC,YAAY,GAAG,SAArB;AAGP,OAAO,MAAMC,gBAAgB,GAAG,GAAzB;AA8BP,OAAO,SAASC,WAAT,CAAqBC,IAArB,EAA2C;AAChD,SAAOT,IAAI,CAACU,GAAL,CAAS,CAAT,EAAYD,IAAZ,CAAP;AACD;AAGD,OAAO,SAASE,WAAT,CAAqBC,KAArB,EAA4C;AACjD,SAAOlB,IAAI,CAACkB,KAAD,CAAX;AACD;A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kD,MAAM,CAAC,CAAD,CAAjB;AACA,QAAME,EAAE,GAAGD,MAAM,CAAC,CAAD,CAAjB;AAEA,QAAME,CAAC,GAAGrD,EAAE,KAAKoD,EAAP,GAAY,CAAZ,GAAgB,CAAC,CAACJ,OAAO,IAAI,CAAZ,IAAiBhD,EAAlB,KAAyBoD,EAAE,GAAGpD,EAA9B,CAA1B;AACA,SAAO3D,IAAI,CAACiH,IAAL,CAAU,EAAV,EAA0BJ,MAA1B,EAAkCC,MAAlC,EAA0CE,CAA1C,CAAP;AACD","sourcesContent":["// TODO - THE UTILITIES IN THIS FILE SHOULD BE IMPORTED FROM WEB-MERCATOR-VIEWPORT MODULE\n\nimport {createMat4, transformVector, clamp, log2} from './math-utils';\n\nimport {mat4, vec2, vec3} from '@math.gl/core';\nimport {assert} from './assert';\n\n// CONSTANTS\nconst PI = Math.PI;\nconst PI_4 = PI / 4;\nconst DEGREES_TO_RADIANS = PI / 180;\nconst RADIANS_TO_DEGREES = 180 / PI;\nconst TILE_SIZE = 512;\n// Average circumference (40075 km equatorial, 40007 km meridional)\nconst EARTH_CIRCUMFERENCE = 40.03e6;\n// Latitude that makes a square world, 2 * atan(E ** PI) - PI / 2\nexport const MAX_LATITUDE = 85.051129;\n\n// Mapbox default altitude\nexport const DEFAULT_ALTITUDE = 1.5;\n\nexport type DistanceScales = {\n unitsPerMeter: number[];\n metersPerUnit: number[];\n unitsPerMeter2?: number[];\n unitsPerDegree: number[];\n degreesPerUnit: number[];\n unitsPerDegree2?: number[];\n};\n\n/**\n * PROJECTION MATRIX PARAMETERS\n *\n * TODO how to document mebers\n * @param fov in radians. fov is variable, depends on pitch and altitude\n * @param aspect width/height\n * @param focalDistance distance at which visual scale factor is 1\n * @param near near clipping plane\n * @param far far clipping plane\n */\ntype ProjectionParameters = {\n fov: number;\n aspect: number;\n focalDistance: number;\n near: number;\n far: number;\n};\n\n/** Logarithimic zoom to linear scale **/\nexport function zoomToScale(zoom: number): number {\n return Math.pow(2, zoom);\n}\n\n/** Linear scale to logarithimic zoom **/\nexport function scaleToZoom(scale: number): number {\n return log2(scale);\n}\n\n/**\n * Project [lng,lat] on sphere onto [x,y] on 512*512 Mercator Zoom 0 tile.\n * Performs the nonlinear part of the web mercator projection.\n * Remaining projection is done with 4x4 matrices which also handles\n * perspective.\n *\n * @param lngLat - [lng, lat] coordinates\n * Specifies a point on the sphere to project onto the map.\n * @return [x,y] coordinates.\n */\nexport function lngLatToWorld(lngLat: number[]): [number, number] {\n const [lng, lat] = lngLat;\n assert(Number.isFinite(lng));\n assert(Number.isFinite(lat) && lat >= -90 && lat <= 90, 'invalid latitude');\n\n const lambda2 = lng * DEGREES_TO_RADIANS;\n const phi2 = lat * DEGREES_TO_RADIANS;\n const x = (TILE_SIZE * (lambda2 + PI)) / (2 * PI);\n const y = (TILE_SIZE * (PI + Math.log(Math.tan(PI_4 + phi2 * 0.5)))) / (2 * PI);\n return [x, y];\n}\n\n/**\n * Unproject world point [x,y] on map onto {lat, lon} on sphere\n *\n * @param xy - array with [x,y] members\n * representing point on projected map plane\n * @return - array with [x,y] of point on sphere.\n * Has toArray method if you need a GeoJSON Array.\n * Per cartographic tradition, lat and lon are specified as degrees.\n */\nexport function worldToLngLat(xy: number[]): [number, number] {\n const [x, y] = xy;\n const lambda2 = (x / TILE_SIZE) * (2 * PI) - PI;\n const phi2 = 2 * (Math.atan(Math.exp((y / TILE_SIZE) * (2 * PI) - PI)) - PI_4);\n return [lambda2 * RADIANS_TO_DEGREES, phi2 * RADIANS_TO_DEGREES];\n}\n\n/**\n * Returns the zoom level that gives a 1 meter pixel at a certain latitude\n * 1 = C*cos(y)/2^z/TILE_SIZE = C*cos(y)/2^(z+9)\n */\nexport function getMeterZoom(options: {latitude: number}): number {\n const {latitude} = options;\n assert(Number.isFinite(latitude));\n const latCosine = Math.cos(latitude * DEGREES_TO_RADIANS);\n return scaleToZoom(EARTH_CIRCUMFERENCE * latCosine) - 9;\n}\n\n/**\n * Calculate the conversion from meter to common units at a given latitude\n * This is a cheaper version of `getDistanceScales`\n * @param latitude center latitude in degrees\n * @returns common units per meter\n */\nexport function unitsPerMeter(latitude: number): number {\n const latCosine = Math.cos(latitude * DEGREES_TO_RADIANS);\n return TILE_SIZE / EARTH_CIRCUMFERENCE / latCosine;\n}\n\n/**\n * Calculate distance scales in meters around current lat/lon, both for\n * degrees and pixels.\n * In mercator projection mode, the distance scales vary significantly\n * with latitude.\n */\nexport function getDistanceScales(options: {\n latitude: number;\n longitude: number;\n highPrecision?: boolean;\n}): DistanceScales {\n const {latitude, longitude, highPrecision = false} = options;\n assert(Number.isFinite(latitude) && Number.isFinite(longitude));\n\n const worldSize = TILE_SIZE;\n const latCosine = Math.cos(latitude * DEGREES_TO_RADIANS);\n\n /**\n * Number of pixels occupied by one degree longitude around current lat/lon:\n unitsPerDegreeX = d(lngLatToWorld([lng, lat])[0])/d(lng)\n = scale * TILE_SIZE * DEGREES_TO_RADIANS / (2 * PI)\n unitsPerDegreeY = d(lngLatToWorld([lng, lat])[1])/d(lat)\n = -scale * TILE_SIZE * DEGREES_TO_RADIANS / cos(lat * DEGREES_TO_RADIANS) / (2 * PI)\n */\n const unitsPerDegreeX = worldSize / 360;\n const unitsPerDegreeY = unitsPerDegreeX / latCosine;\n\n /**\n * Number of pixels occupied by one meter around current lat/lon:\n */\n const altUnitsPerMeter = worldSize / EARTH_CIRCUMFERENCE / latCosine;\n\n /**\n * LngLat: longitude -> east and latitude -> north (bottom left)\n * UTM meter offset: x -> east and y -> north (bottom left)\n * World space: x -> east and y -> south (top left)\n *\n * Y needs to be flipped when converting delta degree/meter to delta pixels\n */\n const result: DistanceScales = {\n unitsPerMeter: [altUnitsPerMeter, altUnitsPerMeter, altUnitsPerMeter],\n metersPerUnit: [1 / altUnitsPerMeter, 1 / altUnitsPerMeter, 1 / altUnitsPerMeter],\n\n unitsPerDegree: [unitsPerDegreeX, unitsPerDegreeY, altUnitsPerMeter],\n degreesPerUnit: [1 / unitsPerDegreeX, 1 / unitsPerDegreeY, 1 / altUnitsPerMeter]\n };\n\n /**\n * Taylor series 2nd order for 1/latCosine\n f'(a) * (x - a)\n = d(1/cos(lat * DEGREES_TO_RADIANS))/d(lat) * dLat\n = DEGREES_TO_RADIANS * tan(lat * DEGREES_TO_RADIANS) / cos(lat * DEGREES_TO_RADIANS) * dLat\n */\n if (highPrecision) {\n const latCosine2 = (DEGREES_TO_RADIANS * Math.tan(latitude * DEGREES_TO_RADIANS)) / latCosine;\n const unitsPerDegreeY2 = (unitsPerDegreeX * latCosine2) / 2;\n const altUnitsPerDegree2 = (worldSize / EARTH_CIRCUMFERENCE) * latCosine2;\n const altUnitsPerMeter2 = (altUnitsPerDegree2 / unitsPerDegreeY) * altUnitsPerMeter;\n\n result.unitsPerDegree2 = [0, unitsPerDegreeY2, altUnitsPerDegree2];\n result.unitsPerMeter2 = [altUnitsPerMeter2, 0, altUnitsPerMeter2];\n }\n\n // Main results, used for converting meters to latlng deltas and scaling offsets\n return result;\n}\n\n/**\n * Offset a lng/lat position by meterOffset (northing, easting)\n */\nexport function addMetersToLngLat(lngLatZ: number[], xyz: number[]): number[] {\n const [longitude, latitude, z0] = lngLatZ;\n const [x, y, z] = xyz;\n\n const {unitsPerMeter, unitsPerMeter2} = getDistanceScales({\n longitude,\n latitude,\n highPrecision: true\n });\n\n const worldspace = lngLatToWorld(lngLatZ);\n worldspace[0] += x * (unitsPerMeter[0] + unitsPerMeter2[0] * y);\n worldspace[1] += y * (unitsPerMeter[1] + unitsPerMeter2[1] * y);\n\n const newLngLat = worldToLngLat(worldspace);\n const newZ = (z0 || 0) + (z || 0);\n\n return Number.isFinite(z0) || Number.isFinite(z) ? [newLngLat[0], newLngLat[1], newZ] : newLngLat;\n}\n\n/**\n *\n * view and projection matrix creation is intentionally kept compatible with\n * mapbox-gl's implementation to ensure that seamless interoperation\n * with mapbox and react-map-gl. See: https://github.com/mapbox/mapbox-gl-js\n */\nexport function getViewMatrix(options: {\n // Viewport props\n height: number;\n pitch: number;\n bearing: number;\n altitude: number;\n // Pre-calculated parameters\n scale: number;\n center?: number[];\n}): number[] {\n const {\n // Viewport props\n height,\n pitch,\n bearing,\n altitude,\n // Pre-calculated parameters\n scale,\n center\n } = options;\n // VIEW MATRIX: PROJECTS MERCATOR WORLD COORDINATES\n // Note that mercator world coordinates typically need to be flipped\n //\n // Note: As usual, matrix operation orders should be read in reverse\n // since vectors will be multiplied from the right during transformation\n const vm = createMat4();\n\n // Move camera to altitude (along the pitch & bearing direction)\n mat4.translate(vm, vm, [0, 0, -altitude]);\n\n // Rotate by bearing, and then by pitch (which tilts the view)\n mat4.rotateX(vm, vm, -pitch * DEGREES_TO_RADIANS);\n mat4.rotateZ(vm, vm, bearing * DEGREES_TO_RADIANS);\n\n const relativeScale = scale / height;\n mat4.scale(vm, vm, [relativeScale, relativeScale, relativeScale]);\n\n if (center) {\n mat4.translate(vm, vm, vec3.negate([], center));\n }\n\n return vm;\n}\n\n/**\n * Calculates mapbox compatible projection matrix from parameters\n *\n * @param options.width Width of \"viewport\" or window\n * @param options.height Height of \"viewport\" or window\n * @param options.scale Scale at the current zoom\n * @param options.center Offset of the target, vec3 in world space\n * @param options.offset Offset of the focal point, vec2 in screen space\n * @param options.pitch Camera angle in degrees (0 is straight down)\n * @param options.fovy field of view in degrees\n * @param options.altitude if provided, field of view is calculated using `altitudeToFovy()`\n * @param options.nearZMultiplier control z buffer\n * @param options.farZMultiplier control z buffer\n * @returns project parameters object\n */\nexport function getProjectionParameters(options: {\n width: number;\n height: number;\n scale?: number;\n center?: number[];\n offset?: [number, number];\n fovy?: number;\n altitude?: number;\n pitch?: number;\n nearZMultiplier?: number;\n farZMultiplier?: number;\n}): ProjectionParameters {\n const {\n width,\n height,\n altitude,\n pitch = 0,\n offset,\n center,\n scale,\n nearZMultiplier = 1,\n farZMultiplier = 1\n } = options;\n let {fovy = altitudeToFovy(DEFAULT_ALTITUDE)} = options;\n\n // For back-compatibility allow field of view to be\n // derived from altitude\n if (altitude !== undefined) {\n fovy = altitudeToFovy(altitude);\n }\n\n const fovRadians = fovy * DEGREES_TO_RADIANS;\n const pitchRadians = pitch * DEGREES_TO_RADIANS;\n\n // Distance from camera to the target\n const focalDistance = fovyToAltitude(fovy);\n\n let cameraToSeaLevelDistance = focalDistance;\n\n if (center) {\n cameraToSeaLevelDistance += (center[2] * scale) / Math.cos(pitchRadians) / height;\n }\n\n const fovAboveCenter = fovRadians * (0.5 + (offset ? offset[1] : 0) / height);\n\n // Find the distance from the center point to the center top\n // in focal distance units using law of sines.\n const topHalfSurfaceDistance =\n (Math.sin(fovAboveCenter) * cameraToSeaLevelDistance) /\n Math.sin(clamp(Math.PI / 2 - pitchRadians - fovAboveCenter, 0.01, Math.PI - 0.01));\n\n // Calculate z distance of the farthest fragment that should be rendered.\n const furthestDistance =\n Math.sin(pitchRadians) * topHalfSurfaceDistance + cameraToSeaLevelDistance;\n // Matches mapbox limit\n const horizonDistance = cameraToSeaLevelDistance * 10;\n\n // Calculate z value of the farthest fragment that should be rendered.\n const farZ = Math.min(furthestDistance * farZMultiplier, horizonDistance);\n\n return {\n fov: fovRadians,\n aspect: width / height,\n focalDistance,\n near: nearZMultiplier,\n far: farZ\n };\n}\n\n/**\n * CALCULATE PROJECTION MATRIX: PROJECTS FROM CAMERA (VIEW) SPACE TO CLIPSPACE\n *\n * To match mapbox's z buffer:\n * - \\<= 0.28: nearZMultiplier: 0.1, farZmultiplier: 1\n * - \\>= 0.29: nearZMultiplier: 1 / height, farZMultiplier: 1.01\n *\n * @param options Viewport options\n * @param options.width Width of \"viewport\" or window\n * @param options.height Height of \"viewport\" or window\n * @param options.scale Scale at the current zoom\n * @param options.center Offset of the target, vec3 in world space\n * @param options.offset Offset of the focal point, vec2 in screen space\n * @param options.pitch Camera angle in degrees (0 is straight down)\n * @param options.fovy field of view in degrees\n * @param options.altitude if provided, field of view is calculated using `altitudeToFovy()`\n * @param options.nearZMultiplier control z buffer\n * @param options.farZMultiplier control z buffer\n * @returns 4x4 projection matrix\n */\nexport function getProjectionMatrix(options: {\n width: number;\n height: number;\n pitch: number;\n scale?: number;\n center?: number[];\n offset?: [number, number];\n fovy?: number;\n altitude?: number;\n nearZMultiplier: number;\n farZMultiplier: number;\n}): number[] {\n const {fov, aspect, near, far} = getProjectionParameters(options);\n\n const projectionMatrix = mat4.perspective(\n [] as number[],\n fov, // fov in radians\n aspect, // aspect ratio\n near, // near plane\n far // far plane\n );\n\n return projectionMatrix;\n}\n\n/**\n *\n * Convert an altitude to field of view such that the\n * focal distance is equal to the altitude\n *\n * @param altitude - altitude of camera in screen units\n * @return fovy field of view in degrees\n */\nexport function altitudeToFovy(altitude: number): number {\n return 2 * Math.atan(0.5 / altitude) * RADIANS_TO_DEGREES;\n}\n\n/**\n *\n * Convert an field of view such that the\n * focal distance is equal to the altitude\n *\n * @param fovy - field of view in degrees\n * @return altitude altitude of camera in screen units\n */\nexport function fovyToAltitude(fovy: number): number {\n return 0.5 / Math.tan(0.5 * fovy * DEGREES_TO_RADIANS);\n}\n\n/**\n * Project flat coordinates to pixels on screen.\n *\n * @param xyz - flat coordinate on 512*512 Mercator Zoom 0 tile\n * @param pixelProjectionMatrix - projection matrix 4x4\n * @return [x, y, depth] pixel coordinate on screen.\n */\nexport function worldToPixels(xyz: number[], pixelProjectionMatrix: number[]): number[];\n\n// Project flat coordinates to pixels on screen.\nexport function worldToPixels(xyz: number[], pixelProjectionMatrix: number[]): number[] {\n const [x, y, z = 0] = xyz;\n assert(Number.isFinite(x) && Number.isFinite(y) && Number.isFinite(z));\n\n return transformVector(pixelProjectionMatrix, [x, y, z, 1]);\n}\n\n/**\n * Unproject pixels on screen to flat coordinates.\n *\n * @param xyz - pixel coordinate on screen.\n * @param pixelUnprojectionMatrix - unprojection matrix 4x4\n * @param targetZ - if pixel coordinate does not have a 3rd component (depth),\n * targetZ is used as the elevation plane to unproject onto\n * @return [x, y, Z] flat coordinates on 512*512 Mercator Zoom 0 tile.\n */\nexport function pixelsToWorld(\n xyz: number[],\n pixelUnprojectionMatrix: number[],\n targetZ: number = 0\n): number[] {\n const [x, y, z] = xyz;\n assert(Number.isFinite(x) && Number.isFinite(y), 'invalid pixel coordinate');\n\n if (Number.isFinite(z)) {\n // Has depth component\n const coord = transformVector(pixelUnprojectionMatrix, [x, y, z, 1]);\n return coord;\n }\n\n // since we don't know the correct projected z value for the point,\n // unproject two points to get a line and then find the point on that line with z=0\n const coord0 = transformVector(pixelUnprojectionMatrix, [x, y, 0, 1]);\n const coord1 = transformVector(pixelUnprojectionMatrix, [x, y, 1, 1]);\n\n const z0 = coord0[2];\n const z1 = coord1[2];\n\n const t = z0 === z1 ? 0 : ((targetZ || 0) - z0) / (z1 - z0);\n return vec2.lerp([] as number[], coord0, coord1, t);\n}\n"],"file":"web-mercator-utils.js"}
@@ -1 +1 @@
1
- {"version":3,"file":"web-mercator-viewport.d.ts","sourceRoot":"","sources":["../src/web-mercator-viewport.ts"],"names":[],"mappings":"AAGA,OAAO,EAYL,cAAc,EACf,MAAM,sBAAsB,CAAC;AAG9B,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,cAAc,CAAC;AAMnD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,oBAAY,wBAAwB,GAAG;IAErC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF;;;;;;;GAOG;AACH,qBAAa,mBAAmB;IAC9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EAAE,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAC5C,OAAO,GAAE,IAAI,CAAC,gBAAgB,EAAE,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAM,GAClE,mBAAmB;IAMtB;;;;;OAKG;IACH,SAAS,CAAC,OAAO,CAAC,EAAE;QAAC,CAAC,CAAC,EAAE,MAAM,CAAA;KAAC,GAAG,MAAM,EAAE,EAAE;IAa7C;;;;;OAKG;IACH,iBAAiB,CAAC,OAAO,GAAE;QAAC,CAAC,CAAC,EAAE,MAAM,CAAA;KAAM,GAAG,MAAM,EAAE,EAAE;IAMzD,qCAAqC;IACrC,kBAAkB,CAAC,EAAC,MAAM,EAAE,GAAG,EAAC,EAAE;QAAC,MAAM,EAAE,MAAM,EAAE,CAAC;QAAC,GAAG,EAAE,MAAM,EAAE,CAAA;KAAC,GAAG,MAAM,EAAE;CAG/E"}
@@ -3,9 +3,7 @@ import { createMat4 } from "./math-utils.js";
3
3
  import { zoomToScale, pixelsToWorld, lngLatToWorld, worldToLngLat, worldToPixels, altitudeToFovy, fovyToAltitude, DEFAULT_ALTITUDE, getProjectionMatrix, getDistanceScales, getViewMatrix } from "./web-mercator-utils.js";
4
4
  import { fitBounds } from "./fit-bounds.js";
5
5
  import { getBounds } from "./get-bounds.js";
6
- import * as mat4 from 'gl-matrix/mat4';
7
- import * as vec2 from 'gl-matrix/vec2';
8
- import * as vec3 from 'gl-matrix/vec3';
6
+ import { mat4, vec2, vec3 } from '@math.gl/core';
9
7
  export class WebMercatorViewport {
10
8
  constructor(props = {
11
9
  width: 1,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/web-mercator-viewport.ts"],"names":["createMat4","zoomToScale","pixelsToWorld","lngLatToWorld","worldToLngLat","worldToPixels","altitudeToFovy","fovyToAltitude","DEFAULT_ALTITUDE","getProjectionMatrix","getDistanceScales","getViewMatrix","fitBounds","getBounds","mat4","vec2","vec3","WebMercatorViewport","constructor","props","width","height","viewport","equals","projectionMatrix","viewMatrix","lngLatZ","options","topLeft","worldPosition","projectPosition","coord","pixelProjectionMatrix","x","y","y2","length","xyz","targetZ","undefined","z","targetZWorld","distanceScales","unitsPerMeter","pixelUnprojectionMatrix","X","Y","Z","unprojectPosition","Number","isFinite","metersPerUnit","altitude","fovy","latitude","longitude","zoom","pitch","bearing","position","nearZMultiplier","farZMultiplier","scale","Math","max","center","push","add","mul","meterOffset","_initMatrices","Object","freeze","vpm","multiply","viewProjectionMatrix","m","translate","mInverse","invert","Error","projectFlat","lngLat","unprojectFlat","xy","getMapCenterByLngLatPosition","pos","fromLocation","toLocation","negate","newCenter","bounds","assign","corners","getBoundingRegion","west","min","map","p","east","south","north","getLocationAtPoint"],"mappings":";SACQA,U;SAGNC,W,EACAC,a,EACAC,a,EACAC,a,EACAC,a,EACAC,c,EACAC,c,EACAC,gB,EACAC,mB,EACAC,iB,EACAC,a;SAGMC,S;SACAC,S;AAGR,OAAO,KAAKC,IAAZ,MAAsB,gBAAtB;AACA,OAAO,KAAKC,IAAZ,MAAsB,gBAAtB;AACA,OAAO,KAAKC,IAAZ,MAAsB,gBAAtB;AAiDA,OAAO,MAAMC,mBAAN,CAA0B;AA+B/BC,EAAAA,WAAW,CAACC,KAA+B,GAAG;AAACC,IAAAA,KAAK,EAAE,CAAR;AAAWC,IAAAA,MAAM,EAAE;AAAnB,GAAnC,EAA0D;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA,oCAkI3DC,QAAD,IAAmD;AAC1D,UAAI,EAAEA,QAAQ,YAAYL,mBAAtB,CAAJ,EAAgD;AAC9C,eAAO,KAAP;AACD;;AAED,aACEK,QAAQ,CAACF,KAAT,KAAmB,KAAKA,KAAxB,IACAE,QAAQ,CAACD,MAAT,KAAoB,KAAKA,MADzB,IAEAP,IAAI,CAACS,MAAL,CAA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,GAAGtC,IAAI,CAACC,GAAL,CAAS,GAAG6B,OAAO,CAACI,GAAR,CAAaC,CAAD,IAAOA,CAAC,CAAC,CAAD,CAApB,CAAZ,CAAd;AACA,WAAO,CACL,CAACH,IAAD,EAAOK,KAAP,CADK,EAEL,CAACD,IAAD,EAAOE,KAAP,CAFK,CAAP;AAID;;AAQDP,EAAAA,iBAAiB,CAACnE,OAAqB,GAAG,EAAzB,EAAyC;AACxD,WAAOd,SAAS,CAAC,IAAD,EAAOc,OAAO,CAACa,CAAR,IAAa,CAApB,CAAhB;AACD;;AAKD8D,EAAAA,kBAAkB,CAAC;AAACpB,IAAAA,MAAD;AAASI,IAAAA;AAAT,GAAD,EAA6D;AAC7E,WAAO,KAAKD,4BAAL,CAAkC;AAACH,MAAAA,MAAD;AAASI,MAAAA;AAAT,KAAlC,CAAP;AACD;;AAhV8B","sourcesContent":["// View and Projection Matrix calculations for mapbox-js style map view properties\nimport {createMat4} from './math-utils';\n\nimport {\n zoomToScale,\n pixelsToWorld,\n lngLatToWorld,\n worldToLngLat,\n worldToPixels,\n altitudeToFovy,\n fovyToAltitude,\n DEFAULT_ALTITUDE,\n getProjectionMatrix,\n getDistanceScales,\n getViewMatrix,\n DistanceScales\n} from './web-mercator-utils';\nimport {fitBounds} from './fit-bounds';\nimport {getBounds} from './get-bounds';\nimport type {FitBoundsOptions} from './fit-bounds';\n\nimport * as mat4 from 'gl-matrix/mat4';\nimport * as vec2 from 'gl-matrix/vec2';\nimport * as vec3 from 'gl-matrix/vec3';\n\n/**\n * @param width=1 - Width of \"viewport\" or window\n * @param height=1 - Height of \"viewport\" or window\n * @param scale=1 - Either use scale or zoom\n * @param pitch=0 - Camera angle in degrees (0 is straight down)\n * @param bearing=0 - Map rotation in degrees (0 means north is up)\n * @param fovy= - Field of view of camera in degrees\n * @param altitude= - Altitude of camera in screen units \n *\n * Web mercator projection short-hand parameters\n * @param latitude - Center of viewport on map\n * @param longitude - Center of viewport on map\n * @param zoom - Scale = Math.pow(2,zoom) on map\n\n * Notes:\n * - Only one of center or [latitude, longitude] can be specified\n * - [latitude, longitude] can only be specified when \"mercator\" is true\n * - Altitude has a default value that matches assumptions in mapbox-gl\n * - Field of view is independent from altitude, provide `altitudeToFovy(1.5)` (default value) to match assumptions in mapbox-gl\n * - width and height are forced to 1 if supplied as 0, to avoid\n * division by zero. This is intended to reduce the burden of apps to\n * to check values before instantiating a Viewport.\n */\nexport type WebMercatorViewportProps = {\n // Map state\n width: number;\n height: number;\n latitude?: number;\n longitude?: number;\n position?: number[];\n zoom?: number;\n pitch?: number;\n bearing?: number;\n altitude?: number;\n fovy?: number;\n nearZMultiplier?: number;\n farZMultiplier?: number;\n};\n\n/**\n * The WebMercatorViewport class creates\n * - view/projection matrices\n * - \"uniform values\" (for shaders) from mercator params\n *\n * Note: Instances are immutable in the sense that they only have accessors.\n * A new viewport instance should be created if any parameters have changed.\n */\nexport class WebMercatorViewport {\n readonly latitude: number;\n readonly longitude: number;\n readonly zoom: number;\n readonly pitch: number;\n readonly bearing: number;\n readonly altitude: number;\n readonly fovy: number;\n\n readonly meterOffset: number[];\n readonly center: number[];\n\n readonly width: number;\n readonly height: number;\n readonly scale: number;\n readonly distanceScales: DistanceScales;\n\n readonly viewMatrix: number[];\n readonly projectionMatrix: number[];\n\n viewProjectionMatrix: number[];\n pixelProjectionMatrix: number[];\n pixelUnprojectionMatrix: number[];\n\n /**\n * @classdesc\n * Creates view/projection matrices from mercator params\n * Note: The Viewport is immutable in the sense that it only has accessors.\n * A new viewport instance should be created if any parameters have changed.\n */\n // eslint-disable-next-line max-statements\n constructor(props: WebMercatorViewportProps = {width: 1, height: 1}) {\n let {\n // Map state\n width,\n height,\n altitude = null,\n fovy = null\n } = props;\n const {\n latitude = 0,\n longitude = 0,\n zoom = 0,\n pitch = 0,\n bearing = 0,\n position = null,\n nearZMultiplier = 0.02,\n farZMultiplier = 1.01\n } = props;\n\n // Silently allow apps to send in 0,0 to facilitate isomorphic render etc\n width = width || 1;\n height = height || 1;\n\n // `fovy` & `altitude` are independent parameters, one for the\n // projection and the latter for the view matrix. In the past,\n // the `fovy` was always derived from the `altitude`\n if (fovy === null && altitude === null) {\n altitude = DEFAULT_ALTITUDE;\n fovy = altitudeToFovy(altitude);\n } else if (fovy === null) {\n fovy = altitudeToFovy(altitude);\n } else if (altitude === null) {\n altitude = fovyToAltitude(fovy);\n }\n\n const scale = zoomToScale(zoom);\n // Altitude - prevent division by 0\n // TODO - just throw an Error instead?\n altitude = Math.max(0.75, altitude);\n\n const distanceScales = getDistanceScales({longitude, latitude});\n\n const center: number[] = lngLatToWorld([longitude, latitude]);\n center.push(0);\n\n if (position) {\n vec3.add(center, center, vec3.mul([], position, distanceScales.unitsPerMeter));\n }\n\n this.projectionMatrix = getProjectionMatrix({\n width,\n height,\n scale,\n center,\n pitch,\n fovy,\n nearZMultiplier,\n farZMultiplier\n });\n\n this.viewMatrix = getViewMatrix({\n height,\n scale,\n center,\n pitch,\n bearing,\n altitude\n });\n\n // Save parameters\n this.width = width;\n this.height = height;\n this.scale = scale;\n\n this.latitude = latitude;\n this.longitude = longitude;\n this.zoom = zoom;\n this.pitch = pitch;\n this.bearing = bearing;\n this.altitude = altitude;\n this.fovy = fovy;\n this.center = center;\n this.meterOffset = position || [0, 0, 0];\n\n this.distanceScales = distanceScales;\n\n this._initMatrices();\n\n Object.freeze(this);\n }\n\n _initMatrices(): void {\n const {width, height, projectionMatrix, viewMatrix} = this;\n\n // Note: As usual, matrix operations should be applied in \"reverse\" order\n // since vectors will be multiplied in from the right during transformation\n const vpm = createMat4();\n mat4.multiply(vpm, vpm, projectionMatrix);\n mat4.multiply(vpm, vpm, viewMatrix);\n this.viewProjectionMatrix = vpm;\n\n // Calculate matrices and scales needed for projection\n /**\n * Builds matrices that converts preprojected lngLats to screen pixels\n * and vice versa.\n * Note: Currently returns bottom-left coordinates!\n * Note: Starts with the GL projection matrix and adds steps to the\n * scale and translate that matrix onto the window.\n * Note: WebGL controls clip space to screen projection with gl.viewport\n * and does not need this step.\n */\n const m = createMat4();\n\n // matrix for conversion from location to screen coordinates\n mat4.scale(m, m, [width / 2, -height / 2, 1]);\n mat4.translate(m, m, [1, -1, 0]);\n mat4.multiply(m, m, vpm);\n\n const mInverse = mat4.invert(createMat4(), m);\n if (!mInverse) {\n throw new Error('Pixel project matrix not invertible');\n }\n\n this.pixelProjectionMatrix = m;\n this.pixelUnprojectionMatrix = mInverse;\n }\n\n /** Two viewports are equal if width and height are identical, and if\n * their view and projection matrices are (approximately) equal.\n */\n equals = (viewport: WebMercatorViewport | null): boolean => {\n if (!(viewport instanceof WebMercatorViewport)) {\n return false;\n }\n\n return (\n viewport.width === this.width &&\n viewport.height === this.height &&\n mat4.equals(viewport.projectionMatrix, this.projectionMatrix) &&\n mat4.equals(viewport.viewMatrix, this.viewMatrix)\n );\n };\n\n /**\n * Projects xyz (possibly latitude and longitude) to pixel coordinates in window\n * using viewport projection parameters\n * - [longitude, latitude] to [x, y]\n * - [longitude, latitude, Z] => [x, y, z]\n * Note: By default, returns top-left coordinates for canvas/SVG type render\n *\n * @param lngLatZ - [lng, lat] or [lng, lat, Z]\n * @param options - options\n * @param options.topLeft=true - Whether projected coords are top left\n * @return - screen coordinates [x, y] or [x, y, z], z as pixel depth\n */\n project = (lngLatZ: number[], options: {topLeft?: boolean} = {}): number[] => {\n const {topLeft = true} = options;\n const worldPosition = this.projectPosition(lngLatZ);\n const coord = worldToPixels(worldPosition, this.pixelProjectionMatrix);\n\n const [x, y] = coord;\n const y2 = topLeft ? y : this.height - y;\n return lngLatZ.length === 2 ? [x, y2] : [x, y2, coord[2]];\n };\n\n /**\n * Unproject pixel coordinates on screen onto world coordinates, possibly `[lon, lat]` on map.\n *\n * - [x, y] => [lng, lat]\n * - [x, y, z] => [lng, lat, Z]\n *\n * @param xyz - screen coordinates, z as pixel depth\n * @param options - options\n * @param options.topLeft=true - Whether projected coords are top left\n * @param options.targetZ=0 - If pixel depth is unknown, targetZ is used as\n * the elevation plane to unproject onto\n * @return - [lng, lat, Z] or [X, Y, Z]\n */\n unproject = (xyz: number[], options: {topLeft?: boolean; targetZ?: number} = {}): number[] => {\n const {topLeft = true, targetZ = undefined} = options;\n const [x, y, z] = xyz;\n\n const y2 = topLeft ? y : this.height - y;\n const targetZWorld = targetZ && targetZ * this.distanceScales.unitsPerMeter[2];\n const coord = pixelsToWorld([x, y2, z], this.pixelUnprojectionMatrix, targetZWorld);\n const [X, Y, Z] = this.unprojectPosition(coord);\n\n if (Number.isFinite(z)) {\n return [X, Y, Z];\n }\n return Number.isFinite(targetZ) ? [X, Y, targetZ] : [X, Y];\n };\n\n // NON_LINEAR PROJECTION HOOKS\n // Used for web meractor projection\n\n projectPosition = (xyz: number[]): [number, number, number] => {\n const [X, Y] = lngLatToWorld(xyz);\n const Z = (xyz[2] || 0) * this.distanceScales.unitsPerMeter[2];\n return [X, Y, Z];\n };\n\n unprojectPosition = (xyz: number[]): [number, number, number] => {\n const [X, Y] = worldToLngLat(xyz);\n const Z = (xyz[2] || 0) * this.distanceScales.metersPerUnit[2];\n return [X, Y, Z];\n };\n\n /**\n * Project [lng,lat] on sphere onto [x,y] on 512*512 Mercator Zoom 0 tile.\n * Performs the nonlinear part of the web mercator projection.\n * Remaining projection is done with 4x4 matrices which also handles\n * perspective.\n *\n * @param lngLat - [lng, lat] coordinates\n * Specifies a point on the sphere to project onto the map.\n * @return [x,y] coordinates.\n */\n projectFlat(lngLat: number[]): number[] {\n return lngLatToWorld(lngLat);\n }\n\n /**\n * Unproject world point [x,y] on map onto {lat, lon} on sphere\n *\n * @param xy - array with [x,y] members\n * representing point on projected map plane\n * @return - array with [lat,lon] of point on sphere.\n * Has toArray method if you need a GeoJSON Array.\n * Per cartographic tradition, lat and lon are specified as degrees.\n */\n unprojectFlat(xy: number[]): number[] {\n return worldToLngLat(xy);\n }\n\n /**\n * Get the map center that place a given [lng, lat] coordinate at screen point [x, y]\n * @param opt\n * @param opt.lngLat - [lng,lat] coordinates\n * Specifies a point on the sphere.\n * @param opt.pos - [x,y] coordinates\n * Specifies a point on the screen.\n * @return [lng,lat] new map center.\n */\n getMapCenterByLngLatPosition({lngLat, pos}: {lngLat: number[]; pos: number[]}): number[] {\n const fromLocation = pixelsToWorld(pos, this.pixelUnprojectionMatrix);\n const toLocation = lngLatToWorld(lngLat);\n const translate = vec2.add([], toLocation, vec2.negate([], fromLocation));\n const newCenter = vec2.add([], this.center, translate);\n return worldToLngLat(newCenter);\n }\n\n /**\n * Returns a new viewport that fit around the given rectangle.\n * Only supports non-perspective mode.\n * @param bounds - [[lon, lat], [lon, lat]]\n * @param [options]\n * @param [options.padding] - The amount of padding in pixels to add to the given bounds.\n * @param [options.offset] - The center of the given bounds relative to the map's center,\n * [x, y] measured in pixels.\n * @returns {WebMercatorViewport}\n */\n fitBounds(\n bounds: [[number, number], [number, number]],\n options: Omit<FitBoundsOptions, 'width' | 'height' | 'bounds'> = {}\n ): WebMercatorViewport {\n const {width, height} = this;\n const {longitude, latitude, zoom} = fitBounds(Object.assign({width, height, bounds}, options));\n return new WebMercatorViewport({width, height, longitude, latitude, zoom});\n }\n\n /**\n * Returns the bounding box of the viewport.\n * @param [options]\n * @param [options.z] - The altitude at which the bounds should be calculated.\n * @returns {Array} bounds - [[lon, lat], [lon, lat]]\n */\n getBounds(options?: {z?: number}): number[][] {\n const corners = this.getBoundingRegion(options);\n\n const west = Math.min(...corners.map((p) => p[0]));\n const east = Math.max(...corners.map((p) => p[0]));\n const south = Math.min(...corners.map((p) => p[1]));\n const north = Math.max(...corners.map((p) => p[1]));\n return [\n [west, south],\n [east, north]\n ];\n }\n\n /**\n * Returns the bounding box of the viewport.\n * @param [options]\n * @param [options.z] - The altitude at which the bounds should be calculated.\n * @returns {Array} an array of 4 points that define the visible region\n */\n getBoundingRegion(options: {z?: number} = {}): number[][] {\n return getBounds(this, options.z || 0);\n }\n\n // DEPRECATED\n\n /** @deprecated Legacy method name */\n getLocationAtPoint({lngLat, pos}: {lngLat: number[]; pos: number[]}): number[] {\n return this.getMapCenterByLngLatPosition({lngLat, pos});\n }\n}\n"],"file":"web-mercator-viewport.js"}
1
+ {"version":3,"sources":["../src/web-mercator-viewport.ts"],"names":["createMat4","zoomToScale","pixelsToWorld","lngLatToWorld","worldToLngLat","worldToPixels","altitudeToFovy","fovyToAltitude","DEFAULT_ALTITUDE","getProjectionMatrix","getDistanceScales","getViewMatrix","fitBounds","getBounds","mat4","vec2","vec3","WebMercatorViewport","constructor","props","width","height","viewport","equals","projectionMatrix","viewMatrix","lngLatZ","options","topLeft","worldPosition","projectPosition","coord","pixelProjectionMatrix","x","y","y2","length","xyz","targetZ","undefined","z","targetZWorld","distanceScales","unitsPerMeter","pixelUnprojectionMatrix","X","Y","Z","unprojectPosition","Number","isFinite","metersPerUnit","altitude","fovy","latitude","longitude","zoom","pitch","bearing","position","nearZMultiplier","farZMultiplier","scale","Math","max","center","push","add","mul","meterOffset","_initMatrices","Object","freeze","vpm","multiply","viewProjectionMatrix","m","translate","mInverse","invert","Error","projectFlat","lngLat","unprojectFlat","xy","getMapCenterByLngLatPosition","pos","fromLocation","toLocation","negate","newCenter","bounds","assign","corners","getBoundingRegion","west","min","map","p","east","south","north","getLocationAtPoint"],"mappings":";SACQA,U;SAGNC,W,EACAC,a,EACAC,a,EACAC,a,EACAC,a,EACAC,c,EACAC,c,EACAC,gB,EACAC,mB,EACAC,iB,EACAC,a;SAGMC,S;SACAC,S;AAGR,SAAQC,IAAR,EAAcC,IAAd,EAAoBC,IAApB,QAA+B,eAA/B;AAiDA,OAAO,MAAMC,mBAAN,CAA0B;AA+B/BC,EAAAA,WAAW,CAACC,KAA+B,GAAG;AAACC,IAAAA,KAAK,EAAE,CAAR;AAAWC,IAAAA,MAAM,EAAE;AAAnB,GAAnC,EAA0D;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA,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AAG6B,OAAO,CAACI,GAAR,CAAaC,CAAD,IAAOA,CAAC,CAAC,CAAD,CAApB,CAAZ,CAAb;AACA,UAAME,KAAK,GAAGrC,IAAI,CAACiC,GAAL,CAAS,GAAGH,OAAO,CAACI,GAAR,CAAaC,CAAD,IAAOA,CAAC,CAAC,CAAD,CAApB,CAAZ,CAAd;AACA,UAAMG,KAAK,GAAGtC,IAAI,CAACC,GAAL,CAAS,GAAG6B,OAAO,CAACI,GAAR,CAAaC,CAAD,IAAOA,CAAC,CAAC,CAAD,CAApB,CAAZ,CAAd;AACA,WAAO,CACL,CAACH,IAAD,EAAOK,KAAP,CADK,EAEL,CAACD,IAAD,EAAOE,KAAP,CAFK,CAAP;AAID;;AAQDP,EAAAA,iBAAiB,CAACnE,OAAqB,GAAG,EAAzB,EAAyC;AACxD,WAAOd,SAAS,CAAC,IAAD,EAAOc,OAAO,CAACa,CAAR,IAAa,CAApB,CAAhB;AACD;;AAKD8D,EAAAA,kBAAkB,CAAC;AAACpB,IAAAA,MAAD;AAASI,IAAAA;AAAT,GAAD,EAA6D;AAC7E,WAAO,KAAKD,4BAAL,CAAkC;AAACH,MAAAA,MAAD;AAASI,MAAAA;AAAT,KAAlC,CAAP;AACD;;AAhV8B","sourcesContent":["// View and Projection Matrix calculations for mapbox-js style map view properties\nimport {createMat4} from './math-utils';\n\nimport {\n zoomToScale,\n pixelsToWorld,\n lngLatToWorld,\n worldToLngLat,\n worldToPixels,\n altitudeToFovy,\n fovyToAltitude,\n DEFAULT_ALTITUDE,\n getProjectionMatrix,\n getDistanceScales,\n getViewMatrix,\n DistanceScales\n} from './web-mercator-utils';\nimport {fitBounds} from './fit-bounds';\nimport {getBounds} from './get-bounds';\nimport type {FitBoundsOptions} from './fit-bounds';\n\nimport {mat4, vec2, vec3} from '@math.gl/core';\n\n/**\n * @param width=1 - Width of \"viewport\" or window\n * @param height=1 - Height of \"viewport\" or window\n * @param scale=1 - Either use scale or zoom\n * @param pitch=0 - Camera angle in degrees (0 is straight down)\n * @param bearing=0 - Map rotation in degrees (0 means north is up)\n * @param fovy= - Field of view of camera in degrees\n * @param altitude= - Altitude of camera in screen units \n *\n * Web mercator projection short-hand parameters\n * @param latitude - Center of viewport on map\n * @param longitude - Center of viewport on map\n * @param zoom - Scale = Math.pow(2,zoom) on map\n\n * Notes:\n * - Only one of center or [latitude, longitude] can be specified\n * - [latitude, longitude] can only be specified when \"mercator\" is true\n * - Altitude has a default value that matches assumptions in mapbox-gl\n * - Field of view is independent from altitude, provide `altitudeToFovy(1.5)` (default value) to match assumptions in mapbox-gl\n * - width and height are forced to 1 if supplied as 0, to avoid\n * division by zero. This is intended to reduce the burden of apps to\n * to check values before instantiating a Viewport.\n */\nexport type WebMercatorViewportProps = {\n // Map state\n width: number;\n height: number;\n latitude?: number;\n longitude?: number;\n position?: number[];\n zoom?: number;\n pitch?: number;\n bearing?: number;\n altitude?: number;\n fovy?: number;\n nearZMultiplier?: number;\n farZMultiplier?: number;\n};\n\n/**\n * The WebMercatorViewport class creates\n * - view/projection matrices\n * - \"uniform values\" (for shaders) from mercator params\n *\n * Note: Instances are immutable in the sense that they only have accessors.\n * A new viewport instance should be created if any parameters have changed.\n */\nexport class WebMercatorViewport {\n readonly latitude: number;\n readonly longitude: number;\n readonly zoom: number;\n readonly pitch: number;\n readonly bearing: number;\n readonly altitude: number;\n readonly fovy: number;\n\n readonly meterOffset: number[];\n readonly center: number[];\n\n readonly width: number;\n readonly height: number;\n readonly scale: number;\n readonly distanceScales: DistanceScales;\n\n readonly viewMatrix: number[];\n readonly projectionMatrix: number[];\n\n viewProjectionMatrix: number[];\n pixelProjectionMatrix: number[];\n pixelUnprojectionMatrix: number[];\n\n /**\n * @classdesc\n * Creates view/projection matrices from mercator params\n * Note: The Viewport is immutable in the sense that it only has accessors.\n * A new viewport instance should be created if any parameters have changed.\n */\n // eslint-disable-next-line max-statements\n constructor(props: WebMercatorViewportProps = {width: 1, height: 1}) {\n let {\n // Map state\n width,\n height,\n altitude = null,\n fovy = null\n } = props;\n const {\n latitude = 0,\n longitude = 0,\n zoom = 0,\n pitch = 0,\n bearing = 0,\n position = null,\n nearZMultiplier = 0.02,\n farZMultiplier = 1.01\n } = props;\n\n // Silently allow apps to send in 0,0 to facilitate isomorphic render etc\n width = width || 1;\n height = height || 1;\n\n // `fovy` & `altitude` are independent parameters, one for the\n // projection and the latter for the view matrix. In the past,\n // the `fovy` was always derived from the `altitude`\n if (fovy === null && altitude === null) {\n altitude = DEFAULT_ALTITUDE;\n fovy = altitudeToFovy(altitude);\n } else if (fovy === null) {\n fovy = altitudeToFovy(altitude);\n } else if (altitude === null) {\n altitude = fovyToAltitude(fovy);\n }\n\n const scale = zoomToScale(zoom);\n // Altitude - prevent division by 0\n // TODO - just throw an Error instead?\n altitude = Math.max(0.75, altitude);\n\n const distanceScales = getDistanceScales({longitude, latitude});\n\n const center: number[] = lngLatToWorld([longitude, latitude]);\n center.push(0);\n\n if (position) {\n vec3.add(center, center, vec3.mul([], position, distanceScales.unitsPerMeter));\n }\n\n this.projectionMatrix = getProjectionMatrix({\n width,\n height,\n scale,\n center,\n pitch,\n fovy,\n nearZMultiplier,\n farZMultiplier\n });\n\n this.viewMatrix = getViewMatrix({\n height,\n scale,\n center,\n pitch,\n bearing,\n altitude\n });\n\n // Save parameters\n this.width = width;\n this.height = height;\n this.scale = scale;\n\n this.latitude = latitude;\n this.longitude = longitude;\n this.zoom = zoom;\n this.pitch = pitch;\n this.bearing = bearing;\n this.altitude = altitude;\n this.fovy = fovy;\n this.center = center;\n this.meterOffset = position || [0, 0, 0];\n\n this.distanceScales = distanceScales;\n\n this._initMatrices();\n\n Object.freeze(this);\n }\n\n _initMatrices(): void {\n const {width, height, projectionMatrix, viewMatrix} = this;\n\n // Note: As usual, matrix operations should be applied in \"reverse\" order\n // since vectors will be multiplied in from the right during transformation\n const vpm = createMat4();\n mat4.multiply(vpm, vpm, projectionMatrix);\n mat4.multiply(vpm, vpm, viewMatrix);\n this.viewProjectionMatrix = vpm;\n\n // Calculate matrices and scales needed for projection\n /**\n * Builds matrices that converts preprojected lngLats to screen pixels\n * and vice versa.\n * Note: Currently returns bottom-left coordinates!\n * Note: Starts with the GL projection matrix and adds steps to the\n * scale and translate that matrix onto the window.\n * Note: WebGL controls clip space to screen projection with gl.viewport\n * and does not need this step.\n */\n const m = createMat4();\n\n // matrix for conversion from location to screen coordinates\n mat4.scale(m, m, [width / 2, -height / 2, 1]);\n mat4.translate(m, m, [1, -1, 0]);\n mat4.multiply(m, m, vpm);\n\n const mInverse = mat4.invert(createMat4(), m);\n if (!mInverse) {\n throw new Error('Pixel project matrix not invertible');\n }\n\n this.pixelProjectionMatrix = m;\n this.pixelUnprojectionMatrix = mInverse;\n }\n\n /** Two viewports are equal if width and height are identical, and if\n * their view and projection matrices are (approximately) equal.\n */\n equals = (viewport: WebMercatorViewport | null): boolean => {\n if (!(viewport instanceof WebMercatorViewport)) {\n return false;\n }\n\n return (\n viewport.width === this.width &&\n viewport.height === this.height &&\n mat4.equals(viewport.projectionMatrix, this.projectionMatrix) &&\n mat4.equals(viewport.viewMatrix, this.viewMatrix)\n );\n };\n\n /**\n * Projects xyz (possibly latitude and longitude) to pixel coordinates in window\n * using viewport projection parameters\n * - [longitude, latitude] to [x, y]\n * - [longitude, latitude, Z] => [x, y, z]\n * Note: By default, returns top-left coordinates for canvas/SVG type render\n *\n * @param lngLatZ - [lng, lat] or [lng, lat, Z]\n * @param options - options\n * @param options.topLeft=true - Whether projected coords are top left\n * @return - screen coordinates [x, y] or [x, y, z], z as pixel depth\n */\n project = (lngLatZ: number[], options: {topLeft?: boolean} = {}): number[] => {\n const {topLeft = true} = options;\n const worldPosition = this.projectPosition(lngLatZ);\n const coord = worldToPixels(worldPosition, this.pixelProjectionMatrix);\n\n const [x, y] = coord;\n const y2 = topLeft ? y : this.height - y;\n return lngLatZ.length === 2 ? [x, y2] : [x, y2, coord[2]];\n };\n\n /**\n * Unproject pixel coordinates on screen onto world coordinates, possibly `[lon, lat]` on map.\n *\n * - [x, y] => [lng, lat]\n * - [x, y, z] => [lng, lat, Z]\n *\n * @param xyz - screen coordinates, z as pixel depth\n * @param options - options\n * @param options.topLeft=true - Whether projected coords are top left\n * @param options.targetZ=0 - If pixel depth is unknown, targetZ is used as\n * the elevation plane to unproject onto\n * @return - [lng, lat, Z] or [X, Y, Z]\n */\n unproject = (xyz: number[], options: {topLeft?: boolean; targetZ?: number} = {}): number[] => {\n const {topLeft = true, targetZ = undefined} = options;\n const [x, y, z] = xyz;\n\n const y2 = topLeft ? y : this.height - y;\n const targetZWorld = targetZ && targetZ * this.distanceScales.unitsPerMeter[2];\n const coord = pixelsToWorld([x, y2, z], this.pixelUnprojectionMatrix, targetZWorld);\n const [X, Y, Z] = this.unprojectPosition(coord);\n\n if (Number.isFinite(z)) {\n return [X, Y, Z];\n }\n return Number.isFinite(targetZ) ? [X, Y, targetZ] : [X, Y];\n };\n\n // NON_LINEAR PROJECTION HOOKS\n // Used for web meractor projection\n\n projectPosition = (xyz: number[]): [number, number, number] => {\n const [X, Y] = lngLatToWorld(xyz);\n const Z = (xyz[2] || 0) * this.distanceScales.unitsPerMeter[2];\n return [X, Y, Z];\n };\n\n unprojectPosition = (xyz: number[]): [number, number, number] => {\n const [X, Y] = worldToLngLat(xyz);\n const Z = (xyz[2] || 0) * this.distanceScales.metersPerUnit[2];\n return [X, Y, Z];\n };\n\n /**\n * Project [lng,lat] on sphere onto [x,y] on 512*512 Mercator Zoom 0 tile.\n * Performs the nonlinear part of the web mercator projection.\n * Remaining projection is done with 4x4 matrices which also handles\n * perspective.\n *\n * @param lngLat - [lng, lat] coordinates\n * Specifies a point on the sphere to project onto the map.\n * @return [x,y] coordinates.\n */\n projectFlat(lngLat: number[]): number[] {\n return lngLatToWorld(lngLat);\n }\n\n /**\n * Unproject world point [x,y] on map onto {lat, lon} on sphere\n *\n * @param xy - array with [x,y] members\n * representing point on projected map plane\n * @return - array with [lat,lon] of point on sphere.\n * Has toArray method if you need a GeoJSON Array.\n * Per cartographic tradition, lat and lon are specified as degrees.\n */\n unprojectFlat(xy: number[]): number[] {\n return worldToLngLat(xy);\n }\n\n /**\n * Get the map center that place a given [lng, lat] coordinate at screen point [x, y]\n * @param opt\n * @param opt.lngLat - [lng,lat] coordinates\n * Specifies a point on the sphere.\n * @param opt.pos - [x,y] coordinates\n * Specifies a point on the screen.\n * @return [lng,lat] new map center.\n */\n getMapCenterByLngLatPosition({lngLat, pos}: {lngLat: number[]; pos: number[]}): number[] {\n const fromLocation = pixelsToWorld(pos, this.pixelUnprojectionMatrix);\n const toLocation = lngLatToWorld(lngLat);\n const translate = vec2.add([], toLocation, vec2.negate([], fromLocation));\n const newCenter = vec2.add([], this.center, translate);\n return worldToLngLat(newCenter);\n }\n\n /**\n * Returns a new viewport that fit around the given rectangle.\n * Only supports non-perspective mode.\n * @param bounds - [[lon, lat], [lon, lat]]\n * @param [options]\n * @param [options.padding] - The amount of padding in pixels to add to the given bounds.\n * @param [options.offset] - The center of the given bounds relative to the map's center,\n * [x, y] measured in pixels.\n * @returns {WebMercatorViewport}\n */\n fitBounds(\n bounds: [[number, number], [number, number]],\n options: Omit<FitBoundsOptions, 'width' | 'height' | 'bounds'> = {}\n ): WebMercatorViewport {\n const {width, height} = this;\n const {longitude, latitude, zoom} = fitBounds(Object.assign({width, height, bounds}, options));\n return new WebMercatorViewport({width, height, longitude, latitude, zoom});\n }\n\n /**\n * Returns the bounding box of the viewport.\n * @param [options]\n * @param [options.z] - The altitude at which the bounds should be calculated.\n * @returns {Array} bounds - [[lon, lat], [lon, lat]]\n */\n getBounds(options?: {z?: number}): number[][] {\n const corners = this.getBoundingRegion(options);\n\n const west = Math.min(...corners.map((p) => p[0]));\n const east = Math.max(...corners.map((p) => p[0]));\n const south = Math.min(...corners.map((p) => p[1]));\n const north = Math.max(...corners.map((p) => p[1]));\n return [\n [west, south],\n [east, north]\n ];\n }\n\n /**\n * Returns the bounding box of the viewport.\n * @param [options]\n * @param [options.z] - The altitude at which the bounds should be calculated.\n * @returns {Array} an array of 4 points that define the visible region\n */\n getBoundingRegion(options: {z?: number} = {}): number[][] {\n return getBounds(this, options.z || 0);\n }\n\n // DEPRECATED\n\n /** @deprecated Legacy method name */\n getLocationAtPoint({lngLat, pos}: {lngLat: number[]; pos: number[]}): number[] {\n return this.getMapCenterByLngLatPosition({lngLat, pos});\n }\n}\n"],"file":"web-mercator-viewport.js"}
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "author": "Uber Technologies, Inc.",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
- "version": "4.0.0-alpha.4",
7
+ "version": "4.0.0-beta.1",
8
8
  "keywords": [
9
9
  "webgl",
10
10
  "javascript",
@@ -34,12 +34,10 @@
34
34
  "src"
35
35
  ],
36
36
  "dependencies": {
37
- "@babel/runtime": "^7.12.0",
38
- "gl-matrix": "^3.4.3"
37
+ "@babel/runtime": "^7.12.0"
39
38
  },
40
39
  "devDependencies": {
41
- "mapbox-gl": "^1.0.0",
42
40
  "mock-browser": "^0.92.14"
43
41
  },
44
- "gitHead": "c58e63bfb9c25cd5a4fb2599b2b52c272ed55c67"
42
+ "gitHead": "5a2364216b6aadbece690e05b9b5b71753aee472"
45
43
  }
@@ -1,6 +1,6 @@
1
1
  import {lerp} from './math-utils';
2
2
  import {scaleToZoom, zoomToScale, lngLatToWorld, worldToLngLat} from './web-mercator-utils';
3
- import * as vec2 from 'gl-matrix/vec2';
3
+ import {vec2} from '@math.gl/core';
4
4
 
5
5
  import type {ViewportProps} from './normalize-viewport-props';
6
6
 
package/src/get-bounds.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable camelcase */
2
- import {lerp as vec2_lerp} from 'gl-matrix/vec2';
2
+ import {vec2} from '@math.gl/core';
3
3
  import type {WebMercatorViewport} from './web-mercator-viewport';
4
4
  import {worldToLngLat} from './web-mercator-utils';
5
5
  import {transformVector} from './math-utils';
@@ -51,7 +51,7 @@ function unprojectOnFarPlane(viewport: WebMercatorViewport, x: number, targetZ:
51
51
 
52
52
  const z = targetZ * viewport.distanceScales.unitsPerMeter[2];
53
53
  const t = (z - coord0[2]) / (coord1[2] - coord0[2]);
54
- const coord = vec2_lerp([], coord0, coord1, t);
54
+ const coord = vec2.lerp([], coord0, coord1, t);
55
55
 
56
56
  const result = worldToLngLat(coord);
57
57
  result.push(targetZ);
package/src/math-utils.ts CHANGED
@@ -1,4 +1,4 @@
1
- import {transformMat4, scale} from 'gl-matrix/vec4';
1
+ import {vec4} from '@math.gl/core';
2
2
 
3
3
  // Helper, avoids low-precision 32 bit matrices from gl-matrix mat4.create()
4
4
  export function createMat4(): number[] {
@@ -7,8 +7,8 @@ export function createMat4(): number[] {
7
7
 
8
8
  // Transforms a vec4 with a projection matrix
9
9
  export function transformVector(matrix: number[], vector: number[]): number[] {
10
- const result = transformMat4([] as number[], vector, matrix);
11
- scale(result, result, 1 / result[3]);
10
+ const result = vec4.transformMat4([] as number[], vector, matrix);
11
+ vec4.scale(result, result, 1 / result[3]);
12
12
  return result;
13
13
  }
14
14
 
@@ -2,9 +2,7 @@
2
2
 
3
3
  import {createMat4, transformVector, clamp, log2} from './math-utils';
4
4
 
5
- import * as mat4 from 'gl-matrix/mat4';
6
- import * as vec2 from 'gl-matrix/vec2';
7
- import * as vec3 from 'gl-matrix/vec3';
5
+ import {mat4, vec2, vec3} from '@math.gl/core';
8
6
  import {assert} from './assert';
9
7
 
10
8
  // CONSTANTS
@@ -19,9 +19,7 @@ import {fitBounds} from './fit-bounds';
19
19
  import {getBounds} from './get-bounds';
20
20
  import type {FitBoundsOptions} from './fit-bounds';
21
21
 
22
- import * as mat4 from 'gl-matrix/mat4';
23
- import * as vec2 from 'gl-matrix/vec2';
24
- import * as vec3 from 'gl-matrix/vec3';
22
+ import {mat4, vec2, vec3} from '@math.gl/core';
25
23
 
26
24
  /**
27
25
  * @param width=1 - Width of "viewport" or window