@math.gl/web-mercator 3.5.7 → 3.6.0-alpha.3

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.
Files changed (92) hide show
  1. package/dist/assert.d.ts +2 -0
  2. package/dist/assert.d.ts.map +1 -0
  3. package/dist/assert.js +8 -0
  4. package/dist/es5/assert.js.map +1 -1
  5. package/dist/es5/fit-bounds.js +27 -24
  6. package/dist/es5/fit-bounds.js.map +1 -1
  7. package/dist/es5/fly-to-viewport.js +23 -16
  8. package/dist/es5/fly-to-viewport.js.map +1 -1
  9. package/dist/es5/get-bounds.js +1 -1
  10. package/dist/es5/get-bounds.js.map +1 -1
  11. package/dist/es5/index.js.map +1 -1
  12. package/dist/es5/math-utils.js +3 -9
  13. package/dist/es5/math-utils.js.map +1 -1
  14. package/dist/es5/normalize-viewport-props.js +10 -10
  15. package/dist/es5/normalize-viewport-props.js.map +1 -1
  16. package/dist/es5/web-mercator-utils.js +44 -60
  17. package/dist/es5/web-mercator-utils.js.map +1 -1
  18. package/dist/es5/web-mercator-viewport.js +69 -51
  19. package/dist/es5/web-mercator-viewport.js.map +1 -1
  20. package/dist/esm/assert.js.map +1 -1
  21. package/dist/esm/fit-bounds.js +24 -22
  22. package/dist/esm/fit-bounds.js.map +1 -1
  23. package/dist/esm/fly-to-viewport.js +13 -9
  24. package/dist/esm/fly-to-viewport.js.map +1 -1
  25. package/dist/esm/get-bounds.js +1 -1
  26. package/dist/esm/get-bounds.js.map +1 -1
  27. package/dist/esm/index.js.map +1 -1
  28. package/dist/esm/math-utils.js +3 -3
  29. package/dist/esm/math-utils.js.map +1 -1
  30. package/dist/esm/normalize-viewport-props.js +13 -9
  31. package/dist/esm/normalize-viewport-props.js.map +1 -1
  32. package/dist/esm/web-mercator-utils.js +46 -52
  33. package/dist/esm/web-mercator-utils.js.map +1 -1
  34. package/dist/esm/web-mercator-viewport.js +76 -34
  35. package/dist/esm/web-mercator-viewport.js.map +1 -1
  36. package/dist/fit-bounds.d.ts +50 -0
  37. package/dist/fit-bounds.d.ts.map +1 -0
  38. package/dist/fit-bounds.js +63 -0
  39. package/dist/fly-to-viewport.d.ts +19 -0
  40. package/dist/fly-to-viewport.d.ts.map +1 -0
  41. package/dist/fly-to-viewport.js +87 -0
  42. package/dist/get-bounds.d.ts +3 -0
  43. package/dist/get-bounds.d.ts.map +1 -0
  44. package/dist/get-bounds.js +51 -0
  45. package/dist/index.d.ts +11 -0
  46. package/dist/index.d.ts.map +1 -0
  47. package/dist/index.js +8 -0
  48. package/dist/math-utils.d.ts +7 -0
  49. package/dist/math-utils.d.ts.map +1 -0
  50. package/dist/math-utils.js +26 -0
  51. package/dist/normalize-viewport-props.d.ts +16 -0
  52. package/dist/normalize-viewport-props.d.ts.map +1 -0
  53. package/dist/normalize-viewport-props.js +41 -0
  54. package/dist/{es5/web-mercator-utils.d.ts → web-mercator-utils.d.ts} +78 -95
  55. package/dist/web-mercator-utils.d.ts.map +1 -0
  56. package/dist/web-mercator-utils.js +290 -0
  57. package/dist/web-mercator-viewport.d.ts +182 -0
  58. package/dist/web-mercator-viewport.d.ts.map +1 -0
  59. package/dist/web-mercator-viewport.js +281 -0
  60. package/package.json +4 -4
  61. package/src/{assert.js → assert.ts} +1 -1
  62. package/src/fit-bounds.ts +127 -0
  63. package/src/{fly-to-viewport.js → fly-to-viewport.ts} +52 -14
  64. package/src/{get-bounds.js → get-bounds.ts} +7 -5
  65. package/src/{index.js → index.ts} +4 -0
  66. package/src/math-utils.ts +32 -0
  67. package/src/{normalize-viewport-props.js → normalize-viewport-props.ts} +19 -10
  68. package/src/{web-mercator-utils.js → web-mercator-utils.ts} +184 -76
  69. package/src/web-mercator-viewport.ts +415 -0
  70. package/dist/es5/fit-bounds.d.ts +0 -64
  71. package/dist/es5/fly-to-viewport.d.ts +0 -31
  72. package/dist/es5/get-bounds.d.ts +0 -3
  73. package/dist/es5/index.d.ts +0 -24
  74. package/dist/es5/normalize-viewport-props.d.ts +0 -16
  75. package/dist/es5/web-mercator-viewport.d.ts +0 -187
  76. package/dist/esm/fit-bounds.d.ts +0 -64
  77. package/dist/esm/fly-to-viewport.d.ts +0 -31
  78. package/dist/esm/get-bounds.d.ts +0 -3
  79. package/dist/esm/index.d.ts +0 -24
  80. package/dist/esm/normalize-viewport-props.d.ts +0 -16
  81. package/dist/esm/web-mercator-utils.d.ts +0 -190
  82. package/dist/esm/web-mercator-viewport.d.ts +0 -187
  83. package/src/fit-bounds.d.ts +0 -64
  84. package/src/fit-bounds.js +0 -76
  85. package/src/fly-to-viewport.d.ts +0 -31
  86. package/src/get-bounds.d.ts +0 -3
  87. package/src/index.d.ts +0 -24
  88. package/src/math-utils.js +0 -32
  89. package/src/normalize-viewport-props.d.ts +0 -16
  90. package/src/web-mercator-utils.d.ts +0 -190
  91. package/src/web-mercator-viewport.d.ts +0 -187
  92. package/src/web-mercator-viewport.js +0 -262
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/web-mercator-viewport.js"],"names":["createMat4","zoomToScale","pixelsToWorld","lngLatToWorld","worldToLngLat","worldToPixels","altitudeToFovy","fovyToAltitude","DEFAULT_ALTITUDE","getProjectionMatrix","getDistanceScales","getViewMatrix","fitBounds","getBounds","mat4","vec2","vec3","WebMercatorViewport","constructor","width","height","latitude","longitude","zoom","pitch","bearing","altitude","fovy","position","nearZMultiplier","farZMultiplier","scale","Math","max","distanceScales","center","add","mul","unitsPerMeter","projectionMatrix","viewMatrix","meterOffset","_initMatrices","equals","bind","project","unproject","projectPosition","unprojectPosition","Object","freeze","vpm","multiply","viewProjectionMatrix","m","translate","mInverse","invert","Error","pixelProjectionMatrix","pixelUnprojectionMatrix","viewport","xyz","topLeft","worldPosition","coord","x","y","y2","length","targetZ","undefined","z","targetZWorld","X","Y","Z","Number","isFinite","metersPerUnit","projectFlat","lngLat","unprojectFlat","xy","getMapCenterByLngLatPosition","pos","fromLocation","toLocation","negate","newCenter","getLocationAtPoint","bounds","options","assign","corners","getBoundingRegion","west","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,IAAOA,CAAC,CAAC,CAAD,CAApB,CAAZ,CAAd;AACA,WAAO,CACL,CAACH,IAAD,EAAOK,KAAP,CADK,EAEL,CAACD,IAAD,EAAOE,KAAP,CAFK,CAAP;AAID;;AAEDP,EAAAA,iBAAiB,CAACH,OAAO,GAAG,EAAX,EAAe;AAC9B,WAAO/E,SAAS,CAAC,IAAD,EAAO+E,OAAO,CAACpB,CAAR,IAAa,CAApB,CAAhB;AACD;;AA7OsC","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} from './web-mercator-utils';\nimport fitBounds from './fit-bounds';\nimport getBounds from './get-bounds';\n\nimport * as mat4 from 'gl-matrix/mat4';\nimport * as vec2 from 'gl-matrix/vec2';\nimport * as vec3 from 'gl-matrix/vec3';\n\nexport default class WebMercatorViewport {\n // eslint-disable-next-line max-statements\n constructor(\n {\n // Map state\n width,\n height,\n latitude = 0,\n longitude = 0,\n zoom = 0,\n pitch = 0,\n bearing = 0,\n altitude = null,\n fovy = null,\n position = null,\n nearZMultiplier = 0.02,\n farZMultiplier = 1.01\n } = {width: 1, height: 1}\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 = lngLatToWorld([longitude, latitude]);\n center[2] = 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 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 // Bind methods for easy access\n this.equals = this.equals.bind(this);\n this.project = this.project.bind(this);\n this.unproject = this.unproject.bind(this);\n this.projectPosition = this.projectPosition.bind(this);\n this.unprojectPosition = this.unprojectPosition.bind(this);\n\n Object.freeze(this);\n }\n\n _initMatrices() {\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 equals(viewport) {\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 // Projects xyz (possibly latitude and longitude) to pixel coordinates in window\n // using viewport projection parameters\n project(xyz, {topLeft = true} = {}) {\n const worldPosition = this.projectPosition(xyz);\n const coord = worldToPixels(worldPosition, this.pixelProjectionMatrix);\n\n const [x, y] = coord;\n const y2 = topLeft ? y : this.height - y;\n return xyz.length === 2 ? [x, y2] : [x, y2, coord[2]];\n }\n\n // Unproject pixel coordinates on screen onto world coordinates,\n // (possibly [lon, lat]) on map.\n unproject(xyz, {topLeft = true, targetZ = undefined} = {}) {\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) {\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) {\n const [X, Y] = worldToLngLat(xyz);\n const Z = (xyz[2] || 0) * this.distanceScales.metersPerUnit[2];\n return [X, Y, Z];\n }\n\n // Project [lng,lat] on sphere onto [x,y] on 512*512 Mercator Zoom 0 tile.\n projectFlat(lngLat) {\n return lngLatToWorld(lngLat);\n }\n\n // Unproject world point [x,y] on map onto {lat, lon} on sphere\n unprojectFlat(xy) {\n return worldToLngLat(xy);\n }\n\n // Get the map center that place a given [lng, lat] coordinate at screen point [x, y]\n getMapCenterByLngLatPosition({lngLat, pos}) {\n const fromLocation = pixelsToWorld(pos, this.pixelUnprojectionMatrix);\n const toLocation = lngLatToWorld(lngLat);\n\n const translate = vec2.add([], toLocation, vec2.negate([], fromLocation));\n const newCenter = vec2.add([], this.center, translate);\n\n return worldToLngLat(newCenter);\n }\n\n // Legacy method name\n getLocationAtPoint({lngLat, pos}) {\n return this.getMapCenterByLngLatPosition({lngLat, pos});\n }\n\n // Returns a new viewport that fit around the given rectangle.\n fitBounds(bounds, options = {}) {\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 getBounds(options) {\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 getBoundingRegion(options = {}) {\n return getBounds(this, options.z || 0);\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","altitude","fovy","latitude","longitude","zoom","pitch","bearing","position","nearZMultiplier","farZMultiplier","scale","Math","max","distanceScales","center","push","add","mul","unitsPerMeter","projectionMatrix","viewMatrix","meterOffset","_initMatrices","equals","bind","project","unproject","projectPosition","unprojectPosition","Object","freeze","vpm","multiply","viewProjectionMatrix","m","translate","mInverse","invert","Error","pixelProjectionMatrix","pixelUnprojectionMatrix","viewport","lngLatZ","options","topLeft","worldPosition","coord","x","y","y2","length","xyz","targetZ","undefined","z","targetZWorld","X","Y","Z","Number","isFinite","metersPerUnit","projectFlat","lngLat","unprojectFlat","xy","getMapCenterByLngLatPosition","pos","fromLocation","toLocation","negate","newCenter","bounds","assign","corners","getBoundingRegion","west","min","map","p","east","south","north","getLocationAtPoint"],"mappings":";AACA,SAAQA,UAAR,QAAyB,cAAzB;AAEA,SACEC,WADF,EAEEC,aAFF,EAGEC,aAHF,EAIEC,aAJF,EAKEC,aALF,EAMEC,cANF,EAOEC,cAPF,EAQEC,gBARF,EASEC,mBATF,EAUEC,iBAVF,EAWEC,aAXF,QAaO,sBAbP;AAcA,OAAOC,SAAP,MAAsB,cAAtB;AACA,OAAOC,SAAP,MAAsB,cAAtB;AAGA,OAAO,KAAKC,IAAZ,MAAsB,gBAAtB;AACA,OAAO,KAAKC,IAAZ,MAAsB,gBAAtB;AACA,OAAO,KAAKC,IAAZ,MAAsB,gBAAtB;AAiDA,eAAe,MAAMC,mBAAN,CAA0B;AA+BvCC,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;;AACnE,QAAI;AAEFD,MAAAA,KAFE;AAGFC,MAAAA,MAHE;AAIFC,MAAAA,QAAQ,GAAG,IAJT;AAKFC,MAAAA,IAAI,GAAG;AALL,QAMAJ,KANJ;AAOA,UAAM;AACJK,MAAAA,QAAQ,GAAG,CADP;AAEJC,MAAAA,SAAS,GAAG,CAFR;AAGJC,MAAAA,IAAI,GAAG,CAHH;AAIJC,MAAAA,KAAK,GAAG,CAJJ;AAKJC,MAAAA,OAAO,G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AGrE,IAAI,CAACC,GAAL,CAAS,GAAG8D,OAAO,CAACI,GAAR,CAAaC,CAAD,IAAOA,CAAC,CAAC,CAAD,CAApB,CAAZ,CAAb;AACA,UAAME,KAAK,GAAGtE,IAAI,CAACkE,GAAL,CAAS,GAAGH,OAAO,CAACI,GAAR,CAAaC,CAAD,IAAOA,CAAC,CAAC,CAAD,CAApB,CAAZ,CAAd;AACA,UAAMG,KAAK,GAAGvE,IAAI,CAACC,GAAL,CAAS,GAAG8D,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,CAAChC,OAAqB,GAAG,EAAzB,EAAyC;AACxD,WAAOpD,SAAS,CAAC,IAAD,EAAOoD,OAAO,CAACW,CAAR,IAAa,CAApB,CAAhB;AACD;;AAKD6B,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;;AArVsC","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 default 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 = 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 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 // Bind methods for easy access\n this.equals = this.equals.bind(this);\n this.project = this.project.bind(this);\n this.unproject = this.unproject.bind(this);\n this.projectPosition = this.projectPosition.bind(this);\n this.unprojectPosition = this.unprojectPosition.bind(this);\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"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Options for fitBounds
3
+ * @param width - viewport width
4
+ * @param height - viewport height
5
+ * @param bounds - [[lon, lat], [lon, lat]]
6
+ * @param minExtent - The width/height of the bounded area will never be smaller than this
7
+ * @param padding - The amount of padding in pixels
8
+ * to add to the given bounds. Can also be an object with top, bottom, left and right
9
+ * properties defining the padding.
10
+ * @param options.offset= - The center of the given bounds relative to the map's center,
11
+ */
12
+ export declare type FitBoundsOptions = {
13
+ width: number;
14
+ height: number;
15
+ bounds: [[number, number], [number, number]];
16
+ minExtent?: number;
17
+ maxZoom?: number;
18
+ padding?: number | Padding;
19
+ offset?: number[];
20
+ };
21
+ /**
22
+ * An object describing the padding to add to the bounds.
23
+ * @property top - Padding from top in pixels to add to the given bounds
24
+ * @property bottom - Padding from bottom in pixels to add to the given bounds
25
+ * @property left - Padding from left in pixels to add to the given bounds
26
+ * @property right - Padding from right in pixels to add to the given bounds
27
+ */
28
+ export declare type Padding = {
29
+ top: number;
30
+ bottom: number;
31
+ left: number;
32
+ right: number;
33
+ };
34
+ declare type ViewportProps = {
35
+ longitude: number;
36
+ latitude: number;
37
+ zoom: number;
38
+ };
39
+ /**
40
+ * Returns map settings {latitude, longitude, zoom}
41
+ * that will contain the provided corners within the provided width.
42
+ *
43
+ * > _Note: Only supports non-perspective mode._
44
+ *
45
+ * @param options fit bounds parameters
46
+ * @returns - latitude, longitude and zoom
47
+ */
48
+ export default function fitBounds(options: FitBoundsOptions): ViewportProps;
49
+ export {};
50
+ //# sourceMappingURL=fit-bounds.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fit-bounds.d.ts","sourceRoot":"","sources":["../src/fit-bounds.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;GAUG;AACH,oBAAY,gBAAgB,GAAG;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC7C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB,CAAC;AAEF;;;;;;GAMG;AACH,oBAAY,OAAO,GAAG;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,aAAK,aAAa,GAAG;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,aAAa,CAiD1E"}
@@ -0,0 +1,63 @@
1
+ import assert from './assert';
2
+ import { log2, clamp } from './math-utils';
3
+ import { MAX_LATITUDE, lngLatToWorld, worldToLngLat } from './web-mercator-utils';
4
+ /**
5
+ * Returns map settings {latitude, longitude, zoom}
6
+ * that will contain the provided corners within the provided width.
7
+ *
8
+ * > _Note: Only supports non-perspective mode._
9
+ *
10
+ * @param options fit bounds parameters
11
+ * @returns - latitude, longitude and zoom
12
+ */
13
+ export default function fitBounds(options) {
14
+ const { width, height, bounds, minExtent = 0, // 0.01 would be about 1000 meters (degree is ~110KM)
15
+ maxZoom = 24, // ~x4,000,000 => About 10 meter extents
16
+ offset = [0, 0] } = options;
17
+ const [[west, south], [east, north]] = bounds;
18
+ const padding = getPaddingObject(options.padding);
19
+ const nw = lngLatToWorld([west, clamp(north, -MAX_LATITUDE, MAX_LATITUDE)]);
20
+ const se = lngLatToWorld([east, clamp(south, -MAX_LATITUDE, MAX_LATITUDE)]);
21
+ // width/height on the Web Mercator plane
22
+ const size = [
23
+ Math.max(Math.abs(se[0] - nw[0]), minExtent),
24
+ Math.max(Math.abs(se[1] - nw[1]), minExtent)
25
+ ];
26
+ const targetSize = [
27
+ width - padding.left - padding.right - Math.abs(offset[0]) * 2,
28
+ height - padding.top - padding.bottom - Math.abs(offset[1]) * 2
29
+ ];
30
+ assert(targetSize[0] > 0 && targetSize[1] > 0);
31
+ // scale = screen pixels per unit on the Web Mercator plane
32
+ const scaleX = targetSize[0] / size[0];
33
+ const scaleY = targetSize[1] / size[1];
34
+ // Find how much we need to shift the center
35
+ const offsetX = (padding.right - padding.left) / 2 / scaleX;
36
+ const offsetY = (padding.bottom - padding.top) / 2 / scaleY;
37
+ const center = [(se[0] + nw[0]) / 2 + offsetX, (se[1] + nw[1]) / 2 + offsetY];
38
+ const centerLngLat = worldToLngLat(center);
39
+ const zoom = Math.min(maxZoom, log2(Math.abs(Math.min(scaleX, scaleY))));
40
+ assert(Number.isFinite(zoom));
41
+ return {
42
+ longitude: centerLngLat[0],
43
+ latitude: centerLngLat[1],
44
+ zoom
45
+ };
46
+ }
47
+ // Helpers
48
+ function getPaddingObject(padding = 0) {
49
+ if (typeof padding === 'number') {
50
+ return {
51
+ top: padding,
52
+ bottom: padding,
53
+ left: padding,
54
+ right: padding
55
+ };
56
+ }
57
+ // Make sure all the required properties are set
58
+ assert(Number.isFinite(padding.top) &&
59
+ Number.isFinite(padding.bottom) &&
60
+ Number.isFinite(padding.left) &&
61
+ Number.isFinite(padding.right));
62
+ return padding;
63
+ }
@@ -0,0 +1,19 @@
1
+ import type { ViewportProps } from './normalize-viewport-props';
2
+ export declare type FlytoTransitionOptions = {
3
+ curve?: number;
4
+ speed?: number;
5
+ screenSpeed?: number;
6
+ maxDuration?: number;
7
+ };
8
+ /**
9
+ * mapbox-gl-js flyTo : https://www.mapbox.com/mapbox-gl-js/api/#map#flyto.
10
+ * It implements “Smooth and efficient zooming and panning.” algorithm by
11
+ * "Jarke J. van Wijk and Wim A.A. Nuij"
12
+ */
13
+ export default function flyToViewport(startProps: ViewportProps, endProps: ViewportProps, t: number, options?: FlytoTransitionOptions): {
14
+ longitude: number;
15
+ latitude: number;
16
+ zoom: number;
17
+ };
18
+ export declare function getFlyToDuration(startProps: ViewportProps, endProps: ViewportProps, options?: FlytoTransitionOptions): number;
19
+ //# sourceMappingURL=fly-to-viewport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fly-to-viewport.d.ts","sourceRoot":"","sources":["../src/fly-to-viewport.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,4BAA4B,CAAC;AAU9D,oBAAY,sBAAsB,GAAG;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,aAAa,CACnC,UAAU,EAAE,aAAa,EACzB,QAAQ,EAAE,aAAa,EACvB,CAAC,EAAE,MAAM,EACT,OAAO,CAAC,EAAE,sBAAsB,GAC/B;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACd,CAsCA;AAGD,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,aAAa,EACzB,QAAQ,EAAE,aAAa,EACvB,OAAO,CAAC,EAAE,sBAAsB,GAC/B,MAAM,CAaR"}
@@ -0,0 +1,87 @@
1
+ import { lerp } from './math-utils';
2
+ import { scaleToZoom, zoomToScale, lngLatToWorld, worldToLngLat } from './web-mercator-utils';
3
+ import * as vec2 from 'gl-matrix/vec2';
4
+ const EPSILON = 0.01;
5
+ const VIEWPORT_TRANSITION_PROPS = ['longitude', 'latitude', 'zoom'];
6
+ const DEFAULT_OPTS = {
7
+ curve: 1.414,
8
+ speed: 1.2
9
+ // screenSpeed and maxDuration are used only if specified
10
+ };
11
+ /**
12
+ * mapbox-gl-js flyTo : https://www.mapbox.com/mapbox-gl-js/api/#map#flyto.
13
+ * It implements “Smooth and efficient zooming and panning.” algorithm by
14
+ * "Jarke J. van Wijk and Wim A.A. Nuij"
15
+ */
16
+ export default function flyToViewport(startProps, endProps, t, options) {
17
+ // Equations from above paper are referred where needed.
18
+ const { startZoom, startCenterXY, uDelta, w0, u1, S, rho, rho2, r0 } = getFlyToTransitionParams(startProps, endProps, options);
19
+ // If change in center is too small, do linear interpolaiton.
20
+ if (u1 < EPSILON) {
21
+ const viewport = {};
22
+ for (const key of VIEWPORT_TRANSITION_PROPS) {
23
+ const startValue = startProps[key];
24
+ const endValue = endProps[key];
25
+ viewport[key] = lerp(startValue, endValue, t);
26
+ }
27
+ // @ts-expect-error
28
+ return viewport;
29
+ }
30
+ const s = t * S;
31
+ const w = Math.cosh(r0) / Math.cosh(r0 + rho * s);
32
+ const u = (w0 * ((Math.cosh(r0) * Math.tanh(r0 + rho * s) - Math.sinh(r0)) / rho2)) / u1;
33
+ const scaleIncrement = 1 / w; // Using w method for scaling.
34
+ const newZoom = startZoom + scaleToZoom(scaleIncrement);
35
+ const newCenterWorld = vec2.scale([], uDelta, u);
36
+ vec2.add(newCenterWorld, newCenterWorld, startCenterXY);
37
+ const newCenter = worldToLngLat(newCenterWorld);
38
+ return {
39
+ longitude: newCenter[0],
40
+ latitude: newCenter[1],
41
+ zoom: newZoom
42
+ };
43
+ }
44
+ // returns transition duration in milliseconds
45
+ export function getFlyToDuration(startProps, endProps, options) {
46
+ const opts = { ...DEFAULT_OPTS, ...options };
47
+ const { screenSpeed, speed, maxDuration } = opts;
48
+ const { S, rho } = getFlyToTransitionParams(startProps, endProps, opts);
49
+ const length = 1000 * S;
50
+ let duration;
51
+ if (Number.isFinite(screenSpeed)) {
52
+ duration = length / (screenSpeed / rho);
53
+ }
54
+ else {
55
+ duration = length / speed;
56
+ }
57
+ return Number.isFinite(maxDuration) && duration > maxDuration ? 0 : duration;
58
+ }
59
+ // Private Methods
60
+ // Calculate all parameters that are static for given startProps and endProps
61
+ function getFlyToTransitionParams(startProps, endProps, opts) {
62
+ opts = Object.assign({}, DEFAULT_OPTS, opts);
63
+ const rho = opts.curve;
64
+ const startZoom = startProps.zoom;
65
+ const startCenter = [startProps.longitude, startProps.latitude];
66
+ const startScale = zoomToScale(startZoom);
67
+ const endZoom = endProps.zoom;
68
+ const endCenter = [endProps.longitude, endProps.latitude];
69
+ const scale = zoomToScale(endZoom - startZoom);
70
+ const startCenterXY = lngLatToWorld(startCenter);
71
+ const endCenterXY = lngLatToWorld(endCenter);
72
+ const uDelta = vec2.sub([], endCenterXY, startCenterXY);
73
+ const w0 = Math.max(startProps.width, startProps.height);
74
+ const w1 = w0 / scale;
75
+ const u1 = vec2.length(uDelta) * startScale;
76
+ // u0 is treated as '0' in Eq (9).
77
+ // If u1 is too small, will generate invalid number
78
+ const _u1 = Math.max(u1, EPSILON);
79
+ // Implement Equation (9) from above algorithm.
80
+ const rho2 = rho * rho;
81
+ const b0 = (w1 * w1 - w0 * w0 + rho2 * rho2 * _u1 * _u1) / (2 * w0 * rho2 * _u1);
82
+ const b1 = (w1 * w1 - w0 * w0 - rho2 * rho2 * _u1 * _u1) / (2 * w1 * rho2 * _u1);
83
+ const r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0);
84
+ const r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
85
+ const S = (r1 - r0) / rho;
86
+ return { startZoom, startCenterXY, uDelta, w0, u1, S, rho, rho2, r0, r1 };
87
+ }
@@ -0,0 +1,3 @@
1
+ import type WebMercatorViewport from './web-mercator-viewport';
2
+ export default function getBounds(viewport: WebMercatorViewport, z?: number): number[][];
3
+ //# sourceMappingURL=get-bounds.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-bounds.d.ts","sourceRoot":"","sources":["../src/get-bounds.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,mBAAmB,MAAM,yBAAyB,CAAC;AAS/D,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,QAAQ,EAAE,mBAAmB,EAAE,CAAC,GAAE,MAAU,GAAG,MAAM,EAAE,EAAE,CAyB1F"}
@@ -0,0 +1,51 @@
1
+ import { worldToLngLat } from './web-mercator-utils';
2
+ import * as vec2 from 'gl-matrix/vec2';
3
+ import { transformVector } from './math-utils';
4
+ const DEGREES_TO_RADIANS = Math.PI / 180;
5
+ /*
6
+ * Returns the quad at the intersection of the frustum and the given z plane
7
+ * @param {WebMercatorViewport} viewport
8
+ * @param {Number} z - elevation in meters
9
+ */
10
+ export default function getBounds(viewport, z = 0) {
11
+ // eslint-disable-next-line @typescript-eslint/unbound-method
12
+ const { width, height, unproject } = viewport;
13
+ const unprojectOps = { targetZ: z };
14
+ const bottomLeft = unproject([0, height], unprojectOps);
15
+ const bottomRight = unproject([width, height], unprojectOps);
16
+ let topLeft;
17
+ let topRight;
18
+ const halfFov = viewport.fovy
19
+ ? 0.5 * viewport.fovy * DEGREES_TO_RADIANS
20
+ : Math.atan(0.5 / viewport.altitude);
21
+ const angleToGround = (90 - viewport.pitch) * DEGREES_TO_RADIANS;
22
+ // The top plane is parallel to the ground if halfFov == angleToGround
23
+ if (halfFov > angleToGround - 0.01) {
24
+ // intersect with the far plane
25
+ topLeft = unprojectOnFarPlane(viewport, 0, z);
26
+ topRight = unprojectOnFarPlane(viewport, width, z);
27
+ }
28
+ else {
29
+ // intersect with the top plane
30
+ topLeft = unproject([0, 0], unprojectOps);
31
+ topRight = unproject([width, 0], unprojectOps);
32
+ }
33
+ return [bottomLeft, bottomRight, topRight, topLeft];
34
+ }
35
+ /*
36
+ * Find a point on the far clipping plane of the viewport
37
+ * @param {WebMercatorViewport} viewport
38
+ * @param {Number} x - projected x in screen space
39
+ * @param {Number} targetZ - the elevation of the point in meters
40
+ */
41
+ function unprojectOnFarPlane(viewport, x, targetZ) {
42
+ const { pixelUnprojectionMatrix } = viewport;
43
+ const coord0 = transformVector(pixelUnprojectionMatrix, [x, 0, 1, 1]);
44
+ const coord1 = transformVector(pixelUnprojectionMatrix, [x, viewport.height, 1, 1]);
45
+ const z = targetZ * viewport.distanceScales.unitsPerMeter[2];
46
+ const t = (z - coord0[2]) / (coord1[2] - coord0[2]);
47
+ const coord = vec2.lerp([], coord0, coord1, t);
48
+ const result = worldToLngLat(coord);
49
+ result.push(targetZ);
50
+ return result;
51
+ }
@@ -0,0 +1,11 @@
1
+ export { default } from './web-mercator-viewport';
2
+ export { default as WebMercatorViewport } from './web-mercator-viewport';
3
+ export { default as getBounds } from './get-bounds';
4
+ export { default as fitBounds } from './fit-bounds';
5
+ export { default as normalizeViewportProps } from './normalize-viewport-props';
6
+ export { default as flyToViewport, getFlyToDuration } from './fly-to-viewport';
7
+ export { MAX_LATITUDE, lngLatToWorld, worldToLngLat, worldToPixels, pixelsToWorld, zoomToScale, scaleToZoom, altitudeToFovy, fovyToAltitude, getMeterZoom, getDistanceScales, addMetersToLngLat, getViewMatrix, getProjectionMatrix, getProjectionParameters } from './web-mercator-utils';
8
+ /** Types */
9
+ export type { FitBoundsOptions } from './fit-bounds';
10
+ export type { DistanceScales } from './web-mercator-utils';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAC,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAC,OAAO,IAAI,mBAAmB,EAAC,MAAM,yBAAyB,CAAC;AAEvE,OAAO,EAAC,OAAO,IAAI,SAAS,EAAC,MAAM,cAAc,CAAC;AAClD,OAAO,EAAC,OAAO,IAAI,SAAS,EAAC,MAAM,cAAc,CAAC;AAClD,OAAO,EAAC,OAAO,IAAI,sBAAsB,EAAC,MAAM,4BAA4B,CAAC;AAC7E,OAAO,EAAC,OAAO,IAAI,aAAa,EAAE,gBAAgB,EAAC,MAAM,mBAAmB,CAAC;AAE7E,OAAO,EACL,YAAY,EACZ,aAAa,EACb,aAAa,EACb,aAAa,EACb,aAAa,EACb,WAAW,EACX,WAAW,EACX,cAAc,EACd,cAAc,EACd,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EACb,mBAAmB,EACnB,uBAAuB,EACxB,MAAM,sBAAsB,CAAC;AAE9B,YAAY;AACZ,YAAY,EAAC,gBAAgB,EAAC,MAAM,cAAc,CAAC;AACnD,YAAY,EAAC,cAAc,EAAC,MAAM,sBAAsB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ // Classic web-mercator-project
2
+ export { default } from './web-mercator-viewport';
3
+ export { default as WebMercatorViewport } from './web-mercator-viewport';
4
+ export { default as getBounds } from './get-bounds';
5
+ export { default as fitBounds } from './fit-bounds';
6
+ export { default as normalizeViewportProps } from './normalize-viewport-props';
7
+ export { default as flyToViewport, getFlyToDuration } from './fly-to-viewport';
8
+ export { MAX_LATITUDE, lngLatToWorld, worldToLngLat, worldToPixels, pixelsToWorld, zoomToScale, scaleToZoom, altitudeToFovy, fovyToAltitude, getMeterZoom, getDistanceScales, addMetersToLngLat, getViewMatrix, getProjectionMatrix, getProjectionParameters } from './web-mercator-utils';
@@ -0,0 +1,7 @@
1
+ export declare function createMat4(): number[];
2
+ export declare function transformVector(matrix: number[], vector: number[]): number[];
3
+ export declare function mod(value: number, divisor: number): number;
4
+ export declare function lerp(start: number, end: number, step: number): number;
5
+ export declare function clamp(x: number, min: number, max: number): number;
6
+ export declare const log2: (x: number) => number;
7
+ //# sourceMappingURL=math-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"math-utils.d.ts","sourceRoot":"","sources":["../src/math-utils.ts"],"names":[],"mappings":"AAGA,wBAAgB,UAAU,IAAI,MAAM,EAAE,CAErC;AAGD,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAI5E;AAED,wBAAgB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAG1D;AAED,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAErE;AAED,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAEjE;AAMD,eAAO,MAAM,IAAI,uBAAsB,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { transformMat4, scale } from 'gl-matrix/vec4';
2
+ // Helper, avoids low-precision 32 bit matrices from gl-matrix mat4.create()
3
+ export function createMat4() {
4
+ return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
5
+ }
6
+ // Transforms a vec4 with a projection matrix
7
+ export function transformVector(matrix, vector) {
8
+ const result = transformMat4([], vector, matrix);
9
+ scale(result, result, 1 / result[3]);
10
+ return result;
11
+ }
12
+ export function mod(value, divisor) {
13
+ const modulus = value % divisor;
14
+ return modulus < 0 ? divisor + modulus : modulus;
15
+ }
16
+ export function lerp(start, end, step) {
17
+ return step * end + (1 - step) * start;
18
+ }
19
+ export function clamp(x, min, max) {
20
+ return x < min ? min : x > max ? max : x;
21
+ }
22
+ function ieLog2(x) {
23
+ return Math.log(x) * Math.LOG2E;
24
+ }
25
+ // Handle missing log2 in IE 11
26
+ export const log2 = Math.log2 || ieLog2;
@@ -0,0 +1,16 @@
1
+ /** Description of viewport */
2
+ export declare type ViewportProps = {
3
+ width: number;
4
+ height: number;
5
+ longitude: number;
6
+ latitude: number;
7
+ zoom: number;
8
+ pitch?: number;
9
+ bearing?: number;
10
+ };
11
+ /**
12
+ * Apply mathematical constraints to viewport props
13
+ * @param props
14
+ */
15
+ export default function normalizeViewportProps(props: ViewportProps): ViewportProps;
16
+ //# sourceMappingURL=normalize-viewport-props.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize-viewport-props.d.ts","sourceRoot":"","sources":["../src/normalize-viewport-props.ts"],"names":[],"mappings":"AAMA,8BAA8B;AAC9B,oBAAY,aAAa,GAAG;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;GAGG;AAEH,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAAC,KAAK,EAAE,aAAa,GAAG,aAAa,CAgClF"}
@@ -0,0 +1,41 @@
1
+ import { worldToLngLat } from './web-mercator-utils';
2
+ import { mod, log2 } from './math-utils';
3
+ // defined by mapbox-gl
4
+ const TILE_SIZE = 512;
5
+ /**
6
+ * Apply mathematical constraints to viewport props
7
+ * @param props
8
+ */
9
+ // eslint-disable-next-line complexity
10
+ export default function normalizeViewportProps(props) {
11
+ const { width, height, pitch = 0 } = props;
12
+ let { longitude, latitude, zoom, bearing = 0 } = props;
13
+ // Normalize degrees
14
+ if (longitude < -180 || longitude > 180) {
15
+ longitude = mod(longitude + 180, 360) - 180;
16
+ }
17
+ if (bearing < -180 || bearing > 180) {
18
+ bearing = mod(bearing + 180, 360) - 180;
19
+ }
20
+ // Constrain zoom and shift center at low zoom levels
21
+ const minZoom = log2(height / TILE_SIZE);
22
+ if (zoom <= minZoom) {
23
+ zoom = minZoom;
24
+ latitude = 0;
25
+ }
26
+ else {
27
+ // Eliminate white space above and below the map
28
+ const halfHeightPixels = height / 2 / Math.pow(2, zoom);
29
+ const minLatitude = worldToLngLat([0, halfHeightPixels])[1];
30
+ if (latitude < minLatitude) {
31
+ latitude = minLatitude;
32
+ }
33
+ else {
34
+ const maxLatitude = worldToLngLat([0, TILE_SIZE - halfHeightPixels])[1];
35
+ if (latitude > maxLatitude) {
36
+ latitude = maxLatitude;
37
+ }
38
+ }
39
+ }
40
+ return { width, height, longitude, latitude, zoom, pitch, bearing };
41
+ }