@gisatcz/deckgl-geolib 2.6.0-dev.1 → 2.6.0-dev.2
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/cjs/index.js +147 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/index.min.js +2 -2
- package/dist/cjs/index.min.js.map +1 -1
- package/dist/esm/index.js +146 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +2 -2
- package/dist/esm/index.min.js.map +1 -1
- package/dist/esm/types/index.d.ts +2 -0
- package/dist/esm/types/utils/terrainPickingUtils.d.ts +61 -0
- package/package.json +12 -12
package/dist/cjs/index.js
CHANGED
|
@@ -8312,6 +8312,151 @@ class CogTerrainLayer extends core.CompositeLayer {
|
|
|
8312
8312
|
}
|
|
8313
8313
|
}
|
|
8314
8314
|
|
|
8315
|
+
/**
|
|
8316
|
+
* Terrain coordinate extraction utility for CogTerrainLayer
|
|
8317
|
+
* Enables precise lat/lon/elevation extraction from 3D terrain picks
|
|
8318
|
+
*/
|
|
8319
|
+
/**
|
|
8320
|
+
* Extracts precise geographic coordinates and elevation from a CogTerrainLayer pick result
|
|
8321
|
+
*
|
|
8322
|
+
* @param pickResult - DeckGL pickObject result from terrain-layer pick
|
|
8323
|
+
* @returns TerrainCoordinate with lon/lat/elevation, or null if extraction fails
|
|
8324
|
+
*
|
|
8325
|
+
* @requires deck.gl >=9.3.0 (for `pickable: '3d'` support)
|
|
8326
|
+
* @note Requires `pickable: '3d'` on CogTerrainLayer. With 3D picking enabled,
|
|
8327
|
+
* deck.gl's terrain layer provides info.coordinate as a 3-element array [lon, lat, elevation]
|
|
8328
|
+
* where elevation is read directly from the terrain mesh at the picked point.
|
|
8329
|
+
* This gives accurate 3D coordinates regardless of camera pitch or bearing.
|
|
8330
|
+
*
|
|
8331
|
+
* @example
|
|
8332
|
+
* ```ts
|
|
8333
|
+
* const cogLayer = new CogTerrainLayer({
|
|
8334
|
+
* // ...
|
|
8335
|
+
* pickable: '3d', // Requires deck.gl >=9.3.0
|
|
8336
|
+
* onClick: (info) => {
|
|
8337
|
+
* const coord = extractTerrainCoordinate(info);
|
|
8338
|
+
* if (coord) {
|
|
8339
|
+
* console.log(`Clicked at ${coord.latitude}, ${coord.longitude}, elevation: ${coord.elevation}m`);
|
|
8340
|
+
* }
|
|
8341
|
+
* }
|
|
8342
|
+
* });
|
|
8343
|
+
* ```
|
|
8344
|
+
*/
|
|
8345
|
+
function extractTerrainCoordinate(pickResult) {
|
|
8346
|
+
try {
|
|
8347
|
+
// With pickable: '3d', info.coordinate is a 3-element array [lon, lat, elevation]
|
|
8348
|
+
if (!pickResult?.coordinate || pickResult.coordinate.length < 3) {
|
|
8349
|
+
return null;
|
|
8350
|
+
}
|
|
8351
|
+
const [longitude, latitude, elevation] = pickResult.coordinate;
|
|
8352
|
+
if (longitude === undefined || latitude === undefined || elevation === undefined) {
|
|
8353
|
+
return null;
|
|
8354
|
+
}
|
|
8355
|
+
return {
|
|
8356
|
+
longitude,
|
|
8357
|
+
latitude,
|
|
8358
|
+
elevation,
|
|
8359
|
+
};
|
|
8360
|
+
}
|
|
8361
|
+
catch {
|
|
8362
|
+
// Silently return null on any error
|
|
8363
|
+
return null;
|
|
8364
|
+
}
|
|
8365
|
+
}
|
|
8366
|
+
/**
|
|
8367
|
+
* Samples terrain coordinates in a grid around a pick point for debugging
|
|
8368
|
+
* Useful for understanding terrain data layout and accuracy
|
|
8369
|
+
*
|
|
8370
|
+
* @param pickResult - DeckGL pickObject result from terrain-layer pick
|
|
8371
|
+
* @param gridSize - Odd number for grid dimensions (default: 3 for 3x3 grid).
|
|
8372
|
+
* gridSize=3 → 3×3 grid (offset±1), gridSize=5 → 5×5 grid (offset±2).
|
|
8373
|
+
* Uses WebMercator projection for accurate latitude mapping.
|
|
8374
|
+
* @returns Array of TerrainCoordinate samples, or empty array if extraction fails
|
|
8375
|
+
*
|
|
8376
|
+
* @example
|
|
8377
|
+
* ```ts
|
|
8378
|
+
* const samples = sampleTerrainTileCoordinates(info, 5); // 5x5 grid around click
|
|
8379
|
+
* samples.forEach(coord => {
|
|
8380
|
+
* console.log(`Sample: ${coord.latitude}, ${coord.longitude}, elev: ${coord.elevation}m`);
|
|
8381
|
+
* });
|
|
8382
|
+
* ```
|
|
8383
|
+
*/
|
|
8384
|
+
function sampleTerrainTileCoordinates(pickResult, gridSize = 3) {
|
|
8385
|
+
try {
|
|
8386
|
+
// Validate input has required structure
|
|
8387
|
+
if (!pickResult?.tile?.content) {
|
|
8388
|
+
return [];
|
|
8389
|
+
}
|
|
8390
|
+
const tileResult = pickResult.tile.content[0];
|
|
8391
|
+
if (!tileResult?.raw) {
|
|
8392
|
+
return [];
|
|
8393
|
+
}
|
|
8394
|
+
const { raw, width, height } = tileResult;
|
|
8395
|
+
const bbox = pickResult.tile.bbox;
|
|
8396
|
+
if (!bbox) {
|
|
8397
|
+
return [];
|
|
8398
|
+
}
|
|
8399
|
+
const west = bbox.west ?? bbox[0];
|
|
8400
|
+
const south = bbox.south ?? bbox[1];
|
|
8401
|
+
const east = bbox.east ?? bbox[2];
|
|
8402
|
+
const north = bbox.north ?? bbox[3];
|
|
8403
|
+
if (west === undefined || south === undefined || east === undefined || north === undefined) {
|
|
8404
|
+
return [];
|
|
8405
|
+
}
|
|
8406
|
+
const coordinate = pickResult.coordinate;
|
|
8407
|
+
if (!coordinate || coordinate.length < 2) {
|
|
8408
|
+
return [];
|
|
8409
|
+
}
|
|
8410
|
+
const [centerLon, centerLat] = coordinate;
|
|
8411
|
+
// Calculate grid offset (in pixels): gridSize must be odd; gridSize=3 → offset=1, gridSize=5 → offset=2
|
|
8412
|
+
const offset = Math.floor(gridSize / 2);
|
|
8413
|
+
// Get center pixel from clicked coordinate using WebMercator projection
|
|
8414
|
+
const centerNormX = (centerLon - west) / (east - west);
|
|
8415
|
+
// WebMercator non-linear latitude projection
|
|
8416
|
+
const centerLatRad = centerLat * Math.PI / 180;
|
|
8417
|
+
const northRad = north * Math.PI / 180;
|
|
8418
|
+
const southRad = south * Math.PI / 180;
|
|
8419
|
+
const mercatorCenterY = Math.log(Math.tan(Math.PI / 4 + centerLatRad / 2));
|
|
8420
|
+
const mercatorNorth = Math.log(Math.tan(Math.PI / 4 + northRad / 2));
|
|
8421
|
+
const mercatorSouth = Math.log(Math.tan(Math.PI / 4 + southRad / 2));
|
|
8422
|
+
const centerNormY = (mercatorNorth - mercatorCenterY) / (mercatorNorth - mercatorSouth);
|
|
8423
|
+
const centerPixelX = Math.floor(centerNormX * (width - 1));
|
|
8424
|
+
const centerPixelY = Math.floor(centerNormY * (height - 1));
|
|
8425
|
+
const samples = [];
|
|
8426
|
+
// Sample grid around clicked point
|
|
8427
|
+
for (let dy = -offset; dy <= offset; dy++) {
|
|
8428
|
+
for (let dx = -offset; dx <= offset; dx++) {
|
|
8429
|
+
const pixelX = centerPixelX + dx;
|
|
8430
|
+
const pixelY = centerPixelY + dy;
|
|
8431
|
+
// Stay within tile bounds
|
|
8432
|
+
if (pixelX < 0 || pixelX >= width || pixelY < 0 || pixelY >= height) {
|
|
8433
|
+
continue;
|
|
8434
|
+
}
|
|
8435
|
+
const pixelIndex = pixelY * width + pixelX;
|
|
8436
|
+
const elevation = raw[pixelIndex];
|
|
8437
|
+
if (elevation === undefined || elevation === null) {
|
|
8438
|
+
continue;
|
|
8439
|
+
}
|
|
8440
|
+
// Convert pixel to geographic coordinates using WebMercator projection
|
|
8441
|
+
const lon = west + (pixelX / (width - 1)) * (east - west);
|
|
8442
|
+
// Inverse WebMercator transform for latitude
|
|
8443
|
+
const normV = pixelY / (height - 1);
|
|
8444
|
+
const mercatorY = mercatorNorth - normV * (mercatorNorth - mercatorSouth);
|
|
8445
|
+
const lat = (2 * Math.atan(Math.exp(mercatorY)) - Math.PI / 2) * 180 / Math.PI;
|
|
8446
|
+
samples.push({
|
|
8447
|
+
longitude: lon,
|
|
8448
|
+
latitude: lat,
|
|
8449
|
+
elevation,
|
|
8450
|
+
});
|
|
8451
|
+
}
|
|
8452
|
+
}
|
|
8453
|
+
return samples;
|
|
8454
|
+
}
|
|
8455
|
+
catch {
|
|
8456
|
+
return [];
|
|
8457
|
+
}
|
|
8458
|
+
}
|
|
8459
|
+
|
|
8315
8460
|
// src/index.ts
|
|
8316
8461
|
// Initialize global error suppression for deck.gl AbortErrors
|
|
8317
8462
|
suppressGlobalAbortErrors();
|
|
@@ -15529,5 +15674,7 @@ exports.CogBitmapLayer = CogBitmapLayer;
|
|
|
15529
15674
|
exports.CogTerrainLayer = CogTerrainLayer;
|
|
15530
15675
|
exports.CogTiles = CogTiles;
|
|
15531
15676
|
exports.GeoImage = GeoImage;
|
|
15677
|
+
exports.extractTerrainCoordinate = extractTerrainCoordinate;
|
|
15678
|
+
exports.sampleTerrainTileCoordinates = sampleTerrainTileCoordinates;
|
|
15532
15679
|
exports.suppressGlobalAbortErrors = suppressGlobalAbortErrors;
|
|
15533
15680
|
//# sourceMappingURL=index.js.map
|