@math.gl/web-mercator 3.6.0-alpha.1 → 3.6.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es5/fit-bounds.js +37 -31
- package/dist/es5/fit-bounds.js.map +1 -1
- package/dist/es5/fly-to-viewport.js +98 -75
- package/dist/es5/fly-to-viewport.js.map +1 -1
- package/dist/es5/get-bounds.js +25 -26
- package/dist/es5/get-bounds.js.map +1 -1
- package/dist/es5/index.js +31 -23
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/math-utils.js +8 -3
- package/dist/es5/math-utils.js.map +1 -1
- package/dist/es5/normalize-viewport-props.js +21 -23
- package/dist/es5/normalize-viewport-props.js.map +1 -1
- package/dist/es5/web-mercator-utils.js +118 -92
- package/dist/es5/web-mercator-utils.js.map +1 -1
- package/dist/es5/web-mercator-viewport.js +239 -178
- package/dist/es5/web-mercator-viewport.js.map +1 -1
- package/dist/esm/fit-bounds.js +6 -13
- package/dist/esm/fit-bounds.js.map +1 -1
- package/dist/esm/fly-to-viewport.js.map +1 -1
- package/dist/esm/get-bounds.js +1 -1
- package/dist/esm/get-bounds.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/math-utils.js +3 -0
- package/dist/esm/math-utils.js.map +1 -1
- package/dist/esm/normalize-viewport-props.js.map +1 -1
- package/dist/esm/web-mercator-utils.js +2 -1
- package/dist/esm/web-mercator-utils.js.map +1 -1
- package/dist/esm/web-mercator-viewport.js +1 -1
- package/dist/esm/web-mercator-viewport.js.map +1 -1
- package/dist/fit-bounds.d.ts +3 -2
- package/dist/fit-bounds.d.ts.map +1 -1
- package/dist/fit-bounds.js +6 -13
- package/dist/fly-to-viewport.d.ts +6 -6
- package/dist/fly-to-viewport.d.ts.map +1 -1
- package/dist/get-bounds.js +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/math-utils.d.ts +2 -1
- package/dist/math-utils.d.ts.map +1 -1
- package/dist/math-utils.js +3 -0
- package/dist/normalize-viewport-props.d.ts +1 -2
- package/dist/normalize-viewport-props.d.ts.map +1 -1
- package/dist/web-mercator-utils.d.ts +4 -3
- package/dist/web-mercator-utils.d.ts.map +1 -1
- package/dist/web-mercator-utils.js +3 -2
- package/dist/web-mercator-viewport.d.ts +4 -5
- package/dist/web-mercator-viewport.d.ts.map +1 -1
- package/dist/web-mercator-viewport.js +1 -2
- package/package.json +3 -3
- package/src/fit-bounds.ts +8 -16
- package/src/fly-to-viewport.ts +26 -11
- package/src/get-bounds.ts +4 -4
- package/src/index.ts +5 -0
- package/src/math-utils.ts +6 -2
- package/src/normalize-viewport-props.ts +1 -1
- package/src/web-mercator-utils.ts +9 -8
- package/src/web-mercator-viewport.ts +8 -10
|
@@ -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","altitude","fovy","latitude","longitude","zoom","pitch","bearing","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","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","getLocation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Ad;AACA,UAAMG,KAAK,GAAGtE,IAAI,CAACC,GAAL,CAAS,GAAG6D,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,WAAOnD,SAAS,CAAC,IAAD,EAAOmD,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;;AAxVsC","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';\nimport type {Bounds, 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: {\n unitsPerMeter: number[];\n };\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[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 */\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) {\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 // @ts-expect-error\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","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,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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"}
|
package/dist/fit-bounds.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export declare type Padding = {
|
|
|
31
31
|
left: number;
|
|
32
32
|
right: number;
|
|
33
33
|
};
|
|
34
|
-
|
|
34
|
+
declare type ViewportProps = {
|
|
35
35
|
longitude: number;
|
|
36
36
|
latitude: number;
|
|
37
37
|
zoom: number;
|
|
@@ -45,5 +45,6 @@ export declare type Bounds = {
|
|
|
45
45
|
* @param options fit bounds parameters
|
|
46
46
|
* @returns - latitude, longitude and zoom
|
|
47
47
|
*/
|
|
48
|
-
export default function fitBounds(options: FitBoundsOptions):
|
|
48
|
+
export default function fitBounds(options: FitBoundsOptions): ViewportProps;
|
|
49
|
+
export {};
|
|
49
50
|
//# sourceMappingURL=fit-bounds.d.ts.map
|
package/dist/fit-bounds.d.ts.map
CHANGED
|
@@ -1 +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,
|
|
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"}
|
package/dist/fit-bounds.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import WebMercatorViewport from './web-mercator-viewport';
|
|
2
1
|
import assert from './assert';
|
|
3
|
-
import { log2 } from './math-utils';
|
|
2
|
+
import { log2, clamp } from './math-utils';
|
|
3
|
+
import { MAX_LATITUDE, lngLatToWorld, worldToLngLat } from './web-mercator-utils';
|
|
4
4
|
/**
|
|
5
5
|
* Returns map settings {latitude, longitude, zoom}
|
|
6
6
|
* that will contain the provided corners within the provided width.
|
|
@@ -16,15 +16,8 @@ export default function fitBounds(options) {
|
|
|
16
16
|
offset = [0, 0] } = options;
|
|
17
17
|
const [[west, south], [east, north]] = bounds;
|
|
18
18
|
const padding = getPaddingObject(options.padding);
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
height,
|
|
22
|
-
longitude: 0,
|
|
23
|
-
latitude: 0,
|
|
24
|
-
zoom: 0
|
|
25
|
-
});
|
|
26
|
-
const nw = viewport.project([west, north]);
|
|
27
|
-
const se = viewport.project([east, south]);
|
|
19
|
+
const nw = lngLatToWorld([west, clamp(north, -MAX_LATITUDE, MAX_LATITUDE)]);
|
|
20
|
+
const se = lngLatToWorld([east, clamp(south, -MAX_LATITUDE, MAX_LATITUDE)]);
|
|
28
21
|
// width/height on the Web Mercator plane
|
|
29
22
|
const size = [
|
|
30
23
|
Math.max(Math.abs(se[0] - nw[0]), minExtent),
|
|
@@ -42,8 +35,8 @@ export default function fitBounds(options) {
|
|
|
42
35
|
const offsetX = (padding.right - padding.left) / 2 / scaleX;
|
|
43
36
|
const offsetY = (padding.bottom - padding.top) / 2 / scaleY;
|
|
44
37
|
const center = [(se[0] + nw[0]) / 2 + offsetX, (se[1] + nw[1]) / 2 + offsetY];
|
|
45
|
-
const centerLngLat =
|
|
46
|
-
const zoom = Math.min(maxZoom,
|
|
38
|
+
const centerLngLat = worldToLngLat(center);
|
|
39
|
+
const zoom = Math.min(maxZoom, log2(Math.abs(Math.min(scaleX, scaleY))));
|
|
47
40
|
assert(Number.isFinite(zoom));
|
|
48
41
|
return {
|
|
49
42
|
longitude: centerLngLat[0],
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
+
import type { ViewportProps } from './normalize-viewport-props';
|
|
1
2
|
export declare type FlytoTransitionOptions = {
|
|
2
3
|
curve?: number;
|
|
3
4
|
speed?: number;
|
|
4
5
|
screenSpeed?: number;
|
|
5
6
|
maxDuration?: number;
|
|
6
7
|
};
|
|
7
|
-
export declare type ViewportProps = {
|
|
8
|
-
longitude: number;
|
|
9
|
-
latitude: number;
|
|
10
|
-
zoom: number;
|
|
11
|
-
};
|
|
12
8
|
/**
|
|
13
9
|
* mapbox-gl-js flyTo : https://www.mapbox.com/mapbox-gl-js/api/#map#flyto.
|
|
14
10
|
* It implements “Smooth and efficient zooming and panning.” algorithm by
|
|
15
11
|
* "Jarke J. van Wijk and Wim A.A. Nuij"
|
|
16
12
|
*/
|
|
17
|
-
export default function flyToViewport(startProps: ViewportProps, endProps: ViewportProps, t: number, options?: FlytoTransitionOptions):
|
|
13
|
+
export default function flyToViewport(startProps: ViewportProps, endProps: ViewportProps, t: number, options?: FlytoTransitionOptions): {
|
|
14
|
+
longitude: number;
|
|
15
|
+
latitude: number;
|
|
16
|
+
zoom: number;
|
|
17
|
+
};
|
|
18
18
|
export declare function getFlyToDuration(startProps: ViewportProps, endProps: ViewportProps, options?: FlytoTransitionOptions): number;
|
|
19
19
|
//# sourceMappingURL=fly-to-viewport.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fly-to-viewport.d.ts","sourceRoot":"","sources":["../src/fly-to-viewport.ts"],"names":[],"mappings":"
|
|
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"}
|
package/dist/get-bounds.js
CHANGED
|
@@ -46,6 +46,6 @@ function unprojectOnFarPlane(viewport, x, targetZ) {
|
|
|
46
46
|
const t = (z - coord0[2]) / (coord1[2] - coord0[2]);
|
|
47
47
|
const coord = vec2.lerp([], coord0, coord1, t);
|
|
48
48
|
const result = worldToLngLat(coord);
|
|
49
|
-
result
|
|
49
|
+
result.push(targetZ);
|
|
50
50
|
return result;
|
|
51
51
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,5 +4,8 @@ export { default as getBounds } from './get-bounds';
|
|
|
4
4
|
export { default as fitBounds } from './fit-bounds';
|
|
5
5
|
export { default as normalizeViewportProps } from './normalize-viewport-props';
|
|
6
6
|
export { default as flyToViewport, getFlyToDuration } from './fly-to-viewport';
|
|
7
|
-
export { lngLatToWorld, worldToLngLat, worldToPixels, pixelsToWorld, zoomToScale, scaleToZoom, altitudeToFovy, fovyToAltitude, getMeterZoom, getDistanceScales, addMetersToLngLat, getViewMatrix, getProjectionMatrix, getProjectionParameters } from './web-mercator-utils';
|
|
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';
|
|
8
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +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,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"}
|
|
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
CHANGED
|
@@ -5,4 +5,4 @@ export { default as getBounds } from './get-bounds';
|
|
|
5
5
|
export { default as fitBounds } from './fit-bounds';
|
|
6
6
|
export { default as normalizeViewportProps } from './normalize-viewport-props';
|
|
7
7
|
export { default as flyToViewport, getFlyToDuration } from './fly-to-viewport';
|
|
8
|
-
export { lngLatToWorld, worldToLngLat, worldToPixels, pixelsToWorld, zoomToScale, scaleToZoom, altitudeToFovy, fovyToAltitude, getMeterZoom, getDistanceScales, addMetersToLngLat, getViewMatrix, getProjectionMatrix, getProjectionParameters } from './web-mercator-utils';
|
|
8
|
+
export { MAX_LATITUDE, lngLatToWorld, worldToLngLat, worldToPixels, pixelsToWorld, zoomToScale, scaleToZoom, altitudeToFovy, fovyToAltitude, getMeterZoom, getDistanceScales, addMetersToLngLat, getViewMatrix, getProjectionMatrix, getProjectionParameters } from './web-mercator-utils';
|
package/dist/math-utils.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare function createMat4(): number[];
|
|
2
|
-
export declare function transformVector(matrix:
|
|
2
|
+
export declare function transformVector(matrix: number[], vector: number[]): number[];
|
|
3
3
|
export declare function mod(value: number, divisor: number): number;
|
|
4
4
|
export declare function lerp(start: number, end: number, step: number): number;
|
|
5
|
+
export declare function clamp(x: number, min: number, max: number): number;
|
|
5
6
|
export declare const log2: (x: number) => number;
|
|
6
7
|
//# sourceMappingURL=math-utils.d.ts.map
|
package/dist/math-utils.d.ts.map
CHANGED
|
@@ -1 +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,
|
|
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"}
|
package/dist/math-utils.js
CHANGED
|
@@ -16,6 +16,9 @@ export function mod(value, divisor) {
|
|
|
16
16
|
export function lerp(start, end, step) {
|
|
17
17
|
return step * end + (1 - step) * start;
|
|
18
18
|
}
|
|
19
|
+
export function clamp(x, min, max) {
|
|
20
|
+
return x < min ? min : x > max ? max : x;
|
|
21
|
+
}
|
|
19
22
|
function ieLog2(x) {
|
|
20
23
|
return Math.log(x) * Math.LOG2E;
|
|
21
24
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Description of viewport */
|
|
2
|
-
declare type ViewportProps = {
|
|
2
|
+
export declare type ViewportProps = {
|
|
3
3
|
width: number;
|
|
4
4
|
height: number;
|
|
5
5
|
longitude: number;
|
|
@@ -13,5 +13,4 @@ declare type ViewportProps = {
|
|
|
13
13
|
* @param props
|
|
14
14
|
*/
|
|
15
15
|
export default function normalizeViewportProps(props: ViewportProps): ViewportProps;
|
|
16
|
-
export {};
|
|
17
16
|
//# sourceMappingURL=normalize-viewport-props.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize-viewport-props.d.ts","sourceRoot":"","sources":["../src/normalize-viewport-props.ts"],"names":[],"mappings":"AAMA,8BAA8B;AAC9B,
|
|
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"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export declare const MAX_LATITUDE = 85.051129;
|
|
1
2
|
export declare const DEFAULT_ALTITUDE = 1.5;
|
|
2
3
|
export declare type DistanceScales = {
|
|
3
4
|
unitsPerMeter: number[];
|
|
@@ -38,7 +39,7 @@ export declare function scaleToZoom(scale: number): number;
|
|
|
38
39
|
* Specifies a point on the sphere to project onto the map.
|
|
39
40
|
* @return [x,y] coordinates.
|
|
40
41
|
*/
|
|
41
|
-
export declare function lngLatToWorld(lngLat: number[]): number
|
|
42
|
+
export declare function lngLatToWorld(lngLat: number[]): [number, number];
|
|
42
43
|
/**
|
|
43
44
|
* Unproject world point [x,y] on map onto {lat, lon} on sphere
|
|
44
45
|
*
|
|
@@ -48,7 +49,7 @@ export declare function lngLatToWorld(lngLat: number[]): number[];
|
|
|
48
49
|
* Has toArray method if you need a GeoJSON Array.
|
|
49
50
|
* Per cartographic tradition, lat and lon are specified as degrees.
|
|
50
51
|
*/
|
|
51
|
-
export declare function worldToLngLat(xy: number[]): number
|
|
52
|
+
export declare function worldToLngLat(xy: number[]): [number, number];
|
|
52
53
|
/**
|
|
53
54
|
* Returns the zoom level that gives a 1 meter pixel at a certain latitude
|
|
54
55
|
* 1 = C*cos(y)/2^z/TILE_SIZE = C*cos(y)/2^(z+9)
|
|
@@ -83,7 +84,7 @@ export declare function getViewMatrix(options: {
|
|
|
83
84
|
bearing: number;
|
|
84
85
|
altitude: number;
|
|
85
86
|
scale: number;
|
|
86
|
-
center
|
|
87
|
+
center?: number[];
|
|
87
88
|
}): number[];
|
|
88
89
|
/**
|
|
89
90
|
* Calculates mapbox compatible projection matrix from parameters
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-mercator-utils.d.ts","sourceRoot":"","sources":["../src/web-mercator-utils.ts"],"names":[],"mappings":"
|
|
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,CAAC;CAC5B,CAAC;AAEF;;;;;;;;;GASG;AACH,aAAK,oBAAoB,GAAG;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,yCAAyC;AACzC,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED,yCAAyC;AACzC,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAUhE;AAED;;;;;;;;GAQG;AAC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IACf,KAAK,EAAE,MAAM,CAAC;IACd,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"}
|
|
@@ -12,6 +12,8 @@ const RADIANS_TO_DEGREES = 180 / PI;
|
|
|
12
12
|
const TILE_SIZE = 512;
|
|
13
13
|
// Average circumference (40075 km equatorial, 40007 km meridional)
|
|
14
14
|
const EARTH_CIRCUMFERENCE = 40.03e6;
|
|
15
|
+
// Latitude that makes a square world, 2 * atan(E ** PI) - PI / 2
|
|
16
|
+
export const MAX_LATITUDE = 85.051129;
|
|
15
17
|
// Mapbox default altitude
|
|
16
18
|
export const DEFAULT_ALTITUDE = 1.5;
|
|
17
19
|
/** Logarithimic zoom to linear scale **/
|
|
@@ -135,7 +137,6 @@ export function addMetersToLngLat(lngLatZ, xyz) {
|
|
|
135
137
|
const worldspace = lngLatToWorld(lngLatZ);
|
|
136
138
|
worldspace[0] += x * (unitsPerMeter[0] + unitsPerMeter2[0] * y);
|
|
137
139
|
worldspace[1] += y * (unitsPerMeter[1] + unitsPerMeter2[1] * y);
|
|
138
|
-
// @ts-ignore
|
|
139
140
|
const newLngLat = worldToLngLat(worldspace);
|
|
140
141
|
const newZ = (z0 || 0) + (z || 0);
|
|
141
142
|
return Number.isFinite(z0) || Number.isFinite(z) ? [newLngLat[0], newLngLat[1], newZ] : newLngLat;
|
|
@@ -151,7 +152,7 @@ export function getViewMatrix(options) {
|
|
|
151
152
|
// Viewport props
|
|
152
153
|
height, pitch, bearing, altitude,
|
|
153
154
|
// Pre-calculated parameters
|
|
154
|
-
scale, center
|
|
155
|
+
scale, center } = options;
|
|
155
156
|
// VIEW MATRIX: PROJECTS MERCATOR WORLD COORDINATES
|
|
156
157
|
// Note that mercator world coordinates typically need to be flipped
|
|
157
158
|
//
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DistanceScales } from './web-mercator-utils';
|
|
1
2
|
import type { FitBoundsOptions } from './fit-bounds';
|
|
2
3
|
/**
|
|
3
4
|
* @param width=1 - Width of "viewport" or window
|
|
@@ -57,9 +58,7 @@ export default class WebMercatorViewport {
|
|
|
57
58
|
readonly width: number;
|
|
58
59
|
readonly height: number;
|
|
59
60
|
readonly scale: number;
|
|
60
|
-
readonly distanceScales:
|
|
61
|
-
unitsPerMeter: number[];
|
|
62
|
-
};
|
|
61
|
+
readonly distanceScales: DistanceScales;
|
|
63
62
|
readonly viewMatrix: number[];
|
|
64
63
|
readonly projectionMatrix: number[];
|
|
65
64
|
viewProjectionMatrix: number[];
|
|
@@ -109,8 +108,8 @@ export default class WebMercatorViewport {
|
|
|
109
108
|
topLeft?: boolean;
|
|
110
109
|
targetZ?: number;
|
|
111
110
|
}): number[];
|
|
112
|
-
projectPosition(xyz:
|
|
113
|
-
unprojectPosition(xyz:
|
|
111
|
+
projectPosition(xyz: number[]): [number, number, number];
|
|
112
|
+
unprojectPosition(xyz: number[]): [number, number, number];
|
|
114
113
|
/**
|
|
115
114
|
* Project [lng,lat] on sphere onto [x,y] on 512*512 Mercator Zoom 0 tile.
|
|
116
115
|
* Performs the nonlinear part of the web mercator projection.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-mercator-viewport.d.ts","sourceRoot":"","sources":["../src/web-mercator-viewport.ts"],"names":[],"mappings":"
|
|
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,MAAM,CAAC,OAAO,OAAO,mBAAmB;IACtC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,QAAQ,CAAC,WAAW,EAAE,MAAM,EAAE,CAAC;IAC/B,QAAQ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AE,GAAG,MAAM,EAAE;IAIrC;;;;;;;;OAQG;IACH,4BAA4B,CAAC,EAAC,MAAM,EAAE,GAAG,EAAC,EAAE;QAAC,MAAM,EAAE,MAAM,EAAE,CAAC;QAAC,GAAG,EAAE,MAAM,EAAE,CAAA;KAAC,GAAG,MAAM,EAAE;IAQxF;;;;;;;;;OASG;IACH,SAAS,CACP,MAAM,EAAE,CAAC,CAAC,MAAM,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"}
|
|
@@ -49,7 +49,7 @@ export default class WebMercatorViewport {
|
|
|
49
49
|
altitude = Math.max(0.75, altitude);
|
|
50
50
|
const distanceScales = getDistanceScales({ longitude, latitude });
|
|
51
51
|
const center = lngLatToWorld([longitude, latitude]);
|
|
52
|
-
center
|
|
52
|
+
center.push(0);
|
|
53
53
|
if (position) {
|
|
54
54
|
vec3.add(center, center, vec3.mul([], position, distanceScales.unitsPerMeter));
|
|
55
55
|
}
|
|
@@ -188,7 +188,6 @@ export default class WebMercatorViewport {
|
|
|
188
188
|
}
|
|
189
189
|
unprojectPosition(xyz) {
|
|
190
190
|
const [X, Y] = worldToLngLat(xyz);
|
|
191
|
-
// @ts-expect-error
|
|
192
191
|
const Z = (xyz[2] || 0) * this.distanceScales.metersPerUnit[2];
|
|
193
192
|
return [X, Y, Z];
|
|
194
193
|
}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Utilities for perspective-enabled Web Mercator projections",
|
|
4
4
|
"author": "Uber Technologies, Inc.",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "3.6.0-alpha.
|
|
6
|
+
"version": "3.6.0-alpha.4",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"webgl",
|
|
9
9
|
"javascript",
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@babel/runtime": "^7.12.0",
|
|
30
|
-
"gl-matrix": "
|
|
30
|
+
"gl-matrix": "^3.4.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"mapbox-gl": "^1.0.0",
|
|
34
34
|
"mock-browser": "^0.92.14"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "d2ce86da8b6f07f0af0236818138442f68e1d8e4"
|
|
37
37
|
}
|
package/src/fit-bounds.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import WebMercatorViewport from './web-mercator-viewport';
|
|
2
1
|
import assert from './assert';
|
|
3
|
-
import {log2} from './math-utils';
|
|
2
|
+
import {log2, clamp} from './math-utils';
|
|
3
|
+
import {MAX_LATITUDE, lngLatToWorld, worldToLngLat} from './web-mercator-utils';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Options for fitBounds
|
|
@@ -38,7 +38,7 @@ export type Padding = {
|
|
|
38
38
|
right: number;
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
type ViewportProps = {
|
|
42
42
|
longitude: number;
|
|
43
43
|
latitude: number;
|
|
44
44
|
zoom: number;
|
|
@@ -53,7 +53,7 @@ export type Bounds = {
|
|
|
53
53
|
* @param options fit bounds parameters
|
|
54
54
|
* @returns - latitude, longitude and zoom
|
|
55
55
|
*/
|
|
56
|
-
export default function fitBounds(options: FitBoundsOptions):
|
|
56
|
+
export default function fitBounds(options: FitBoundsOptions): ViewportProps {
|
|
57
57
|
const {
|
|
58
58
|
width,
|
|
59
59
|
height,
|
|
@@ -66,16 +66,8 @@ export default function fitBounds(options: FitBoundsOptions): Bounds {
|
|
|
66
66
|
const [[west, south], [east, north]] = bounds;
|
|
67
67
|
const padding = getPaddingObject(options.padding);
|
|
68
68
|
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
height,
|
|
72
|
-
longitude: 0,
|
|
73
|
-
latitude: 0,
|
|
74
|
-
zoom: 0
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
const nw = viewport.project([west, north]);
|
|
78
|
-
const se = viewport.project([east, south]);
|
|
69
|
+
const nw = lngLatToWorld([west, clamp(north, -MAX_LATITUDE, MAX_LATITUDE)]);
|
|
70
|
+
const se = lngLatToWorld([east, clamp(south, -MAX_LATITUDE, MAX_LATITUDE)]);
|
|
79
71
|
|
|
80
72
|
// width/height on the Web Mercator plane
|
|
81
73
|
const size = [
|
|
@@ -100,8 +92,8 @@ export default function fitBounds(options: FitBoundsOptions): Bounds {
|
|
|
100
92
|
|
|
101
93
|
const center = [(se[0] + nw[0]) / 2 + offsetX, (se[1] + nw[1]) / 2 + offsetY];
|
|
102
94
|
|
|
103
|
-
const centerLngLat =
|
|
104
|
-
const zoom = Math.min(maxZoom,
|
|
95
|
+
const centerLngLat = worldToLngLat(center);
|
|
96
|
+
const zoom = Math.min(maxZoom, log2(Math.abs(Math.min(scaleX, scaleY))));
|
|
105
97
|
|
|
106
98
|
assert(Number.isFinite(zoom));
|
|
107
99
|
|
package/src/fly-to-viewport.ts
CHANGED
|
@@ -2,8 +2,10 @@ import {lerp} from './math-utils';
|
|
|
2
2
|
import {scaleToZoom, zoomToScale, lngLatToWorld, worldToLngLat} from './web-mercator-utils';
|
|
3
3
|
import * as vec2 from 'gl-matrix/vec2';
|
|
4
4
|
|
|
5
|
+
import type {ViewportProps} from './normalize-viewport-props';
|
|
6
|
+
|
|
5
7
|
const EPSILON = 0.01;
|
|
6
|
-
const VIEWPORT_TRANSITION_PROPS = ['longitude', 'latitude', 'zoom'];
|
|
8
|
+
const VIEWPORT_TRANSITION_PROPS = ['longitude', 'latitude', 'zoom'] as const;
|
|
7
9
|
const DEFAULT_OPTS = {
|
|
8
10
|
curve: 1.414,
|
|
9
11
|
speed: 1.2
|
|
@@ -17,12 +19,6 @@ export type FlytoTransitionOptions = {
|
|
|
17
19
|
maxDuration?: number;
|
|
18
20
|
};
|
|
19
21
|
|
|
20
|
-
export type ViewportProps = {
|
|
21
|
-
longitude: number;
|
|
22
|
-
latitude: number;
|
|
23
|
-
zoom: number;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
22
|
/**
|
|
27
23
|
* mapbox-gl-js flyTo : https://www.mapbox.com/mapbox-gl-js/api/#map#flyto.
|
|
28
24
|
* It implements “Smooth and efficient zooming and panning.” algorithm by
|
|
@@ -33,7 +29,11 @@ export default function flyToViewport(
|
|
|
33
29
|
endProps: ViewportProps,
|
|
34
30
|
t: number,
|
|
35
31
|
options?: FlytoTransitionOptions
|
|
36
|
-
):
|
|
32
|
+
): {
|
|
33
|
+
longitude: number;
|
|
34
|
+
latitude: number;
|
|
35
|
+
zoom: number;
|
|
36
|
+
} {
|
|
37
37
|
// Equations from above paper are referred where needed.
|
|
38
38
|
|
|
39
39
|
const {startZoom, startCenterXY, uDelta, w0, u1, S, rho, rho2, r0} = getFlyToTransitionParams(
|
|
@@ -83,7 +83,7 @@ export function getFlyToDuration(
|
|
|
83
83
|
const {screenSpeed, speed, maxDuration} = opts;
|
|
84
84
|
const {S, rho} = getFlyToTransitionParams(startProps, endProps, opts);
|
|
85
85
|
const length = 1000 * S;
|
|
86
|
-
let duration;
|
|
86
|
+
let duration: number;
|
|
87
87
|
if (Number.isFinite(screenSpeed)) {
|
|
88
88
|
duration = length / (screenSpeed / rho);
|
|
89
89
|
} else {
|
|
@@ -96,7 +96,22 @@ export function getFlyToDuration(
|
|
|
96
96
|
// Private Methods
|
|
97
97
|
|
|
98
98
|
// Calculate all parameters that are static for given startProps and endProps
|
|
99
|
-
function getFlyToTransitionParams(
|
|
99
|
+
function getFlyToTransitionParams(
|
|
100
|
+
startProps: ViewportProps,
|
|
101
|
+
endProps: ViewportProps,
|
|
102
|
+
opts: FlytoTransitionOptions
|
|
103
|
+
): {
|
|
104
|
+
startZoom: number;
|
|
105
|
+
startCenterXY: number[];
|
|
106
|
+
uDelta: number[];
|
|
107
|
+
w0: number;
|
|
108
|
+
u1: number;
|
|
109
|
+
S: number;
|
|
110
|
+
rho: number;
|
|
111
|
+
rho2: number;
|
|
112
|
+
r0: number;
|
|
113
|
+
r1: number;
|
|
114
|
+
} {
|
|
100
115
|
opts = Object.assign({}, DEFAULT_OPTS, opts);
|
|
101
116
|
const rho = opts.curve;
|
|
102
117
|
const startZoom = startProps.zoom;
|
|
@@ -108,7 +123,7 @@ function getFlyToTransitionParams(startProps, endProps, opts) {
|
|
|
108
123
|
|
|
109
124
|
const startCenterXY = lngLatToWorld(startCenter);
|
|
110
125
|
const endCenterXY = lngLatToWorld(endCenter);
|
|
111
|
-
const uDelta = vec2.sub([], endCenterXY, startCenterXY);
|
|
126
|
+
const uDelta = vec2.sub([] as number[], endCenterXY, startCenterXY);
|
|
112
127
|
|
|
113
128
|
const w0 = Math.max(startProps.width, startProps.height);
|
|
114
129
|
const w1 = w0 / scale;
|
package/src/get-bounds.ts
CHANGED
|
@@ -16,8 +16,8 @@ export default function getBounds(viewport: WebMercatorViewport, z: number = 0):
|
|
|
16
16
|
const unprojectOps = {targetZ: z};
|
|
17
17
|
const bottomLeft = unproject([0, height], unprojectOps);
|
|
18
18
|
const bottomRight = unproject([width, height], unprojectOps);
|
|
19
|
-
let topLeft;
|
|
20
|
-
let topRight;
|
|
19
|
+
let topLeft: number[];
|
|
20
|
+
let topRight: number[];
|
|
21
21
|
|
|
22
22
|
const halfFov = viewport.fovy
|
|
23
23
|
? 0.5 * viewport.fovy * DEGREES_TO_RADIANS
|
|
@@ -43,7 +43,7 @@ export default function getBounds(viewport: WebMercatorViewport, z: number = 0):
|
|
|
43
43
|
* @param {Number} x - projected x in screen space
|
|
44
44
|
* @param {Number} targetZ - the elevation of the point in meters
|
|
45
45
|
*/
|
|
46
|
-
function unprojectOnFarPlane(viewport: WebMercatorViewport, x: number, targetZ) {
|
|
46
|
+
function unprojectOnFarPlane(viewport: WebMercatorViewport, x: number, targetZ: number): number[] {
|
|
47
47
|
const {pixelUnprojectionMatrix} = viewport;
|
|
48
48
|
const coord0 = transformVector(pixelUnprojectionMatrix, [x, 0, 1, 1]);
|
|
49
49
|
const coord1 = transformVector(pixelUnprojectionMatrix, [x, viewport.height, 1, 1]);
|
|
@@ -53,6 +53,6 @@ function unprojectOnFarPlane(viewport: WebMercatorViewport, x: number, targetZ)
|
|
|
53
53
|
const coord = vec2.lerp([], coord0, coord1, t);
|
|
54
54
|
|
|
55
55
|
const result = worldToLngLat(coord);
|
|
56
|
-
result
|
|
56
|
+
result.push(targetZ);
|
|
57
57
|
return result;
|
|
58
58
|
}
|