@math.gl/web-mercator 4.0.0-beta.1 → 4.0.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 +0 -1
- package/dist/assert.js +6 -4
- package/dist/fit-bounds.d.ts +3 -4
- package/dist/fit-bounds.js +56 -41
- package/dist/fly-to-viewport.d.ts +2 -3
- package/dist/fly-to-viewport.js +74 -97
- package/dist/get-bounds.d.ts +1 -2
- package/dist/get-bounds.js +44 -37
- package/dist/index.cjs +19 -57
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +9 -10
- package/dist/index.js +2 -1
- package/dist/math-utils.d.ts +0 -1
- package/dist/math-utils.js +12 -12
- package/dist/normalize-viewport-props.d.ts +1 -2
- package/dist/normalize-viewport-props.js +35 -49
- package/dist/web-mercator-utils.d.ts +2 -3
- package/dist/web-mercator-utils.js +273 -154
- package/dist/web-mercator-viewport.d.ts +3 -4
- package/dist/web-mercator-viewport.js +265 -256
- package/package.json +4 -7
- package/dist/assert.d.ts.map +0 -1
- package/dist/assert.js.map +0 -1
- package/dist/fit-bounds.d.ts.map +0 -1
- package/dist/fit-bounds.js.map +0 -1
- package/dist/fly-to-viewport.d.ts.map +0 -1
- package/dist/fly-to-viewport.js.map +0 -1
- package/dist/get-bounds.d.ts.map +0 -1
- package/dist/get-bounds.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/math-utils.d.ts.map +0 -1
- package/dist/math-utils.js.map +0 -1
- package/dist/normalize-viewport-props.d.ts.map +0 -1
- package/dist/normalize-viewport-props.js.map +0 -1
- package/dist/web-mercator-utils.d.ts.map +0 -1
- package/dist/web-mercator-utils.js.map +0 -1
- package/dist/web-mercator-viewport.d.ts.map +0 -1
- package/dist/web-mercator-viewport.js.map +0 -1
|
@@ -1,266 +1,275 @@
|
|
|
1
|
-
|
|
1
|
+
// View and Projection Matrix calculations for mapbox-js style map view properties
|
|
2
2
|
import { createMat4 } from "./math-utils.js";
|
|
3
3
|
import { zoomToScale, pixelsToWorld, lngLatToWorld, worldToLngLat, worldToPixels, altitudeToFovy, fovyToAltitude, DEFAULT_ALTITUDE, getProjectionMatrix, getDistanceScales, getViewMatrix } from "./web-mercator-utils.js";
|
|
4
4
|
import { fitBounds } from "./fit-bounds.js";
|
|
5
5
|
import { getBounds } from "./get-bounds.js";
|
|
6
6
|
import { mat4, vec2, vec3 } from '@math.gl/core';
|
|
7
|
+
/**
|
|
8
|
+
* The WebMercatorViewport class creates
|
|
9
|
+
* - view/projection matrices
|
|
10
|
+
* - "uniform values" (for shaders) from mercator params
|
|
11
|
+
*
|
|
12
|
+
* Note: Instances are immutable in the sense that they only have accessors.
|
|
13
|
+
* A new viewport instance should be created if any parameters have changed.
|
|
14
|
+
*/
|
|
7
15
|
export class WebMercatorViewport {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
16
|
+
/**
|
|
17
|
+
* @classdesc
|
|
18
|
+
* Creates view/projection matrices from mercator params
|
|
19
|
+
* Note: The Viewport is immutable in the sense that it only has accessors.
|
|
20
|
+
* A new viewport instance should be created if any parameters have changed.
|
|
21
|
+
*/
|
|
22
|
+
// eslint-disable-next-line max-statements
|
|
23
|
+
constructor(props = { width: 1, height: 1 }) {
|
|
24
|
+
/** Two viewports are equal if width and height are identical, and if
|
|
25
|
+
* their view and projection matrices are (approximately) equal.
|
|
26
|
+
*/
|
|
27
|
+
this.equals = (viewport) => {
|
|
28
|
+
if (!(viewport instanceof WebMercatorViewport)) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
return (viewport.width === this.width &&
|
|
32
|
+
viewport.height === this.height &&
|
|
33
|
+
mat4.equals(viewport.projectionMatrix, this.projectionMatrix) &&
|
|
34
|
+
mat4.equals(viewport.viewMatrix, this.viewMatrix));
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Projects xyz (possibly latitude and longitude) to pixel coordinates in window
|
|
38
|
+
* using viewport projection parameters
|
|
39
|
+
* - [longitude, latitude] to [x, y]
|
|
40
|
+
* - [longitude, latitude, Z] => [x, y, z]
|
|
41
|
+
* Note: By default, returns top-left coordinates for canvas/SVG type render
|
|
42
|
+
*
|
|
43
|
+
* @param lngLatZ - [lng, lat] or [lng, lat, Z]
|
|
44
|
+
* @param options - options
|
|
45
|
+
* @param options.topLeft=true - Whether projected coords are top left
|
|
46
|
+
* @return - screen coordinates [x, y] or [x, y, z], z as pixel depth
|
|
47
|
+
*/
|
|
48
|
+
this.project = (lngLatZ, options = {}) => {
|
|
49
|
+
const { topLeft = true } = options;
|
|
50
|
+
const worldPosition = this.projectPosition(lngLatZ);
|
|
51
|
+
const coord = worldToPixels(worldPosition, this.pixelProjectionMatrix);
|
|
52
|
+
const [x, y] = coord;
|
|
53
|
+
const y2 = topLeft ? y : this.height - y;
|
|
54
|
+
return lngLatZ.length === 2 ? [x, y2] : [x, y2, coord[2]];
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Unproject pixel coordinates on screen onto world coordinates, possibly `[lon, lat]` on map.
|
|
58
|
+
*
|
|
59
|
+
* - [x, y] => [lng, lat]
|
|
60
|
+
* - [x, y, z] => [lng, lat, Z]
|
|
61
|
+
*
|
|
62
|
+
* @param xyz - screen coordinates, z as pixel depth
|
|
63
|
+
* @param options - options
|
|
64
|
+
* @param options.topLeft=true - Whether projected coords are top left
|
|
65
|
+
* @param options.targetZ=0 - If pixel depth is unknown, targetZ is used as
|
|
66
|
+
* the elevation plane to unproject onto
|
|
67
|
+
* @return - [lng, lat, Z] or [X, Y, Z]
|
|
68
|
+
*/
|
|
69
|
+
this.unproject = (xyz, options = {}) => {
|
|
70
|
+
const { topLeft = true, targetZ = undefined } = options;
|
|
71
|
+
const [x, y, z] = xyz;
|
|
72
|
+
const y2 = topLeft ? y : this.height - y;
|
|
73
|
+
const targetZWorld = targetZ && targetZ * this.distanceScales.unitsPerMeter[2];
|
|
74
|
+
const coord = pixelsToWorld([x, y2, z], this.pixelUnprojectionMatrix, targetZWorld);
|
|
75
|
+
const [X, Y, Z] = this.unprojectPosition(coord);
|
|
76
|
+
if (Number.isFinite(z)) {
|
|
77
|
+
return [X, Y, Z];
|
|
78
|
+
}
|
|
79
|
+
return Number.isFinite(targetZ) ? [X, Y, targetZ] : [X, Y];
|
|
80
|
+
};
|
|
81
|
+
// NON_LINEAR PROJECTION HOOKS
|
|
82
|
+
// Used for web meractor projection
|
|
83
|
+
this.projectPosition = (xyz) => {
|
|
84
|
+
const [X, Y] = lngLatToWorld(xyz);
|
|
85
|
+
const Z = (xyz[2] || 0) * this.distanceScales.unitsPerMeter[2];
|
|
86
|
+
return [X, Y, Z];
|
|
87
|
+
};
|
|
88
|
+
this.unprojectPosition = (xyz) => {
|
|
89
|
+
const [X, Y] = worldToLngLat(xyz);
|
|
90
|
+
const Z = (xyz[2] || 0) * this.distanceScales.metersPerUnit[2];
|
|
91
|
+
return [X, Y, Z];
|
|
92
|
+
};
|
|
93
|
+
let {
|
|
94
|
+
// Map state
|
|
95
|
+
width, height, altitude = null, fovy = null } = props;
|
|
96
|
+
const { latitude = 0, longitude = 0, zoom = 0, pitch = 0, bearing = 0, position = null, nearZMultiplier = 0.02, farZMultiplier = 1.01 } = props;
|
|
97
|
+
// Silently allow apps to send in 0,0 to facilitate isomorphic render etc
|
|
98
|
+
width = width || 1;
|
|
99
|
+
height = height || 1;
|
|
100
|
+
// `fovy` & `altitude` are independent parameters, one for the
|
|
101
|
+
// projection and the latter for the view matrix. In the past,
|
|
102
|
+
// the `fovy` was always derived from the `altitude`
|
|
103
|
+
if (fovy === null && altitude === null) {
|
|
104
|
+
altitude = DEFAULT_ALTITUDE;
|
|
105
|
+
fovy = altitudeToFovy(altitude);
|
|
106
|
+
}
|
|
107
|
+
else if (fovy === null) {
|
|
108
|
+
fovy = altitudeToFovy(altitude);
|
|
109
|
+
}
|
|
110
|
+
else if (altitude === null) {
|
|
111
|
+
altitude = fovyToAltitude(fovy);
|
|
112
|
+
}
|
|
113
|
+
const scale = zoomToScale(zoom);
|
|
114
|
+
// Altitude - prevent division by 0
|
|
115
|
+
// TODO - just throw an Error instead?
|
|
116
|
+
altitude = Math.max(0.75, altitude);
|
|
117
|
+
const distanceScales = getDistanceScales({ longitude, latitude });
|
|
118
|
+
const center = lngLatToWorld([longitude, latitude]);
|
|
119
|
+
center.push(0);
|
|
120
|
+
if (position) {
|
|
121
|
+
vec3.add(center, center, vec3.mul([], position, distanceScales.unitsPerMeter));
|
|
122
|
+
}
|
|
123
|
+
this.projectionMatrix = getProjectionMatrix({
|
|
124
|
+
width,
|
|
125
|
+
height,
|
|
126
|
+
scale,
|
|
127
|
+
center,
|
|
128
|
+
pitch,
|
|
129
|
+
fovy,
|
|
130
|
+
nearZMultiplier,
|
|
131
|
+
farZMultiplier
|
|
132
|
+
});
|
|
133
|
+
this.viewMatrix = getViewMatrix({
|
|
134
|
+
height,
|
|
135
|
+
scale,
|
|
136
|
+
center,
|
|
137
|
+
pitch,
|
|
138
|
+
bearing,
|
|
139
|
+
altitude
|
|
140
|
+
});
|
|
141
|
+
// Save parameters
|
|
142
|
+
this.width = width;
|
|
143
|
+
this.height = height;
|
|
144
|
+
this.scale = scale;
|
|
145
|
+
this.latitude = latitude;
|
|
146
|
+
this.longitude = longitude;
|
|
147
|
+
this.zoom = zoom;
|
|
148
|
+
this.pitch = pitch;
|
|
149
|
+
this.bearing = bearing;
|
|
150
|
+
this.altitude = altitude;
|
|
151
|
+
this.fovy = fovy;
|
|
152
|
+
this.center = center;
|
|
153
|
+
this.meterOffset = position || [0, 0, 0];
|
|
154
|
+
this.distanceScales = distanceScales;
|
|
155
|
+
this._initMatrices();
|
|
156
|
+
Object.freeze(this);
|
|
123
157
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
158
|
+
_initMatrices() {
|
|
159
|
+
const { width, height, projectionMatrix, viewMatrix } = this;
|
|
160
|
+
// Note: As usual, matrix operations should be applied in "reverse" order
|
|
161
|
+
// since vectors will be multiplied in from the right during transformation
|
|
162
|
+
const vpm = createMat4();
|
|
163
|
+
mat4.multiply(vpm, vpm, projectionMatrix);
|
|
164
|
+
mat4.multiply(vpm, vpm, viewMatrix);
|
|
165
|
+
this.viewProjectionMatrix = vpm;
|
|
166
|
+
// Calculate matrices and scales needed for projection
|
|
167
|
+
/**
|
|
168
|
+
* Builds matrices that converts preprojected lngLats to screen pixels
|
|
169
|
+
* and vice versa.
|
|
170
|
+
* Note: Currently returns bottom-left coordinates!
|
|
171
|
+
* Note: Starts with the GL projection matrix and adds steps to the
|
|
172
|
+
* scale and translate that matrix onto the window.
|
|
173
|
+
* Note: WebGL controls clip space to screen projection with gl.viewport
|
|
174
|
+
* and does not need this step.
|
|
175
|
+
*/
|
|
176
|
+
const m = createMat4();
|
|
177
|
+
// matrix for conversion from location to screen coordinates
|
|
178
|
+
mat4.scale(m, m, [width / 2, -height / 2, 1]);
|
|
179
|
+
mat4.translate(m, m, [1, -1, 0]);
|
|
180
|
+
mat4.multiply(m, m, vpm);
|
|
181
|
+
const mInverse = mat4.invert(createMat4(), m);
|
|
182
|
+
if (!mInverse) {
|
|
183
|
+
throw new Error('Pixel project matrix not invertible');
|
|
184
|
+
}
|
|
185
|
+
this.pixelProjectionMatrix = m;
|
|
186
|
+
this.pixelUnprojectionMatrix = mInverse;
|
|
136
187
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
188
|
+
/**
|
|
189
|
+
* Project [lng,lat] on sphere onto [x,y] on 512*512 Mercator Zoom 0 tile.
|
|
190
|
+
* Performs the nonlinear part of the web mercator projection.
|
|
191
|
+
* Remaining projection is done with 4x4 matrices which also handles
|
|
192
|
+
* perspective.
|
|
193
|
+
*
|
|
194
|
+
* @param lngLat - [lng, lat] coordinates
|
|
195
|
+
* Specifies a point on the sphere to project onto the map.
|
|
196
|
+
* @return [x,y] coordinates.
|
|
197
|
+
*/
|
|
198
|
+
projectFlat(lngLat) {
|
|
199
|
+
return lngLatToWorld(lngLat);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Unproject world point [x,y] on map onto {lat, lon} on sphere
|
|
203
|
+
*
|
|
204
|
+
* @param xy - array with [x,y] members
|
|
205
|
+
* representing point on projected map plane
|
|
206
|
+
* @return - array with [lat,lon] of point on sphere.
|
|
207
|
+
* Has toArray method if you need a GeoJSON Array.
|
|
208
|
+
* Per cartographic tradition, lat and lon are specified as degrees.
|
|
209
|
+
*/
|
|
210
|
+
unprojectFlat(xy) {
|
|
211
|
+
return worldToLngLat(xy);
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Get the map center that place a given [lng, lat] coordinate at screen point [x, y]
|
|
215
|
+
* @param opt
|
|
216
|
+
* @param opt.lngLat - [lng,lat] coordinates
|
|
217
|
+
* Specifies a point on the sphere.
|
|
218
|
+
* @param opt.pos - [x,y] coordinates
|
|
219
|
+
* Specifies a point on the screen.
|
|
220
|
+
* @return [lng,lat] new map center.
|
|
221
|
+
*/
|
|
222
|
+
getMapCenterByLngLatPosition({ lngLat, pos }) {
|
|
223
|
+
const fromLocation = pixelsToWorld(pos, this.pixelUnprojectionMatrix);
|
|
224
|
+
const toLocation = lngLatToWorld(lngLat);
|
|
225
|
+
const translate = vec2.add([], toLocation, vec2.negate([], fromLocation));
|
|
226
|
+
const newCenter = vec2.add([], this.center, translate);
|
|
227
|
+
return worldToLngLat(newCenter);
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Returns a new viewport that fit around the given rectangle.
|
|
231
|
+
* Only supports non-perspective mode.
|
|
232
|
+
* @param bounds - [[lon, lat], [lon, lat]]
|
|
233
|
+
* @param [options]
|
|
234
|
+
* @param [options.padding] - The amount of padding in pixels to add to the given bounds.
|
|
235
|
+
* @param [options.offset] - The center of the given bounds relative to the map's center,
|
|
236
|
+
* [x, y] measured in pixels.
|
|
237
|
+
* @returns {WebMercatorViewport}
|
|
238
|
+
*/
|
|
239
|
+
fitBounds(bounds, options = {}) {
|
|
240
|
+
const { width, height } = this;
|
|
241
|
+
const { longitude, latitude, zoom } = fitBounds(Object.assign({ width, height, bounds }, options));
|
|
242
|
+
return new WebMercatorViewport({ width, height, longitude, latitude, zoom });
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Returns the bounding box of the viewport.
|
|
246
|
+
* @param [options]
|
|
247
|
+
* @param [options.z] - The altitude at which the bounds should be calculated.
|
|
248
|
+
* @returns {Array} bounds - [[lon, lat], [lon, lat]]
|
|
249
|
+
*/
|
|
250
|
+
getBounds(options) {
|
|
251
|
+
const corners = this.getBoundingRegion(options);
|
|
252
|
+
const west = Math.min(...corners.map((p) => p[0]));
|
|
253
|
+
const east = Math.max(...corners.map((p) => p[0]));
|
|
254
|
+
const south = Math.min(...corners.map((p) => p[1]));
|
|
255
|
+
const north = Math.max(...corners.map((p) => p[1]));
|
|
256
|
+
return [
|
|
257
|
+
[west, south],
|
|
258
|
+
[east, north]
|
|
259
|
+
];
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Returns the bounding box of the viewport.
|
|
263
|
+
* @param [options]
|
|
264
|
+
* @param [options.z] - The altitude at which the bounds should be calculated.
|
|
265
|
+
* @returns {Array} an array of 4 points that define the visible region
|
|
266
|
+
*/
|
|
267
|
+
getBoundingRegion(options = {}) {
|
|
268
|
+
return getBounds(this, options.z || 0);
|
|
269
|
+
}
|
|
270
|
+
// DEPRECATED
|
|
271
|
+
/** @deprecated Legacy method name */
|
|
272
|
+
getLocationAtPoint({ lngLat, pos }) {
|
|
273
|
+
return this.getMapCenterByLngLatPosition({ lngLat, pos });
|
|
194
274
|
}
|
|
195
|
-
|
|
196
|
-
this.pixelProjectionMatrix = m;
|
|
197
|
-
this.pixelUnprojectionMatrix = mInverse;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
projectFlat(lngLat) {
|
|
201
|
-
return lngLatToWorld(lngLat);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
unprojectFlat(xy) {
|
|
205
|
-
return worldToLngLat(xy);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
getMapCenterByLngLatPosition({
|
|
209
|
-
lngLat,
|
|
210
|
-
pos
|
|
211
|
-
}) {
|
|
212
|
-
const fromLocation = pixelsToWorld(pos, this.pixelUnprojectionMatrix);
|
|
213
|
-
const toLocation = lngLatToWorld(lngLat);
|
|
214
|
-
const translate = vec2.add([], toLocation, vec2.negate([], fromLocation));
|
|
215
|
-
const newCenter = vec2.add([], this.center, translate);
|
|
216
|
-
return worldToLngLat(newCenter);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
fitBounds(bounds, options = {}) {
|
|
220
|
-
const {
|
|
221
|
-
width,
|
|
222
|
-
height
|
|
223
|
-
} = this;
|
|
224
|
-
const {
|
|
225
|
-
longitude,
|
|
226
|
-
latitude,
|
|
227
|
-
zoom
|
|
228
|
-
} = fitBounds(Object.assign({
|
|
229
|
-
width,
|
|
230
|
-
height,
|
|
231
|
-
bounds
|
|
232
|
-
}, options));
|
|
233
|
-
return new WebMercatorViewport({
|
|
234
|
-
width,
|
|
235
|
-
height,
|
|
236
|
-
longitude,
|
|
237
|
-
latitude,
|
|
238
|
-
zoom
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
getBounds(options) {
|
|
243
|
-
const corners = this.getBoundingRegion(options);
|
|
244
|
-
const west = Math.min(...corners.map(p => p[0]));
|
|
245
|
-
const east = Math.max(...corners.map(p => p[0]));
|
|
246
|
-
const south = Math.min(...corners.map(p => p[1]));
|
|
247
|
-
const north = Math.max(...corners.map(p => p[1]));
|
|
248
|
-
return [[west, south], [east, north]];
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
getBoundingRegion(options = {}) {
|
|
252
|
-
return getBounds(this, options.z || 0);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
getLocationAtPoint({
|
|
256
|
-
lngLat,
|
|
257
|
-
pos
|
|
258
|
-
}) {
|
|
259
|
-
return this.getMapCenterByLngLatPosition({
|
|
260
|
-
lngLat,
|
|
261
|
-
pos
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
|
|
265
275
|
}
|
|
266
|
-
//# sourceMappingURL=web-mercator-viewport.js.map
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"author": "Uber Technologies, Inc.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"version": "4.0.
|
|
7
|
+
"version": "4.0.1",
|
|
8
8
|
"keywords": [
|
|
9
9
|
"webgl",
|
|
10
10
|
"javascript",
|
|
@@ -24,20 +24,17 @@
|
|
|
24
24
|
"module": "dist/index.js",
|
|
25
25
|
"exports": {
|
|
26
26
|
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
27
28
|
"import": "./dist/index.js",
|
|
28
|
-
"require": "./dist/index.cjs"
|
|
29
|
-
"types": "./dist/index.d.ts"
|
|
29
|
+
"require": "./dist/index.cjs"
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
32
|
"files": [
|
|
33
33
|
"dist",
|
|
34
34
|
"src"
|
|
35
35
|
],
|
|
36
|
-
"dependencies": {
|
|
37
|
-
"@babel/runtime": "^7.12.0"
|
|
38
|
-
},
|
|
39
36
|
"devDependencies": {
|
|
40
37
|
"mock-browser": "^0.92.14"
|
|
41
38
|
},
|
|
42
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "33f369ba3a259f79acc3fa8181190c9da8841648"
|
|
43
40
|
}
|
package/dist/assert.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../src/assert.ts"],"names":[],"mappings":"AAGA,wBAAgB,MAAM,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAIjE"}
|
package/dist/assert.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/assert.ts"],"names":["assert","condition","message","Error"],"mappings":"AAGA,OAAO,SAASA,MAAT,CAAgBC,SAAhB,EAAoCC,OAApC,EAA4D;AACjE,MAAI,CAACD,SAAL,EAAgB;AACd,UAAM,IAAIE,KAAJ,CAAUD,OAAO,IAAI,0CAArB,CAAN;AACD;AACF","sourcesContent":["// Replacement for the external assert method to reduce bundle size\n// Note: We don't use the second \"message\" argument in calling code,\n// so no need to support it here\nexport function assert(condition: unknown, message?: string): void {\n if (!condition) {\n throw new Error(message || '@math.gl/web-mercator: assertion failed.');\n }\n}\n"],"file":"assert.js"}
|
package/dist/fit-bounds.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fit-bounds.d.ts","sourceRoot":"","sources":["../src/fit-bounds.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;GAUG;AACH,oBAAY,gBAAgB,GAAG;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC7C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB,CAAC;AAEF;;;;;;GAMG;AACH,oBAAY,OAAO,GAAG;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,aAAK,aAAa,GAAG;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,aAAa,CAiDlE"}
|
package/dist/fit-bounds.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/fit-bounds.ts"],"names":["assert","log2","clamp","MAX_LATITUDE","lngLatToWorld","worldToLngLat","fitBounds","options","width","height","bounds","minExtent","maxZoom","offset","west","south","east","north","padding","getPaddingObject","nw","se","size","Math","max","abs","targetSize","left","right","top","bottom","scaleX","scaleY","offsetX","offsetY","center","centerLngLat","zoom","min","Number","isFinite","longitude","latitude"],"mappings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,CADlB;AAELM,IAAAA,QAAQ,EAAEN,YAAY,CAAC,CAAD,CAFjB;AAGLC,IAAAA;AAHK,GAAP;AAKD;;AAGD,SAASlB,gBAAT,CAA0BD,OAAyB,GAAG,CAAtD,EAAkE;AAChE,MAAI,OAAOA,OAAP,KAAmB,QAAvB,EAAiC;AAC/B,WAAO;AACLW,MAAAA,GAAG,EAAEX,OADA;AAELY,MAAAA,MAAM,EAAEZ,OAFH;AAGLS,MAAAA,IAAI,EAAET,OAHD;AAILU,MAAAA,KAAK,EAAEV;AAJF,KAAP;AAMD;;AAGDlB,EAAAA,MAAM,CACJuC,MAAM,CAACC,QAAP,CAAgBtB,OAAO,CAACW,GAAxB,KACEU,MAAM,CAACC,QAAP,CAAgBtB,OAAO,CAACY,MAAxB,CADF,IAEES,MAAM,CAACC,QAAP,CAAgBtB,OAAO,CAACS,IAAxB,CAFF,IAGEY,MAAM,CAACC,QAAP,CAAgBtB,OAAO,CAACU,KAAxB,CAJE,CAAN;AAOA,SAAOV,OAAP;AACD","sourcesContent":["import {assert} from './assert';\nimport {log2, clamp} from './math-utils';\nimport {MAX_LATITUDE, lngLatToWorld, worldToLngLat} from './web-mercator-utils';\n\n/**\n * Options for fitBounds\n * @param width - viewport width\n * @param height - viewport height\n * @param bounds - [[lon, lat], [lon, lat]]\n * @param minExtent - The width/height of the bounded area will never be smaller than this\n * @param padding - The amount of padding in pixels\n * to add to the given bounds. Can also be an object with top, bottom, left and right\n * properties defining the padding.\n * @param options.offset= - The center of the given bounds relative to the map's center,\n */\nexport type FitBoundsOptions = {\n width: number;\n height: number;\n bounds: [[number, number], [number, number]];\n minExtent?: number; // 0.01 would be about 1000 meters (degree is ~110KM)\n maxZoom?: number; // ~x4,000,000 => About 10 meter extents\n // options\n padding?: number | Padding;\n offset?: number[];\n};\n\n/**\n * An object describing the padding to add to the bounds.\n * @property top - Padding from top in pixels to add to the given bounds\n * @property bottom - Padding from bottom in pixels to add to the given bounds\n * @property left - Padding from left in pixels to add to the given bounds\n * @property right - Padding from right in pixels to add to the given bounds\n */\nexport type Padding = {\n top: number;\n bottom: number;\n left: number;\n right: number;\n};\n\ntype ViewportProps = {\n longitude: number;\n latitude: number;\n zoom: number;\n};\n\n/**\n * Returns map settings {latitude, longitude, zoom}\n * that will contain the provided corners within the provided width.\n *\n * > _Note: Only supports non-perspective mode._\n *\n * @param options fit bounds parameters\n * @returns - latitude, longitude and zoom\n */\nexport function fitBounds(options: FitBoundsOptions): ViewportProps {\n const {\n width,\n height,\n bounds,\n minExtent = 0, // 0.01 would be about 1000 meters (degree is ~110KM)\n maxZoom = 24, // ~x4,000,000 => About 10 meter extents\n offset = [0, 0]\n } = options;\n\n const [[west, south], [east, north]] = bounds;\n const padding = getPaddingObject(options.padding);\n\n const nw = lngLatToWorld([west, clamp(north, -MAX_LATITUDE, MAX_LATITUDE)]);\n const se = lngLatToWorld([east, clamp(south, -MAX_LATITUDE, MAX_LATITUDE)]);\n\n // width/height on the Web Mercator plane\n const size = [\n Math.max(Math.abs(se[0] - nw[0]), minExtent),\n Math.max(Math.abs(se[1] - nw[1]), minExtent)\n ];\n\n const targetSize = [\n width - padding.left - padding.right - Math.abs(offset[0]) * 2,\n height - padding.top - padding.bottom - Math.abs(offset[1]) * 2\n ];\n\n assert(targetSize[0] > 0 && targetSize[1] > 0);\n\n // scale = screen pixels per unit on the Web Mercator plane\n const scaleX = targetSize[0] / size[0];\n const scaleY = targetSize[1] / size[1];\n\n // Find how much we need to shift the center\n const offsetX = (padding.right - padding.left) / 2 / scaleX;\n const offsetY = (padding.top - padding.bottom) / 2 / scaleY;\n\n const center = [(se[0] + nw[0]) / 2 + offsetX, (se[1] + nw[1]) / 2 + offsetY];\n\n const centerLngLat = worldToLngLat(center);\n const zoom = Math.min(maxZoom, log2(Math.abs(Math.min(scaleX, scaleY))));\n\n assert(Number.isFinite(zoom));\n\n return {\n longitude: centerLngLat[0],\n latitude: centerLngLat[1],\n zoom\n };\n}\n\n// Helpers\nfunction getPaddingObject(padding: number | Padding = 0): Padding {\n if (typeof padding === 'number') {\n return {\n top: padding,\n bottom: padding,\n left: padding,\n right: padding\n };\n }\n\n // Make sure all the required properties are set\n assert(\n Number.isFinite(padding.top) &&\n Number.isFinite(padding.bottom) &&\n Number.isFinite(padding.left) &&\n Number.isFinite(padding.right)\n );\n\n return padding;\n}\n"],"file":"fit-bounds.js"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fly-to-viewport.d.ts","sourceRoot":"","sources":["../src/fly-to-viewport.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,4BAA4B,CAAC;AAU9D,oBAAY,sBAAsB,GAAG;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,UAAU,EAAE,aAAa,EACzB,QAAQ,EAAE,aAAa,EACvB,CAAC,EAAE,MAAM,EACT,OAAO,CAAC,EAAE,sBAAsB,GAC/B;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACd,CAuCA;AAGD,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,aAAa,EACzB,QAAQ,EAAE,aAAa,EACvB,OAAO,CAAC,EAAE,sBAAsB,GAC/B,MAAM,CAaR"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/fly-to-viewport.ts"],"names":["lerp","scaleToZoom","zoomToScale","lngLatToWorld","worldToLngLat","vec2","EPSILON","VIEWPORT_TRANSITION_PROPS","DEFAULT_OPTS","curve","speed","flyToViewport","startProps","endProps","t","options","startZoom","startCenterXY","uDelta","w0","u1","S","rho","rho2","r0","getFlyToTransitionParams","viewport","key","startValue","endValue","s","w","Math","cosh","u","tanh","sinh","scaleIncrement","newZoom","newCenterWorld","scale","add","newCenter","longitude","latitude","zoom","getFlyToDuration","opts","screenSpeed","maxDuration","length","duration","Number","isFinite","Object","assign","startCenter","startScale","endZoom","endCenter","endCenterXY","sub","max","width","height","w1","_u1","b0","b1","log","sqrt","r1"],"mappings":"SAAQA,I;SACAC,W,EAAaC,W,EAAaC,a,EAAeC,a;AACjD,SAAQC,IAAR,QAAmB,eAAnB;AAIA,MAAMC,OAAO,GAAG,IAAhB;AACA,MAAMC,yBAAyB,GAAG,CAAC,WAAD,EAAc,UAAd,EAA0B,MAA1B,CAAlC;AACA,MAAMC,YAAY,GAAG;AACnBC,EAAAA,KAAK,EAAE,KADY;AAEnBC,EAAAA,KAAK,EAAE;AAFY,CAArB;AAkBA,OAAO,SAASC,aAAT,CACLC,UADK,EAELC,QAFK,EAGLC,CAHK,EAILC,OAJK,EASL;AAGA,QAAM;AAACC,IAAAA,SAAD;AAAYC,IAAAA,aAAZ;AAA2BC,IAAAA,MAA3B;AAAmCC,IAAAA,EAAnC;AAAuCC,IAAAA,EAAvC;AAA2CC,IAAAA,CAA3C;AAA8CC,IAAAA,GAA9C;AAAmDC,IAAAA,IAAnD;AAAyDC,IAAAA;AAAzD,MAA+DC,wBAAwB,CAC3Fb,UAD2F,EAE3FC,QAF2F,EAG3FE,OAH2F,CAA7F;;AAOA,MAAIK,EAAE,GAAGd,OAAT,EAAkB;AAChB,UAAMoB,QAAQ,GAAG,EAAjB;;AACA,SAAK,MAAMC,GAAX,IAAkBpB,yBAAlB,EAA6C;AAC3C,YAAMqB,UAAU,GAAGhB,UAAU,CAACe,GAAD,CAA7B;AACA,YAAME,QAAQ,GAAGhB,QAAQ,CAACc,GAAD,CAAzB;AAEAD,MAAAA,QAAQ,CAACC,GAAD,CAAR,GAAgB3B,IAAI,CAAC4B,UAAD,EAAaC,QAAb,EAAuBf,CAAvB,CAApB;AACD;;AAED,WAAOY,QAAP;AACD;;AAED,QAAM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AmDC,IAAAA,IAAnD;AAAyDC,IAAAA,EAAzD;AAA6D+C,IAAAA;AAA7D,GAAP;AACD","sourcesContent":["import {lerp} from './math-utils';\nimport {scaleToZoom, zoomToScale, lngLatToWorld, worldToLngLat} from './web-mercator-utils';\nimport {vec2} from '@math.gl/core';\n\nimport type {ViewportProps} from './normalize-viewport-props';\n\nconst EPSILON = 0.01;\nconst VIEWPORT_TRANSITION_PROPS = ['longitude', 'latitude', 'zoom'] as const;\nconst DEFAULT_OPTS = {\n curve: 1.414,\n speed: 1.2\n // screenSpeed and maxDuration are used only if specified\n};\n\nexport type FlytoTransitionOptions = {\n curve?: number;\n speed?: number;\n screenSpeed?: number;\n maxDuration?: number;\n};\n\n/**\n * mapbox-gl-js flyTo : https://www.mapbox.com/mapbox-gl-js/api/#map#flyto.\n * It implements “Smooth and efficient zooming and panning.” algorithm by\n * \"Jarke J. van Wijk and Wim A.A. Nuij\"\n */\nexport function flyToViewport(\n startProps: ViewportProps,\n endProps: ViewportProps,\n t: number,\n options?: FlytoTransitionOptions\n): {\n longitude: number;\n latitude: number;\n zoom: number;\n} {\n // Equations from above paper are referred where needed.\n\n const {startZoom, startCenterXY, uDelta, w0, u1, S, rho, rho2, r0} = getFlyToTransitionParams(\n startProps,\n endProps,\n options\n );\n\n // If change in center is too small, do linear interpolaiton.\n if (u1 < EPSILON) {\n const viewport = {};\n for (const key of VIEWPORT_TRANSITION_PROPS) {\n const startValue = startProps[key];\n const endValue = endProps[key];\n // @ts-ignore-error properties are populated dynamically\n viewport[key] = lerp(startValue, endValue, t);\n }\n // @ts-expect-error properties are populated dynamically\n return viewport;\n }\n\n const s = t * S;\n\n const w = Math.cosh(r0) / Math.cosh(r0 + rho * s);\n const u = (w0 * ((Math.cosh(r0) * Math.tanh(r0 + rho * s) - Math.sinh(r0)) / rho2)) / u1;\n\n const scaleIncrement = 1 / w; // Using w method for scaling.\n const newZoom = startZoom + scaleToZoom(scaleIncrement);\n\n const newCenterWorld = vec2.scale([], uDelta, u);\n vec2.add(newCenterWorld, newCenterWorld, startCenterXY);\n\n const newCenter = worldToLngLat(newCenterWorld);\n return {\n longitude: newCenter[0],\n latitude: newCenter[1],\n zoom: newZoom\n };\n}\n\n// returns transition duration in milliseconds\nexport function getFlyToDuration(\n startProps: ViewportProps,\n endProps: ViewportProps,\n options?: FlytoTransitionOptions\n): number {\n const opts = {...DEFAULT_OPTS, ...options};\n const {screenSpeed, speed, maxDuration} = opts;\n const {S, rho} = getFlyToTransitionParams(startProps, endProps, opts);\n const length = 1000 * S;\n let duration: number;\n if (Number.isFinite(screenSpeed)) {\n duration = length / (screenSpeed / rho);\n } else {\n duration = length / speed;\n }\n\n return Number.isFinite(maxDuration) && duration > maxDuration ? 0 : duration;\n}\n\n// Private Methods\n\n// Calculate all parameters that are static for given startProps and endProps\nfunction getFlyToTransitionParams(\n startProps: ViewportProps,\n endProps: ViewportProps,\n opts: FlytoTransitionOptions\n): {\n startZoom: number;\n startCenterXY: number[];\n uDelta: number[];\n w0: number;\n u1: number;\n S: number;\n rho: number;\n rho2: number;\n r0: number;\n r1: number;\n} {\n opts = Object.assign({}, DEFAULT_OPTS, opts);\n const rho = opts.curve;\n const startZoom = startProps.zoom;\n const startCenter = [startProps.longitude, startProps.latitude];\n const startScale = zoomToScale(startZoom);\n const endZoom = endProps.zoom;\n const endCenter = [endProps.longitude, endProps.latitude];\n const scale = zoomToScale(endZoom - startZoom);\n\n const startCenterXY = lngLatToWorld(startCenter);\n const endCenterXY = lngLatToWorld(endCenter);\n const uDelta = vec2.sub([] as number[], endCenterXY, startCenterXY);\n\n const w0 = Math.max(startProps.width, startProps.height);\n const w1 = w0 / scale;\n const u1 = vec2.length(uDelta) * startScale;\n // u0 is treated as '0' in Eq (9).\n\n // If u1 is too small, will generate invalid number\n const _u1 = Math.max(u1, EPSILON);\n\n // Implement Equation (9) from above algorithm.\n const rho2 = rho * rho;\n const b0 = (w1 * w1 - w0 * w0 + rho2 * rho2 * _u1 * _u1) / (2 * w0 * rho2 * _u1);\n const b1 = (w1 * w1 - w0 * w0 - rho2 * rho2 * _u1 * _u1) / (2 * w1 * rho2 * _u1);\n const r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0);\n const r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);\n const S = (r1 - r0) / rho;\n\n return {startZoom, startCenterXY, uDelta, w0, u1, S, rho, rho2, r0, r1};\n}\n"],"file":"fly-to-viewport.js"}
|
package/dist/get-bounds.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-bounds.d.ts","sourceRoot":"","sources":["../src/get-bounds.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,mBAAmB,EAAC,MAAM,yBAAyB,CAAC;AAWjE,wBAAgB,SAAS,CAAC,QAAQ,EAAE,mBAAmB,EAAE,CAAC,GAAE,MAAU,GAAG,MAAM,EAAE,EAAE,CAyBlF"}
|