@@ -25,6 +25,7 @@ import {
2525} from '../../../utils/MapUtils' ;
2626import { reprojectBbox } from '../../../utils/CoordinatesUtils' ;
2727import { throttle , isEqual , debounce } from 'lodash' ;
28+ import TIFFImageryProvider from 'tiff-imagery-provider' ;
2829
2930class CesiumMap extends React . Component {
3031 static propTypes = {
@@ -265,7 +266,9 @@ class CesiumMap extends React.Component {
265266 onClick = ( map , movement ) => {
266267 if ( this . props . onClick && movement . position !== null ) {
267268 const cartesian = map . camera . pickEllipsoid ( movement . position , map . scene . globe . ellipsoid ) ;
269+
268270 const intersectedFeatures = this . getIntersectedFeatures ( map , movement . position ) ;
271+
269272 let cartographic = ClickUtils . getMouseXYZ ( map , movement ) || cartesian && Cesium . Cartographic . fromCartesian ( cartesian ) ;
270273 if ( cartographic ) {
271274 const latitude = cartographic . latitude * 180.0 / Math . PI ;
@@ -284,23 +287,25 @@ class CesiumMap extends React.Component {
284287
285288 const y = ( 90.0 - latitude ) / 180.0 * this . props . standardHeight * ( this . props . zoom + 1 ) ;
286289 const x = ( 180.0 + longitude ) / 360.0 * this . props . standardWidth * ( this . props . zoom + 1 ) ;
287- this . props . onClick ( {
288- pixel : {
289- x : x ,
290- y : y
291- } ,
290+ const latlng = { lat : latitude , lng : longitude , z : elevation } ;
291+ const pixel = { x, y } ;
292+ const pointToBuildRequest = {
293+ pixel,
292294 height : ( this . props . mapOptions && this . props . mapOptions . terrainProvider ) || intersectedFeatures . length > 0
293295 ? cartographic . height
294296 : undefined ,
295297 cartographic,
296- latlng : {
297- lat : latitude ,
298- lng : longitude ,
299- z : elevation
300- } ,
298+ latlng,
301299 crs : "EPSG:4326" ,
302300 intersectedFeatures,
303301 resolution : getResolutions ( ) [ Math . round ( this . props . zoom ) ]
302+ } ;
303+
304+ this . getIntersectedPixels ( map , { ...movement . position , ...cartographic } ) . then ( intersectedPixels => {
305+
306+ pointToBuildRequest . intersectedPixels = intersectedPixels ;
307+
308+ this . props . onClick ( pointToBuildRequest ) ;
304309 } ) ;
305310 }
306311 }
@@ -389,6 +394,33 @@ class CesiumMap extends React.Component {
389394 return this . props . zoomToHeight / Math . pow ( 2 , zoom - 1 ) ;
390395 } ;
391396
397+ /**
398+ * wrapper for TIFFImageryProvider pickFeatures() is async operation and we need append results and call onClick
399+ * https://github.com/hongfaqiu/TIFFImageryProvider/blob/v2.17.1/packages/TIFFImageryProvider/src/TIFFImageryProvider.ts#L768
400+ * @param {zoom } map
401+ * @param {x, y, longitude, latitude } position
402+ * @returns Array of layers with relative intersected pixels
403+ */
404+ getIntersectedPixels = ( map , position ) => {
405+
406+ const tiffLayers = map . imageryLayers . _layers . filter ( layer =>
407+ layer . rendered &&
408+ layer . imageryProvider instanceof TIFFImageryProvider
409+ ) ;
410+
411+ return Promise . all ( tiffLayers . map ( layer => {
412+ return layer . imageryProvider . pickFeatures ( position . x , position . y , map . zoom , position . longitude , position . latitude )
413+ . then ( pickedLayers => {
414+ const { data} = pickedLayers [ 0 ] || { } ;
415+ return {
416+ id : layer . _imageryProvider . layerId ,
417+ // remap bands index start from 1 instead of 0 to be consistent with 2D pick and avoid confusion with users
418+ bands : Object . fromEntries ( Object . entries ( data ) . map ( ( [ key , value ] ) => [ Number ( key ) + 1 , value ] ) )
419+ } ;
420+ } ) ;
421+ } ) ) ;
422+ }
423+
392424 getIntersectedFeatures = ( map , position ) => {
393425 // for consistency with 2D view we allow to drill pick through the first feature
394426 // and intersect all the features behind
0 commit comments