@antv/l7-map 2.5.46 → 2.5.50

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.
@@ -8,7 +8,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
8
8
 
9
9
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
10
10
 
11
- import { mat2, mat4, vec3, vec4 } from 'gl-matrix';
11
+ import { mat2, mat4, vec4 } from 'gl-matrix';
12
12
  import Point from '../geo/point';
13
13
  import { clamp, interpolate, wrap } from '../util';
14
14
  import EdgeInsets from './edge_insets';
@@ -612,7 +612,7 @@ var Transform = function () {
612
612
  var furthestDistance = Math.cos(Math.PI / 2 - this._pitch) * topHalfSurfaceDistance + this.cameraToCenterDistance;
613
613
  var farZ = furthestDistance * 1.01;
614
614
  var nearZ = this.height / 50;
615
- var m = mat4.create();
615
+ var m = new Float64Array(16);
616
616
  mat4.perspective(m, this._fov, this.width / this.height, nearZ, farZ);
617
617
  m[8] = -offset.x * 2 / this.width;
618
618
  m[9] = offset.y * 2 / this.height;
@@ -621,17 +621,17 @@ var Transform = function () {
621
621
  mat4.rotateX(m, m, this._pitch);
622
622
  mat4.rotateZ(m, m, this.angle);
623
623
  mat4.translate(m, m, [-x, -y, 0]);
624
- this.mercatorMatrix = mat4.scale(mat4.create(), m, [this.worldSize, this.worldSize, this.worldSize]);
625
- mat4.scale(m, m, vec3.fromValues(1, 1, mercatorZfromAltitude(1, this.center.lat) * this.worldSize));
624
+ this.mercatorMatrix = mat4.scale([], m, [this.worldSize, this.worldSize, this.worldSize]);
625
+ mat4.scale(m, m, [1, 1, mercatorZfromAltitude(1, this.center.lat) * this.worldSize, 1]);
626
626
  this.projMatrix = m;
627
- this.invProjMatrix = mat4.invert(mat4.create(), this.projMatrix);
627
+ this.invProjMatrix = mat4.invert([], this.projMatrix);
628
628
  var xShift = this.width % 2 / 2;
629
629
  var yShift = this.height % 2 / 2;
630
630
  var angleCos = Math.cos(this.angle);
631
631
  var angleSin = Math.sin(this.angle);
632
632
  var dx = x - Math.round(x) + angleCos * xShift + angleSin * yShift;
633
633
  var dy = y - Math.round(y) + angleCos * yShift + angleSin * xShift;
634
- var alignedM = mat4.clone(m);
634
+ var alignedM = new Float64Array(m);
635
635
  mat4.translate(alignedM, alignedM, [dx > 0.5 ? dx - 1 : dx, dy > 0.5 ? dy - 1 : dy, 0]);
636
636
  this.alignedProjMatrix = alignedM;
637
637
  m = mat4.create();
@@ -643,8 +643,8 @@ var Transform = function () {
643
643
  mat4.translate(m, m, [-1, -1, 0]);
644
644
  mat4.scale(m, m, [2 / this.width, 2 / this.height, 1]);
645
645
  this.glCoordMatrix = m;
646
- this.pixelMatrix = mat4.multiply(mat4.create(), this.labelPlaneMatrix, this.projMatrix);
647
- m = mat4.invert(mat4.create(), this.pixelMatrix);
646
+ this.pixelMatrix = mat4.multiply(new Float64Array(16), this.labelPlaneMatrix, this.projMatrix);
647
+ m = mat4.invert(new Float64Array(16), this.pixelMatrix);
648
648
 
649
649
  if (!m) {
650
650
  throw new Error('failed to invert matrix');
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/geo/transform.ts"],"names":["mat2","mat4","vec3","vec4","Point","clamp","interpolate","wrap","EdgeInsets","LngLat","LngLatBounds","MercatorCoordinate","mercatorXfromLng","mercatorYfromLat","mercatorZfromAltitude","EXTENT","Transform","minZoom","maxZoom","minPitch","maxPitch","renderWorldCopies","tileSize","maxValidLatitude","_renderWorldCopies","undefined","_minZoom","_maxZoom","_minPitch","_maxPitch","setMaxBounds","width","height","_center","zoom","angle","_fov","_pitch","unmodified","edgeInsets","posMatrixCache","alignedPosMatrixCache","Math","max","min","pitch","scale","centerPoint","_sub","size","_div","PI","bearing","b","calcMatrices","rotationMatrix","create","rotate","p","fov","_zoom","z","zoomScale","tileZoom","floor","zoomFraction","constrain","center","lat","lng","toJSON","padding","equals","getCenter","project","clone","latRange","start","target","t","options","roundZoom","round","scaleZoom","pixelsToGLUnits","pow","log","LN2","lnglat","worldSize","point","x","y","toLngLat","a","pointCoordinate","loc","locationCoordinate","newCenter","coordinateLocation","targetZ","coord0","Float32Array","coord1","transformMat4","pixelMatrixInverse","w0","w1","x0","x1","y0","y1","z0","z1","extend","pointLocation","length","lngRange","bounds","getWest","getEast","getSouth","getNorth","mercatorMatrix","slice","coord","topPoint","pixelMatrix","cameraToCenterDistance","yOffset","tan","add","queryGeometry","c","getCameraPoint","minX","minY","maxX","maxY","fromValues","coordinatePoint","fromLngLat","projMatrix","constraining","sy","sx","x2","y2","s","unproject","h2","w2","halfFov","offset","centerOffset","groundAngle","fovAboveCenter","topHalfSurfaceDistance","sin","furthestDistance","cos","farZ","nearZ","m","perspective","translate","rotateX","rotateZ","invProjMatrix","invert","xShift","yShift","angleCos","angleSin","dx","dy","alignedM","alignedProjMatrix","labelPlaneMatrix","glCoordMatrix","multiply","Error"],"mappings":";;;;;;;;;;AACA,SAASA,IAAT,EAAeC,IAAf,EAAqBC,IAArB,EAA2BC,IAA3B,QAAuC,WAAvC;AACA,OAAOC,KAAP,MAAiC,cAAjC;AACA,SAASC,KAAT,EAAgBC,WAAhB,EAA6BC,IAA7B,QAAyC,SAAzC;AAGA,OAAOC,UAAP,MAA4C,eAA5C;AACA,OAAOC,MAAP,MAAmB,WAAnB;AACA,OAAOC,YAAP,MAAyB,kBAAzB;AACA,OAAOC,kBAAP,IACEC,gBADF,EAEEC,gBAFF,EAGEC,qBAHF,QAIO,YAJP;AAKA,OAAO,IAAMC,MAAM,GAAG,IAAf;;IACcC,S;AAoNnB,qBACEC,OADF,EAEEC,OAFF,EAGEC,QAHF,EAIEC,QAJF,EAKEC,iBALF,EAME;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;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CAArB;AACA,WAAKe,gBAAL,GAAwBf,CAAxB;AAEAA,MAAAA,CAAC,GAAGlK,IAAI,CAACuD,MAAL,EAAJ;AACAvD,MAAAA,IAAI,CAAC6C,KAAL,CAAWqH,CAAX,EAAcA,CAAd,EAAiB,CAAC,CAAD,EAAI,CAAC,CAAL,EAAQ,CAAR,CAAjB;AACAlK,MAAAA,IAAI,CAACoK,SAAL,CAAeF,CAAf,EAAkBA,CAAlB,EAAqB,CAAC,CAAC,CAAF,EAAK,CAAC,CAAN,EAAS,CAAT,CAArB;AACAlK,MAAAA,IAAI,CAAC6C,KAAL,CAAWqH,CAAX,EAAcA,CAAd,EAAiB,CAAC,IAAI,KAAKpI,KAAV,EAAiB,IAAI,KAAKC,MAA1B,EAAkC,CAAlC,CAAjB;AACA,WAAKmJ,aAAL,GAAqBhB,CAArB;AAGA,WAAKpC,WAAL,GAAmB9H,IAAI,CAACmL,QAAL,CACjBnL,IAAI,CAACuD,MAAL,EADiB,EAEjB,KAAK0H,gBAFY,EAGjB,KAAKpC,UAHY,CAAnB;AAOAqB,MAAAA,CAAC,GAAGlK,IAAI,CAACwK,MAAL,CAAYxK,IAAI,CAACuD,MAAL,EAAZ,EAA2B,KAAKuE,WAAhC,CAAJ;;AACA,UAAI,CAACoC,CAAL,EAAQ;AACN,cAAM,IAAIkB,KAAJ,CAAU,yBAAV,CAAN;AACD;;AACD,WAAK5E,kBAAL,GAA0B0D,CAA1B;AAEA,WAAK3H,cAAL,GAAsB,EAAtB;AACA,WAAKC,qBAAL,GAA6B,EAA7B;AACD;;;;;;SA5+BkBzB,S","sourcesContent":["// @ts-ignore\nimport { mat2, mat4, vec3, vec4 } from 'gl-matrix';\nimport Point, { PointLike } from '../geo/point';\nimport { clamp, interpolate, wrap } from '../util';\nimport Aabb from '../utils/Aabb';\nimport Frustum from '../utils/primitives';\nimport EdgeInsets, { IPaddingOptions } from './edge_insets';\nimport LngLat from './lng_lat';\nimport LngLatBounds from './lng_lat_bounds';\nimport MercatorCoordinate, {\n mercatorXfromLng,\n mercatorYfromLat,\n mercatorZfromAltitude,\n} from './mercator';\nexport const EXTENT = 8192;\nexport default class Transform {\n get minZoom(): number {\n return this._minZoom;\n }\n set minZoom(zoom: number) {\n if (this._minZoom === zoom) {\n return;\n }\n this._minZoom = zoom;\n this.zoom = Math.max(this.zoom, zoom);\n }\n\n get maxZoom(): number {\n return this._maxZoom;\n }\n set maxZoom(zoom: number) {\n if (this._maxZoom === zoom) {\n return;\n }\n this._maxZoom = zoom;\n this.zoom = Math.min(this.zoom, zoom);\n }\n\n get minPitch(): number {\n return this._minPitch;\n }\n set minPitch(pitch: number) {\n if (this._minPitch === pitch) {\n return;\n }\n this._minPitch = pitch;\n this._pitch = Math.max(this._pitch, pitch);\n }\n\n get maxPitch(): number {\n return this._maxPitch;\n }\n set maxPitch(pitch: number) {\n if (this._maxPitch === pitch) {\n return;\n }\n this._maxPitch = pitch;\n this._pitch = Math.min(this._pitch, pitch);\n }\n\n get renderWorldCopies(): boolean {\n return this._renderWorldCopies;\n }\n set renderWorldCopies(renderWorldCopies: boolean) {\n if (renderWorldCopies === undefined) {\n renderWorldCopies = true;\n } else if (renderWorldCopies === null) {\n renderWorldCopies = false;\n }\n\n this._renderWorldCopies = renderWorldCopies;\n }\n\n get worldSize(): number {\n return this.tileSize * this.scale;\n }\n\n get centerOffset(): Point {\n return this.centerPoint._sub(this.size._div(2));\n }\n\n get size(): Point {\n return new Point(this.width, this.height);\n }\n\n get bearing(): number {\n return (-this.angle / Math.PI) * 180;\n }\n set bearing(bearing: number) {\n const b = (-wrap(bearing, -180, 180) * Math.PI) / 180;\n if (this.angle === b) {\n return;\n }\n this.unmodified = false;\n this.angle = b;\n this.calcMatrices();\n\n // 2x2 matrix for rotating points\n this.rotationMatrix = mat2.create();\n mat2.rotate(this.rotationMatrix, this.rotationMatrix, this.angle);\n }\n\n get pitch(): number {\n return (this._pitch / Math.PI) * 180;\n }\n set pitch(pitch: number) {\n const p = (clamp(pitch, this._minPitch, this._maxPitch) / 180) * Math.PI;\n if (this._pitch === p) {\n return;\n }\n this.unmodified = false;\n this._pitch = p;\n this.calcMatrices();\n }\n\n get fov(): number {\n return (this._fov / Math.PI) * 180;\n }\n\n set fov(fov: number) {\n fov = Math.max(0.01, Math.min(60, fov));\n if (this._fov === fov) {\n return;\n }\n this.unmodified = false;\n this._fov = (fov / 180) * Math.PI;\n this.calcMatrices();\n }\n\n get zoom(): number {\n return this._zoom;\n }\n\n set zoom(zoom: number) {\n const z = Math.min(Math.max(zoom, this._minZoom), this._maxZoom);\n if (this._zoom === z) {\n return;\n }\n this.unmodified = false;\n this._zoom = z;\n this.scale = this.zoomScale(z);\n this.tileZoom = Math.floor(z);\n this.zoomFraction = z - this.tileZoom;\n this.constrain();\n this.calcMatrices();\n }\n\n get center(): LngLat {\n return this._center;\n }\n\n set center(center: LngLat) {\n if (center.lat === this._center.lat && center.lng === this._center.lng) {\n return;\n }\n this.unmodified = false;\n this._center = center;\n this.constrain();\n this.calcMatrices();\n }\n\n get padding(): IPaddingOptions {\n return this.edgeInsets.toJSON();\n }\n\n set padding(padding: IPaddingOptions) {\n if (this.edgeInsets.equals(padding)) {\n return;\n }\n this.unmodified = false;\n // Update edge-insets inplace\n this.edgeInsets.interpolate(this.edgeInsets, padding, 1);\n this.calcMatrices();\n }\n\n /**\n * The center of the screen in pixels with the top-left corner being (0,0)\n * and +y axis pointing downwards. This accounts for padding.\n *\n * @readonly\n * @type {Point}\n * @memberof Transform\n */\n get centerPoint(): Point {\n return this.edgeInsets.getCenter(this.width, this.height);\n }\n\n get point(): Point {\n return this.project(this.center);\n }\n public tileSize: number;\n public tileZoom: number;\n public lngRange?: [number, number];\n public latRange?: [number, number];\n public maxValidLatitude: number;\n public scale: number;\n public width: number;\n public height: number;\n public angle: number;\n public rotationMatrix: mat2;\n public pixelsToGLUnits: [number, number];\n public cameraToCenterDistance: number;\n public mercatorMatrix: mat4;\n public projMatrix: mat4;\n public invProjMatrix: mat4;\n public alignedProjMatrix: mat4;\n public pixelMatrix: mat4;\n public pixelMatrixInverse: mat4;\n public glCoordMatrix: mat4;\n public labelPlaneMatrix: mat4;\n // tslint:disable:variable-name\n private _fov: number;\n private _pitch: number;\n private _zoom: number;\n private _renderWorldCopies: boolean;\n private _minZoom: number;\n private _maxZoom: number;\n private _minPitch: number;\n private _maxPitch: number;\n private _center: LngLat;\n // tslint:enable\n private zoomFraction: number;\n private unmodified: boolean;\n private edgeInsets: EdgeInsets;\n private constraining: boolean;\n private posMatrixCache: { [_: string]: Float32Array };\n private alignedPosMatrixCache: { [_: string]: Float32Array };\n constructor(\n minZoom: number,\n maxZoom: number,\n minPitch: number,\n maxPitch: number,\n renderWorldCopies: boolean | void,\n ) {\n this.tileSize = 512; // constant\n this.maxValidLatitude = 85.051129; // constant\n\n this._renderWorldCopies = (renderWorldCopies === undefined\n ? true\n : renderWorldCopies) as boolean;\n this._minZoom = minZoom || 0;\n this._maxZoom = maxZoom || 22;\n\n this._minPitch = minPitch === undefined || minPitch === null ? 0 : minPitch;\n this._maxPitch =\n maxPitch === undefined || maxPitch === null ? 60 : maxPitch;\n\n this.setMaxBounds();\n\n this.width = 0;\n this.height = 0;\n this._center = new LngLat(0, 0);\n this.zoom = 0;\n this.angle = 0;\n this._fov = 0.6435011087932844;\n this._pitch = 0;\n this.unmodified = true;\n this.edgeInsets = new EdgeInsets();\n this.posMatrixCache = {};\n this.alignedPosMatrixCache = {};\n }\n\n public clone(): Transform {\n const clone = new Transform(\n this._minZoom,\n this._maxZoom,\n this._minPitch,\n this._maxPitch,\n this._renderWorldCopies,\n );\n clone.tileSize = this.tileSize;\n clone.latRange = this.latRange;\n clone.width = this.width;\n clone.height = this.height;\n clone.center = this._center;\n clone.zoom = this.zoom;\n clone.angle = this.angle;\n clone.fov = this._fov;\n clone.pitch = this._pitch;\n clone.unmodified = this.unmodified;\n clone.edgeInsets = this.edgeInsets.clone();\n clone.calcMatrices();\n return clone;\n }\n\n /**\n * Returns if the padding params match\n *\n * @param {IPaddingOptions} padding\n * @returns {boolean}\n * @memberof Transform\n */\n public isPaddingEqual(padding: IPaddingOptions): boolean {\n return this.edgeInsets.equals(padding);\n }\n\n /**\n * Helper method to upadte edge-insets inplace\n *\n * @param {IPaddingOptions} target\n * @param {number} t\n * @memberof Transform\n */\n public interpolatePadding(\n start: IPaddingOptions,\n target: IPaddingOptions,\n t: number,\n ) {\n this.unmodified = false;\n this.edgeInsets.interpolate(start, target, t);\n this.constrain();\n this.calcMatrices();\n }\n\n /**\n * Return a zoom level that will cover all tiles the transform\n * @param {Object} options options\n * @param {number} options.tileSize Tile size, expressed in screen pixels.\n * @param {boolean} options.roundZoom Target zoom level. If true, the value will be rounded to the closest integer. Otherwise the value will be floored.\n * @returns {number} zoom level An integer zoom level at which all tiles will be visible.\n */\n public coveringZoomLevel(options: { roundZoom?: boolean; tileSize: number }) {\n const z = (options.roundZoom ? Math.round : Math.floor)(\n this.zoom + this.scaleZoom(this.tileSize / options.tileSize),\n );\n // At negative zoom levels load tiles from z0 because negative tile zoom levels don't exist.\n return Math.max(0, z);\n }\n\n /**\n * Return any \"wrapped\" copies of a given tile coordinate that are visible\n * in the current view.\n *\n * @private\n */\n // public getVisibleUnwrappedCoordinates(tileID: CanonicalTileID) {\n // const result = [new UnwrappedTileID(0, tileID)];\n // if (this._renderWorldCopies) {\n // const utl = this.pointCoordinate(new Point(0, 0));\n // const utr = this.pointCoordinate(new Point(this.width, 0));\n // const ubl = this.pointCoordinate(new Point(this.width, this.height));\n // const ubr = this.pointCoordinate(new Point(0, this.height));\n // const w0 = Math.floor(Math.min(utl.x, utr.x, ubl.x, ubr.x));\n // const w1 = Math.floor(Math.max(utl.x, utr.x, ubl.x, ubr.x));\n\n // // Add an extra copy of the world on each side to properly render ImageSources and CanvasSources.\n // // Both sources draw outside the tile boundaries of the tile that \"contains them\" so we need\n // // to add extra copies on both sides in case offscreen tiles need to draw into on-screen ones.\n // const extraWorldCopy = 1;\n\n // for (let w = w0 - extraWorldCopy; w <= w1 + extraWorldCopy; w++) {\n // if (w === 0) {\n // continue;\n // }\n // result.push(new UnwrappedTileID(w, tileID));\n // }\n // }\n // return result;\n // }\n\n /**\n * Return all coordinates that could cover this transform for a covering\n * zoom level.\n * @param {Object} options\n * @param {number} options.tileSize\n * @param {number} options.minzoom\n * @param {number} options.maxzoom\n * @param {boolean} options.roundZoom\n * @param {boolean} options.reparseOverscaled\n * @param {boolean} options.renderWorldCopies\n * @returns {Array<OverscaledTileID>} OverscaledTileIDs\n * @private\n */\n // public coveringTiles(options: {\n // tileSize: number;\n // minzoom?: number;\n // maxzoom?: number;\n // roundZoom?: boolean;\n // reparseOverscaled?: boolean;\n // renderWorldCopies?: boolean;\n // }): OverscaledTileID[] {\n // let z = this.coveringZoomLevel(options);\n // const actualZ = z;\n\n // if (options.minzoom !== undefined && z < options.minzoom) {\n // return [];\n // }\n // if (options.maxzoom !== undefined && z > options.maxzoom) {\n // z = options.maxzoom;\n // }\n\n // const centerCoord = MercatorCoordinate.fromLngLat(this.center);\n // const numTiles = Math.pow(2, z);\n // const centerPoint = [numTiles * centerCoord.x, numTiles * centerCoord.y, 0];\n // const cameraFrustum = Frustum.fromInvProjectionMatrix(\n // this.invProjMatrix,\n // this.worldSize,\n // z,\n // );\n\n // // No change of LOD behavior for pitch lower than 60 and when there is no top padding: return only tile ids from the requested zoom level\n // let minZoom = options.minzoom || 0;\n // // Use 0.1 as an epsilon to avoid for explicit == 0.0 floating point checks\n // if (this._pitch <= 60.0 && this.edgeInsets.top < 0.1) {\n // minZoom = z;\n // }\n\n // // There should always be a certain number of maximum zoom level tiles surrounding the center location\n // const radiusOfMaxLvlLodInTiles = 3;\n\n // const newRootTile = (wrap: number): any => {\n // return {\n // // All tiles are on zero elevation plane => z difference is zero\n // aabb: new Aabb(\n // [wrap * numTiles, 0, 0],\n // [(wrap + 1) * numTiles, numTiles, 0],\n // ),\n // zoom: 0,\n // x: 0,\n // y: 0,\n // wrap,\n // fullyVisible: false,\n // };\n // };\n\n // // Do a depth-first traversal to find visible tiles and proper levels of detail\n // const stack = [];\n // const result = [];\n // const maxZoom = z;\n // const overscaledZ = options.reparseOverscaled ? actualZ : z;\n\n // if (this._renderWorldCopies) {\n // // Render copy of the globe thrice on both sides\n // for (let i = 1; i <= 3; i++) {\n // stack.push(newRootTile(-i));\n // stack.push(newRootTile(i));\n // }\n // }\n\n // stack.push(newRootTile(0));\n\n // while (stack.length > 0) {\n // const it = stack.pop();\n // const x = it.x;\n // const y = it.y;\n // let fullyVisible = it.fullyVisible;\n\n // // Visibility of a tile is not required if any of its ancestor if fully inside the frustum\n // if (!fullyVisible) {\n // const intersectResult = it.aabb.intersects(cameraFrustum);\n\n // if (intersectResult === 0) {\n // continue;\n // }\n\n // fullyVisible = intersectResult === 2;\n // }\n\n // const distanceX = it.aabb.distanceX(centerPoint);\n // const distanceY = it.aabb.distanceY(centerPoint);\n // const longestDim = Math.max(Math.abs(distanceX), Math.abs(distanceY));\n\n // // We're using distance based heuristics to determine if a tile should be split into quadrants or not.\n // // radiusOfMaxLvlLodInTiles defines that there's always a certain number of maxLevel tiles next to the map center.\n // // Using the fact that a parent node in quadtree is twice the size of its children (per dimension)\n // // we can define distance thresholds for each relative level:\n // // f(k) = offset + 2 + 4 + 8 + 16 + ... + 2^k. This is the same as \"offset+2^(k+1)-2\"\n // const distToSplit =\n // radiusOfMaxLvlLodInTiles + (1 << (maxZoom - it.zoom)) - 2;\n\n // // Have we reached the target depth or is the tile too far away to be any split further?\n // if (\n // it.zoom === maxZoom ||\n // (longestDim > distToSplit && it.zoom >= minZoom)\n // ) {\n // result.push({\n // tileID: new OverscaledTileID(\n // it.zoom === maxZoom ? overscaledZ : it.zoom,\n // it.wrap,\n // it.zoom,\n // x,\n // y,\n // ),\n // distanceSq: vec2.sqrLen([\n // centerPoint[0] - 0.5 - x,\n // centerPoint[1] - 0.5 - y,\n // ]),\n // });\n // continue;\n // }\n\n // for (let i = 0; i < 4; i++) {\n // const childX = (x << 1) + (i % 2);\n // const childY = (y << 1) + (i >> 1);\n\n // stack.push({\n // aabb: it.aabb.quadrant(i),\n // zoom: it.zoom + 1,\n // x: childX,\n // y: childY,\n // wrap: it.wrap,\n // fullyVisible,\n // });\n // }\n // }\n\n // return result\n // .sort((a, b) => a.distanceSq - b.distanceSq)\n // .map((a) => a.tileID);\n // }\n\n public resize(width: number, height: number) {\n this.width = width;\n this.height = height;\n\n this.pixelsToGLUnits = [2 / width, -2 / height];\n this.constrain();\n this.calcMatrices();\n }\n\n public zoomScale(zoom: number) {\n return Math.pow(2, zoom);\n }\n public scaleZoom(scale: number) {\n return Math.log(scale) / Math.LN2;\n }\n\n public project(lnglat: LngLat) {\n const lat = clamp(\n lnglat.lat,\n -this.maxValidLatitude,\n this.maxValidLatitude,\n );\n return new Point(\n mercatorXfromLng(lnglat.lng) * this.worldSize,\n mercatorYfromLat(lat) * this.worldSize,\n );\n }\n\n public unproject(point: Point): LngLat {\n return new MercatorCoordinate(\n point.x / this.worldSize,\n point.y / this.worldSize,\n ).toLngLat();\n }\n\n public setLocationAtPoint(lnglat: LngLat, point: Point) {\n const a = this.pointCoordinate(point);\n const b = this.pointCoordinate(this.centerPoint);\n const loc = this.locationCoordinate(lnglat);\n const newCenter = new MercatorCoordinate(\n loc.x - (a.x - b.x),\n loc.y - (a.y - b.y),\n );\n this.center = this.coordinateLocation(newCenter);\n if (this._renderWorldCopies) {\n this.center = this.center.wrap();\n }\n }\n\n public pointCoordinate(p: Point) {\n const targetZ = 0;\n // since we don't know the correct projected z value for the point,\n // unproject two points to get a line and then find the point on that\n // line with z=0\n\n const coord0 = new Float32Array([p.x, p.y, 0, 1]);\n const coord1 = new Float32Array([p.x, p.y, 1, 1]);\n\n vec4.transformMat4(coord0, coord0, this.pixelMatrixInverse);\n vec4.transformMat4(coord1, coord1, this.pixelMatrixInverse);\n\n const w0 = coord0[3];\n const w1 = coord1[3];\n const x0 = coord0[0] / w0;\n const x1 = coord1[0] / w1;\n const y0 = coord0[1] / w0;\n const y1 = coord1[1] / w1;\n const z0 = coord0[2] / w0;\n const z1 = coord1[2] / w1;\n\n const t = z0 === z1 ? 0 : (targetZ - z0) / (z1 - z0);\n\n return new MercatorCoordinate(\n interpolate(x0, x1, t) / this.worldSize,\n interpolate(y0, y1, t) / this.worldSize,\n );\n }\n\n /**\n * Returns the map's geographical bounds. When the bearing or pitch is non-zero, the visible region is not\n * an axis-aligned rectangle, and the result is the smallest bounds that encompasses the visible region.\n * @returns {LngLatBounds} Returns a {@link LngLatBounds} object describing the map's geographical bounds.\n */\n public getBounds(): LngLatBounds {\n return new LngLatBounds()\n .extend(this.pointLocation(new Point(0, 0)))\n .extend(this.pointLocation(new Point(this.width, 0)))\n .extend(this.pointLocation(new Point(this.width, this.height)))\n .extend(this.pointLocation(new Point(0, this.height)));\n }\n\n /**\n * Returns the maximum geographical bounds the map is constrained to, or `null` if none set.\n * @returns {LngLatBounds} {@link LngLatBounds}\n */\n public getMaxBounds(): LngLatBounds | null {\n if (\n !this.latRange ||\n this.latRange.length !== 2 ||\n !this.lngRange ||\n this.lngRange.length !== 2\n ) {\n return null;\n }\n\n return new LngLatBounds(\n [this.lngRange[0], this.latRange[0]],\n [this.lngRange[1], this.latRange[1]],\n );\n }\n\n /**\n * Sets or clears the map's geographical constraints.\n * @param {LngLatBounds} bounds A {@link LngLatBounds} object describing the new geographic boundaries of the map.\n */\n public setMaxBounds(bounds?: LngLatBounds) {\n if (bounds) {\n this.lngRange = [bounds.getWest(), bounds.getEast()];\n this.latRange = [bounds.getSouth(), bounds.getNorth()];\n this.constrain();\n } else {\n this.lngRange = undefined;\n this.latRange = [-this.maxValidLatitude, this.maxValidLatitude];\n }\n }\n\n public customLayerMatrix(): number[] {\n return (this.mercatorMatrix as number[]).slice();\n }\n\n public maxPitchScaleFactor() {\n // calcMatrices hasn't run yet\n if (!this.pixelMatrixInverse) {\n return 1;\n }\n\n const coord = this.pointCoordinate(new Point(0, 0));\n const p = new Float32Array([\n coord.x * this.worldSize,\n coord.y * this.worldSize,\n 0,\n 1,\n ]);\n const topPoint = vec4.transformMat4(p, p, this.pixelMatrix);\n return topPoint[3] / this.cameraToCenterDistance;\n }\n\n /*\n * The camera looks at the map from a 3D (lng, lat, altitude) location. Let's use `cameraLocation`\n * as the name for the location under the camera and on the surface of the earth (lng, lat, 0).\n * `cameraPoint` is the projected position of the `cameraLocation`.\n *\n * This point is useful to us because only fill-extrusions that are between `cameraPoint` and\n * the query point on the surface of the earth can extend and intersect the query.\n *\n * When the map is not pitched the `cameraPoint` is equivalent to the center of the map because\n * the camera is right above the center of the map.\n */\n public getCameraPoint() {\n const pitch = this._pitch;\n const yOffset = Math.tan(pitch) * (this.cameraToCenterDistance || 1);\n return this.centerPoint.add(new Point(0, yOffset));\n }\n\n /*\n * When the map is pitched, some of the 3D features that intersect a query will not intersect\n * the query at the surface of the earth. Instead the feature may be closer and only intersect\n * the query because it extrudes into the air.\n *\n * This returns a geometry that includes all of the original query as well as all possible ares of the\n * screen where the *base* of a visible extrusion could be.\n * - For point queries, the line from the query point to the \"camera point\"\n * - For other geometries, the envelope of the query geometry and the \"camera point\"\n */\n public getCameraQueryGeometry(queryGeometry: Point[]): Point[] {\n const c = this.getCameraPoint();\n\n if (queryGeometry.length === 1) {\n return [queryGeometry[0], c];\n } else {\n let minX = c.x;\n let minY = c.y;\n let maxX = c.x;\n let maxY = c.y;\n for (const p of queryGeometry) {\n minX = Math.min(minX, p.x);\n minY = Math.min(minY, p.y);\n maxX = Math.max(maxX, p.x);\n maxY = Math.max(maxY, p.y);\n }\n return [\n new Point(minX, minY),\n new Point(maxX, minY),\n new Point(maxX, maxY),\n new Point(minX, maxY),\n new Point(minX, minY),\n ];\n }\n }\n\n /**\n * Given a coordinate, return the screen point that corresponds to it\n * @param {Coordinate} coord\n * @returns {Point} screen point\n * @private\n */\n public coordinatePoint(coord: MercatorCoordinate) {\n const p = vec4.fromValues(\n coord.x * this.worldSize,\n coord.y * this.worldSize,\n 0,\n 1,\n );\n vec4.transformMat4(p, p, this.pixelMatrix);\n return new Point(p[0] / p[3], p[1] / p[3]);\n }\n /**\n * Given a location, return the screen point that corresponds to it\n * @param {LngLat} lnglat location\n * @returns {Point} screen point\n * @private\n */\n public locationPoint(lnglat: LngLat) {\n return this.coordinatePoint(this.locationCoordinate(lnglat));\n }\n\n /**\n * Given a point on screen, return its lnglat\n * @param {Point} p screen point\n * @returns {LngLat} lnglat location\n * @private\n */\n public pointLocation(p: Point) {\n return this.coordinateLocation(this.pointCoordinate(p));\n }\n\n /**\n * Given a geographical lnglat, return an unrounded\n * coordinate that represents it at this transform's zoom level.\n * @param {LngLat} lnglat\n * @returns {Coordinate}\n * @private\n */\n public locationCoordinate(lnglat: LngLat) {\n return MercatorCoordinate.fromLngLat(lnglat);\n }\n\n /**\n * Given a Coordinate, return its geographical position.\n * @param {Coordinate} coord\n * @returns {LngLat} lnglat\n * @private\n */\n public coordinateLocation(coord: MercatorCoordinate) {\n return coord.toLngLat();\n }\n\n public getProjectionMatrix(): mat4 {\n return this.projMatrix;\n }\n /**\n * Calculate the posMatrix that, given a tile coordinate, would be used to display the tile on a map.\n * @param {UnwrappedTileID} unwrappedTileID;\n * @private\n */\n // private calculatePosMatrix(\n // unwrappedTileID: UnwrappedTileID,\n // aligned: boolean = false,\n // ): Float32Array {\n // const posMatrixKey = unwrappedTileID.key;\n // const cache = aligned ? this.alignedPosMatrixCache : this.posMatrixCache;\n // if (cache[posMatrixKey]) {\n // return cache[posMatrixKey];\n // }\n\n // const canonical = unwrappedTileID.canonical;\n // const scale = this.worldSize / this.zoomScale(canonical.z);\n // const unwrappedX =\n // canonical.x + Math.pow(2, canonical.z) * unwrappedTileID.wrap;\n\n // const posMatrix = mat4.identity(new Float64Array(16));\n // mat4.translate(posMatrix, posMatrix, [\n // unwrappedX * scale,\n // canonical.y * scale,\n // 0,\n // ]);\n // mat4.scale(posMatrix, posMatrix, [scale / EXTENT, scale / EXTENT, 1]);\n // mat4.multiply(\n // posMatrix,\n // aligned ? this.alignedProjMatrix : this.projMatrix,\n // posMatrix,\n // );\n\n // cache[posMatrixKey] = new Float32Array(posMatrix);\n // return cache[posMatrixKey];\n // }\n\n private constrain() {\n if (!this.center || !this.width || !this.height || this.constraining) {\n return;\n }\n\n this.constraining = true;\n\n let minY = -90;\n let maxY = 90;\n let minX = -180;\n let maxX = 180;\n let sy;\n let sx;\n let x2;\n let y2;\n const size = this.size;\n const unmodified = this.unmodified;\n\n if (this.latRange) {\n const latRange = this.latRange;\n minY = mercatorYfromLat(latRange[1]) * this.worldSize;\n maxY = mercatorYfromLat(latRange[0]) * this.worldSize;\n sy = maxY - minY < size.y ? size.y / (maxY - minY) : 0;\n }\n\n if (this.lngRange) {\n const lngRange = this.lngRange;\n minX = mercatorXfromLng(lngRange[0]) * this.worldSize;\n maxX = mercatorXfromLng(lngRange[1]) * this.worldSize;\n sx = maxX - minX < size.x ? size.x / (maxX - minX) : 0;\n }\n\n const point = this.point;\n\n // how much the map should scale to fit the screen into given latitude/longitude ranges\n const s = Math.max(sx || 0, sy || 0);\n\n if (s) {\n this.center = this.unproject(\n new Point(\n sx ? (maxX + minX) / 2 : point.x,\n sy ? (maxY + minY) / 2 : point.y,\n ),\n );\n this.zoom += this.scaleZoom(s);\n this.unmodified = unmodified;\n this.constraining = false;\n return;\n }\n\n if (this.latRange) {\n const y = point.y;\n const h2 = size.y / 2;\n\n if (y - h2 < minY) {\n y2 = minY + h2;\n }\n if (y + h2 > maxY) {\n y2 = maxY - h2;\n }\n }\n\n if (this.lngRange) {\n const x = point.x;\n const w2 = size.x / 2;\n\n if (x - w2 < minX) {\n x2 = minX + w2;\n }\n if (x + w2 > maxX) {\n x2 = maxX - w2;\n }\n }\n\n // pan the map if the screen goes off the range\n if (x2 !== undefined || y2 !== undefined) {\n this.center = this.unproject(\n new Point(\n x2 !== undefined ? x2 : point.x,\n y2 !== undefined ? y2 : point.y,\n ),\n );\n }\n\n this.unmodified = unmodified;\n this.constraining = false;\n }\n\n private calcMatrices() {\n if (!this.height) {\n return;\n }\n\n const halfFov = this._fov / 2;\n const offset = this.centerOffset;\n this.cameraToCenterDistance = (0.5 / Math.tan(halfFov)) * this.height;\n\n // Find the distance from the center point [width/2 + offset.x, height/2 + offset.y] to the\n // center top point [width/2 + offset.x, 0] in Z units, using the law of sines.\n // 1 Z unit is equivalent to 1 horizontal px at the center of the map\n // (the distance between[width/2, height/2] and [width/2 + 1, height/2])\n const groundAngle = Math.PI / 2 + this._pitch;\n const fovAboveCenter = this._fov * (0.5 + offset.y / this.height);\n const topHalfSurfaceDistance =\n (Math.sin(fovAboveCenter) * this.cameraToCenterDistance) /\n Math.sin(\n clamp(Math.PI - groundAngle - fovAboveCenter, 0.01, Math.PI - 0.01),\n );\n const point = this.point;\n const x = point.x;\n const y = point.y;\n\n // Calculate z distance of the farthest fragment that should be rendered.\n const furthestDistance =\n Math.cos(Math.PI / 2 - this._pitch) * topHalfSurfaceDistance +\n this.cameraToCenterDistance;\n // Add a bit extra to avoid precision problems when a fragment's distance is exactly `furthestDistance`\n const farZ = furthestDistance * 1.01;\n\n // The larger the value of nearZ is\n // - the more depth precision is available for features (good)\n // - clipping starts appearing sooner when the camera is close to 3d features (bad)\n //\n // Smaller values worked well for mapbox-gl-js but deckgl was encountering precision issues\n // when rendering it's layers using custom layers. This value was experimentally chosen and\n // seems to solve z-fighting issues in deckgl while not clipping buildings too close to the camera.\n const nearZ = this.height / 50;\n\n // matrix for conversion from location to GL coordinates (-1 .. 1)\n let m = mat4.create();\n mat4.perspective(m, this._fov, this.width / this.height, nearZ, farZ);\n\n // Apply center of perspective offset\n m[8] = (-offset.x * 2) / this.width;\n m[9] = (offset.y * 2) / this.height;\n\n mat4.scale(m, m, [1, -1, 1]);\n mat4.translate(m, m, [0, 0, -this.cameraToCenterDistance]);\n mat4.rotateX(m, m, this._pitch);\n mat4.rotateZ(m, m, this.angle);\n mat4.translate(m, m, [-x, -y, 0]);\n\n // The mercatorMatrix can be used to transform points from mercator coordinates\n // ([0, 0] nw, [1, 1] se) to GL coordinates.\n this.mercatorMatrix = mat4.scale(mat4.create(), m, [\n this.worldSize,\n this.worldSize,\n this.worldSize,\n ]);\n // scale vertically to meters per pixel (inverse of ground resolution):\n\n mat4.scale(\n m,\n m,\n vec3.fromValues(\n 1,\n 1,\n mercatorZfromAltitude(1, this.center.lat) * this.worldSize,\n ),\n );\n\n this.projMatrix = m;\n this.invProjMatrix = mat4.invert(mat4.create(), this.projMatrix);\n\n // Make a second projection matrix that is aligned to a pixel grid for rendering raster tiles.\n // We're rounding the (floating point) x/y values to achieve to avoid rendering raster images to fractional\n // coordinates. Additionally, we adjust by half a pixel in either direction in case that viewport dimension\n // is an odd integer to preserve rendering to the pixel grid. We're rotating this shift based on the angle\n // of the transformation so that 0°, 90°, 180°, and 270° rasters are crisp, and adjust the shift so that\n // it is always <= 0.5 pixels.\n const xShift = (this.width % 2) / 2;\n const yShift = (this.height % 2) / 2;\n const angleCos = Math.cos(this.angle);\n const angleSin = Math.sin(this.angle);\n const dx = x - Math.round(x) + angleCos * xShift + angleSin * yShift;\n const dy = y - Math.round(y) + angleCos * yShift + angleSin * xShift;\n const alignedM = mat4.clone(m);\n mat4.translate(alignedM, alignedM, [\n dx > 0.5 ? dx - 1 : dx,\n dy > 0.5 ? dy - 1 : dy,\n 0,\n ]);\n this.alignedProjMatrix = alignedM;\n\n m = mat4.create();\n mat4.scale(m, m, [this.width / 2, -this.height / 2, 1]);\n mat4.translate(m, m, [1, -1, 0]);\n this.labelPlaneMatrix = m;\n\n m = mat4.create();\n mat4.scale(m, m, [1, -1, 1]);\n mat4.translate(m, m, [-1, -1, 0]);\n mat4.scale(m, m, [2 / this.width, 2 / this.height, 1]);\n this.glCoordMatrix = m;\n\n // matrix for conversion from location to screen coordinates\n this.pixelMatrix = mat4.multiply(\n mat4.create(),\n this.labelPlaneMatrix,\n this.projMatrix,\n );\n\n // inverse matrix for conversion from screen coordinaes to location\n m = mat4.invert(mat4.create(), this.pixelMatrix);\n if (!m) {\n throw new Error('failed to invert matrix');\n }\n this.pixelMatrixInverse = m;\n\n this.posMatrixCache = {};\n this.alignedPosMatrixCache = {};\n }\n}\n"],"file":"transform.js"}
1
+ {"version":3,"sources":["../../src/geo/transform.ts"],"names":["mat2","mat4","vec4","Point","clamp","interpolate","wrap","EdgeInsets","LngLat","LngLatBounds","MercatorCoordinate","mercatorXfromLng","mercatorYfromLat","mercatorZfromAltitude","EXTENT","Transform","minZoom","maxZoom","minPitch","maxPitch","renderWorldCopies","tileSize","maxValidLatitude","_renderWorldCopies","undefined","_minZoom","_maxZoom","_minPitch","_maxPitch","setMaxBounds","width","height","_center","zoom","angle","_fov","_pitch","unmodified","edgeInsets","posMatrixCache","alignedPosMatrixCache","Math","max","min","pitch","scale","centerPoint","_sub","size","_div","PI","bearing","b","calcMatrices","rotationMatrix","create","rotate","p","fov","_zoom","z","zoomScale","tileZoom","floor","zoomFraction","constrain","center","lat","lng","toJSON","padding","equals","getCenter","project","clone","latRange","start","target","t","options","roundZoom","round","scaleZoom","pixelsToGLUnits","pow","log","LN2","lnglat","worldSize","point","x","y","toLngLat","a","pointCoordinate","loc","locationCoordinate","newCenter","coordinateLocation","targetZ","coord0","Float32Array","coord1","transformMat4","pixelMatrixInverse","w0","w1","x0","x1","y0","y1","z0","z1","extend","pointLocation","length","lngRange","bounds","getWest","getEast","getSouth","getNorth","mercatorMatrix","slice","coord","topPoint","pixelMatrix","cameraToCenterDistance","yOffset","tan","add","queryGeometry","c","getCameraPoint","minX","minY","maxX","maxY","fromValues","coordinatePoint","fromLngLat","projMatrix","constraining","sy","sx","x2","y2","s","unproject","h2","w2","halfFov","offset","centerOffset","groundAngle","fovAboveCenter","topHalfSurfaceDistance","sin","furthestDistance","cos","farZ","nearZ","m","Float64Array","perspective","translate","rotateX","rotateZ","invProjMatrix","invert","xShift","yShift","angleCos","angleSin","dx","dy","alignedM","alignedProjMatrix","labelPlaneMatrix","glCoordMatrix","multiply","Error"],"mappings":";;;;;;;;;;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AAGjK,IAAI,CAACwK,MAAL,CAAY,IAAIN,YAAJ,CAAiB,EAAjB,CAAZ,EAAkC,KAAKrC,WAAvC,CAAJ;;AACA,UAAI,CAACoC,CAAL,EAAQ;AACN,cAAM,IAAImB,KAAJ,CAAU,yBAAV,CAAN;AACD;;AAED,WAAK7E,kBAAL,GAA0B0D,CAA1B;AAEA,WAAK3H,cAAL,GAAsB,EAAtB;AACA,WAAKC,qBAAL,GAA6B,EAA7B;AACD;;;;;;SAtgCkBzB,S","sourcesContent":["// @ts-ignore\nimport { mat2, mat4, vec3, vec4 } from 'gl-matrix';\nimport Point, { PointLike } from '../geo/point';\nimport { clamp, interpolate, wrap } from '../util';\nimport Aabb from '../utils/Aabb';\nimport Frustum from '../utils/primitives';\nimport EdgeInsets, { IPaddingOptions } from './edge_insets';\nimport LngLat from './lng_lat';\nimport LngLatBounds from './lng_lat_bounds';\nimport MercatorCoordinate, {\n mercatorXfromLng,\n mercatorYfromLat,\n mercatorZfromAltitude,\n} from './mercator';\nexport const EXTENT = 8192;\nexport default class Transform {\n get minZoom(): number {\n return this._minZoom;\n }\n set minZoom(zoom: number) {\n if (this._minZoom === zoom) {\n return;\n }\n this._minZoom = zoom;\n this.zoom = Math.max(this.zoom, zoom);\n }\n\n get maxZoom(): number {\n return this._maxZoom;\n }\n set maxZoom(zoom: number) {\n if (this._maxZoom === zoom) {\n return;\n }\n this._maxZoom = zoom;\n this.zoom = Math.min(this.zoom, zoom);\n }\n\n get minPitch(): number {\n return this._minPitch;\n }\n set minPitch(pitch: number) {\n if (this._minPitch === pitch) {\n return;\n }\n this._minPitch = pitch;\n this._pitch = Math.max(this._pitch, pitch);\n }\n\n get maxPitch(): number {\n return this._maxPitch;\n }\n set maxPitch(pitch: number) {\n if (this._maxPitch === pitch) {\n return;\n }\n this._maxPitch = pitch;\n this._pitch = Math.min(this._pitch, pitch);\n }\n\n get renderWorldCopies(): boolean {\n return this._renderWorldCopies;\n }\n set renderWorldCopies(renderWorldCopies: boolean) {\n if (renderWorldCopies === undefined) {\n renderWorldCopies = true;\n } else if (renderWorldCopies === null) {\n renderWorldCopies = false;\n }\n\n this._renderWorldCopies = renderWorldCopies;\n }\n\n get worldSize(): number {\n return this.tileSize * this.scale;\n }\n\n get centerOffset(): Point {\n return this.centerPoint._sub(this.size._div(2));\n }\n\n get size(): Point {\n return new Point(this.width, this.height);\n }\n\n get bearing(): number {\n return (-this.angle / Math.PI) * 180;\n }\n set bearing(bearing: number) {\n const b = (-wrap(bearing, -180, 180) * Math.PI) / 180;\n if (this.angle === b) {\n return;\n }\n this.unmodified = false;\n this.angle = b;\n this.calcMatrices();\n\n // 2x2 matrix for rotating points\n this.rotationMatrix = mat2.create();\n mat2.rotate(this.rotationMatrix, this.rotationMatrix, this.angle);\n }\n\n get pitch(): number {\n return (this._pitch / Math.PI) * 180;\n }\n set pitch(pitch: number) {\n const p = (clamp(pitch, this._minPitch, this._maxPitch) / 180) * Math.PI;\n if (this._pitch === p) {\n return;\n }\n this.unmodified = false;\n this._pitch = p;\n this.calcMatrices();\n }\n\n get fov(): number {\n return (this._fov / Math.PI) * 180;\n }\n\n set fov(fov: number) {\n fov = Math.max(0.01, Math.min(60, fov));\n if (this._fov === fov) {\n return;\n }\n this.unmodified = false;\n this._fov = (fov / 180) * Math.PI;\n this.calcMatrices();\n }\n\n get zoom(): number {\n return this._zoom;\n }\n\n set zoom(zoom: number) {\n const z = Math.min(Math.max(zoom, this._minZoom), this._maxZoom);\n if (this._zoom === z) {\n return;\n }\n this.unmodified = false;\n this._zoom = z;\n this.scale = this.zoomScale(z);\n this.tileZoom = Math.floor(z);\n this.zoomFraction = z - this.tileZoom;\n this.constrain();\n this.calcMatrices();\n }\n\n get center(): LngLat {\n return this._center;\n }\n\n set center(center: LngLat) {\n if (center.lat === this._center.lat && center.lng === this._center.lng) {\n return;\n }\n this.unmodified = false;\n this._center = center;\n this.constrain();\n this.calcMatrices();\n }\n\n get padding(): IPaddingOptions {\n return this.edgeInsets.toJSON();\n }\n\n set padding(padding: IPaddingOptions) {\n if (this.edgeInsets.equals(padding)) {\n return;\n }\n this.unmodified = false;\n // Update edge-insets inplace\n this.edgeInsets.interpolate(this.edgeInsets, padding, 1);\n this.calcMatrices();\n }\n\n /**\n * The center of the screen in pixels with the top-left corner being (0,0)\n * and +y axis pointing downwards. This accounts for padding.\n *\n * @readonly\n * @type {Point}\n * @memberof Transform\n */\n get centerPoint(): Point {\n return this.edgeInsets.getCenter(this.width, this.height);\n }\n\n get point(): Point {\n return this.project(this.center);\n }\n public tileSize: number;\n public tileZoom: number;\n public lngRange?: [number, number];\n public latRange?: [number, number];\n public maxValidLatitude: number;\n public scale: number;\n public width: number;\n public height: number;\n public angle: number;\n public rotationMatrix: mat2;\n public pixelsToGLUnits: [number, number];\n public cameraToCenterDistance: number;\n public mercatorMatrix: mat4;\n public projMatrix: mat4;\n public invProjMatrix: mat4;\n public alignedProjMatrix: mat4;\n public pixelMatrix: mat4;\n public pixelMatrixInverse: mat4;\n public glCoordMatrix: mat4;\n public labelPlaneMatrix: mat4;\n // tslint:disable:variable-name\n private _fov: number;\n private _pitch: number;\n private _zoom: number;\n private _renderWorldCopies: boolean;\n private _minZoom: number;\n private _maxZoom: number;\n private _minPitch: number;\n private _maxPitch: number;\n private _center: LngLat;\n // tslint:enable\n private zoomFraction: number;\n private unmodified: boolean;\n private edgeInsets: EdgeInsets;\n private constraining: boolean;\n private posMatrixCache: { [_: string]: Float32Array };\n private alignedPosMatrixCache: { [_: string]: Float32Array };\n constructor(\n minZoom: number,\n maxZoom: number,\n minPitch: number,\n maxPitch: number,\n renderWorldCopies: boolean | void,\n ) {\n this.tileSize = 512; // constant\n this.maxValidLatitude = 85.051129; // constant\n\n this._renderWorldCopies = (renderWorldCopies === undefined\n ? true\n : renderWorldCopies) as boolean;\n this._minZoom = minZoom || 0;\n this._maxZoom = maxZoom || 22;\n\n this._minPitch = minPitch === undefined || minPitch === null ? 0 : minPitch;\n this._maxPitch =\n maxPitch === undefined || maxPitch === null ? 60 : maxPitch;\n\n this.setMaxBounds();\n\n this.width = 0;\n this.height = 0;\n this._center = new LngLat(0, 0);\n this.zoom = 0;\n this.angle = 0;\n this._fov = 0.6435011087932844;\n this._pitch = 0;\n this.unmodified = true;\n this.edgeInsets = new EdgeInsets();\n this.posMatrixCache = {};\n this.alignedPosMatrixCache = {};\n }\n\n public clone(): Transform {\n const clone = new Transform(\n this._minZoom,\n this._maxZoom,\n this._minPitch,\n this._maxPitch,\n this._renderWorldCopies,\n );\n clone.tileSize = this.tileSize;\n clone.latRange = this.latRange;\n clone.width = this.width;\n clone.height = this.height;\n clone.center = this._center;\n clone.zoom = this.zoom;\n clone.angle = this.angle;\n clone.fov = this._fov;\n clone.pitch = this._pitch;\n clone.unmodified = this.unmodified;\n clone.edgeInsets = this.edgeInsets.clone();\n clone.calcMatrices();\n return clone;\n }\n\n /**\n * Returns if the padding params match\n *\n * @param {IPaddingOptions} padding\n * @returns {boolean}\n * @memberof Transform\n */\n public isPaddingEqual(padding: IPaddingOptions): boolean {\n return this.edgeInsets.equals(padding);\n }\n\n /**\n * Helper method to upadte edge-insets inplace\n *\n * @param {IPaddingOptions} target\n * @param {number} t\n * @memberof Transform\n */\n public interpolatePadding(\n start: IPaddingOptions,\n target: IPaddingOptions,\n t: number,\n ) {\n this.unmodified = false;\n this.edgeInsets.interpolate(start, target, t);\n this.constrain();\n this.calcMatrices();\n }\n\n /**\n * Return a zoom level that will cover all tiles the transform\n * @param {Object} options options\n * @param {number} options.tileSize Tile size, expressed in screen pixels.\n * @param {boolean} options.roundZoom Target zoom level. If true, the value will be rounded to the closest integer. Otherwise the value will be floored.\n * @returns {number} zoom level An integer zoom level at which all tiles will be visible.\n */\n public coveringZoomLevel(options: { roundZoom?: boolean; tileSize: number }) {\n const z = (options.roundZoom ? Math.round : Math.floor)(\n this.zoom + this.scaleZoom(this.tileSize / options.tileSize),\n );\n // At negative zoom levels load tiles from z0 because negative tile zoom levels don't exist.\n return Math.max(0, z);\n }\n\n /**\n * Return any \"wrapped\" copies of a given tile coordinate that are visible\n * in the current view.\n *\n * @private\n */\n // public getVisibleUnwrappedCoordinates(tileID: CanonicalTileID) {\n // const result = [new UnwrappedTileID(0, tileID)];\n // if (this._renderWorldCopies) {\n // const utl = this.pointCoordinate(new Point(0, 0));\n // const utr = this.pointCoordinate(new Point(this.width, 0));\n // const ubl = this.pointCoordinate(new Point(this.width, this.height));\n // const ubr = this.pointCoordinate(new Point(0, this.height));\n // const w0 = Math.floor(Math.min(utl.x, utr.x, ubl.x, ubr.x));\n // const w1 = Math.floor(Math.max(utl.x, utr.x, ubl.x, ubr.x));\n\n // // Add an extra copy of the world on each side to properly render ImageSources and CanvasSources.\n // // Both sources draw outside the tile boundaries of the tile that \"contains them\" so we need\n // // to add extra copies on both sides in case offscreen tiles need to draw into on-screen ones.\n // const extraWorldCopy = 1;\n\n // for (let w = w0 - extraWorldCopy; w <= w1 + extraWorldCopy; w++) {\n // if (w === 0) {\n // continue;\n // }\n // result.push(new UnwrappedTileID(w, tileID));\n // }\n // }\n // return result;\n // }\n\n /**\n * Return all coordinates that could cover this transform for a covering\n * zoom level.\n * @param {Object} options\n * @param {number} options.tileSize\n * @param {number} options.minzoom\n * @param {number} options.maxzoom\n * @param {boolean} options.roundZoom\n * @param {boolean} options.reparseOverscaled\n * @param {boolean} options.renderWorldCopies\n * @returns {Array<OverscaledTileID>} OverscaledTileIDs\n * @private\n */\n // public coveringTiles(options: {\n // tileSize: number;\n // minzoom?: number;\n // maxzoom?: number;\n // roundZoom?: boolean;\n // reparseOverscaled?: boolean;\n // renderWorldCopies?: boolean;\n // }): OverscaledTileID[] {\n // let z = this.coveringZoomLevel(options);\n // const actualZ = z;\n\n // if (options.minzoom !== undefined && z < options.minzoom) {\n // return [];\n // }\n // if (options.maxzoom !== undefined && z > options.maxzoom) {\n // z = options.maxzoom;\n // }\n\n // const centerCoord = MercatorCoordinate.fromLngLat(this.center);\n // const numTiles = Math.pow(2, z);\n // const centerPoint = [numTiles * centerCoord.x, numTiles * centerCoord.y, 0];\n // const cameraFrustum = Frustum.fromInvProjectionMatrix(\n // this.invProjMatrix,\n // this.worldSize,\n // z,\n // );\n\n // // No change of LOD behavior for pitch lower than 60 and when there is no top padding: return only tile ids from the requested zoom level\n // let minZoom = options.minzoom || 0;\n // // Use 0.1 as an epsilon to avoid for explicit == 0.0 floating point checks\n // if (this._pitch <= 60.0 && this.edgeInsets.top < 0.1) {\n // minZoom = z;\n // }\n\n // // There should always be a certain number of maximum zoom level tiles surrounding the center location\n // const radiusOfMaxLvlLodInTiles = 3;\n\n // const newRootTile = (wrap: number): any => {\n // return {\n // // All tiles are on zero elevation plane => z difference is zero\n // aabb: new Aabb(\n // [wrap * numTiles, 0, 0],\n // [(wrap + 1) * numTiles, numTiles, 0],\n // ),\n // zoom: 0,\n // x: 0,\n // y: 0,\n // wrap,\n // fullyVisible: false,\n // };\n // };\n\n // // Do a depth-first traversal to find visible tiles and proper levels of detail\n // const stack = [];\n // const result = [];\n // const maxZoom = z;\n // const overscaledZ = options.reparseOverscaled ? actualZ : z;\n\n // if (this._renderWorldCopies) {\n // // Render copy of the globe thrice on both sides\n // for (let i = 1; i <= 3; i++) {\n // stack.push(newRootTile(-i));\n // stack.push(newRootTile(i));\n // }\n // }\n\n // stack.push(newRootTile(0));\n\n // while (stack.length > 0) {\n // const it = stack.pop();\n // const x = it.x;\n // const y = it.y;\n // let fullyVisible = it.fullyVisible;\n\n // // Visibility of a tile is not required if any of its ancestor if fully inside the frustum\n // if (!fullyVisible) {\n // const intersectResult = it.aabb.intersects(cameraFrustum);\n\n // if (intersectResult === 0) {\n // continue;\n // }\n\n // fullyVisible = intersectResult === 2;\n // }\n\n // const distanceX = it.aabb.distanceX(centerPoint);\n // const distanceY = it.aabb.distanceY(centerPoint);\n // const longestDim = Math.max(Math.abs(distanceX), Math.abs(distanceY));\n\n // // We're using distance based heuristics to determine if a tile should be split into quadrants or not.\n // // radiusOfMaxLvlLodInTiles defines that there's always a certain number of maxLevel tiles next to the map center.\n // // Using the fact that a parent node in quadtree is twice the size of its children (per dimension)\n // // we can define distance thresholds for each relative level:\n // // f(k) = offset + 2 + 4 + 8 + 16 + ... + 2^k. This is the same as \"offset+2^(k+1)-2\"\n // const distToSplit =\n // radiusOfMaxLvlLodInTiles + (1 << (maxZoom - it.zoom)) - 2;\n\n // // Have we reached the target depth or is the tile too far away to be any split further?\n // if (\n // it.zoom === maxZoom ||\n // (longestDim > distToSplit && it.zoom >= minZoom)\n // ) {\n // result.push({\n // tileID: new OverscaledTileID(\n // it.zoom === maxZoom ? overscaledZ : it.zoom,\n // it.wrap,\n // it.zoom,\n // x,\n // y,\n // ),\n // distanceSq: vec2.sqrLen([\n // centerPoint[0] - 0.5 - x,\n // centerPoint[1] - 0.5 - y,\n // ]),\n // });\n // continue;\n // }\n\n // for (let i = 0; i < 4; i++) {\n // const childX = (x << 1) + (i % 2);\n // const childY = (y << 1) + (i >> 1);\n\n // stack.push({\n // aabb: it.aabb.quadrant(i),\n // zoom: it.zoom + 1,\n // x: childX,\n // y: childY,\n // wrap: it.wrap,\n // fullyVisible,\n // });\n // }\n // }\n\n // return result\n // .sort((a, b) => a.distanceSq - b.distanceSq)\n // .map((a) => a.tileID);\n // }\n\n public resize(width: number, height: number) {\n this.width = width;\n this.height = height;\n\n this.pixelsToGLUnits = [2 / width, -2 / height];\n this.constrain();\n this.calcMatrices();\n }\n\n public zoomScale(zoom: number) {\n return Math.pow(2, zoom);\n }\n public scaleZoom(scale: number) {\n return Math.log(scale) / Math.LN2;\n }\n\n public project(lnglat: LngLat) {\n const lat = clamp(\n lnglat.lat,\n -this.maxValidLatitude,\n this.maxValidLatitude,\n );\n return new Point(\n mercatorXfromLng(lnglat.lng) * this.worldSize,\n mercatorYfromLat(lat) * this.worldSize,\n );\n }\n\n public unproject(point: Point): LngLat {\n return new MercatorCoordinate(\n point.x / this.worldSize,\n point.y / this.worldSize,\n ).toLngLat();\n }\n\n public setLocationAtPoint(lnglat: LngLat, point: Point) {\n const a = this.pointCoordinate(point);\n const b = this.pointCoordinate(this.centerPoint);\n const loc = this.locationCoordinate(lnglat);\n const newCenter = new MercatorCoordinate(\n loc.x - (a.x - b.x),\n loc.y - (a.y - b.y),\n );\n this.center = this.coordinateLocation(newCenter);\n if (this._renderWorldCopies) {\n this.center = this.center.wrap();\n }\n }\n\n public pointCoordinate(p: Point) {\n const targetZ = 0;\n // since we don't know the correct projected z value for the point,\n // unproject two points to get a line and then find the point on that\n // line with z=0\n\n const coord0 = new Float32Array([p.x, p.y, 0, 1]);\n const coord1 = new Float32Array([p.x, p.y, 1, 1]);\n\n vec4.transformMat4(coord0, coord0, this.pixelMatrixInverse);\n vec4.transformMat4(coord1, coord1, this.pixelMatrixInverse);\n\n const w0 = coord0[3];\n const w1 = coord1[3];\n const x0 = coord0[0] / w0;\n const x1 = coord1[0] / w1;\n const y0 = coord0[1] / w0;\n const y1 = coord1[1] / w1;\n const z0 = coord0[2] / w0;\n const z1 = coord1[2] / w1;\n\n const t = z0 === z1 ? 0 : (targetZ - z0) / (z1 - z0);\n\n return new MercatorCoordinate(\n interpolate(x0, x1, t) / this.worldSize,\n interpolate(y0, y1, t) / this.worldSize,\n );\n }\n\n /**\n * Returns the map's geographical bounds. When the bearing or pitch is non-zero, the visible region is not\n * an axis-aligned rectangle, and the result is the smallest bounds that encompasses the visible region.\n * @returns {LngLatBounds} Returns a {@link LngLatBounds} object describing the map's geographical bounds.\n */\n public getBounds(): LngLatBounds {\n return new LngLatBounds()\n .extend(this.pointLocation(new Point(0, 0)))\n .extend(this.pointLocation(new Point(this.width, 0)))\n .extend(this.pointLocation(new Point(this.width, this.height)))\n .extend(this.pointLocation(new Point(0, this.height)));\n }\n\n /**\n * Returns the maximum geographical bounds the map is constrained to, or `null` if none set.\n * @returns {LngLatBounds} {@link LngLatBounds}\n */\n public getMaxBounds(): LngLatBounds | null {\n if (\n !this.latRange ||\n this.latRange.length !== 2 ||\n !this.lngRange ||\n this.lngRange.length !== 2\n ) {\n return null;\n }\n\n return new LngLatBounds(\n [this.lngRange[0], this.latRange[0]],\n [this.lngRange[1], this.latRange[1]],\n );\n }\n\n /**\n * Sets or clears the map's geographical constraints.\n * @param {LngLatBounds} bounds A {@link LngLatBounds} object describing the new geographic boundaries of the map.\n */\n public setMaxBounds(bounds?: LngLatBounds) {\n if (bounds) {\n this.lngRange = [bounds.getWest(), bounds.getEast()];\n this.latRange = [bounds.getSouth(), bounds.getNorth()];\n this.constrain();\n } else {\n this.lngRange = undefined;\n this.latRange = [-this.maxValidLatitude, this.maxValidLatitude];\n }\n }\n\n public customLayerMatrix(): number[] {\n return (this.mercatorMatrix as number[]).slice();\n }\n\n public maxPitchScaleFactor() {\n // calcMatrices hasn't run yet\n if (!this.pixelMatrixInverse) {\n return 1;\n }\n\n const coord = this.pointCoordinate(new Point(0, 0));\n const p = new Float32Array([\n coord.x * this.worldSize,\n coord.y * this.worldSize,\n 0,\n 1,\n ]);\n const topPoint = vec4.transformMat4(p, p, this.pixelMatrix);\n return topPoint[3] / this.cameraToCenterDistance;\n }\n\n /*\n * The camera looks at the map from a 3D (lng, lat, altitude) location. Let's use `cameraLocation`\n * as the name for the location under the camera and on the surface of the earth (lng, lat, 0).\n * `cameraPoint` is the projected position of the `cameraLocation`.\n *\n * This point is useful to us because only fill-extrusions that are between `cameraPoint` and\n * the query point on the surface of the earth can extend and intersect the query.\n *\n * When the map is not pitched the `cameraPoint` is equivalent to the center of the map because\n * the camera is right above the center of the map.\n */\n public getCameraPoint() {\n const pitch = this._pitch;\n const yOffset = Math.tan(pitch) * (this.cameraToCenterDistance || 1);\n return this.centerPoint.add(new Point(0, yOffset));\n }\n\n /*\n * When the map is pitched, some of the 3D features that intersect a query will not intersect\n * the query at the surface of the earth. Instead the feature may be closer and only intersect\n * the query because it extrudes into the air.\n *\n * This returns a geometry that includes all of the original query as well as all possible ares of the\n * screen where the *base* of a visible extrusion could be.\n * - For point queries, the line from the query point to the \"camera point\"\n * - For other geometries, the envelope of the query geometry and the \"camera point\"\n */\n public getCameraQueryGeometry(queryGeometry: Point[]): Point[] {\n const c = this.getCameraPoint();\n\n if (queryGeometry.length === 1) {\n return [queryGeometry[0], c];\n } else {\n let minX = c.x;\n let minY = c.y;\n let maxX = c.x;\n let maxY = c.y;\n for (const p of queryGeometry) {\n minX = Math.min(minX, p.x);\n minY = Math.min(minY, p.y);\n maxX = Math.max(maxX, p.x);\n maxY = Math.max(maxY, p.y);\n }\n return [\n new Point(minX, minY),\n new Point(maxX, minY),\n new Point(maxX, maxY),\n new Point(minX, maxY),\n new Point(minX, minY),\n ];\n }\n }\n\n /**\n * Given a coordinate, return the screen point that corresponds to it\n * @param {Coordinate} coord\n * @returns {Point} screen point\n * @private\n */\n public coordinatePoint(coord: MercatorCoordinate) {\n const p = vec4.fromValues(\n coord.x * this.worldSize,\n coord.y * this.worldSize,\n 0,\n 1,\n );\n vec4.transformMat4(p, p, this.pixelMatrix);\n return new Point(p[0] / p[3], p[1] / p[3]);\n }\n /**\n * Given a location, return the screen point that corresponds to it\n * @param {LngLat} lnglat location\n * @returns {Point} screen point\n * @private\n */\n public locationPoint(lnglat: LngLat) {\n return this.coordinatePoint(this.locationCoordinate(lnglat));\n }\n\n /**\n * Given a point on screen, return its lnglat\n * @param {Point} p screen point\n * @returns {LngLat} lnglat location\n * @private\n */\n public pointLocation(p: Point) {\n // if(p.x !== 0 && p.x !== 1001) {\n // console.log(p.x)\n // }\n\n return this.coordinateLocation(this.pointCoordinate(p));\n }\n\n /**\n * Given a geographical lnglat, return an unrounded\n * coordinate that represents it at this transform's zoom level.\n * @param {LngLat} lnglat\n * @returns {Coordinate}\n * @private\n */\n public locationCoordinate(lnglat: LngLat) {\n return MercatorCoordinate.fromLngLat(lnglat);\n }\n\n /**\n * Given a Coordinate, return its geographical position.\n * @param {Coordinate} coord\n * @returns {LngLat} lnglat\n * @private\n */\n public coordinateLocation(coord: MercatorCoordinate) {\n return coord.toLngLat();\n }\n\n public getProjectionMatrix(): mat4 {\n return this.projMatrix;\n }\n /**\n * Calculate the posMatrix that, given a tile coordinate, would be used to display the tile on a map.\n * @param {UnwrappedTileID} unwrappedTileID;\n * @private\n */\n // private calculatePosMatrix(\n // unwrappedTileID: UnwrappedTileID,\n // aligned: boolean = false,\n // ): Float32Array {\n // const posMatrixKey = unwrappedTileID.key;\n // const cache = aligned ? this.alignedPosMatrixCache : this.posMatrixCache;\n // if (cache[posMatrixKey]) {\n // return cache[posMatrixKey];\n // }\n\n // const canonical = unwrappedTileID.canonical;\n // const scale = this.worldSize / this.zoomScale(canonical.z);\n // const unwrappedX =\n // canonical.x + Math.pow(2, canonical.z) * unwrappedTileID.wrap;\n\n // const posMatrix = mat4.identity(new Float64Array(16));\n // mat4.translate(posMatrix, posMatrix, [\n // unwrappedX * scale,\n // canonical.y * scale,\n // 0,\n // ]);\n // mat4.scale(posMatrix, posMatrix, [scale / EXTENT, scale / EXTENT, 1]);\n // mat4.multiply(\n // posMatrix,\n // aligned ? this.alignedProjMatrix : this.projMatrix,\n // posMatrix,\n // );\n\n // cache[posMatrixKey] = new Float32Array(posMatrix);\n // return cache[posMatrixKey];\n // }\n\n private constrain() {\n if (!this.center || !this.width || !this.height || this.constraining) {\n return;\n }\n\n this.constraining = true;\n\n let minY = -90;\n let maxY = 90;\n let minX = -180;\n let maxX = 180;\n let sy;\n let sx;\n let x2;\n let y2;\n const size = this.size;\n const unmodified = this.unmodified;\n\n if (this.latRange) {\n const latRange = this.latRange;\n minY = mercatorYfromLat(latRange[1]) * this.worldSize;\n maxY = mercatorYfromLat(latRange[0]) * this.worldSize;\n sy = maxY - minY < size.y ? size.y / (maxY - minY) : 0;\n }\n\n if (this.lngRange) {\n const lngRange = this.lngRange;\n minX = mercatorXfromLng(lngRange[0]) * this.worldSize;\n maxX = mercatorXfromLng(lngRange[1]) * this.worldSize;\n sx = maxX - minX < size.x ? size.x / (maxX - minX) : 0;\n }\n\n const point = this.point;\n\n // how much the map should scale to fit the screen into given latitude/longitude ranges\n const s = Math.max(sx || 0, sy || 0);\n\n if (s) {\n this.center = this.unproject(\n new Point(\n sx ? (maxX + minX) / 2 : point.x,\n sy ? (maxY + minY) / 2 : point.y,\n ),\n );\n this.zoom += this.scaleZoom(s);\n this.unmodified = unmodified;\n this.constraining = false;\n return;\n }\n\n if (this.latRange) {\n const y = point.y;\n const h2 = size.y / 2;\n\n if (y - h2 < minY) {\n y2 = minY + h2;\n }\n if (y + h2 > maxY) {\n y2 = maxY - h2;\n }\n }\n\n if (this.lngRange) {\n const x = point.x;\n const w2 = size.x / 2;\n\n if (x - w2 < minX) {\n x2 = minX + w2;\n }\n if (x + w2 > maxX) {\n x2 = maxX - w2;\n }\n }\n\n // pan the map if the screen goes off the range\n if (x2 !== undefined || y2 !== undefined) {\n this.center = this.unproject(\n new Point(\n x2 !== undefined ? x2 : point.x,\n y2 !== undefined ? y2 : point.y,\n ),\n );\n }\n\n this.unmodified = unmodified;\n this.constraining = false;\n }\n\n private calcMatrices() {\n if (!this.height) {\n return;\n }\n\n const halfFov = this._fov / 2;\n const offset = this.centerOffset;\n this.cameraToCenterDistance = (0.5 / Math.tan(halfFov)) * this.height;\n\n // Find the distance from the center point [width/2 + offset.x, height/2 + offset.y] to the\n // center top point [width/2 + offset.x, 0] in Z units, using the law of sines.\n // 1 Z unit is equivalent to 1 horizontal px at the center of the map\n // (the distance between[width/2, height/2] and [width/2 + 1, height/2])\n const groundAngle = Math.PI / 2 + this._pitch;\n const fovAboveCenter = this._fov * (0.5 + offset.y / this.height);\n const topHalfSurfaceDistance =\n (Math.sin(fovAboveCenter) * this.cameraToCenterDistance) /\n Math.sin(\n clamp(Math.PI - groundAngle - fovAboveCenter, 0.01, Math.PI - 0.01),\n );\n const point = this.point;\n const x = point.x;\n const y = point.y;\n\n // Calculate z distance of the farthest fragment that should be rendered.\n const furthestDistance =\n Math.cos(Math.PI / 2 - this._pitch) * topHalfSurfaceDistance +\n this.cameraToCenterDistance;\n // Add a bit extra to avoid precision problems when a fragment's distance is exactly `furthestDistance`\n const farZ = furthestDistance * 1.01;\n\n // The larger the value of nearZ is\n // - the more depth precision is available for features (good)\n // - clipping starts appearing sooner when the camera is close to 3d features (bad)\n //\n // Smaller values worked well for mapbox-gl-js but deckgl was encountering precision issues\n // when rendering it's layers using custom layers. This value was experimentally chosen and\n // seems to solve z-fighting issues in deckgl while not clipping buildings too close to the camera.\n const nearZ = this.height / 50;\n\n // matrix for conversion from location to GL coordinates (-1 .. 1)\n // TODO: 使用 Float64Array 的原因是为了避免计算精度问题、 mat4.create() 默认使用 Float32Array\n let m = new Float64Array(16);\n // @ts-ignore\n mat4.perspective(m, this._fov, this.width / this.height, nearZ, farZ);\n\n // Apply center of perspective offset\n m[8] = (-offset.x * 2) / this.width;\n m[9] = (offset.y * 2) / this.height;\n\n // @ts-ignore\n mat4.scale(m, m, [1, -1, 1]);\n // @ts-ignore\n mat4.translate(m, m, [0, 0, -this.cameraToCenterDistance]);\n // @ts-ignore\n mat4.rotateX(m, m, this._pitch);\n // @ts-ignore\n mat4.rotateZ(m, m, this.angle);\n // @ts-ignore\n mat4.translate(m, m, [-x, -y, 0]);\n\n // The mercatorMatrix can be used to transform points from mercator coordinates\n // ([0, 0] nw, [1, 1] se) to GL coordinates.\n // @ts-ignore\n this.mercatorMatrix = mat4.scale([], m, [\n this.worldSize,\n this.worldSize,\n this.worldSize,\n ]);\n // scale vertically to meters per pixel (inverse of ground resolution):\n\n // @ts-ignore\n mat4.scale(m, m, [\n 1,\n 1,\n mercatorZfromAltitude(1, this.center.lat) * this.worldSize,\n 1,\n ]);\n // @ts-ignore\n this.projMatrix = m;\n // @ts-ignore\n this.invProjMatrix = mat4.invert([], this.projMatrix);\n\n // Make a second projection matrix that is aligned to a pixel grid for rendering raster tiles.\n // We're rounding the (floating point) x/y values to achieve to avoid rendering raster images to fractional\n // coordinates. Additionally, we adjust by half a pixel in either direction in case that viewport dimension\n // is an odd integer to preserve rendering to the pixel grid. We're rotating this shift based on the angle\n // of the transformation so that 0°, 90°, 180°, and 270° rasters are crisp, and adjust the shift so that\n // it is always <= 0.5 pixels.\n const xShift = (this.width % 2) / 2;\n const yShift = (this.height % 2) / 2;\n const angleCos = Math.cos(this.angle);\n const angleSin = Math.sin(this.angle);\n const dx = x - Math.round(x) + angleCos * xShift + angleSin * yShift;\n const dy = y - Math.round(y) + angleCos * yShift + angleSin * xShift;\n // const alignedM = mat4.clone(m);\n const alignedM = new Float64Array(m);\n // @ts-ignore\n mat4.translate(alignedM, alignedM, [\n dx > 0.5 ? dx - 1 : dx,\n dy > 0.5 ? dy - 1 : dy,\n 0,\n ]);\n // @ts-ignore\n this.alignedProjMatrix = alignedM;\n\n // @ts-ignore\n m = mat4.create();\n // @ts-ignore\n mat4.scale(m, m, [this.width / 2, -this.height / 2, 1]);\n // @ts-ignore\n mat4.translate(m, m, [1, -1, 0]);\n // @ts-ignore\n this.labelPlaneMatrix = m;\n\n // @ts-ignore\n m = mat4.create();\n // @ts-ignore\n mat4.scale(m, m, [1, -1, 1]);\n // @ts-ignore\n mat4.translate(m, m, [-1, -1, 0]);\n // @ts-ignore\n mat4.scale(m, m, [2 / this.width, 2 / this.height, 1]);\n // @ts-ignore\n this.glCoordMatrix = m;\n\n // matrix for conversion from location to screen coordinates\n this.pixelMatrix = mat4.multiply(\n // @ts-ignore\n new Float64Array(16),\n this.labelPlaneMatrix,\n this.projMatrix,\n );\n\n // inverse matrix for conversion from screen coordinaes to location\n // @ts-ignore\n m = mat4.invert(new Float64Array(16), this.pixelMatrix);\n if (!m) {\n throw new Error('failed to invert matrix');\n }\n // @ts-ignore\n this.pixelMatrixInverse = m;\n\n this.posMatrixCache = {};\n this.alignedPosMatrixCache = {};\n }\n}\n"],"file":"transform.js"}
@@ -609,8 +609,7 @@ var Transform = function () {
609
609
  var furthestDistance = Math.cos(Math.PI / 2 - this._pitch) * topHalfSurfaceDistance + this.cameraToCenterDistance;
610
610
  var farZ = furthestDistance * 1.01;
611
611
  var nearZ = this.height / 50;
612
-
613
- var m = _glMatrix.mat4.create();
612
+ var m = new Float64Array(16);
614
613
 
615
614
  _glMatrix.mat4.perspective(m, this._fov, this.width / this.height, nearZ, farZ);
616
615
 
@@ -627,20 +626,19 @@ var Transform = function () {
627
626
 
628
627
  _glMatrix.mat4.translate(m, m, [-x, -y, 0]);
629
628
 
630
- this.mercatorMatrix = _glMatrix.mat4.scale(_glMatrix.mat4.create(), m, [this.worldSize, this.worldSize, this.worldSize]);
629
+ this.mercatorMatrix = _glMatrix.mat4.scale([], m, [this.worldSize, this.worldSize, this.worldSize]);
631
630
 
632
- _glMatrix.mat4.scale(m, m, _glMatrix.vec3.fromValues(1, 1, (0, _mercator.mercatorZfromAltitude)(1, this.center.lat) * this.worldSize));
631
+ _glMatrix.mat4.scale(m, m, [1, 1, (0, _mercator.mercatorZfromAltitude)(1, this.center.lat) * this.worldSize, 1]);
633
632
 
634
633
  this.projMatrix = m;
635
- this.invProjMatrix = _glMatrix.mat4.invert(_glMatrix.mat4.create(), this.projMatrix);
634
+ this.invProjMatrix = _glMatrix.mat4.invert([], this.projMatrix);
636
635
  var xShift = this.width % 2 / 2;
637
636
  var yShift = this.height % 2 / 2;
638
637
  var angleCos = Math.cos(this.angle);
639
638
  var angleSin = Math.sin(this.angle);
640
639
  var dx = x - Math.round(x) + angleCos * xShift + angleSin * yShift;
641
640
  var dy = y - Math.round(y) + angleCos * yShift + angleSin * xShift;
642
-
643
- var alignedM = _glMatrix.mat4.clone(m);
641
+ var alignedM = new Float64Array(m);
644
642
 
645
643
  _glMatrix.mat4.translate(alignedM, alignedM, [dx > 0.5 ? dx - 1 : dx, dy > 0.5 ? dy - 1 : dy, 0]);
646
644
 
@@ -661,8 +659,8 @@ var Transform = function () {
661
659
  _glMatrix.mat4.scale(m, m, [2 / this.width, 2 / this.height, 1]);
662
660
 
663
661
  this.glCoordMatrix = m;
664
- this.pixelMatrix = _glMatrix.mat4.multiply(_glMatrix.mat4.create(), this.labelPlaneMatrix, this.projMatrix);
665
- m = _glMatrix.mat4.invert(_glMatrix.mat4.create(), this.pixelMatrix);
662
+ this.pixelMatrix = _glMatrix.mat4.multiply(new Float64Array(16), this.labelPlaneMatrix, this.projMatrix);
663
+ m = _glMatrix.mat4.invert(new Float64Array(16), this.pixelMatrix);
666
664
 
667
665
  if (!m) {
668
666
  throw new Error('failed to invert matrix');
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/geo/transform.ts"],"names":["EXTENT","Transform","minZoom","maxZoom","minPitch","maxPitch","renderWorldCopies","tileSize","maxValidLatitude","_renderWorldCopies","undefined","_minZoom","_maxZoom","_minPitch","_maxPitch","setMaxBounds","width","height","_center","LngLat","zoom","angle","_fov","_pitch","unmodified","edgeInsets","EdgeInsets","posMatrixCache","alignedPosMatrixCache","Math","max","min","pitch","scale","centerPoint","_sub","size","_div","Point","PI","bearing","b","calcMatrices","rotationMatrix","mat2","create","rotate","p","fov","_zoom","z","zoomScale","tileZoom","floor","zoomFraction","constrain","center","lat","lng","toJSON","padding","equals","interpolate","getCenter","project","clone","latRange","start","target","t","options","roundZoom","round","scaleZoom","pixelsToGLUnits","pow","log","LN2","lnglat","worldSize","point","MercatorCoordinate","x","y","toLngLat","a","pointCoordinate","loc","locationCoordinate","newCenter","coordinateLocation","wrap","targetZ","coord0","Float32Array","coord1","vec4","transformMat4","pixelMatrixInverse","w0","w1","x0","x1","y0","y1","z0","z1","LngLatBounds","extend","pointLocation","length","lngRange","bounds","getWest","getEast","getSouth","getNorth","mercatorMatrix","slice","coord","topPoint","pixelMatrix","cameraToCenterDistance","yOffset","tan","add","queryGeometry","c","getCameraPoint","minX","minY","maxX","maxY","fromValues","coordinatePoint","fromLngLat","projMatrix","constraining","sy","sx","x2","y2","s","unproject","h2","w2","halfFov","offset","centerOffset","groundAngle","fovAboveCenter","topHalfSurfaceDistance","sin","furthestDistance","cos","farZ","nearZ","m","mat4","perspective","translate","rotateX","rotateZ","vec3","invProjMatrix","invert","xShift","yShift","angleCos","angleSin","dx","dy","align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L,GAAwBjB,CAAxB;AAEAA,MAAAA,CAAC,GAAGC,eAAKjH,MAAL,EAAJ;;AACAiH,qBAAK7H,KAAL,CAAW4H,CAAX,EAAcA,CAAd,EAAiB,CAAC,CAAD,EAAI,CAAC,CAAL,EAAQ,CAAR,CAAjB;;AACAC,qBAAKE,SAAL,CAAeH,CAAf,EAAkBA,CAAlB,EAAqB,CAAC,CAAC,CAAF,EAAK,CAAC,CAAN,EAAS,CAAT,CAArB;;AACAC,qBAAK7H,KAAL,CAAW4H,CAAX,EAAcA,CAAd,EAAiB,CAAC,IAAI,KAAK7I,KAAV,EAAiB,IAAI,KAAKC,MAA1B,EAAkC,CAAlC,CAAjB;;AACA,WAAK8J,aAAL,GAAqBlB,CAArB;AAGA,WAAKpC,WAAL,GAAmBqC,eAAKkB,QAAL,CACjBlB,eAAKjH,MAAL,EADiB,EAEjB,KAAKiI,gBAFY,EAGjB,KAAKtC,UAHY,CAAnB;AAOAqB,MAAAA,CAAC,GAAGC,eAAKO,MAAL,CAAYP,eAAKjH,MAAL,EAAZ,EAA2B,KAAK4E,WAAhC,CAAJ;;AACA,UAAI,CAACoC,CAAL,EAAQ;AACN,cAAM,IAAIoB,KAAJ,CAAU,yBAAV,CAAN;AACD;;AACD,WAAK/E,kBAAL,GAA0B2D,CAA1B;AAEA,WAAKlI,cAAL,GAAsB,EAAtB;AACA,WAAKC,qBAAL,GAA6B,EAA7B;AACD","sourcesContent":["// @ts-ignore\nimport { mat2, mat4, vec3, vec4 } from 'gl-matrix';\nimport Point, { PointLike } from '../geo/point';\nimport { clamp, interpolate, wrap } from '../util';\nimport Aabb from '../utils/Aabb';\nimport Frustum from '../utils/primitives';\nimport EdgeInsets, { IPaddingOptions } from './edge_insets';\nimport LngLat from './lng_lat';\nimport LngLatBounds from './lng_lat_bounds';\nimport MercatorCoordinate, {\n mercatorXfromLng,\n mercatorYfromLat,\n mercatorZfromAltitude,\n} from './mercator';\nexport const EXTENT = 8192;\nexport default class Transform {\n get minZoom(): number {\n return this._minZoom;\n }\n set minZoom(zoom: number) {\n if (this._minZoom === zoom) {\n return;\n }\n this._minZoom = zoom;\n this.zoom = Math.max(this.zoom, zoom);\n }\n\n get maxZoom(): number {\n return this._maxZoom;\n }\n set maxZoom(zoom: number) {\n if (this._maxZoom === zoom) {\n return;\n }\n this._maxZoom = zoom;\n this.zoom = Math.min(this.zoom, zoom);\n }\n\n get minPitch(): number {\n return this._minPitch;\n }\n set minPitch(pitch: number) {\n if (this._minPitch === pitch) {\n return;\n }\n this._minPitch = pitch;\n this._pitch = Math.max(this._pitch, pitch);\n }\n\n get maxPitch(): number {\n return this._maxPitch;\n }\n set maxPitch(pitch: number) {\n if (this._maxPitch === pitch) {\n return;\n }\n this._maxPitch = pitch;\n this._pitch = Math.min(this._pitch, pitch);\n }\n\n get renderWorldCopies(): boolean {\n return this._renderWorldCopies;\n }\n set renderWorldCopies(renderWorldCopies: boolean) {\n if (renderWorldCopies === undefined) {\n renderWorldCopies = true;\n } else if (renderWorldCopies === null) {\n renderWorldCopies = false;\n }\n\n this._renderWorldCopies = renderWorldCopies;\n }\n\n get worldSize(): number {\n return this.tileSize * this.scale;\n }\n\n get centerOffset(): Point {\n return this.centerPoint._sub(this.size._div(2));\n }\n\n get size(): Point {\n return new Point(this.width, this.height);\n }\n\n get bearing(): number {\n return (-this.angle / Math.PI) * 180;\n }\n set bearing(bearing: number) {\n const b = (-wrap(bearing, -180, 180) * Math.PI) / 180;\n if (this.angle === b) {\n return;\n }\n this.unmodified = false;\n this.angle = b;\n this.calcMatrices();\n\n // 2x2 matrix for rotating points\n this.rotationMatrix = mat2.create();\n mat2.rotate(this.rotationMatrix, this.rotationMatrix, this.angle);\n }\n\n get pitch(): number {\n return (this._pitch / Math.PI) * 180;\n }\n set pitch(pitch: number) {\n const p = (clamp(pitch, this._minPitch, this._maxPitch) / 180) * Math.PI;\n if (this._pitch === p) {\n return;\n }\n this.unmodified = false;\n this._pitch = p;\n this.calcMatrices();\n }\n\n get fov(): number {\n return (this._fov / Math.PI) * 180;\n }\n\n set fov(fov: number) {\n fov = Math.max(0.01, Math.min(60, fov));\n if (this._fov === fov) {\n return;\n }\n this.unmodified = false;\n this._fov = (fov / 180) * Math.PI;\n this.calcMatrices();\n }\n\n get zoom(): number {\n return this._zoom;\n }\n\n set zoom(zoom: number) {\n const z = Math.min(Math.max(zoom, this._minZoom), this._maxZoom);\n if (this._zoom === z) {\n return;\n }\n this.unmodified = false;\n this._zoom = z;\n this.scale = this.zoomScale(z);\n this.tileZoom = Math.floor(z);\n this.zoomFraction = z - this.tileZoom;\n this.constrain();\n this.calcMatrices();\n }\n\n get center(): LngLat {\n return this._center;\n }\n\n set center(center: LngLat) {\n if (center.lat === this._center.lat && center.lng === this._center.lng) {\n return;\n }\n this.unmodified = false;\n this._center = center;\n this.constrain();\n this.calcMatrices();\n }\n\n get padding(): IPaddingOptions {\n return this.edgeInsets.toJSON();\n }\n\n set padding(padding: IPaddingOptions) {\n if (this.edgeInsets.equals(padding)) {\n return;\n }\n this.unmodified = false;\n // Update edge-insets inplace\n this.edgeInsets.interpolate(this.edgeInsets, padding, 1);\n this.calcMatrices();\n }\n\n /**\n * The center of the screen in pixels with the top-left corner being (0,0)\n * and +y axis pointing downwards. This accounts for padding.\n *\n * @readonly\n * @type {Point}\n * @memberof Transform\n */\n get centerPoint(): Point {\n return this.edgeInsets.getCenter(this.width, this.height);\n }\n\n get point(): Point {\n return this.project(this.center);\n }\n public tileSize: number;\n public tileZoom: number;\n public lngRange?: [number, number];\n public latRange?: [number, number];\n public maxValidLatitude: number;\n public scale: number;\n public width: number;\n public height: number;\n public angle: number;\n public rotationMatrix: mat2;\n public pixelsToGLUnits: [number, number];\n public cameraToCenterDistance: number;\n public mercatorMatrix: mat4;\n public projMatrix: mat4;\n public invProjMatrix: mat4;\n public alignedProjMatrix: mat4;\n public pixelMatrix: mat4;\n public pixelMatrixInverse: mat4;\n public glCoordMatrix: mat4;\n public labelPlaneMatrix: mat4;\n // tslint:disable:variable-name\n private _fov: number;\n private _pitch: number;\n private _zoom: number;\n private _renderWorldCopies: boolean;\n private _minZoom: number;\n private _maxZoom: number;\n private _minPitch: number;\n private _maxPitch: number;\n private _center: LngLat;\n // tslint:enable\n private zoomFraction: number;\n private unmodified: boolean;\n private edgeInsets: EdgeInsets;\n private constraining: boolean;\n private posMatrixCache: { [_: string]: Float32Array };\n private alignedPosMatrixCache: { [_: string]: Float32Array };\n constructor(\n minZoom: number,\n maxZoom: number,\n minPitch: number,\n maxPitch: number,\n renderWorldCopies: boolean | void,\n ) {\n this.tileSize = 512; // constant\n this.maxValidLatitude = 85.051129; // constant\n\n this._renderWorldCopies = (renderWorldCopies === undefined\n ? true\n : renderWorldCopies) as boolean;\n this._minZoom = minZoom || 0;\n this._maxZoom = maxZoom || 22;\n\n this._minPitch = minPitch === undefined || minPitch === null ? 0 : minPitch;\n this._maxPitch =\n maxPitch === undefined || maxPitch === null ? 60 : maxPitch;\n\n this.setMaxBounds();\n\n this.width = 0;\n this.height = 0;\n this._center = new LngLat(0, 0);\n this.zoom = 0;\n this.angle = 0;\n this._fov = 0.6435011087932844;\n this._pitch = 0;\n this.unmodified = true;\n this.edgeInsets = new EdgeInsets();\n this.posMatrixCache = {};\n this.alignedPosMatrixCache = {};\n }\n\n public clone(): Transform {\n const clone = new Transform(\n this._minZoom,\n this._maxZoom,\n this._minPitch,\n this._maxPitch,\n this._renderWorldCopies,\n );\n clone.tileSize = this.tileSize;\n clone.latRange = this.latRange;\n clone.width = this.width;\n clone.height = this.height;\n clone.center = this._center;\n clone.zoom = this.zoom;\n clone.angle = this.angle;\n clone.fov = this._fov;\n clone.pitch = this._pitch;\n clone.unmodified = this.unmodified;\n clone.edgeInsets = this.edgeInsets.clone();\n clone.calcMatrices();\n return clone;\n }\n\n /**\n * Returns if the padding params match\n *\n * @param {IPaddingOptions} padding\n * @returns {boolean}\n * @memberof Transform\n */\n public isPaddingEqual(padding: IPaddingOptions): boolean {\n return this.edgeInsets.equals(padding);\n }\n\n /**\n * Helper method to upadte edge-insets inplace\n *\n * @param {IPaddingOptions} target\n * @param {number} t\n * @memberof Transform\n */\n public interpolatePadding(\n start: IPaddingOptions,\n target: IPaddingOptions,\n t: number,\n ) {\n this.unmodified = false;\n this.edgeInsets.interpolate(start, target, t);\n this.constrain();\n this.calcMatrices();\n }\n\n /**\n * Return a zoom level that will cover all tiles the transform\n * @param {Object} options options\n * @param {number} options.tileSize Tile size, expressed in screen pixels.\n * @param {boolean} options.roundZoom Target zoom level. If true, the value will be rounded to the closest integer. Otherwise the value will be floored.\n * @returns {number} zoom level An integer zoom level at which all tiles will be visible.\n */\n public coveringZoomLevel(options: { roundZoom?: boolean; tileSize: number }) {\n const z = (options.roundZoom ? Math.round : Math.floor)(\n this.zoom + this.scaleZoom(this.tileSize / options.tileSize),\n );\n // At negative zoom levels load tiles from z0 because negative tile zoom levels don't exist.\n return Math.max(0, z);\n }\n\n /**\n * Return any \"wrapped\" copies of a given tile coordinate that are visible\n * in the current view.\n *\n * @private\n */\n // public getVisibleUnwrappedCoordinates(tileID: CanonicalTileID) {\n // const result = [new UnwrappedTileID(0, tileID)];\n // if (this._renderWorldCopies) {\n // const utl = this.pointCoordinate(new Point(0, 0));\n // const utr = this.pointCoordinate(new Point(this.width, 0));\n // const ubl = this.pointCoordinate(new Point(this.width, this.height));\n // const ubr = this.pointCoordinate(new Point(0, this.height));\n // const w0 = Math.floor(Math.min(utl.x, utr.x, ubl.x, ubr.x));\n // const w1 = Math.floor(Math.max(utl.x, utr.x, ubl.x, ubr.x));\n\n // // Add an extra copy of the world on each side to properly render ImageSources and CanvasSources.\n // // Both sources draw outside the tile boundaries of the tile that \"contains them\" so we need\n // // to add extra copies on both sides in case offscreen tiles need to draw into on-screen ones.\n // const extraWorldCopy = 1;\n\n // for (let w = w0 - extraWorldCopy; w <= w1 + extraWorldCopy; w++) {\n // if (w === 0) {\n // continue;\n // }\n // result.push(new UnwrappedTileID(w, tileID));\n // }\n // }\n // return result;\n // }\n\n /**\n * Return all coordinates that could cover this transform for a covering\n * zoom level.\n * @param {Object} options\n * @param {number} options.tileSize\n * @param {number} options.minzoom\n * @param {number} options.maxzoom\n * @param {boolean} options.roundZoom\n * @param {boolean} options.reparseOverscaled\n * @param {boolean} options.renderWorldCopies\n * @returns {Array<OverscaledTileID>} OverscaledTileIDs\n * @private\n */\n // public coveringTiles(options: {\n // tileSize: number;\n // minzoom?: number;\n // maxzoom?: number;\n // roundZoom?: boolean;\n // reparseOverscaled?: boolean;\n // renderWorldCopies?: boolean;\n // }): OverscaledTileID[] {\n // let z = this.coveringZoomLevel(options);\n // const actualZ = z;\n\n // if (options.minzoom !== undefined && z < options.minzoom) {\n // return [];\n // }\n // if (options.maxzoom !== undefined && z > options.maxzoom) {\n // z = options.maxzoom;\n // }\n\n // const centerCoord = MercatorCoordinate.fromLngLat(this.center);\n // const numTiles = Math.pow(2, z);\n // const centerPoint = [numTiles * centerCoord.x, numTiles * centerCoord.y, 0];\n // const cameraFrustum = Frustum.fromInvProjectionMatrix(\n // this.invProjMatrix,\n // this.worldSize,\n // z,\n // );\n\n // // No change of LOD behavior for pitch lower than 60 and when there is no top padding: return only tile ids from the requested zoom level\n // let minZoom = options.minzoom || 0;\n // // Use 0.1 as an epsilon to avoid for explicit == 0.0 floating point checks\n // if (this._pitch <= 60.0 && this.edgeInsets.top < 0.1) {\n // minZoom = z;\n // }\n\n // // There should always be a certain number of maximum zoom level tiles surrounding the center location\n // const radiusOfMaxLvlLodInTiles = 3;\n\n // const newRootTile = (wrap: number): any => {\n // return {\n // // All tiles are on zero elevation plane => z difference is zero\n // aabb: new Aabb(\n // [wrap * numTiles, 0, 0],\n // [(wrap + 1) * numTiles, numTiles, 0],\n // ),\n // zoom: 0,\n // x: 0,\n // y: 0,\n // wrap,\n // fullyVisible: false,\n // };\n // };\n\n // // Do a depth-first traversal to find visible tiles and proper levels of detail\n // const stack = [];\n // const result = [];\n // const maxZoom = z;\n // const overscaledZ = options.reparseOverscaled ? actualZ : z;\n\n // if (this._renderWorldCopies) {\n // // Render copy of the globe thrice on both sides\n // for (let i = 1; i <= 3; i++) {\n // stack.push(newRootTile(-i));\n // stack.push(newRootTile(i));\n // }\n // }\n\n // stack.push(newRootTile(0));\n\n // while (stack.length > 0) {\n // const it = stack.pop();\n // const x = it.x;\n // const y = it.y;\n // let fullyVisible = it.fullyVisible;\n\n // // Visibility of a tile is not required if any of its ancestor if fully inside the frustum\n // if (!fullyVisible) {\n // const intersectResult = it.aabb.intersects(cameraFrustum);\n\n // if (intersectResult === 0) {\n // continue;\n // }\n\n // fullyVisible = intersectResult === 2;\n // }\n\n // const distanceX = it.aabb.distanceX(centerPoint);\n // const distanceY = it.aabb.distanceY(centerPoint);\n // const longestDim = Math.max(Math.abs(distanceX), Math.abs(distanceY));\n\n // // We're using distance based heuristics to determine if a tile should be split into quadrants or not.\n // // radiusOfMaxLvlLodInTiles defines that there's always a certain number of maxLevel tiles next to the map center.\n // // Using the fact that a parent node in quadtree is twice the size of its children (per dimension)\n // // we can define distance thresholds for each relative level:\n // // f(k) = offset + 2 + 4 + 8 + 16 + ... + 2^k. This is the same as \"offset+2^(k+1)-2\"\n // const distToSplit =\n // radiusOfMaxLvlLodInTiles + (1 << (maxZoom - it.zoom)) - 2;\n\n // // Have we reached the target depth or is the tile too far away to be any split further?\n // if (\n // it.zoom === maxZoom ||\n // (longestDim > distToSplit && it.zoom >= minZoom)\n // ) {\n // result.push({\n // tileID: new OverscaledTileID(\n // it.zoom === maxZoom ? overscaledZ : it.zoom,\n // it.wrap,\n // it.zoom,\n // x,\n // y,\n // ),\n // distanceSq: vec2.sqrLen([\n // centerPoint[0] - 0.5 - x,\n // centerPoint[1] - 0.5 - y,\n // ]),\n // });\n // continue;\n // }\n\n // for (let i = 0; i < 4; i++) {\n // const childX = (x << 1) + (i % 2);\n // const childY = (y << 1) + (i >> 1);\n\n // stack.push({\n // aabb: it.aabb.quadrant(i),\n // zoom: it.zoom + 1,\n // x: childX,\n // y: childY,\n // wrap: it.wrap,\n // fullyVisible,\n // });\n // }\n // }\n\n // return result\n // .sort((a, b) => a.distanceSq - b.distanceSq)\n // .map((a) => a.tileID);\n // }\n\n public resize(width: number, height: number) {\n this.width = width;\n this.height = height;\n\n this.pixelsToGLUnits = [2 / width, -2 / height];\n this.constrain();\n this.calcMatrices();\n }\n\n public zoomScale(zoom: number) {\n return Math.pow(2, zoom);\n }\n public scaleZoom(scale: number) {\n return Math.log(scale) / Math.LN2;\n }\n\n public project(lnglat: LngLat) {\n const lat = clamp(\n lnglat.lat,\n -this.maxValidLatitude,\n this.maxValidLatitude,\n );\n return new Point(\n mercatorXfromLng(lnglat.lng) * this.worldSize,\n mercatorYfromLat(lat) * this.worldSize,\n );\n }\n\n public unproject(point: Point): LngLat {\n return new MercatorCoordinate(\n point.x / this.worldSize,\n point.y / this.worldSize,\n ).toLngLat();\n }\n\n public setLocationAtPoint(lnglat: LngLat, point: Point) {\n const a = this.pointCoordinate(point);\n const b = this.pointCoordinate(this.centerPoint);\n const loc = this.locationCoordinate(lnglat);\n const newCenter = new MercatorCoordinate(\n loc.x - (a.x - b.x),\n loc.y - (a.y - b.y),\n );\n this.center = this.coordinateLocation(newCenter);\n if (this._renderWorldCopies) {\n this.center = this.center.wrap();\n }\n }\n\n public pointCoordinate(p: Point) {\n const targetZ = 0;\n // since we don't know the correct projected z value for the point,\n // unproject two points to get a line and then find the point on that\n // line with z=0\n\n const coord0 = new Float32Array([p.x, p.y, 0, 1]);\n const coord1 = new Float32Array([p.x, p.y, 1, 1]);\n\n vec4.transformMat4(coord0, coord0, this.pixelMatrixInverse);\n vec4.transformMat4(coord1, coord1, this.pixelMatrixInverse);\n\n const w0 = coord0[3];\n const w1 = coord1[3];\n const x0 = coord0[0] / w0;\n const x1 = coord1[0] / w1;\n const y0 = coord0[1] / w0;\n const y1 = coord1[1] / w1;\n const z0 = coord0[2] / w0;\n const z1 = coord1[2] / w1;\n\n const t = z0 === z1 ? 0 : (targetZ - z0) / (z1 - z0);\n\n return new MercatorCoordinate(\n interpolate(x0, x1, t) / this.worldSize,\n interpolate(y0, y1, t) / this.worldSize,\n );\n }\n\n /**\n * Returns the map's geographical bounds. When the bearing or pitch is non-zero, the visible region is not\n * an axis-aligned rectangle, and the result is the smallest bounds that encompasses the visible region.\n * @returns {LngLatBounds} Returns a {@link LngLatBounds} object describing the map's geographical bounds.\n */\n public getBounds(): LngLatBounds {\n return new LngLatBounds()\n .extend(this.pointLocation(new Point(0, 0)))\n .extend(this.pointLocation(new Point(this.width, 0)))\n .extend(this.pointLocation(new Point(this.width, this.height)))\n .extend(this.pointLocation(new Point(0, this.height)));\n }\n\n /**\n * Returns the maximum geographical bounds the map is constrained to, or `null` if none set.\n * @returns {LngLatBounds} {@link LngLatBounds}\n */\n public getMaxBounds(): LngLatBounds | null {\n if (\n !this.latRange ||\n this.latRange.length !== 2 ||\n !this.lngRange ||\n this.lngRange.length !== 2\n ) {\n return null;\n }\n\n return new LngLatBounds(\n [this.lngRange[0], this.latRange[0]],\n [this.lngRange[1], this.latRange[1]],\n );\n }\n\n /**\n * Sets or clears the map's geographical constraints.\n * @param {LngLatBounds} bounds A {@link LngLatBounds} object describing the new geographic boundaries of the map.\n */\n public setMaxBounds(bounds?: LngLatBounds) {\n if (bounds) {\n this.lngRange = [bounds.getWest(), bounds.getEast()];\n this.latRange = [bounds.getSouth(), bounds.getNorth()];\n this.constrain();\n } else {\n this.lngRange = undefined;\n this.latRange = [-this.maxValidLatitude, this.maxValidLatitude];\n }\n }\n\n public customLayerMatrix(): number[] {\n return (this.mercatorMatrix as number[]).slice();\n }\n\n public maxPitchScaleFactor() {\n // calcMatrices hasn't run yet\n if (!this.pixelMatrixInverse) {\n return 1;\n }\n\n const coord = this.pointCoordinate(new Point(0, 0));\n const p = new Float32Array([\n coord.x * this.worldSize,\n coord.y * this.worldSize,\n 0,\n 1,\n ]);\n const topPoint = vec4.transformMat4(p, p, this.pixelMatrix);\n return topPoint[3] / this.cameraToCenterDistance;\n }\n\n /*\n * The camera looks at the map from a 3D (lng, lat, altitude) location. Let's use `cameraLocation`\n * as the name for the location under the camera and on the surface of the earth (lng, lat, 0).\n * `cameraPoint` is the projected position of the `cameraLocation`.\n *\n * This point is useful to us because only fill-extrusions that are between `cameraPoint` and\n * the query point on the surface of the earth can extend and intersect the query.\n *\n * When the map is not pitched the `cameraPoint` is equivalent to the center of the map because\n * the camera is right above the center of the map.\n */\n public getCameraPoint() {\n const pitch = this._pitch;\n const yOffset = Math.tan(pitch) * (this.cameraToCenterDistance || 1);\n return this.centerPoint.add(new Point(0, yOffset));\n }\n\n /*\n * When the map is pitched, some of the 3D features that intersect a query will not intersect\n * the query at the surface of the earth. Instead the feature may be closer and only intersect\n * the query because it extrudes into the air.\n *\n * This returns a geometry that includes all of the original query as well as all possible ares of the\n * screen where the *base* of a visible extrusion could be.\n * - For point queries, the line from the query point to the \"camera point\"\n * - For other geometries, the envelope of the query geometry and the \"camera point\"\n */\n public getCameraQueryGeometry(queryGeometry: Point[]): Point[] {\n const c = this.getCameraPoint();\n\n if (queryGeometry.length === 1) {\n return [queryGeometry[0], c];\n } else {\n let minX = c.x;\n let minY = c.y;\n let maxX = c.x;\n let maxY = c.y;\n for (const p of queryGeometry) {\n minX = Math.min(minX, p.x);\n minY = Math.min(minY, p.y);\n maxX = Math.max(maxX, p.x);\n maxY = Math.max(maxY, p.y);\n }\n return [\n new Point(minX, minY),\n new Point(maxX, minY),\n new Point(maxX, maxY),\n new Point(minX, maxY),\n new Point(minX, minY),\n ];\n }\n }\n\n /**\n * Given a coordinate, return the screen point that corresponds to it\n * @param {Coordinate} coord\n * @returns {Point} screen point\n * @private\n */\n public coordinatePoint(coord: MercatorCoordinate) {\n const p = vec4.fromValues(\n coord.x * this.worldSize,\n coord.y * this.worldSize,\n 0,\n 1,\n );\n vec4.transformMat4(p, p, this.pixelMatrix);\n return new Point(p[0] / p[3], p[1] / p[3]);\n }\n /**\n * Given a location, return the screen point that corresponds to it\n * @param {LngLat} lnglat location\n * @returns {Point} screen point\n * @private\n */\n public locationPoint(lnglat: LngLat) {\n return this.coordinatePoint(this.locationCoordinate(lnglat));\n }\n\n /**\n * Given a point on screen, return its lnglat\n * @param {Point} p screen point\n * @returns {LngLat} lnglat location\n * @private\n */\n public pointLocation(p: Point) {\n return this.coordinateLocation(this.pointCoordinate(p));\n }\n\n /**\n * Given a geographical lnglat, return an unrounded\n * coordinate that represents it at this transform's zoom level.\n * @param {LngLat} lnglat\n * @returns {Coordinate}\n * @private\n */\n public locationCoordinate(lnglat: LngLat) {\n return MercatorCoordinate.fromLngLat(lnglat);\n }\n\n /**\n * Given a Coordinate, return its geographical position.\n * @param {Coordinate} coord\n * @returns {LngLat} lnglat\n * @private\n */\n public coordinateLocation(coord: MercatorCoordinate) {\n return coord.toLngLat();\n }\n\n public getProjectionMatrix(): mat4 {\n return this.projMatrix;\n }\n /**\n * Calculate the posMatrix that, given a tile coordinate, would be used to display the tile on a map.\n * @param {UnwrappedTileID} unwrappedTileID;\n * @private\n */\n // private calculatePosMatrix(\n // unwrappedTileID: UnwrappedTileID,\n // aligned: boolean = false,\n // ): Float32Array {\n // const posMatrixKey = unwrappedTileID.key;\n // const cache = aligned ? this.alignedPosMatrixCache : this.posMatrixCache;\n // if (cache[posMatrixKey]) {\n // return cache[posMatrixKey];\n // }\n\n // const canonical = unwrappedTileID.canonical;\n // const scale = this.worldSize / this.zoomScale(canonical.z);\n // const unwrappedX =\n // canonical.x + Math.pow(2, canonical.z) * unwrappedTileID.wrap;\n\n // const posMatrix = mat4.identity(new Float64Array(16));\n // mat4.translate(posMatrix, posMatrix, [\n // unwrappedX * scale,\n // canonical.y * scale,\n // 0,\n // ]);\n // mat4.scale(posMatrix, posMatrix, [scale / EXTENT, scale / EXTENT, 1]);\n // mat4.multiply(\n // posMatrix,\n // aligned ? this.alignedProjMatrix : this.projMatrix,\n // posMatrix,\n // );\n\n // cache[posMatrixKey] = new Float32Array(posMatrix);\n // return cache[posMatrixKey];\n // }\n\n private constrain() {\n if (!this.center || !this.width || !this.height || this.constraining) {\n return;\n }\n\n this.constraining = true;\n\n let minY = -90;\n let maxY = 90;\n let minX = -180;\n let maxX = 180;\n let sy;\n let sx;\n let x2;\n let y2;\n const size = this.size;\n const unmodified = this.unmodified;\n\n if (this.latRange) {\n const latRange = this.latRange;\n minY = mercatorYfromLat(latRange[1]) * this.worldSize;\n maxY = mercatorYfromLat(latRange[0]) * this.worldSize;\n sy = maxY - minY < size.y ? size.y / (maxY - minY) : 0;\n }\n\n if (this.lngRange) {\n const lngRange = this.lngRange;\n minX = mercatorXfromLng(lngRange[0]) * this.worldSize;\n maxX = mercatorXfromLng(lngRange[1]) * this.worldSize;\n sx = maxX - minX < size.x ? size.x / (maxX - minX) : 0;\n }\n\n const point = this.point;\n\n // how much the map should scale to fit the screen into given latitude/longitude ranges\n const s = Math.max(sx || 0, sy || 0);\n\n if (s) {\n this.center = this.unproject(\n new Point(\n sx ? (maxX + minX) / 2 : point.x,\n sy ? (maxY + minY) / 2 : point.y,\n ),\n );\n this.zoom += this.scaleZoom(s);\n this.unmodified = unmodified;\n this.constraining = false;\n return;\n }\n\n if (this.latRange) {\n const y = point.y;\n const h2 = size.y / 2;\n\n if (y - h2 < minY) {\n y2 = minY + h2;\n }\n if (y + h2 > maxY) {\n y2 = maxY - h2;\n }\n }\n\n if (this.lngRange) {\n const x = point.x;\n const w2 = size.x / 2;\n\n if (x - w2 < minX) {\n x2 = minX + w2;\n }\n if (x + w2 > maxX) {\n x2 = maxX - w2;\n }\n }\n\n // pan the map if the screen goes off the range\n if (x2 !== undefined || y2 !== undefined) {\n this.center = this.unproject(\n new Point(\n x2 !== undefined ? x2 : point.x,\n y2 !== undefined ? y2 : point.y,\n ),\n );\n }\n\n this.unmodified = unmodified;\n this.constraining = false;\n }\n\n private calcMatrices() {\n if (!this.height) {\n return;\n }\n\n const halfFov = this._fov / 2;\n const offset = this.centerOffset;\n this.cameraToCenterDistance = (0.5 / Math.tan(halfFov)) * this.height;\n\n // Find the distance from the center point [width/2 + offset.x, height/2 + offset.y] to the\n // center top point [width/2 + offset.x, 0] in Z units, using the law of sines.\n // 1 Z unit is equivalent to 1 horizontal px at the center of the map\n // (the distance between[width/2, height/2] and [width/2 + 1, height/2])\n const groundAngle = Math.PI / 2 + this._pitch;\n const fovAboveCenter = this._fov * (0.5 + offset.y / this.height);\n const topHalfSurfaceDistance =\n (Math.sin(fovAboveCenter) * this.cameraToCenterDistance) /\n Math.sin(\n clamp(Math.PI - groundAngle - fovAboveCenter, 0.01, Math.PI - 0.01),\n );\n const point = this.point;\n const x = point.x;\n const y = point.y;\n\n // Calculate z distance of the farthest fragment that should be rendered.\n const furthestDistance =\n Math.cos(Math.PI / 2 - this._pitch) * topHalfSurfaceDistance +\n this.cameraToCenterDistance;\n // Add a bit extra to avoid precision problems when a fragment's distance is exactly `furthestDistance`\n const farZ = furthestDistance * 1.01;\n\n // The larger the value of nearZ is\n // - the more depth precision is available for features (good)\n // - clipping starts appearing sooner when the camera is close to 3d features (bad)\n //\n // Smaller values worked well for mapbox-gl-js but deckgl was encountering precision issues\n // when rendering it's layers using custom layers. This value was experimentally chosen and\n // seems to solve z-fighting issues in deckgl while not clipping buildings too close to the camera.\n const nearZ = this.height / 50;\n\n // matrix for conversion from location to GL coordinates (-1 .. 1)\n let m = mat4.create();\n mat4.perspective(m, this._fov, this.width / this.height, nearZ, farZ);\n\n // Apply center of perspective offset\n m[8] = (-offset.x * 2) / this.width;\n m[9] = (offset.y * 2) / this.height;\n\n mat4.scale(m, m, [1, -1, 1]);\n mat4.translate(m, m, [0, 0, -this.cameraToCenterDistance]);\n mat4.rotateX(m, m, this._pitch);\n mat4.rotateZ(m, m, this.angle);\n mat4.translate(m, m, [-x, -y, 0]);\n\n // The mercatorMatrix can be used to transform points from mercator coordinates\n // ([0, 0] nw, [1, 1] se) to GL coordinates.\n this.mercatorMatrix = mat4.scale(mat4.create(), m, [\n this.worldSize,\n this.worldSize,\n this.worldSize,\n ]);\n // scale vertically to meters per pixel (inverse of ground resolution):\n\n mat4.scale(\n m,\n m,\n vec3.fromValues(\n 1,\n 1,\n mercatorZfromAltitude(1, this.center.lat) * this.worldSize,\n ),\n );\n\n this.projMatrix = m;\n this.invProjMatrix = mat4.invert(mat4.create(), this.projMatrix);\n\n // Make a second projection matrix that is aligned to a pixel grid for rendering raster tiles.\n // We're rounding the (floating point) x/y values to achieve to avoid rendering raster images to fractional\n // coordinates. Additionally, we adjust by half a pixel in either direction in case that viewport dimension\n // is an odd integer to preserve rendering to the pixel grid. We're rotating this shift based on the angle\n // of the transformation so that 0°, 90°, 180°, and 270° rasters are crisp, and adjust the shift so that\n // it is always <= 0.5 pixels.\n const xShift = (this.width % 2) / 2;\n const yShift = (this.height % 2) / 2;\n const angleCos = Math.cos(this.angle);\n const angleSin = Math.sin(this.angle);\n const dx = x - Math.round(x) + angleCos * xShift + angleSin * yShift;\n const dy = y - Math.round(y) + angleCos * yShift + angleSin * xShift;\n const alignedM = mat4.clone(m);\n mat4.translate(alignedM, alignedM, [\n dx > 0.5 ? dx - 1 : dx,\n dy > 0.5 ? dy - 1 : dy,\n 0,\n ]);\n this.alignedProjMatrix = alignedM;\n\n m = mat4.create();\n mat4.scale(m, m, [this.width / 2, -this.height / 2, 1]);\n mat4.translate(m, m, [1, -1, 0]);\n this.labelPlaneMatrix = m;\n\n m = mat4.create();\n mat4.scale(m, m, [1, -1, 1]);\n mat4.translate(m, m, [-1, -1, 0]);\n mat4.scale(m, m, [2 / this.width, 2 / this.height, 1]);\n this.glCoordMatrix = m;\n\n // matrix for conversion from location to screen coordinates\n this.pixelMatrix = mat4.multiply(\n mat4.create(),\n this.labelPlaneMatrix,\n this.projMatrix,\n );\n\n // inverse matrix for conversion from screen coordinaes to location\n m = mat4.invert(mat4.create(), this.pixelMatrix);\n if (!m) {\n throw new Error('failed to invert matrix');\n }\n this.pixelMatrixInverse = m;\n\n this.posMatrixCache = {};\n this.alignedPosMatrixCache = {};\n }\n}\n"],"file":"transform.js"}
1
+ {"version":3,"sources":["../../src/geo/transform.ts"],"names":["EXTENT","Transform","minZoom","maxZoom","minPitch","maxPitch","renderWorldCopies","tileSize","maxValidLatitude","_renderWorldCopies","undefined","_minZoom","_maxZoom","_minPitch","_maxPitch","setMaxBounds","width","height","_center","LngLat","zoom","angle","_fov","_pitch","unmodified","edgeInsets","EdgeInsets","posMatrixCache","alignedPosMatrixCache","Math","max","min","pitch","scale","centerPoint","_sub","size","_div","Point","PI","bearing","b","calcMatrices","rotationMatrix","mat2","create","rotate","p","fov","_zoom","z","zoomScale","tileZoom","floor","zoomFraction","constrain","center","lat","lng","toJSON","padding","equals","interpolate","getCenter","project","clone","latRange","start","target","t","options","roundZoom","round","scaleZoom","pixelsToGLUnits","pow","log","LN2","lnglat","worldSize","point","MercatorCoordinate","x","y","toLngLat","a","pointCoordinate","loc","locationCoordinate","newCenter","coordinateLocation","wrap","targetZ","coord0","Float32Array","coord1","vec4","transformMat4","pixelMatrixInverse","w0","w1","x0","x1","y0","y1","z0","z1","LngLatBounds","extend","pointLocation","length","lngRange","bounds","getWest","getEast","getSouth","getNorth","mercatorMatrix","slice","coord","topPoint","pixelMatrix","cameraToCenterDistance","yOffset","tan","add","queryGeometry","c","getCameraPoint","minX","minY","maxX","maxY","fromValues","coordinatePoint","fromLngLat","projMatrix","constraining","sy","sx","x2","y2","s","unproject","h2","w2","halfFov","offset","centerOffset","groundAngle","fovAboveCenter","topHalfSurfaceDistance","sin","furthestDistance","cos","farZ","nearZ","m","Float64Array","mat4","perspective","translate","rotateX","rotateZ","invProjMatrix","invert","xShift","yShift","angleCos","angleSin","dx","dy","alignedM","alignedProjMatrix","labelPlaneMatrix","glCoordMatrix","multiply","Error"],"mappings":";;;;;;;;;;;;;;;;;AACA;;AACA;;AACA;;AAGA;;AACA;;AACA;;AACA;;;;;;;;;;;;AAKO,IAAMA,MAAM,GAAG,IAAf;;;IACcC,S;AAoNnB,qBACEC,OADF,EAEEC,OAFF,EAGEC,QA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AlB,EAAqB,CAAC,CAAC,CAAF,EAAK,CAAC,CAAN,EAAS,CAAT,CAArB;;AAEAE,qBAAK9H,KAAL,CAAW4H,CAAX,EAAcA,CAAd,EAAiB,CAAC,IAAI,KAAK7I,KAAV,EAAiB,IAAI,KAAKC,MAA1B,EAAkC,CAAlC,CAAjB;;AAEA,WAAK8J,aAAL,GAAqBlB,CAArB;AAGA,WAAKpC,WAAL,GAAmBsC,eAAKiB,QAAL,CAEjB,IAAIlB,YAAJ,CAAiB,EAAjB,CAFiB,EAGjB,KAAKgB,gBAHY,EAIjB,KAAKtC,UAJY,CAAnB;AASAqB,MAAAA,CAAC,GAAGE,eAAKM,MAAL,CAAY,IAAIP,YAAJ,CAAiB,EAAjB,CAAZ,EAAkC,KAAKrC,WAAvC,CAAJ;;AACA,UAAI,CAACoC,CAAL,EAAQ;AACN,cAAM,IAAIoB,KAAJ,CAAU,yBAAV,CAAN;AACD;;AAED,WAAK/E,kBAAL,GAA0B2D,CAA1B;AAEA,WAAKlI,cAAL,GAAsB,EAAtB;AACA,WAAKC,qBAAL,GAA6B,EAA7B;AACD","sourcesContent":["// @ts-ignore\nimport { mat2, mat4, vec3, vec4 } from 'gl-matrix';\nimport Point, { PointLike } from '../geo/point';\nimport { clamp, interpolate, wrap } from '../util';\nimport Aabb from '../utils/Aabb';\nimport Frustum from '../utils/primitives';\nimport EdgeInsets, { IPaddingOptions } from './edge_insets';\nimport LngLat from './lng_lat';\nimport LngLatBounds from './lng_lat_bounds';\nimport MercatorCoordinate, {\n mercatorXfromLng,\n mercatorYfromLat,\n mercatorZfromAltitude,\n} from './mercator';\nexport const EXTENT = 8192;\nexport default class Transform {\n get minZoom(): number {\n return this._minZoom;\n }\n set minZoom(zoom: number) {\n if (this._minZoom === zoom) {\n return;\n }\n this._minZoom = zoom;\n this.zoom = Math.max(this.zoom, zoom);\n }\n\n get maxZoom(): number {\n return this._maxZoom;\n }\n set maxZoom(zoom: number) {\n if (this._maxZoom === zoom) {\n return;\n }\n this._maxZoom = zoom;\n this.zoom = Math.min(this.zoom, zoom);\n }\n\n get minPitch(): number {\n return this._minPitch;\n }\n set minPitch(pitch: number) {\n if (this._minPitch === pitch) {\n return;\n }\n this._minPitch = pitch;\n this._pitch = Math.max(this._pitch, pitch);\n }\n\n get maxPitch(): number {\n return this._maxPitch;\n }\n set maxPitch(pitch: number) {\n if (this._maxPitch === pitch) {\n return;\n }\n this._maxPitch = pitch;\n this._pitch = Math.min(this._pitch, pitch);\n }\n\n get renderWorldCopies(): boolean {\n return this._renderWorldCopies;\n }\n set renderWorldCopies(renderWorldCopies: boolean) {\n if (renderWorldCopies === undefined) {\n renderWorldCopies = true;\n } else if (renderWorldCopies === null) {\n renderWorldCopies = false;\n }\n\n this._renderWorldCopies = renderWorldCopies;\n }\n\n get worldSize(): number {\n return this.tileSize * this.scale;\n }\n\n get centerOffset(): Point {\n return this.centerPoint._sub(this.size._div(2));\n }\n\n get size(): Point {\n return new Point(this.width, this.height);\n }\n\n get bearing(): number {\n return (-this.angle / Math.PI) * 180;\n }\n set bearing(bearing: number) {\n const b = (-wrap(bearing, -180, 180) * Math.PI) / 180;\n if (this.angle === b) {\n return;\n }\n this.unmodified = false;\n this.angle = b;\n this.calcMatrices();\n\n // 2x2 matrix for rotating points\n this.rotationMatrix = mat2.create();\n mat2.rotate(this.rotationMatrix, this.rotationMatrix, this.angle);\n }\n\n get pitch(): number {\n return (this._pitch / Math.PI) * 180;\n }\n set pitch(pitch: number) {\n const p = (clamp(pitch, this._minPitch, this._maxPitch) / 180) * Math.PI;\n if (this._pitch === p) {\n return;\n }\n this.unmodified = false;\n this._pitch = p;\n this.calcMatrices();\n }\n\n get fov(): number {\n return (this._fov / Math.PI) * 180;\n }\n\n set fov(fov: number) {\n fov = Math.max(0.01, Math.min(60, fov));\n if (this._fov === fov) {\n return;\n }\n this.unmodified = false;\n this._fov = (fov / 180) * Math.PI;\n this.calcMatrices();\n }\n\n get zoom(): number {\n return this._zoom;\n }\n\n set zoom(zoom: number) {\n const z = Math.min(Math.max(zoom, this._minZoom), this._maxZoom);\n if (this._zoom === z) {\n return;\n }\n this.unmodified = false;\n this._zoom = z;\n this.scale = this.zoomScale(z);\n this.tileZoom = Math.floor(z);\n this.zoomFraction = z - this.tileZoom;\n this.constrain();\n this.calcMatrices();\n }\n\n get center(): LngLat {\n return this._center;\n }\n\n set center(center: LngLat) {\n if (center.lat === this._center.lat && center.lng === this._center.lng) {\n return;\n }\n this.unmodified = false;\n this._center = center;\n this.constrain();\n this.calcMatrices();\n }\n\n get padding(): IPaddingOptions {\n return this.edgeInsets.toJSON();\n }\n\n set padding(padding: IPaddingOptions) {\n if (this.edgeInsets.equals(padding)) {\n return;\n }\n this.unmodified = false;\n // Update edge-insets inplace\n this.edgeInsets.interpolate(this.edgeInsets, padding, 1);\n this.calcMatrices();\n }\n\n /**\n * The center of the screen in pixels with the top-left corner being (0,0)\n * and +y axis pointing downwards. This accounts for padding.\n *\n * @readonly\n * @type {Point}\n * @memberof Transform\n */\n get centerPoint(): Point {\n return this.edgeInsets.getCenter(this.width, this.height);\n }\n\n get point(): Point {\n return this.project(this.center);\n }\n public tileSize: number;\n public tileZoom: number;\n public lngRange?: [number, number];\n public latRange?: [number, number];\n public maxValidLatitude: number;\n public scale: number;\n public width: number;\n public height: number;\n public angle: number;\n public rotationMatrix: mat2;\n public pixelsToGLUnits: [number, number];\n public cameraToCenterDistance: number;\n public mercatorMatrix: mat4;\n public projMatrix: mat4;\n public invProjMatrix: mat4;\n public alignedProjMatrix: mat4;\n public pixelMatrix: mat4;\n public pixelMatrixInverse: mat4;\n public glCoordMatrix: mat4;\n public labelPlaneMatrix: mat4;\n // tslint:disable:variable-name\n private _fov: number;\n private _pitch: number;\n private _zoom: number;\n private _renderWorldCopies: boolean;\n private _minZoom: number;\n private _maxZoom: number;\n private _minPitch: number;\n private _maxPitch: number;\n private _center: LngLat;\n // tslint:enable\n private zoomFraction: number;\n private unmodified: boolean;\n private edgeInsets: EdgeInsets;\n private constraining: boolean;\n private posMatrixCache: { [_: string]: Float32Array };\n private alignedPosMatrixCache: { [_: string]: Float32Array };\n constructor(\n minZoom: number,\n maxZoom: number,\n minPitch: number,\n maxPitch: number,\n renderWorldCopies: boolean | void,\n ) {\n this.tileSize = 512; // constant\n this.maxValidLatitude = 85.051129; // constant\n\n this._renderWorldCopies = (renderWorldCopies === undefined\n ? true\n : renderWorldCopies) as boolean;\n this._minZoom = minZoom || 0;\n this._maxZoom = maxZoom || 22;\n\n this._minPitch = minPitch === undefined || minPitch === null ? 0 : minPitch;\n this._maxPitch =\n maxPitch === undefined || maxPitch === null ? 60 : maxPitch;\n\n this.setMaxBounds();\n\n this.width = 0;\n this.height = 0;\n this._center = new LngLat(0, 0);\n this.zoom = 0;\n this.angle = 0;\n this._fov = 0.6435011087932844;\n this._pitch = 0;\n this.unmodified = true;\n this.edgeInsets = new EdgeInsets();\n this.posMatrixCache = {};\n this.alignedPosMatrixCache = {};\n }\n\n public clone(): Transform {\n const clone = new Transform(\n this._minZoom,\n this._maxZoom,\n this._minPitch,\n this._maxPitch,\n this._renderWorldCopies,\n );\n clone.tileSize = this.tileSize;\n clone.latRange = this.latRange;\n clone.width = this.width;\n clone.height = this.height;\n clone.center = this._center;\n clone.zoom = this.zoom;\n clone.angle = this.angle;\n clone.fov = this._fov;\n clone.pitch = this._pitch;\n clone.unmodified = this.unmodified;\n clone.edgeInsets = this.edgeInsets.clone();\n clone.calcMatrices();\n return clone;\n }\n\n /**\n * Returns if the padding params match\n *\n * @param {IPaddingOptions} padding\n * @returns {boolean}\n * @memberof Transform\n */\n public isPaddingEqual(padding: IPaddingOptions): boolean {\n return this.edgeInsets.equals(padding);\n }\n\n /**\n * Helper method to upadte edge-insets inplace\n *\n * @param {IPaddingOptions} target\n * @param {number} t\n * @memberof Transform\n */\n public interpolatePadding(\n start: IPaddingOptions,\n target: IPaddingOptions,\n t: number,\n ) {\n this.unmodified = false;\n this.edgeInsets.interpolate(start, target, t);\n this.constrain();\n this.calcMatrices();\n }\n\n /**\n * Return a zoom level that will cover all tiles the transform\n * @param {Object} options options\n * @param {number} options.tileSize Tile size, expressed in screen pixels.\n * @param {boolean} options.roundZoom Target zoom level. If true, the value will be rounded to the closest integer. Otherwise the value will be floored.\n * @returns {number} zoom level An integer zoom level at which all tiles will be visible.\n */\n public coveringZoomLevel(options: { roundZoom?: boolean; tileSize: number }) {\n const z = (options.roundZoom ? Math.round : Math.floor)(\n this.zoom + this.scaleZoom(this.tileSize / options.tileSize),\n );\n // At negative zoom levels load tiles from z0 because negative tile zoom levels don't exist.\n return Math.max(0, z);\n }\n\n /**\n * Return any \"wrapped\" copies of a given tile coordinate that are visible\n * in the current view.\n *\n * @private\n */\n // public getVisibleUnwrappedCoordinates(tileID: CanonicalTileID) {\n // const result = [new UnwrappedTileID(0, tileID)];\n // if (this._renderWorldCopies) {\n // const utl = this.pointCoordinate(new Point(0, 0));\n // const utr = this.pointCoordinate(new Point(this.width, 0));\n // const ubl = this.pointCoordinate(new Point(this.width, this.height));\n // const ubr = this.pointCoordinate(new Point(0, this.height));\n // const w0 = Math.floor(Math.min(utl.x, utr.x, ubl.x, ubr.x));\n // const w1 = Math.floor(Math.max(utl.x, utr.x, ubl.x, ubr.x));\n\n // // Add an extra copy of the world on each side to properly render ImageSources and CanvasSources.\n // // Both sources draw outside the tile boundaries of the tile that \"contains them\" so we need\n // // to add extra copies on both sides in case offscreen tiles need to draw into on-screen ones.\n // const extraWorldCopy = 1;\n\n // for (let w = w0 - extraWorldCopy; w <= w1 + extraWorldCopy; w++) {\n // if (w === 0) {\n // continue;\n // }\n // result.push(new UnwrappedTileID(w, tileID));\n // }\n // }\n // return result;\n // }\n\n /**\n * Return all coordinates that could cover this transform for a covering\n * zoom level.\n * @param {Object} options\n * @param {number} options.tileSize\n * @param {number} options.minzoom\n * @param {number} options.maxzoom\n * @param {boolean} options.roundZoom\n * @param {boolean} options.reparseOverscaled\n * @param {boolean} options.renderWorldCopies\n * @returns {Array<OverscaledTileID>} OverscaledTileIDs\n * @private\n */\n // public coveringTiles(options: {\n // tileSize: number;\n // minzoom?: number;\n // maxzoom?: number;\n // roundZoom?: boolean;\n // reparseOverscaled?: boolean;\n // renderWorldCopies?: boolean;\n // }): OverscaledTileID[] {\n // let z = this.coveringZoomLevel(options);\n // const actualZ = z;\n\n // if (options.minzoom !== undefined && z < options.minzoom) {\n // return [];\n // }\n // if (options.maxzoom !== undefined && z > options.maxzoom) {\n // z = options.maxzoom;\n // }\n\n // const centerCoord = MercatorCoordinate.fromLngLat(this.center);\n // const numTiles = Math.pow(2, z);\n // const centerPoint = [numTiles * centerCoord.x, numTiles * centerCoord.y, 0];\n // const cameraFrustum = Frustum.fromInvProjectionMatrix(\n // this.invProjMatrix,\n // this.worldSize,\n // z,\n // );\n\n // // No change of LOD behavior for pitch lower than 60 and when there is no top padding: return only tile ids from the requested zoom level\n // let minZoom = options.minzoom || 0;\n // // Use 0.1 as an epsilon to avoid for explicit == 0.0 floating point checks\n // if (this._pitch <= 60.0 && this.edgeInsets.top < 0.1) {\n // minZoom = z;\n // }\n\n // // There should always be a certain number of maximum zoom level tiles surrounding the center location\n // const radiusOfMaxLvlLodInTiles = 3;\n\n // const newRootTile = (wrap: number): any => {\n // return {\n // // All tiles are on zero elevation plane => z difference is zero\n // aabb: new Aabb(\n // [wrap * numTiles, 0, 0],\n // [(wrap + 1) * numTiles, numTiles, 0],\n // ),\n // zoom: 0,\n // x: 0,\n // y: 0,\n // wrap,\n // fullyVisible: false,\n // };\n // };\n\n // // Do a depth-first traversal to find visible tiles and proper levels of detail\n // const stack = [];\n // const result = [];\n // const maxZoom = z;\n // const overscaledZ = options.reparseOverscaled ? actualZ : z;\n\n // if (this._renderWorldCopies) {\n // // Render copy of the globe thrice on both sides\n // for (let i = 1; i <= 3; i++) {\n // stack.push(newRootTile(-i));\n // stack.push(newRootTile(i));\n // }\n // }\n\n // stack.push(newRootTile(0));\n\n // while (stack.length > 0) {\n // const it = stack.pop();\n // const x = it.x;\n // const y = it.y;\n // let fullyVisible = it.fullyVisible;\n\n // // Visibility of a tile is not required if any of its ancestor if fully inside the frustum\n // if (!fullyVisible) {\n // const intersectResult = it.aabb.intersects(cameraFrustum);\n\n // if (intersectResult === 0) {\n // continue;\n // }\n\n // fullyVisible = intersectResult === 2;\n // }\n\n // const distanceX = it.aabb.distanceX(centerPoint);\n // const distanceY = it.aabb.distanceY(centerPoint);\n // const longestDim = Math.max(Math.abs(distanceX), Math.abs(distanceY));\n\n // // We're using distance based heuristics to determine if a tile should be split into quadrants or not.\n // // radiusOfMaxLvlLodInTiles defines that there's always a certain number of maxLevel tiles next to the map center.\n // // Using the fact that a parent node in quadtree is twice the size of its children (per dimension)\n // // we can define distance thresholds for each relative level:\n // // f(k) = offset + 2 + 4 + 8 + 16 + ... + 2^k. This is the same as \"offset+2^(k+1)-2\"\n // const distToSplit =\n // radiusOfMaxLvlLodInTiles + (1 << (maxZoom - it.zoom)) - 2;\n\n // // Have we reached the target depth or is the tile too far away to be any split further?\n // if (\n // it.zoom === maxZoom ||\n // (longestDim > distToSplit && it.zoom >= minZoom)\n // ) {\n // result.push({\n // tileID: new OverscaledTileID(\n // it.zoom === maxZoom ? overscaledZ : it.zoom,\n // it.wrap,\n // it.zoom,\n // x,\n // y,\n // ),\n // distanceSq: vec2.sqrLen([\n // centerPoint[0] - 0.5 - x,\n // centerPoint[1] - 0.5 - y,\n // ]),\n // });\n // continue;\n // }\n\n // for (let i = 0; i < 4; i++) {\n // const childX = (x << 1) + (i % 2);\n // const childY = (y << 1) + (i >> 1);\n\n // stack.push({\n // aabb: it.aabb.quadrant(i),\n // zoom: it.zoom + 1,\n // x: childX,\n // y: childY,\n // wrap: it.wrap,\n // fullyVisible,\n // });\n // }\n // }\n\n // return result\n // .sort((a, b) => a.distanceSq - b.distanceSq)\n // .map((a) => a.tileID);\n // }\n\n public resize(width: number, height: number) {\n this.width = width;\n this.height = height;\n\n this.pixelsToGLUnits = [2 / width, -2 / height];\n this.constrain();\n this.calcMatrices();\n }\n\n public zoomScale(zoom: number) {\n return Math.pow(2, zoom);\n }\n public scaleZoom(scale: number) {\n return Math.log(scale) / Math.LN2;\n }\n\n public project(lnglat: LngLat) {\n const lat = clamp(\n lnglat.lat,\n -this.maxValidLatitude,\n this.maxValidLatitude,\n );\n return new Point(\n mercatorXfromLng(lnglat.lng) * this.worldSize,\n mercatorYfromLat(lat) * this.worldSize,\n );\n }\n\n public unproject(point: Point): LngLat {\n return new MercatorCoordinate(\n point.x / this.worldSize,\n point.y / this.worldSize,\n ).toLngLat();\n }\n\n public setLocationAtPoint(lnglat: LngLat, point: Point) {\n const a = this.pointCoordinate(point);\n const b = this.pointCoordinate(this.centerPoint);\n const loc = this.locationCoordinate(lnglat);\n const newCenter = new MercatorCoordinate(\n loc.x - (a.x - b.x),\n loc.y - (a.y - b.y),\n );\n this.center = this.coordinateLocation(newCenter);\n if (this._renderWorldCopies) {\n this.center = this.center.wrap();\n }\n }\n\n public pointCoordinate(p: Point) {\n const targetZ = 0;\n // since we don't know the correct projected z value for the point,\n // unproject two points to get a line and then find the point on that\n // line with z=0\n\n const coord0 = new Float32Array([p.x, p.y, 0, 1]);\n const coord1 = new Float32Array([p.x, p.y, 1, 1]);\n\n vec4.transformMat4(coord0, coord0, this.pixelMatrixInverse);\n vec4.transformMat4(coord1, coord1, this.pixelMatrixInverse);\n\n const w0 = coord0[3];\n const w1 = coord1[3];\n const x0 = coord0[0] / w0;\n const x1 = coord1[0] / w1;\n const y0 = coord0[1] / w0;\n const y1 = coord1[1] / w1;\n const z0 = coord0[2] / w0;\n const z1 = coord1[2] / w1;\n\n const t = z0 === z1 ? 0 : (targetZ - z0) / (z1 - z0);\n\n return new MercatorCoordinate(\n interpolate(x0, x1, t) / this.worldSize,\n interpolate(y0, y1, t) / this.worldSize,\n );\n }\n\n /**\n * Returns the map's geographical bounds. When the bearing or pitch is non-zero, the visible region is not\n * an axis-aligned rectangle, and the result is the smallest bounds that encompasses the visible region.\n * @returns {LngLatBounds} Returns a {@link LngLatBounds} object describing the map's geographical bounds.\n */\n public getBounds(): LngLatBounds {\n return new LngLatBounds()\n .extend(this.pointLocation(new Point(0, 0)))\n .extend(this.pointLocation(new Point(this.width, 0)))\n .extend(this.pointLocation(new Point(this.width, this.height)))\n .extend(this.pointLocation(new Point(0, this.height)));\n }\n\n /**\n * Returns the maximum geographical bounds the map is constrained to, or `null` if none set.\n * @returns {LngLatBounds} {@link LngLatBounds}\n */\n public getMaxBounds(): LngLatBounds | null {\n if (\n !this.latRange ||\n this.latRange.length !== 2 ||\n !this.lngRange ||\n this.lngRange.length !== 2\n ) {\n return null;\n }\n\n return new LngLatBounds(\n [this.lngRange[0], this.latRange[0]],\n [this.lngRange[1], this.latRange[1]],\n );\n }\n\n /**\n * Sets or clears the map's geographical constraints.\n * @param {LngLatBounds} bounds A {@link LngLatBounds} object describing the new geographic boundaries of the map.\n */\n public setMaxBounds(bounds?: LngLatBounds) {\n if (bounds) {\n this.lngRange = [bounds.getWest(), bounds.getEast()];\n this.latRange = [bounds.getSouth(), bounds.getNorth()];\n this.constrain();\n } else {\n this.lngRange = undefined;\n this.latRange = [-this.maxValidLatitude, this.maxValidLatitude];\n }\n }\n\n public customLayerMatrix(): number[] {\n return (this.mercatorMatrix as number[]).slice();\n }\n\n public maxPitchScaleFactor() {\n // calcMatrices hasn't run yet\n if (!this.pixelMatrixInverse) {\n return 1;\n }\n\n const coord = this.pointCoordinate(new Point(0, 0));\n const p = new Float32Array([\n coord.x * this.worldSize,\n coord.y * this.worldSize,\n 0,\n 1,\n ]);\n const topPoint = vec4.transformMat4(p, p, this.pixelMatrix);\n return topPoint[3] / this.cameraToCenterDistance;\n }\n\n /*\n * The camera looks at the map from a 3D (lng, lat, altitude) location. Let's use `cameraLocation`\n * as the name for the location under the camera and on the surface of the earth (lng, lat, 0).\n * `cameraPoint` is the projected position of the `cameraLocation`.\n *\n * This point is useful to us because only fill-extrusions that are between `cameraPoint` and\n * the query point on the surface of the earth can extend and intersect the query.\n *\n * When the map is not pitched the `cameraPoint` is equivalent to the center of the map because\n * the camera is right above the center of the map.\n */\n public getCameraPoint() {\n const pitch = this._pitch;\n const yOffset = Math.tan(pitch) * (this.cameraToCenterDistance || 1);\n return this.centerPoint.add(new Point(0, yOffset));\n }\n\n /*\n * When the map is pitched, some of the 3D features that intersect a query will not intersect\n * the query at the surface of the earth. Instead the feature may be closer and only intersect\n * the query because it extrudes into the air.\n *\n * This returns a geometry that includes all of the original query as well as all possible ares of the\n * screen where the *base* of a visible extrusion could be.\n * - For point queries, the line from the query point to the \"camera point\"\n * - For other geometries, the envelope of the query geometry and the \"camera point\"\n */\n public getCameraQueryGeometry(queryGeometry: Point[]): Point[] {\n const c = this.getCameraPoint();\n\n if (queryGeometry.length === 1) {\n return [queryGeometry[0], c];\n } else {\n let minX = c.x;\n let minY = c.y;\n let maxX = c.x;\n let maxY = c.y;\n for (const p of queryGeometry) {\n minX = Math.min(minX, p.x);\n minY = Math.min(minY, p.y);\n maxX = Math.max(maxX, p.x);\n maxY = Math.max(maxY, p.y);\n }\n return [\n new Point(minX, minY),\n new Point(maxX, minY),\n new Point(maxX, maxY),\n new Point(minX, maxY),\n new Point(minX, minY),\n ];\n }\n }\n\n /**\n * Given a coordinate, return the screen point that corresponds to it\n * @param {Coordinate} coord\n * @returns {Point} screen point\n * @private\n */\n public coordinatePoint(coord: MercatorCoordinate) {\n const p = vec4.fromValues(\n coord.x * this.worldSize,\n coord.y * this.worldSize,\n 0,\n 1,\n );\n vec4.transformMat4(p, p, this.pixelMatrix);\n return new Point(p[0] / p[3], p[1] / p[3]);\n }\n /**\n * Given a location, return the screen point that corresponds to it\n * @param {LngLat} lnglat location\n * @returns {Point} screen point\n * @private\n */\n public locationPoint(lnglat: LngLat) {\n return this.coordinatePoint(this.locationCoordinate(lnglat));\n }\n\n /**\n * Given a point on screen, return its lnglat\n * @param {Point} p screen point\n * @returns {LngLat} lnglat location\n * @private\n */\n public pointLocation(p: Point) {\n // if(p.x !== 0 && p.x !== 1001) {\n // console.log(p.x)\n // }\n\n return this.coordinateLocation(this.pointCoordinate(p));\n }\n\n /**\n * Given a geographical lnglat, return an unrounded\n * coordinate that represents it at this transform's zoom level.\n * @param {LngLat} lnglat\n * @returns {Coordinate}\n * @private\n */\n public locationCoordinate(lnglat: LngLat) {\n return MercatorCoordinate.fromLngLat(lnglat);\n }\n\n /**\n * Given a Coordinate, return its geographical position.\n * @param {Coordinate} coord\n * @returns {LngLat} lnglat\n * @private\n */\n public coordinateLocation(coord: MercatorCoordinate) {\n return coord.toLngLat();\n }\n\n public getProjectionMatrix(): mat4 {\n return this.projMatrix;\n }\n /**\n * Calculate the posMatrix that, given a tile coordinate, would be used to display the tile on a map.\n * @param {UnwrappedTileID} unwrappedTileID;\n * @private\n */\n // private calculatePosMatrix(\n // unwrappedTileID: UnwrappedTileID,\n // aligned: boolean = false,\n // ): Float32Array {\n // const posMatrixKey = unwrappedTileID.key;\n // const cache = aligned ? this.alignedPosMatrixCache : this.posMatrixCache;\n // if (cache[posMatrixKey]) {\n // return cache[posMatrixKey];\n // }\n\n // const canonical = unwrappedTileID.canonical;\n // const scale = this.worldSize / this.zoomScale(canonical.z);\n // const unwrappedX =\n // canonical.x + Math.pow(2, canonical.z) * unwrappedTileID.wrap;\n\n // const posMatrix = mat4.identity(new Float64Array(16));\n // mat4.translate(posMatrix, posMatrix, [\n // unwrappedX * scale,\n // canonical.y * scale,\n // 0,\n // ]);\n // mat4.scale(posMatrix, posMatrix, [scale / EXTENT, scale / EXTENT, 1]);\n // mat4.multiply(\n // posMatrix,\n // aligned ? this.alignedProjMatrix : this.projMatrix,\n // posMatrix,\n // );\n\n // cache[posMatrixKey] = new Float32Array(posMatrix);\n // return cache[posMatrixKey];\n // }\n\n private constrain() {\n if (!this.center || !this.width || !this.height || this.constraining) {\n return;\n }\n\n this.constraining = true;\n\n let minY = -90;\n let maxY = 90;\n let minX = -180;\n let maxX = 180;\n let sy;\n let sx;\n let x2;\n let y2;\n const size = this.size;\n const unmodified = this.unmodified;\n\n if (this.latRange) {\n const latRange = this.latRange;\n minY = mercatorYfromLat(latRange[1]) * this.worldSize;\n maxY = mercatorYfromLat(latRange[0]) * this.worldSize;\n sy = maxY - minY < size.y ? size.y / (maxY - minY) : 0;\n }\n\n if (this.lngRange) {\n const lngRange = this.lngRange;\n minX = mercatorXfromLng(lngRange[0]) * this.worldSize;\n maxX = mercatorXfromLng(lngRange[1]) * this.worldSize;\n sx = maxX - minX < size.x ? size.x / (maxX - minX) : 0;\n }\n\n const point = this.point;\n\n // how much the map should scale to fit the screen into given latitude/longitude ranges\n const s = Math.max(sx || 0, sy || 0);\n\n if (s) {\n this.center = this.unproject(\n new Point(\n sx ? (maxX + minX) / 2 : point.x,\n sy ? (maxY + minY) / 2 : point.y,\n ),\n );\n this.zoom += this.scaleZoom(s);\n this.unmodified = unmodified;\n this.constraining = false;\n return;\n }\n\n if (this.latRange) {\n const y = point.y;\n const h2 = size.y / 2;\n\n if (y - h2 < minY) {\n y2 = minY + h2;\n }\n if (y + h2 > maxY) {\n y2 = maxY - h2;\n }\n }\n\n if (this.lngRange) {\n const x = point.x;\n const w2 = size.x / 2;\n\n if (x - w2 < minX) {\n x2 = minX + w2;\n }\n if (x + w2 > maxX) {\n x2 = maxX - w2;\n }\n }\n\n // pan the map if the screen goes off the range\n if (x2 !== undefined || y2 !== undefined) {\n this.center = this.unproject(\n new Point(\n x2 !== undefined ? x2 : point.x,\n y2 !== undefined ? y2 : point.y,\n ),\n );\n }\n\n this.unmodified = unmodified;\n this.constraining = false;\n }\n\n private calcMatrices() {\n if (!this.height) {\n return;\n }\n\n const halfFov = this._fov / 2;\n const offset = this.centerOffset;\n this.cameraToCenterDistance = (0.5 / Math.tan(halfFov)) * this.height;\n\n // Find the distance from the center point [width/2 + offset.x, height/2 + offset.y] to the\n // center top point [width/2 + offset.x, 0] in Z units, using the law of sines.\n // 1 Z unit is equivalent to 1 horizontal px at the center of the map\n // (the distance between[width/2, height/2] and [width/2 + 1, height/2])\n const groundAngle = Math.PI / 2 + this._pitch;\n const fovAboveCenter = this._fov * (0.5 + offset.y / this.height);\n const topHalfSurfaceDistance =\n (Math.sin(fovAboveCenter) * this.cameraToCenterDistance) /\n Math.sin(\n clamp(Math.PI - groundAngle - fovAboveCenter, 0.01, Math.PI - 0.01),\n );\n const point = this.point;\n const x = point.x;\n const y = point.y;\n\n // Calculate z distance of the farthest fragment that should be rendered.\n const furthestDistance =\n Math.cos(Math.PI / 2 - this._pitch) * topHalfSurfaceDistance +\n this.cameraToCenterDistance;\n // Add a bit extra to avoid precision problems when a fragment's distance is exactly `furthestDistance`\n const farZ = furthestDistance * 1.01;\n\n // The larger the value of nearZ is\n // - the more depth precision is available for features (good)\n // - clipping starts appearing sooner when the camera is close to 3d features (bad)\n //\n // Smaller values worked well for mapbox-gl-js but deckgl was encountering precision issues\n // when rendering it's layers using custom layers. This value was experimentally chosen and\n // seems to solve z-fighting issues in deckgl while not clipping buildings too close to the camera.\n const nearZ = this.height / 50;\n\n // matrix for conversion from location to GL coordinates (-1 .. 1)\n // TODO: 使用 Float64Array 的原因是为了避免计算精度问题、 mat4.create() 默认使用 Float32Array\n let m = new Float64Array(16);\n // @ts-ignore\n mat4.perspective(m, this._fov, this.width / this.height, nearZ, farZ);\n\n // Apply center of perspective offset\n m[8] = (-offset.x * 2) / this.width;\n m[9] = (offset.y * 2) / this.height;\n\n // @ts-ignore\n mat4.scale(m, m, [1, -1, 1]);\n // @ts-ignore\n mat4.translate(m, m, [0, 0, -this.cameraToCenterDistance]);\n // @ts-ignore\n mat4.rotateX(m, m, this._pitch);\n // @ts-ignore\n mat4.rotateZ(m, m, this.angle);\n // @ts-ignore\n mat4.translate(m, m, [-x, -y, 0]);\n\n // The mercatorMatrix can be used to transform points from mercator coordinates\n // ([0, 0] nw, [1, 1] se) to GL coordinates.\n // @ts-ignore\n this.mercatorMatrix = mat4.scale([], m, [\n this.worldSize,\n this.worldSize,\n this.worldSize,\n ]);\n // scale vertically to meters per pixel (inverse of ground resolution):\n\n // @ts-ignore\n mat4.scale(m, m, [\n 1,\n 1,\n mercatorZfromAltitude(1, this.center.lat) * this.worldSize,\n 1,\n ]);\n // @ts-ignore\n this.projMatrix = m;\n // @ts-ignore\n this.invProjMatrix = mat4.invert([], this.projMatrix);\n\n // Make a second projection matrix that is aligned to a pixel grid for rendering raster tiles.\n // We're rounding the (floating point) x/y values to achieve to avoid rendering raster images to fractional\n // coordinates. Additionally, we adjust by half a pixel in either direction in case that viewport dimension\n // is an odd integer to preserve rendering to the pixel grid. We're rotating this shift based on the angle\n // of the transformation so that 0°, 90°, 180°, and 270° rasters are crisp, and adjust the shift so that\n // it is always <= 0.5 pixels.\n const xShift = (this.width % 2) / 2;\n const yShift = (this.height % 2) / 2;\n const angleCos = Math.cos(this.angle);\n const angleSin = Math.sin(this.angle);\n const dx = x - Math.round(x) + angleCos * xShift + angleSin * yShift;\n const dy = y - Math.round(y) + angleCos * yShift + angleSin * xShift;\n // const alignedM = mat4.clone(m);\n const alignedM = new Float64Array(m);\n // @ts-ignore\n mat4.translate(alignedM, alignedM, [\n dx > 0.5 ? dx - 1 : dx,\n dy > 0.5 ? dy - 1 : dy,\n 0,\n ]);\n // @ts-ignore\n this.alignedProjMatrix = alignedM;\n\n // @ts-ignore\n m = mat4.create();\n // @ts-ignore\n mat4.scale(m, m, [this.width / 2, -this.height / 2, 1]);\n // @ts-ignore\n mat4.translate(m, m, [1, -1, 0]);\n // @ts-ignore\n this.labelPlaneMatrix = m;\n\n // @ts-ignore\n m = mat4.create();\n // @ts-ignore\n mat4.scale(m, m, [1, -1, 1]);\n // @ts-ignore\n mat4.translate(m, m, [-1, -1, 0]);\n // @ts-ignore\n mat4.scale(m, m, [2 / this.width, 2 / this.height, 1]);\n // @ts-ignore\n this.glCoordMatrix = m;\n\n // matrix for conversion from location to screen coordinates\n this.pixelMatrix = mat4.multiply(\n // @ts-ignore\n new Float64Array(16),\n this.labelPlaneMatrix,\n this.projMatrix,\n );\n\n // inverse matrix for conversion from screen coordinaes to location\n // @ts-ignore\n m = mat4.invert(new Float64Array(16), this.pixelMatrix);\n if (!m) {\n throw new Error('failed to invert matrix');\n }\n // @ts-ignore\n this.pixelMatrixInverse = m;\n\n this.posMatrixCache = {};\n this.alignedPosMatrixCache = {};\n }\n}\n"],"file":"transform.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antv/l7-map",
3
- "version": "2.5.46",
3
+ "version": "2.5.50",
4
4
  "description": "l7 map",
5
5
  "keywords": [],
6
6
  "author": "thinkinggis <lzx199065@gmail.com>",
@@ -37,12 +37,12 @@
37
37
  },
38
38
  "homepage": "https://github.com/antvis/L7#readme",
39
39
  "dependencies": {
40
- "@antv/l7-utils": "^2.5.46",
40
+ "@antv/l7-utils": "^2.5.50",
41
41
  "@babel/runtime": "^7.7.7",
42
42
  "@mapbox/point-geometry": "^0.1.0",
43
43
  "@mapbox/unitbezier": "^0.0.0",
44
44
  "eventemitter3": "^4.0.4",
45
45
  "lodash": "^4.17.15"
46
46
  },
47
- "gitHead": "069e6a635ba8c56150384e8f8940b31bdd0b9a82"
47
+ "gitHead": "968604064cd7986555eac9f641a5fdd3c5544bcc"
48
48
  }