MCPcopy
hub / github.com/CesiumGS/cesium / pickImageryHelper

Function pickImageryHelper

packages/engine/Source/Scene/ImageryLayerCollection.js:347–419  ·  view source on GitHub ↗
(scene, pickedLocation, pickFeatures, callback)

Source from the content-addressed store, hash-verified

345const applicableRectangleScratch = new Rectangle();
346
347function pickImageryHelper(scene, pickedLocation, pickFeatures, callback) {
348 // Find the terrain tile containing the picked location.
349 const tilesToRender = scene.globe._surface._tilesToRender;
350 let pickedTile;
351
352 for (
353 let textureIndex = 0;
354 !defined(pickedTile) && textureIndex < tilesToRender.length;
355 ++textureIndex
356 ) {
357 const tile = tilesToRender[textureIndex];
358 if (Rectangle.contains(tile.rectangle, pickedLocation)) {
359 pickedTile = tile;
360 }
361 }
362
363 if (!defined(pickedTile)) {
364 return;
365 }
366
367 // Pick against all attached imagery tiles containing the pickedLocation.
368 const imageryTiles = pickedTile.data.imagery;
369
370 for (let i = imageryTiles.length - 1; i >= 0; --i) {
371 const terrainImagery = imageryTiles[i];
372 const imagery = terrainImagery.readyImagery;
373 if (!defined(imagery)) {
374 continue;
375 }
376 if (!imagery.imageryLayer.ready) {
377 continue;
378 }
379 const provider = imagery.imageryLayer.imageryProvider;
380 if (pickFeatures && !defined(provider.pickFeatures)) {
381 continue;
382 }
383
384 if (!Rectangle.contains(imagery.rectangle, pickedLocation)) {
385 continue;
386 }
387
388 // If this imagery came from a parent, it may not be applicable to its entire rectangle.
389 // Check the textureCoordinateRectangle.
390 const applicableRectangle = applicableRectangleScratch;
391
392 const epsilon = 1 / 1024; // 1/4 of a pixel in a typical 256x256 tile.
393 applicableRectangle.west = CesiumMath.lerp(
394 pickedTile.rectangle.west,
395 pickedTile.rectangle.east,
396 terrainImagery.textureCoordinateRectangle.x - epsilon,
397 );
398 applicableRectangle.east = CesiumMath.lerp(
399 pickedTile.rectangle.west,
400 pickedTile.rectangle.east,
401 terrainImagery.textureCoordinateRectangle.z + epsilon,
402 );
403 applicableRectangle.south = CesiumMath.lerp(
404 pickedTile.rectangle.south,

Callers 1

Calls 4

callbackFunction · 0.70
definedFunction · 0.50
containsMethod · 0.45
lerpMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…