@math.gl/web-mercator 3.5.6 → 3.6.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assert.d.ts +2 -0
- package/dist/assert.d.ts.map +1 -0
- package/dist/assert.js +8 -0
- package/dist/es5/assert.js.map +1 -1
- package/dist/es5/fit-bounds.js +40 -50
- package/dist/es5/fit-bounds.js.map +1 -1
- package/dist/es5/fly-to-viewport.js +82 -98
- package/dist/es5/fly-to-viewport.js.map +1 -1
- package/dist/es5/get-bounds.js +25 -24
- package/dist/es5/get-bounds.js.map +1 -1
- package/dist/es5/index.js +23 -25
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/math-utils.js +5 -11
- package/dist/es5/math-utils.js.map +1 -1
- package/dist/es5/normalize-viewport-props.js +25 -23
- package/dist/es5/normalize-viewport-props.js.map +1 -1
- package/dist/es5/web-mercator-utils.js +104 -144
- package/dist/es5/web-mercator-utils.js.map +1 -1
- package/dist/es5/web-mercator-viewport.js +198 -241
- package/dist/es5/web-mercator-viewport.js.map +1 -1
- package/dist/esm/assert.js.map +1 -1
- package/dist/esm/fit-bounds.js +24 -22
- package/dist/esm/fit-bounds.js.map +1 -1
- package/dist/esm/fly-to-viewport.js +13 -9
- package/dist/esm/fly-to-viewport.js.map +1 -1
- package/dist/esm/get-bounds.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/math-utils.js +3 -3
- package/dist/esm/math-utils.js.map +1 -1
- package/dist/esm/normalize-viewport-props.js +13 -9
- package/dist/esm/normalize-viewport-props.js.map +1 -1
- package/dist/esm/web-mercator-utils.js +46 -52
- package/dist/esm/web-mercator-utils.js.map +1 -1
- package/dist/esm/web-mercator-viewport.js +75 -33
- package/dist/esm/web-mercator-viewport.js.map +1 -1
- package/dist/fit-bounds.d.ts +49 -0
- package/dist/fit-bounds.d.ts.map +1 -0
- package/dist/fit-bounds.js +70 -0
- package/dist/fly-to-viewport.d.ts +19 -0
- package/dist/fly-to-viewport.d.ts.map +1 -0
- package/dist/fly-to-viewport.js +87 -0
- package/dist/get-bounds.d.ts +3 -0
- package/dist/get-bounds.d.ts.map +1 -0
- package/dist/get-bounds.js +51 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/math-utils.d.ts +6 -0
- package/dist/math-utils.d.ts.map +1 -0
- package/dist/math-utils.js +23 -0
- package/dist/normalize-viewport-props.d.ts +17 -0
- package/dist/normalize-viewport-props.d.ts.map +1 -0
- package/dist/normalize-viewport-props.js +41 -0
- package/dist/{es5/web-mercator-utils.d.ts → web-mercator-utils.d.ts} +77 -94
- package/dist/web-mercator-utils.d.ts.map +1 -0
- package/dist/web-mercator-utils.js +289 -0
- package/dist/web-mercator-viewport.d.ts +183 -0
- package/dist/web-mercator-viewport.d.ts.map +1 -0
- package/dist/web-mercator-viewport.js +282 -0
- package/package.json +3 -3
- package/src/{assert.js → assert.ts} +1 -1
- package/src/fit-bounds.ts +135 -0
- package/src/{fly-to-viewport.js → fly-to-viewport.ts} +33 -10
- package/src/{get-bounds.js → get-bounds.ts} +4 -2
- package/src/{index.js → index.ts} +0 -0
- package/src/{math-utils.js → math-utils.ts} +7 -7
- package/src/{normalize-viewport-props.js → normalize-viewport-props.ts} +19 -10
- package/src/{web-mercator-utils.js → web-mercator-utils.ts} +181 -72
- package/src/web-mercator-viewport.ts +417 -0
- package/dist/es5/fit-bounds.d.ts +0 -64
- package/dist/es5/fly-to-viewport.d.ts +0 -31
- package/dist/es5/get-bounds.d.ts +0 -3
- package/dist/es5/index.d.ts +0 -23
- package/dist/es5/normalize-viewport-props.d.ts +0 -16
- package/dist/es5/web-mercator-viewport.d.ts +0 -187
- package/dist/esm/fit-bounds.d.ts +0 -64
- package/dist/esm/fly-to-viewport.d.ts +0 -31
- package/dist/esm/get-bounds.d.ts +0 -3
- package/dist/esm/index.d.ts +0 -23
- package/dist/esm/normalize-viewport-props.d.ts +0 -16
- package/dist/esm/web-mercator-utils.d.ts +0 -189
- package/dist/esm/web-mercator-viewport.d.ts +0 -187
- package/src/fit-bounds.d.ts +0 -64
- package/src/fit-bounds.js +0 -84
- package/src/fly-to-viewport.d.ts +0 -31
- package/src/get-bounds.d.ts +0 -3
- package/src/index.d.ts +0 -23
- package/src/normalize-viewport-props.d.ts +0 -16
- package/src/web-mercator-utils.d.ts +0 -189
- package/src/web-mercator-viewport.d.ts +0 -187
- package/src/web-mercator-viewport.js +0 -262
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
1
2
|
import { createMat4 } from './math-utils';
|
|
2
3
|
import { zoomToScale, pixelsToWorld, lngLatToWorld, worldToLngLat, worldToPixels, altitudeToFovy, fovyToAltitude, DEFAULT_ALTITUDE, getProjectionMatrix, getDistanceScales, getViewMatrix } from './web-mercator-utils';
|
|
3
4
|
import fitBounds from './fit-bounds';
|
|
@@ -6,23 +7,62 @@ import * as mat4 from 'gl-matrix/mat4';
|
|
|
6
7
|
import * as vec2 from 'gl-matrix/vec2';
|
|
7
8
|
import * as vec3 from 'gl-matrix/vec3';
|
|
8
9
|
export default class WebMercatorViewport {
|
|
9
|
-
constructor({
|
|
10
|
-
width,
|
|
11
|
-
height,
|
|
12
|
-
latitude = 0,
|
|
13
|
-
longitude = 0,
|
|
14
|
-
zoom = 0,
|
|
15
|
-
pitch = 0,
|
|
16
|
-
bearing = 0,
|
|
17
|
-
altitude = null,
|
|
18
|
-
fovy = null,
|
|
19
|
-
position = null,
|
|
20
|
-
nearZMultiplier = 0.02,
|
|
21
|
-
farZMultiplier = 1.01
|
|
22
|
-
} = {
|
|
10
|
+
constructor(props = {
|
|
23
11
|
width: 1,
|
|
24
12
|
height: 1
|
|
25
13
|
}) {
|
|
14
|
+
_defineProperty(this, "latitude", void 0);
|
|
15
|
+
|
|
16
|
+
_defineProperty(this, "longitude", void 0);
|
|
17
|
+
|
|
18
|
+
_defineProperty(this, "zoom", void 0);
|
|
19
|
+
|
|
20
|
+
_defineProperty(this, "pitch", void 0);
|
|
21
|
+
|
|
22
|
+
_defineProperty(this, "bearing", void 0);
|
|
23
|
+
|
|
24
|
+
_defineProperty(this, "altitude", void 0);
|
|
25
|
+
|
|
26
|
+
_defineProperty(this, "fovy", void 0);
|
|
27
|
+
|
|
28
|
+
_defineProperty(this, "meterOffset", void 0);
|
|
29
|
+
|
|
30
|
+
_defineProperty(this, "center", void 0);
|
|
31
|
+
|
|
32
|
+
_defineProperty(this, "width", void 0);
|
|
33
|
+
|
|
34
|
+
_defineProperty(this, "height", void 0);
|
|
35
|
+
|
|
36
|
+
_defineProperty(this, "scale", void 0);
|
|
37
|
+
|
|
38
|
+
_defineProperty(this, "distanceScales", void 0);
|
|
39
|
+
|
|
40
|
+
_defineProperty(this, "viewMatrix", void 0);
|
|
41
|
+
|
|
42
|
+
_defineProperty(this, "projectionMatrix", void 0);
|
|
43
|
+
|
|
44
|
+
_defineProperty(this, "viewProjectionMatrix", void 0);
|
|
45
|
+
|
|
46
|
+
_defineProperty(this, "pixelProjectionMatrix", void 0);
|
|
47
|
+
|
|
48
|
+
_defineProperty(this, "pixelUnprojectionMatrix", void 0);
|
|
49
|
+
|
|
50
|
+
let {
|
|
51
|
+
width,
|
|
52
|
+
height,
|
|
53
|
+
altitude = null,
|
|
54
|
+
fovy = null
|
|
55
|
+
} = props;
|
|
56
|
+
const {
|
|
57
|
+
latitude = 0,
|
|
58
|
+
longitude = 0,
|
|
59
|
+
zoom = 0,
|
|
60
|
+
pitch = 0,
|
|
61
|
+
bearing = 0,
|
|
62
|
+
position = null,
|
|
63
|
+
nearZMultiplier = 0.02,
|
|
64
|
+
farZMultiplier = 1.01
|
|
65
|
+
} = props;
|
|
26
66
|
width = width || 1;
|
|
27
67
|
height = height || 1;
|
|
28
68
|
|
|
@@ -121,20 +161,22 @@ export default class WebMercatorViewport {
|
|
|
121
161
|
return viewport.width === this.width && viewport.height === this.height && mat4.equals(viewport.projectionMatrix, this.projectionMatrix) && mat4.equals(viewport.viewMatrix, this.viewMatrix);
|
|
122
162
|
}
|
|
123
163
|
|
|
124
|
-
project(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
164
|
+
project(lngLatZ, options = {}) {
|
|
165
|
+
const {
|
|
166
|
+
topLeft = true
|
|
167
|
+
} = options;
|
|
168
|
+
const worldPosition = this.projectPosition(lngLatZ);
|
|
128
169
|
const coord = worldToPixels(worldPosition, this.pixelProjectionMatrix);
|
|
129
170
|
const [x, y] = coord;
|
|
130
171
|
const y2 = topLeft ? y : this.height - y;
|
|
131
|
-
return
|
|
172
|
+
return lngLatZ.length === 2 ? [x, y2] : [x, y2, coord[2]];
|
|
132
173
|
}
|
|
133
174
|
|
|
134
|
-
unproject(xyz, {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
175
|
+
unproject(xyz, options = {}) {
|
|
176
|
+
const {
|
|
177
|
+
topLeft = true,
|
|
178
|
+
targetZ = undefined
|
|
179
|
+
} = options;
|
|
138
180
|
const [x, y, z] = xyz;
|
|
139
181
|
const y2 = topLeft ? y : this.height - y;
|
|
140
182
|
const targetZWorld = targetZ && targetZ * this.distanceScales.unitsPerMeter[2];
|
|
@@ -179,16 +221,6 @@ export default class WebMercatorViewport {
|
|
|
179
221
|
return worldToLngLat(newCenter);
|
|
180
222
|
}
|
|
181
223
|
|
|
182
|
-
getLocationAtPoint({
|
|
183
|
-
lngLat,
|
|
184
|
-
pos
|
|
185
|
-
}) {
|
|
186
|
-
return this.getMapCenterByLngLatPosition({
|
|
187
|
-
lngLat,
|
|
188
|
-
pos
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
|
|
192
224
|
fitBounds(bounds, options = {}) {
|
|
193
225
|
const {
|
|
194
226
|
width,
|
|
@@ -225,5 +257,15 @@ export default class WebMercatorViewport {
|
|
|
225
257
|
return getBounds(this, options.z || 0);
|
|
226
258
|
}
|
|
227
259
|
|
|
260
|
+
getLocationAtPoint({
|
|
261
|
+
lngLat,
|
|
262
|
+
pos
|
|
263
|
+
}) {
|
|
264
|
+
return this.getMapCenterByLngLatPosition({
|
|
265
|
+
lngLat,
|
|
266
|
+
pos
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
|
|
228
270
|
}
|
|
229
271
|
//# sourceMappingURL=web-mercator-viewport.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/web-mercator-viewport.js"],"names":["createMat4","zoomToScale","pixelsToWorld","lngLatToWorld","worldToLngLat","worldToPixels","altitudeToFovy","fovyToAltitude","DEFAULT_ALTITUDE","getProjectionMatrix","getDistanceScales","getViewMatrix","fitBounds","getBounds","mat4","vec2","vec3","WebMercatorViewport","constructor","width","height","latitude","longitude","zoom","pitch","bearing","altitude","fovy","position","nearZMultiplier","farZMultiplier","scale","Math","max","distanceScales","center","add","mul","unitsPerMeter","projectionMatrix","viewMatrix","meterOffset","_initMatrices","equals","bind","project","unproject","projectPosition","unprojectPosition","Object","freeze","vpm","multiply","viewProjectionMatrix","m","translate","mInverse","invert","Error","pixelProjectionMatrix","pixelUnprojectionMatrix","viewport","xyz","topLeft","worldPosition","coord","x","y","y2","length","targetZ","undefined","z","targetZWorld","X","Y","Z","Number","isFinite","metersPerUnit","projectFlat","lngLat","unprojectFlat","xy","getMapCenterByLngLatPosition","pos","fromLocation","toLocation","negate","newCenter","getLocationAtPoint","bounds","options","assign","corners","getBoundingRegion","west","min","map","p","east","south","north"],"mappings":"AACA,SAAQA,UAAR,QAAyB,cAAzB;AAEA,SACEC,WADF,EAEEC,aAFF,EAGEC,aAHF,EAIEC,aAJF,EAKEC,aALF,EAMEC,cANF,EAOEC,cAPF,EAQEC,gBARF,EASEC,mBATF,EAUEC,iBAVF,EAWEC,aAXF,QAYO,sBAZP;AAaA,OAAOC,SAAP,MAAsB,cAAtB;AACA,OAAOC,SAAP,MAAsB,cAAtB;AAEA,OAAO,KAAKC,IAAZ,MAAsB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for mapbox-js style map view properties\nimport {createMat4} from './math-utils';\n\nimport {\n zoomToScale,\n pixelsToWorld,\n lngLatToWorld,\n worldToLngLat,\n worldToPixels,\n altitudeToFovy,\n fovyToAltitude,\n DEFAULT_ALTITUDE,\n getProjectionMatrix,\n getDistanceScales,\n getViewMatrix\n} from './web-mercator-utils';\nimport fitBounds from './fit-bounds';\nimport getBounds from './get-bounds';\n\nimport * as mat4 from 'gl-matrix/mat4';\nimport * as vec2 from 'gl-matrix/vec2';\nimport * as vec3 from 'gl-matrix/vec3';\n\nexport default class WebMercatorViewport {\n // eslint-disable-next-line max-statements\n constructor(\n {\n // Map state\n width,\n height,\n latitude = 0,\n longitude = 0,\n zoom = 0,\n pitch = 0,\n bearing = 0,\n altitude = null,\n fovy = null,\n position = null,\n nearZMultiplier = 0.02,\n farZMultiplier = 1.01\n } = {width: 1, height: 1}\n ) {\n // Silently allow apps to send in 0,0 to facilitate isomorphic render etc\n width = width || 1;\n height = height || 1;\n\n // `fovy` & `altitude` are independent parameters, one for the\n // projection and the latter for the view matrix. In the past,\n // the `fovy` was always derived from the `altitude`\n if (fovy === null && altitude === null) {\n altitude = DEFAULT_ALTITUDE;\n fovy = altitudeToFovy(altitude);\n } else if (fovy === null) {\n fovy = altitudeToFovy(altitude);\n } else if (altitude === null) {\n altitude = fovyToAltitude(fovy);\n }\n\n const scale = zoomToScale(zoom);\n // Altitude - prevent division by 0\n // TODO - just throw an Error instead?\n altitude = Math.max(0.75, altitude);\n\n const distanceScales = getDistanceScales({longitude, latitude});\n\n const center = lngLatToWorld([longitude, latitude]);\n center[2] = 0;\n\n if (position) {\n vec3.add(center, center, vec3.mul([], position, distanceScales.unitsPerMeter));\n }\n\n this.projectionMatrix = getProjectionMatrix({\n width,\n height,\n pitch,\n fovy,\n nearZMultiplier,\n farZMultiplier\n });\n\n this.viewMatrix = getViewMatrix({\n height,\n scale,\n center,\n pitch,\n bearing,\n altitude\n });\n\n // Save parameters\n this.width = width;\n this.height = height;\n this.scale = scale;\n\n this.latitude = latitude;\n this.longitude = longitude;\n this.zoom = zoom;\n this.pitch = pitch;\n this.bearing = bearing;\n this.altitude = altitude;\n this.fovy = fovy;\n this.center = center;\n this.meterOffset = position || [0, 0, 0];\n\n this.distanceScales = distanceScales;\n\n this._initMatrices();\n\n // Bind methods for easy access\n this.equals = this.equals.bind(this);\n this.project = this.project.bind(this);\n this.unproject = this.unproject.bind(this);\n this.projectPosition = this.projectPosition.bind(this);\n this.unprojectPosition = this.unprojectPosition.bind(this);\n\n Object.freeze(this);\n }\n\n _initMatrices() {\n const {width, height, projectionMatrix, viewMatrix} = this;\n\n // Note: As usual, matrix operations should be applied in \"reverse\" order\n // since vectors will be multiplied in from the right during transformation\n const vpm = createMat4();\n mat4.multiply(vpm, vpm, projectionMatrix);\n mat4.multiply(vpm, vpm, viewMatrix);\n this.viewProjectionMatrix = vpm;\n\n // Calculate matrices and scales needed for projection\n /**\n * Builds matrices that converts preprojected lngLats to screen pixels\n * and vice versa.\n * Note: Currently returns bottom-left coordinates!\n * Note: Starts with the GL projection matrix and adds steps to the\n * scale and translate that matrix onto the window.\n * Note: WebGL controls clip space to screen projection with gl.viewport\n * and does not need this step.\n */\n const m = createMat4();\n\n // matrix for conversion from location to screen coordinates\n mat4.scale(m, m, [width / 2, -height / 2, 1]);\n mat4.translate(m, m, [1, -1, 0]);\n mat4.multiply(m, m, vpm);\n\n const mInverse = mat4.invert(createMat4(), m);\n if (!mInverse) {\n throw new Error('Pixel project matrix not invertible');\n }\n\n this.pixelProjectionMatrix = m;\n this.pixelUnprojectionMatrix = mInverse;\n }\n\n // Two viewports are equal if width and height are identical, and if\n // their view and projection matrices are (approximately) equal.\n equals(viewport) {\n if (!(viewport instanceof WebMercatorViewport)) {\n return false;\n }\n\n return (\n viewport.width === this.width &&\n viewport.height === this.height &&\n mat4.equals(viewport.projectionMatrix, this.projectionMatrix) &&\n mat4.equals(viewport.viewMatrix, this.viewMatrix)\n );\n }\n\n // Projects xyz (possibly latitude and longitude) to pixel coordinates in window\n // using viewport projection parameters\n project(xyz, {topLeft = true} = {}) {\n const worldPosition = this.projectPosition(xyz);\n const coord = worldToPixels(worldPosition, this.pixelProjectionMatrix);\n\n const [x, y] = coord;\n const y2 = topLeft ? y : this.height - y;\n return xyz.length === 2 ? [x, y2] : [x, y2, coord[2]];\n }\n\n // Unproject pixel coordinates on screen onto world coordinates,\n // (possibly [lon, lat]) on map.\n unproject(xyz, {topLeft = true, targetZ = undefined} = {}) {\n const [x, y, z] = xyz;\n\n const y2 = topLeft ? y : this.height - y;\n const targetZWorld = targetZ && targetZ * this.distanceScales.unitsPerMeter[2];\n const coord = pixelsToWorld([x, y2, z], this.pixelUnprojectionMatrix, targetZWorld);\n const [X, Y, Z] = this.unprojectPosition(coord);\n\n if (Number.isFinite(z)) {\n return [X, Y, Z];\n }\n return Number.isFinite(targetZ) ? [X, Y, targetZ] : [X, Y];\n }\n\n // NON_LINEAR PROJECTION HOOKS\n // Used for web meractor projection\n\n projectPosition(xyz) {\n const [X, Y] = lngLatToWorld(xyz);\n const Z = (xyz[2] || 0) * this.distanceScales.unitsPerMeter[2];\n return [X, Y, Z];\n }\n\n unprojectPosition(xyz) {\n const [X, Y] = worldToLngLat(xyz);\n const Z = (xyz[2] || 0) * this.distanceScales.metersPerUnit[2];\n return [X, Y, Z];\n }\n\n // Project [lng,lat] on sphere onto [x,y] on 512*512 Mercator Zoom 0 tile.\n projectFlat(lngLat) {\n return lngLatToWorld(lngLat);\n }\n\n // Unproject world point [x,y] on map onto {lat, lon} on sphere\n unprojectFlat(xy) {\n return worldToLngLat(xy);\n }\n\n // Get the map center that place a given [lng, lat] coordinate at screen point [x, y]\n getMapCenterByLngLatPosition({lngLat, pos}) {\n const fromLocation = pixelsToWorld(pos, this.pixelUnprojectionMatrix);\n const toLocation = lngLatToWorld(lngLat);\n\n const translate = vec2.add([], toLocation, vec2.negate([], fromLocation));\n const newCenter = vec2.add([], this.center, translate);\n\n return worldToLngLat(newCenter);\n }\n\n // Legacy method name\n getLocationAtPoint({lngLat, pos}) {\n return this.getMapCenterByLngLatPosition({lngLat, pos});\n }\n\n // Returns a new viewport that fit around the given rectangle.\n fitBounds(bounds, options = {}) {\n const {width, height} = this;\n const {longitude, latitude, zoom} = fitBounds(Object.assign({width, height, bounds}, options));\n return new WebMercatorViewport({width, height, longitude, latitude, zoom});\n }\n\n getBounds(options) {\n const corners = this.getBoundingRegion(options);\n\n const west = Math.min(...corners.map((p) => p[0]));\n const east = Math.max(...corners.map((p) => p[0]));\n const south = Math.min(...corners.map((p) => p[1]));\n const north = Math.max(...corners.map((p) => p[1]));\n return [\n [west, south],\n [east, north]\n ];\n }\n\n getBoundingRegion(options = {}) {\n return getBounds(this, options.z || 0);\n }\n}\n"],"file":"web-mercator-viewport.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/web-mercator-viewport.ts"],"names":["createMat4","zoomToScale","pixelsToWorld","lngLatToWorld","worldToLngLat","worldToPixels","altitudeToFovy","fovyToAltitude","DEFAULT_ALTITUDE","getProjectionMatrix","getDistanceScales","getViewMatrix","fitBounds","getBounds","mat4","vec2","vec3","WebMercatorViewport","constructor","props","width","height","altitude","fovy","latitude","longitude","zoom","pitch","bearing","position","nearZMultiplier","farZMultiplier","scale","Math","max","distanceScales","center","add","mul","unitsPerMeter","projectionMatrix","viewMatrix","meterOffset","_initMatrices","equals","bind","project","unproject","projectPosition","unprojectPosition","Object","freeze","vpm","multiply","viewProjectionMatrix","m","translate","mInverse","invert","Error","pixelProjectionMatrix","pixelUnprojectionMatrix","viewport","lngLatZ","options","topLeft","worldPosition","coord","x","y","y2","length","xyz","targetZ","undefined","z","targetZWorld","X","Y","Z","Number","isFinite","metersPerUnit","projectFlat","lngLat","unprojectFlat","xy","getMapCenterByLngLatPosition","pos","fromLocation","toLocation","negate","newCenter","bounds","assign","corners","getBoundingRegion","west","min","map","p","east","south","north","getLocationAtPoint"],"mappings":";AACA,SAAQA,UAAR,QAAyB,cAAzB;AAEA,SACE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G6D,OAAO,CAACI,GAAR,CAAaC,CAAD,IAAOA,CAAC,CAAC,CAAD,CAApB,CAAZ,CAAd;AACA,WAAO,CACL,CAACH,IAAD,EAAOK,KAAP,CADK,EAEL,CAACD,IAAD,EAAOE,KAAP,CAFK,CAAP;AAID;;AAQDP,EAAAA,iBAAiB,CAAChC,OAAqB,GAAG,EAAzB,EAAyC;AACxD,WAAOnD,SAAS,CAAC,IAAD,EAAOmD,OAAO,CAACW,CAAR,IAAa,CAApB,CAAhB;AACD;;AAKD6B,EAAAA,kBAAkB,CAAC;AAACpB,IAAAA,MAAD;AAASI,IAAAA;AAAT,GAAD,EAA6D;AAC7E,WAAO,KAAKD,4BAAL,CAAkC;AAACH,MAAAA,MAAD;AAASI,MAAAA;AAAT,KAAlC,CAAP;AACD;;AAxVsC","sourcesContent":["// View and Projection Matrix calculations for mapbox-js style map view properties\nimport {createMat4} from './math-utils';\n\nimport {\n zoomToScale,\n pixelsToWorld,\n lngLatToWorld,\n worldToLngLat,\n worldToPixels,\n altitudeToFovy,\n fovyToAltitude,\n DEFAULT_ALTITUDE,\n getProjectionMatrix,\n getDistanceScales,\n getViewMatrix\n} from './web-mercator-utils';\nimport fitBounds from './fit-bounds';\nimport getBounds from './get-bounds';\nimport type {Bounds, FitBoundsOptions} from './fit-bounds';\n\nimport * as mat4 from 'gl-matrix/mat4';\nimport * as vec2 from 'gl-matrix/vec2';\nimport * as vec3 from 'gl-matrix/vec3';\n\n/**\n * @param width=1 - Width of \"viewport\" or window\n * @param height=1 - Height of \"viewport\" or window\n * @param scale=1 - Either use scale or zoom\n * @param pitch=0 - Camera angle in degrees (0 is straight down)\n * @param bearing=0 - Map rotation in degrees (0 means north is up)\n * @param fovy= - Field of view of camera in degrees\n * @param altitude= - Altitude of camera in screen units \n *\n * Web mercator projection short-hand parameters\n * @param latitude - Center of viewport on map\n * @param longitude - Center of viewport on map\n * @param zoom - Scale = Math.pow(2,zoom) on map\n\n * Notes:\n * - Only one of center or [latitude, longitude] can be specified\n * - [latitude, longitude] can only be specified when \"mercator\" is true\n * - Altitude has a default value that matches assumptions in mapbox-gl\n * - Field of view is independent from altitude, provide `altitudeToFovy(1.5)` (default value) to match assumptions in mapbox-gl\n * - width and height are forced to 1 if supplied as 0, to avoid\n * division by zero. This is intended to reduce the burden of apps to\n * to check values before instantiating a Viewport.\n */\nexport type WebMercatorViewportProps = {\n // Map state\n width: number;\n height: number;\n latitude?: number;\n longitude?: number;\n position?: number[];\n zoom?: number;\n pitch?: number;\n bearing?: number;\n altitude?: number;\n fovy?: number;\n nearZMultiplier?: number;\n farZMultiplier?: number;\n};\n\n/**\n * The WebMercatorViewport class creates\n * - view/projection matrices\n * - \"uniform values\" (for shaders) from mercator params\n *\n * Note: Instances are immutable in the sense that they only have accessors.\n * A new viewport instance should be created if any parameters have changed.\n */\nexport default class WebMercatorViewport {\n readonly latitude: number;\n readonly longitude: number;\n readonly zoom: number;\n readonly pitch: number;\n readonly bearing: number;\n readonly altitude: number;\n readonly fovy: number;\n\n readonly meterOffset: number[];\n readonly center: number[];\n\n readonly width: number;\n readonly height: number;\n readonly scale: number;\n readonly distanceScales: {\n unitsPerMeter: number[];\n };\n\n readonly viewMatrix: number[];\n readonly projectionMatrix: number[];\n\n viewProjectionMatrix: number[];\n pixelProjectionMatrix: number[];\n pixelUnprojectionMatrix: number[];\n\n /**\n * @classdesc\n * Creates view/projection matrices from mercator params\n * Note: The Viewport is immutable in the sense that it only has accessors.\n * A new viewport instance should be created if any parameters have changed.\n */\n // eslint-disable-next-line max-statements\n constructor(props: WebMercatorViewportProps = {width: 1, height: 1}) {\n let {\n // Map state\n width,\n height,\n altitude = null,\n fovy = null\n } = props;\n const {\n latitude = 0,\n longitude = 0,\n zoom = 0,\n pitch = 0,\n bearing = 0,\n position = null,\n nearZMultiplier = 0.02,\n farZMultiplier = 1.01\n } = props;\n\n // Silently allow apps to send in 0,0 to facilitate isomorphic render etc\n width = width || 1;\n height = height || 1;\n\n // `fovy` & `altitude` are independent parameters, one for the\n // projection and the latter for the view matrix. In the past,\n // the `fovy` was always derived from the `altitude`\n if (fovy === null && altitude === null) {\n altitude = DEFAULT_ALTITUDE;\n fovy = altitudeToFovy(altitude);\n } else if (fovy === null) {\n fovy = altitudeToFovy(altitude);\n } else if (altitude === null) {\n altitude = fovyToAltitude(fovy);\n }\n\n const scale = zoomToScale(zoom);\n // Altitude - prevent division by 0\n // TODO - just throw an Error instead?\n altitude = Math.max(0.75, altitude);\n\n const distanceScales = getDistanceScales({longitude, latitude});\n\n const center = lngLatToWorld([longitude, latitude]);\n center[2] = 0;\n\n if (position) {\n vec3.add(center, center, vec3.mul([], position, distanceScales.unitsPerMeter));\n }\n\n this.projectionMatrix = getProjectionMatrix({\n width,\n height,\n pitch,\n fovy,\n nearZMultiplier,\n farZMultiplier\n });\n\n this.viewMatrix = getViewMatrix({\n height,\n scale,\n center,\n pitch,\n bearing,\n altitude\n });\n\n // Save parameters\n this.width = width;\n this.height = height;\n this.scale = scale;\n\n this.latitude = latitude;\n this.longitude = longitude;\n this.zoom = zoom;\n this.pitch = pitch;\n this.bearing = bearing;\n this.altitude = altitude;\n this.fovy = fovy;\n this.center = center;\n this.meterOffset = position || [0, 0, 0];\n\n this.distanceScales = distanceScales;\n\n this._initMatrices();\n\n // Bind methods for easy access\n this.equals = this.equals.bind(this);\n this.project = this.project.bind(this);\n this.unproject = this.unproject.bind(this);\n this.projectPosition = this.projectPosition.bind(this);\n this.unprojectPosition = this.unprojectPosition.bind(this);\n\n Object.freeze(this);\n }\n\n _initMatrices() {\n const {width, height, projectionMatrix, viewMatrix} = this;\n\n // Note: As usual, matrix operations should be applied in \"reverse\" order\n // since vectors will be multiplied in from the right during transformation\n const vpm = createMat4();\n mat4.multiply(vpm, vpm, projectionMatrix);\n mat4.multiply(vpm, vpm, viewMatrix);\n this.viewProjectionMatrix = vpm;\n\n // Calculate matrices and scales needed for projection\n /**\n * Builds matrices that converts preprojected lngLats to screen pixels\n * and vice versa.\n * Note: Currently returns bottom-left coordinates!\n * Note: Starts with the GL projection matrix and adds steps to the\n * scale and translate that matrix onto the window.\n * Note: WebGL controls clip space to screen projection with gl.viewport\n * and does not need this step.\n */\n const m = createMat4();\n\n // matrix for conversion from location to screen coordinates\n mat4.scale(m, m, [width / 2, -height / 2, 1]);\n mat4.translate(m, m, [1, -1, 0]);\n mat4.multiply(m, m, vpm);\n\n const mInverse = mat4.invert(createMat4(), m);\n if (!mInverse) {\n throw new Error('Pixel project matrix not invertible');\n }\n\n this.pixelProjectionMatrix = m;\n this.pixelUnprojectionMatrix = mInverse;\n }\n\n /** Two viewports are equal if width and height are identical, and if\n * their view and projection matrices are (approximately) equal.\n */\n equals(viewport: WebMercatorViewport | null): boolean {\n if (!(viewport instanceof WebMercatorViewport)) {\n return false;\n }\n\n return (\n viewport.width === this.width &&\n viewport.height === this.height &&\n mat4.equals(viewport.projectionMatrix, this.projectionMatrix) &&\n mat4.equals(viewport.viewMatrix, this.viewMatrix)\n );\n }\n\n /**\n * Projects xyz (possibly latitude and longitude) to pixel coordinates in window\n * using viewport projection parameters\n * - [longitude, latitude] to [x, y]\n * - [longitude, latitude, Z] => [x, y, z]\n * Note: By default, returns top-left coordinates for canvas/SVG type render\n *\n * @param lngLatZ - [lng, lat] or [lng, lat, Z]\n * @param options - options\n * @param options.topLeft=true - Whether projected coords are top left\n * @return - screen coordinates [x, y] or [x, y, z], z as pixel depth\n */\n project(lngLatZ: number[], options: {topLeft?: boolean} = {}): number[] {\n const {topLeft = true} = options;\n const worldPosition = this.projectPosition(lngLatZ);\n const coord = worldToPixels(worldPosition, this.pixelProjectionMatrix);\n\n const [x, y] = coord;\n const y2 = topLeft ? y : this.height - y;\n return lngLatZ.length === 2 ? [x, y2] : [x, y2, coord[2]];\n }\n\n /**\n * Unproject pixel coordinates on screen onto world coordinates, possibly `[lon, lat]` on map.\n *\n * - [x, y] => [lng, lat]\n * - [x, y, z] => [lng, lat, Z]\n *\n * @param xyz - screen coordinates, z as pixel depth\n * @param options - options\n * @param options.topLeft=true - Whether projected coords are top left\n * @param options.targetZ=0 - If pixel depth is unknown, targetZ is used as\n * the elevation plane to unproject onto\n * @return - [lng, lat, Z] or [X, Y, Z]\n */\n unproject(xyz: number[], options: {topLeft?: boolean; targetZ?: number} = {}): number[] {\n const {topLeft = true, targetZ = undefined} = options;\n const [x, y, z] = xyz;\n\n const y2 = topLeft ? y : this.height - y;\n const targetZWorld = targetZ && targetZ * this.distanceScales.unitsPerMeter[2];\n const coord = pixelsToWorld([x, y2, z], this.pixelUnprojectionMatrix, targetZWorld);\n const [X, Y, Z] = this.unprojectPosition(coord);\n\n if (Number.isFinite(z)) {\n return [X, Y, Z];\n }\n return Number.isFinite(targetZ) ? [X, Y, targetZ] : [X, Y];\n }\n\n // NON_LINEAR PROJECTION HOOKS\n // Used for web meractor projection\n\n projectPosition(xyz) {\n const [X, Y] = lngLatToWorld(xyz);\n const Z = (xyz[2] || 0) * this.distanceScales.unitsPerMeter[2];\n return [X, Y, Z];\n }\n\n unprojectPosition(xyz) {\n const [X, Y] = worldToLngLat(xyz);\n // @ts-expect-error\n const Z = (xyz[2] || 0) * this.distanceScales.metersPerUnit[2];\n return [X, Y, Z];\n }\n\n /**\n * Project [lng,lat] on sphere onto [x,y] on 512*512 Mercator Zoom 0 tile.\n * Performs the nonlinear part of the web mercator projection.\n * Remaining projection is done with 4x4 matrices which also handles\n * perspective.\n *\n * @param lngLat - [lng, lat] coordinates\n * Specifies a point on the sphere to project onto the map.\n * @return [x,y] coordinates.\n */\n projectFlat(lngLat: number[]): number[] {\n return lngLatToWorld(lngLat);\n }\n\n /**\n * Unproject world point [x,y] on map onto {lat, lon} on sphere\n *\n * @param xy - array with [x,y] members\n * representing point on projected map plane\n * @return - array with [lat,lon] of point on sphere.\n * Has toArray method if you need a GeoJSON Array.\n * Per cartographic tradition, lat and lon are specified as degrees.\n */\n unprojectFlat(xy: number[]): number[] {\n return worldToLngLat(xy);\n }\n\n /**\n * Get the map center that place a given [lng, lat] coordinate at screen point [x, y]\n * @param opt\n * @param opt.lngLat - [lng,lat] coordinates\n * Specifies a point on the sphere.\n * @param opt.pos - [x,y] coordinates\n * Specifies a point on the screen.\n * @return [lng,lat] new map center.\n */\n getMapCenterByLngLatPosition({lngLat, pos}: {lngLat: number[]; pos: number[]}): number[] {\n const fromLocation = pixelsToWorld(pos, this.pixelUnprojectionMatrix);\n const toLocation = lngLatToWorld(lngLat);\n const translate = vec2.add([], toLocation, vec2.negate([], fromLocation));\n const newCenter = vec2.add([], this.center, translate);\n return worldToLngLat(newCenter);\n }\n\n /**\n * Returns a new viewport that fit around the given rectangle.\n * Only supports non-perspective mode.\n * @param bounds - [[lon, lat], [lon, lat]]\n * @param [options]\n * @param [options.padding] - The amount of padding in pixels to add to the given bounds.\n * @param [options.offset] - The center of the given bounds relative to the map's center,\n * [x, y] measured in pixels.\n * @returns {WebMercatorViewport}\n */\n fitBounds(\n bounds: [[number, number], [number, number]],\n options: Omit<FitBoundsOptions, 'width' | 'height' | 'bounds'> = {}\n ): WebMercatorViewport {\n const {width, height} = this;\n const {longitude, latitude, zoom} = fitBounds(Object.assign({width, height, bounds}, options));\n return new WebMercatorViewport({width, height, longitude, latitude, zoom});\n }\n\n /**\n * Returns the bounding box of the viewport.\n * @param [options]\n * @param [options.z] - The altitude at which the bounds should be calculated.\n * @returns {Array} bounds - [[lon, lat], [lon, lat]]\n */\n getBounds(options?: {z?: number}): number[][] {\n const corners = this.getBoundingRegion(options);\n\n const west = Math.min(...corners.map((p) => p[0]));\n const east = Math.max(...corners.map((p) => p[0]));\n const south = Math.min(...corners.map((p) => p[1]));\n const north = Math.max(...corners.map((p) => p[1]));\n return [\n [west, south],\n [east, north]\n ];\n }\n\n /**\n * Returns the bounding box of the viewport.\n * @param [options]\n * @param [options.z] - The altitude at which the bounds should be calculated.\n * @returns {Array} an array of 4 points that define the visible region\n */\n getBoundingRegion(options: {z?: number} = {}): number[][] {\n return getBounds(this, options.z || 0);\n }\n\n // DEPRECATED\n\n /** @deprecated Legacy method name */\n getLocationAtPoint({lngLat, pos}: {lngLat: number[]; pos: number[]}): number[] {\n return this.getMapCenterByLngLatPosition({lngLat, pos});\n }\n}\n"],"file":"web-mercator-viewport.js"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for fitBounds
|
|
3
|
+
* @param width - viewport width
|
|
4
|
+
* @param height - viewport height
|
|
5
|
+
* @param bounds - [[lon, lat], [lon, lat]]
|
|
6
|
+
* @param minExtent - The width/height of the bounded area will never be smaller than this
|
|
7
|
+
* @param padding - The amount of padding in pixels
|
|
8
|
+
* to add to the given bounds. Can also be an object with top, bottom, left and right
|
|
9
|
+
* properties defining the padding.
|
|
10
|
+
* @param options.offset= - The center of the given bounds relative to the map's center,
|
|
11
|
+
*/
|
|
12
|
+
export declare type FitBoundsOptions = {
|
|
13
|
+
width: number;
|
|
14
|
+
height: number;
|
|
15
|
+
bounds: [[number, number], [number, number]];
|
|
16
|
+
minExtent?: number;
|
|
17
|
+
maxZoom?: number;
|
|
18
|
+
padding?: number | Padding;
|
|
19
|
+
offset?: number[];
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* An object describing the padding to add to the bounds.
|
|
23
|
+
* @property top - Padding from top in pixels to add to the given bounds
|
|
24
|
+
* @property bottom - Padding from bottom in pixels to add to the given bounds
|
|
25
|
+
* @property left - Padding from left in pixels to add to the given bounds
|
|
26
|
+
* @property right - Padding from right in pixels to add to the given bounds
|
|
27
|
+
*/
|
|
28
|
+
export declare type Padding = {
|
|
29
|
+
top: number;
|
|
30
|
+
bottom: number;
|
|
31
|
+
left: number;
|
|
32
|
+
right: number;
|
|
33
|
+
};
|
|
34
|
+
export declare type Bounds = {
|
|
35
|
+
longitude: number;
|
|
36
|
+
latitude: number;
|
|
37
|
+
zoom: number;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Returns map settings {latitude, longitude, zoom}
|
|
41
|
+
* that will contain the provided corners within the provided width.
|
|
42
|
+
*
|
|
43
|
+
* > _Note: Only supports non-perspective mode._
|
|
44
|
+
*
|
|
45
|
+
* @param options fit bounds parameters
|
|
46
|
+
* @returns - latitude, longitude and zoom
|
|
47
|
+
*/
|
|
48
|
+
export default function fitBounds(options: FitBoundsOptions): Bounds;
|
|
49
|
+
//# sourceMappingURL=fit-bounds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fit-bounds.d.ts","sourceRoot":"","sources":["../src/fit-bounds.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;GAUG;AACH,oBAAY,gBAAgB,GAAG;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC7C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB,CAAC;AAEF;;;;;;GAMG;AACH,oBAAY,OAAO,GAAG;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,oBAAY,MAAM,GAAG;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,MAAM,CAyDnE"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import WebMercatorViewport from './web-mercator-viewport';
|
|
2
|
+
import assert from './assert';
|
|
3
|
+
import { log2 } from './math-utils';
|
|
4
|
+
/**
|
|
5
|
+
* Returns map settings {latitude, longitude, zoom}
|
|
6
|
+
* that will contain the provided corners within the provided width.
|
|
7
|
+
*
|
|
8
|
+
* > _Note: Only supports non-perspective mode._
|
|
9
|
+
*
|
|
10
|
+
* @param options fit bounds parameters
|
|
11
|
+
* @returns - latitude, longitude and zoom
|
|
12
|
+
*/
|
|
13
|
+
export default function fitBounds(options) {
|
|
14
|
+
const { width, height, bounds, minExtent = 0, // 0.01 would be about 1000 meters (degree is ~110KM)
|
|
15
|
+
maxZoom = 24, // ~x4,000,000 => About 10 meter extents
|
|
16
|
+
offset = [0, 0] } = options;
|
|
17
|
+
const [[west, south], [east, north]] = bounds;
|
|
18
|
+
const padding = getPaddingObject(options.padding);
|
|
19
|
+
const viewport = new WebMercatorViewport({
|
|
20
|
+
width,
|
|
21
|
+
height,
|
|
22
|
+
longitude: 0,
|
|
23
|
+
latitude: 0,
|
|
24
|
+
zoom: 0
|
|
25
|
+
});
|
|
26
|
+
const nw = viewport.project([west, north]);
|
|
27
|
+
const se = viewport.project([east, south]);
|
|
28
|
+
// width/height on the Web Mercator plane
|
|
29
|
+
const size = [
|
|
30
|
+
Math.max(Math.abs(se[0] - nw[0]), minExtent),
|
|
31
|
+
Math.max(Math.abs(se[1] - nw[1]), minExtent)
|
|
32
|
+
];
|
|
33
|
+
const targetSize = [
|
|
34
|
+
width - padding.left - padding.right - Math.abs(offset[0]) * 2,
|
|
35
|
+
height - padding.top - padding.bottom - Math.abs(offset[1]) * 2
|
|
36
|
+
];
|
|
37
|
+
assert(targetSize[0] > 0 && targetSize[1] > 0);
|
|
38
|
+
// scale = screen pixels per unit on the Web Mercator plane
|
|
39
|
+
const scaleX = targetSize[0] / size[0];
|
|
40
|
+
const scaleY = targetSize[1] / size[1];
|
|
41
|
+
// Find how much we need to shift the center
|
|
42
|
+
const offsetX = (padding.right - padding.left) / 2 / scaleX;
|
|
43
|
+
const offsetY = (padding.bottom - padding.top) / 2 / scaleY;
|
|
44
|
+
const center = [(se[0] + nw[0]) / 2 + offsetX, (se[1] + nw[1]) / 2 + offsetY];
|
|
45
|
+
const centerLngLat = viewport.unproject(center);
|
|
46
|
+
const zoom = Math.min(maxZoom, viewport.zoom + log2(Math.abs(Math.min(scaleX, scaleY))));
|
|
47
|
+
assert(Number.isFinite(zoom));
|
|
48
|
+
return {
|
|
49
|
+
longitude: centerLngLat[0],
|
|
50
|
+
latitude: centerLngLat[1],
|
|
51
|
+
zoom
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
// Helpers
|
|
55
|
+
function getPaddingObject(padding = 0) {
|
|
56
|
+
if (typeof padding === 'number') {
|
|
57
|
+
return {
|
|
58
|
+
top: padding,
|
|
59
|
+
bottom: padding,
|
|
60
|
+
left: padding,
|
|
61
|
+
right: padding
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
// Make sure all the required properties are set
|
|
65
|
+
assert(Number.isFinite(padding.top) &&
|
|
66
|
+
Number.isFinite(padding.bottom) &&
|
|
67
|
+
Number.isFinite(padding.left) &&
|
|
68
|
+
Number.isFinite(padding.right));
|
|
69
|
+
return padding;
|
|
70
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare type FlytoTransitionOptions = {
|
|
2
|
+
curve?: number;
|
|
3
|
+
speed?: number;
|
|
4
|
+
screenSpeed?: number;
|
|
5
|
+
maxDuration?: number;
|
|
6
|
+
};
|
|
7
|
+
export declare type ViewportProps = {
|
|
8
|
+
longitude: number;
|
|
9
|
+
latitude: number;
|
|
10
|
+
zoom: number;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* mapbox-gl-js flyTo : https://www.mapbox.com/mapbox-gl-js/api/#map#flyto.
|
|
14
|
+
* It implements “Smooth and efficient zooming and panning.” algorithm by
|
|
15
|
+
* "Jarke J. van Wijk and Wim A.A. Nuij"
|
|
16
|
+
*/
|
|
17
|
+
export default function flyToViewport(startProps: ViewportProps, endProps: ViewportProps, t: number, options?: FlytoTransitionOptions): ViewportProps;
|
|
18
|
+
export declare function getFlyToDuration(startProps: ViewportProps, endProps: ViewportProps, options?: FlytoTransitionOptions): number;
|
|
19
|
+
//# sourceMappingURL=fly-to-viewport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fly-to-viewport.d.ts","sourceRoot":"","sources":["../src/fly-to-viewport.ts"],"names":[],"mappings":"AAYA,oBAAY,sBAAsB,GAAG;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,oBAAY,aAAa,GAAG;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,aAAa,CACnC,UAAU,EAAE,aAAa,EACzB,QAAQ,EAAE,aAAa,EACvB,CAAC,EAAE,MAAM,EACT,OAAO,CAAC,EAAE,sBAAsB,GAC/B,aAAa,CAsCf;AAGD,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,aAAa,EACzB,QAAQ,EAAE,aAAa,EACvB,OAAO,CAAC,EAAE,sBAAsB,GAC/B,MAAM,CAaR"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { lerp } from './math-utils';
|
|
2
|
+
import { scaleToZoom, zoomToScale, lngLatToWorld, worldToLngLat } from './web-mercator-utils';
|
|
3
|
+
import * as vec2 from 'gl-matrix/vec2';
|
|
4
|
+
const EPSILON = 0.01;
|
|
5
|
+
const VIEWPORT_TRANSITION_PROPS = ['longitude', 'latitude', 'zoom'];
|
|
6
|
+
const DEFAULT_OPTS = {
|
|
7
|
+
curve: 1.414,
|
|
8
|
+
speed: 1.2
|
|
9
|
+
// screenSpeed and maxDuration are used only if specified
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* mapbox-gl-js flyTo : https://www.mapbox.com/mapbox-gl-js/api/#map#flyto.
|
|
13
|
+
* It implements “Smooth and efficient zooming and panning.” algorithm by
|
|
14
|
+
* "Jarke J. van Wijk and Wim A.A. Nuij"
|
|
15
|
+
*/
|
|
16
|
+
export default function flyToViewport(startProps, endProps, t, options) {
|
|
17
|
+
// Equations from above paper are referred where needed.
|
|
18
|
+
const { startZoom, startCenterXY, uDelta, w0, u1, S, rho, rho2, r0 } = getFlyToTransitionParams(startProps, endProps, options);
|
|
19
|
+
// If change in center is too small, do linear interpolaiton.
|
|
20
|
+
if (u1 < EPSILON) {
|
|
21
|
+
const viewport = {};
|
|
22
|
+
for (const key of VIEWPORT_TRANSITION_PROPS) {
|
|
23
|
+
const startValue = startProps[key];
|
|
24
|
+
const endValue = endProps[key];
|
|
25
|
+
viewport[key] = lerp(startValue, endValue, t);
|
|
26
|
+
}
|
|
27
|
+
// @ts-expect-error
|
|
28
|
+
return viewport;
|
|
29
|
+
}
|
|
30
|
+
const s = t * S;
|
|
31
|
+
const w = Math.cosh(r0) / Math.cosh(r0 + rho * s);
|
|
32
|
+
const u = (w0 * ((Math.cosh(r0) * Math.tanh(r0 + rho * s) - Math.sinh(r0)) / rho2)) / u1;
|
|
33
|
+
const scaleIncrement = 1 / w; // Using w method for scaling.
|
|
34
|
+
const newZoom = startZoom + scaleToZoom(scaleIncrement);
|
|
35
|
+
const newCenterWorld = vec2.scale([], uDelta, u);
|
|
36
|
+
vec2.add(newCenterWorld, newCenterWorld, startCenterXY);
|
|
37
|
+
const newCenter = worldToLngLat(newCenterWorld);
|
|
38
|
+
return {
|
|
39
|
+
longitude: newCenter[0],
|
|
40
|
+
latitude: newCenter[1],
|
|
41
|
+
zoom: newZoom
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
// returns transition duration in milliseconds
|
|
45
|
+
export function getFlyToDuration(startProps, endProps, options) {
|
|
46
|
+
const opts = { ...DEFAULT_OPTS, ...options };
|
|
47
|
+
const { screenSpeed, speed, maxDuration } = opts;
|
|
48
|
+
const { S, rho } = getFlyToTransitionParams(startProps, endProps, opts);
|
|
49
|
+
const length = 1000 * S;
|
|
50
|
+
let duration;
|
|
51
|
+
if (Number.isFinite(screenSpeed)) {
|
|
52
|
+
duration = length / (screenSpeed / rho);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
duration = length / speed;
|
|
56
|
+
}
|
|
57
|
+
return Number.isFinite(maxDuration) && duration > maxDuration ? 0 : duration;
|
|
58
|
+
}
|
|
59
|
+
// Private Methods
|
|
60
|
+
// Calculate all parameters that are static for given startProps and endProps
|
|
61
|
+
function getFlyToTransitionParams(startProps, endProps, opts) {
|
|
62
|
+
opts = Object.assign({}, DEFAULT_OPTS, opts);
|
|
63
|
+
const rho = opts.curve;
|
|
64
|
+
const startZoom = startProps.zoom;
|
|
65
|
+
const startCenter = [startProps.longitude, startProps.latitude];
|
|
66
|
+
const startScale = zoomToScale(startZoom);
|
|
67
|
+
const endZoom = endProps.zoom;
|
|
68
|
+
const endCenter = [endProps.longitude, endProps.latitude];
|
|
69
|
+
const scale = zoomToScale(endZoom - startZoom);
|
|
70
|
+
const startCenterXY = lngLatToWorld(startCenter);
|
|
71
|
+
const endCenterXY = lngLatToWorld(endCenter);
|
|
72
|
+
const uDelta = vec2.sub([], endCenterXY, startCenterXY);
|
|
73
|
+
const w0 = Math.max(startProps.width, startProps.height);
|
|
74
|
+
const w1 = w0 / scale;
|
|
75
|
+
const u1 = vec2.length(uDelta) * startScale;
|
|
76
|
+
// u0 is treated as '0' in Eq (9).
|
|
77
|
+
// If u1 is too small, will generate invalid number
|
|
78
|
+
const _u1 = Math.max(u1, EPSILON);
|
|
79
|
+
// Implement Equation (9) from above algorithm.
|
|
80
|
+
const rho2 = rho * rho;
|
|
81
|
+
const b0 = (w1 * w1 - w0 * w0 + rho2 * rho2 * _u1 * _u1) / (2 * w0 * rho2 * _u1);
|
|
82
|
+
const b1 = (w1 * w1 - w0 * w0 - rho2 * rho2 * _u1 * _u1) / (2 * w1 * rho2 * _u1);
|
|
83
|
+
const r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0);
|
|
84
|
+
const r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
|
|
85
|
+
const S = (r1 - r0) / rho;
|
|
86
|
+
return { startZoom, startCenterXY, uDelta, w0, u1, S, rho, rho2, r0, r1 };
|
|
87
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-bounds.d.ts","sourceRoot":"","sources":["../src/get-bounds.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,mBAAmB,MAAM,yBAAyB,CAAC;AAS/D,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,QAAQ,EAAE,mBAAmB,EAAE,CAAC,GAAE,MAAU,GAAG,MAAM,EAAE,EAAE,CAyB1F"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { worldToLngLat } from './web-mercator-utils';
|
|
2
|
+
import * as vec2 from 'gl-matrix/vec2';
|
|
3
|
+
import { transformVector } from './math-utils';
|
|
4
|
+
const DEGREES_TO_RADIANS = Math.PI / 180;
|
|
5
|
+
/*
|
|
6
|
+
* Returns the quad at the intersection of the frustum and the given z plane
|
|
7
|
+
* @param {WebMercatorViewport} viewport
|
|
8
|
+
* @param {Number} z - elevation in meters
|
|
9
|
+
*/
|
|
10
|
+
export default function getBounds(viewport, z = 0) {
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
12
|
+
const { width, height, unproject } = viewport;
|
|
13
|
+
const unprojectOps = { targetZ: z };
|
|
14
|
+
const bottomLeft = unproject([0, height], unprojectOps);
|
|
15
|
+
const bottomRight = unproject([width, height], unprojectOps);
|
|
16
|
+
let topLeft;
|
|
17
|
+
let topRight;
|
|
18
|
+
const halfFov = viewport.fovy
|
|
19
|
+
? 0.5 * viewport.fovy * DEGREES_TO_RADIANS
|
|
20
|
+
: Math.atan(0.5 / viewport.altitude);
|
|
21
|
+
const angleToGround = (90 - viewport.pitch) * DEGREES_TO_RADIANS;
|
|
22
|
+
// The top plane is parallel to the ground if halfFov == angleToGround
|
|
23
|
+
if (halfFov > angleToGround - 0.01) {
|
|
24
|
+
// intersect with the far plane
|
|
25
|
+
topLeft = unprojectOnFarPlane(viewport, 0, z);
|
|
26
|
+
topRight = unprojectOnFarPlane(viewport, width, z);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
// intersect with the top plane
|
|
30
|
+
topLeft = unproject([0, 0], unprojectOps);
|
|
31
|
+
topRight = unproject([width, 0], unprojectOps);
|
|
32
|
+
}
|
|
33
|
+
return [bottomLeft, bottomRight, topRight, topLeft];
|
|
34
|
+
}
|
|
35
|
+
/*
|
|
36
|
+
* Find a point on the far clipping plane of the viewport
|
|
37
|
+
* @param {WebMercatorViewport} viewport
|
|
38
|
+
* @param {Number} x - projected x in screen space
|
|
39
|
+
* @param {Number} targetZ - the elevation of the point in meters
|
|
40
|
+
*/
|
|
41
|
+
function unprojectOnFarPlane(viewport, x, targetZ) {
|
|
42
|
+
const { pixelUnprojectionMatrix } = viewport;
|
|
43
|
+
const coord0 = transformVector(pixelUnprojectionMatrix, [x, 0, 1, 1]);
|
|
44
|
+
const coord1 = transformVector(pixelUnprojectionMatrix, [x, viewport.height, 1, 1]);
|
|
45
|
+
const z = targetZ * viewport.distanceScales.unitsPerMeter[2];
|
|
46
|
+
const t = (z - coord0[2]) / (coord1[2] - coord0[2]);
|
|
47
|
+
const coord = vec2.lerp([], coord0, coord1, t);
|
|
48
|
+
const result = worldToLngLat(coord);
|
|
49
|
+
result[2] = targetZ;
|
|
50
|
+
return result;
|
|
51
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { default } from './web-mercator-viewport';
|
|
2
|
+
export { default as WebMercatorViewport } from './web-mercator-viewport';
|
|
3
|
+
export { default as getBounds } from './get-bounds';
|
|
4
|
+
export { default as fitBounds } from './fit-bounds';
|
|
5
|
+
export { default as normalizeViewportProps } from './normalize-viewport-props';
|
|
6
|
+
export { default as flyToViewport, getFlyToDuration } from './fly-to-viewport';
|
|
7
|
+
export { lngLatToWorld, worldToLngLat, worldToPixels, pixelsToWorld, zoomToScale, scaleToZoom, altitudeToFovy, fovyToAltitude, getMeterZoom, getDistanceScales, addMetersToLngLat, getViewMatrix, getProjectionMatrix, getProjectionParameters } from './web-mercator-utils';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAC,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAC,OAAO,IAAI,mBAAmB,EAAC,MAAM,yBAAyB,CAAC;AAEvE,OAAO,EAAC,OAAO,IAAI,SAAS,EAAC,MAAM,cAAc,CAAC;AAClD,OAAO,EAAC,OAAO,IAAI,SAAS,EAAC,MAAM,cAAc,CAAC;AAClD,OAAO,EAAC,OAAO,IAAI,sBAAsB,EAAC,MAAM,4BAA4B,CAAC;AAC7E,OAAO,EAAC,OAAO,IAAI,aAAa,EAAE,gBAAgB,EAAC,MAAM,mBAAmB,CAAC;AAE7E,OAAO,EACL,aAAa,EACb,aAAa,EACb,aAAa,EACb,aAAa,EACb,WAAW,EACX,WAAW,EACX,cAAc,EACd,cAAc,EACd,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EACb,mBAAmB,EACnB,uBAAuB,EACxB,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Classic web-mercator-project
|
|
2
|
+
export { default } from './web-mercator-viewport';
|
|
3
|
+
export { default as WebMercatorViewport } from './web-mercator-viewport';
|
|
4
|
+
export { default as getBounds } from './get-bounds';
|
|
5
|
+
export { default as fitBounds } from './fit-bounds';
|
|
6
|
+
export { default as normalizeViewportProps } from './normalize-viewport-props';
|
|
7
|
+
export { default as flyToViewport, getFlyToDuration } from './fly-to-viewport';
|
|
8
|
+
export { lngLatToWorld, worldToLngLat, worldToPixels, pixelsToWorld, zoomToScale, scaleToZoom, altitudeToFovy, fovyToAltitude, getMeterZoom, getDistanceScales, addMetersToLngLat, getViewMatrix, getProjectionMatrix, getProjectionParameters } from './web-mercator-utils';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function createMat4(): number[];
|
|
2
|
+
export declare function transformVector(matrix: any, vector: any): any;
|
|
3
|
+
export declare function mod(value: number, divisor: number): number;
|
|
4
|
+
export declare function lerp(start: number, end: number, step: number): number;
|
|
5
|
+
export declare const log2: (x: number) => number;
|
|
6
|
+
//# sourceMappingURL=math-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"math-utils.d.ts","sourceRoot":"","sources":["../src/math-utils.ts"],"names":[],"mappings":"AAGA,wBAAgB,UAAU,IAAI,MAAM,EAAE,CAErC;AAGD,wBAAgB,eAAe,CAAC,MAAM,KAAA,EAAE,MAAM,KAAA,OAI7C;AAED,wBAAgB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAG1D;AAED,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAErE;AAMD,eAAO,MAAM,IAAI,uBAAsB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { transformMat4, scale } from 'gl-matrix/vec4';
|
|
2
|
+
// Helper, avoids low-precision 32 bit matrices from gl-matrix mat4.create()
|
|
3
|
+
export function createMat4() {
|
|
4
|
+
return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
5
|
+
}
|
|
6
|
+
// Transforms a vec4 with a projection matrix
|
|
7
|
+
export function transformVector(matrix, vector) {
|
|
8
|
+
const result = transformMat4([], vector, matrix);
|
|
9
|
+
scale(result, result, 1 / result[3]);
|
|
10
|
+
return result;
|
|
11
|
+
}
|
|
12
|
+
export function mod(value, divisor) {
|
|
13
|
+
const modulus = value % divisor;
|
|
14
|
+
return modulus < 0 ? divisor + modulus : modulus;
|
|
15
|
+
}
|
|
16
|
+
export function lerp(start, end, step) {
|
|
17
|
+
return step * end + (1 - step) * start;
|
|
18
|
+
}
|
|
19
|
+
function ieLog2(x) {
|
|
20
|
+
return Math.log(x) * Math.LOG2E;
|
|
21
|
+
}
|
|
22
|
+
// Handle missing log2 in IE 11
|
|
23
|
+
export const log2 = Math.log2 || ieLog2;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Description of viewport */
|
|
2
|
+
declare type ViewportProps = {
|
|
3
|
+
width: number;
|
|
4
|
+
height: number;
|
|
5
|
+
longitude: number;
|
|
6
|
+
latitude: number;
|
|
7
|
+
zoom: number;
|
|
8
|
+
pitch?: number;
|
|
9
|
+
bearing?: number;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Apply mathematical constraints to viewport props
|
|
13
|
+
* @param props
|
|
14
|
+
*/
|
|
15
|
+
export default function normalizeViewportProps(props: ViewportProps): ViewportProps;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=normalize-viewport-props.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize-viewport-props.d.ts","sourceRoot":"","sources":["../src/normalize-viewport-props.ts"],"names":[],"mappings":"AAMA,8BAA8B;AAC9B,aAAK,aAAa,GAAG;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;GAGG;AAEH,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAAC,KAAK,EAAE,aAAa,GAAG,aAAa,CAgClF"}
|