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