@@ -31,14 +31,15 @@ import '../ui/ngv-layer-details.js';
3131import '../ui/ngv-layers-list.js' ;
3232import {
3333 applyClippingTo3dTileset ,
34+ getModelFootprintPositions ,
3435 removeClippingFrom3dTilesets ,
3536 updateModelClipping ,
3637} from './interactionHelpers.js' ;
3738import type { ControlType } from './controlsHelpers.js' ;
3839import type { DragState } from './controlsDragMath.js' ;
3940import { applyDrag , startDrag } from './controlsDragMath.js' ;
4041import type { INGVCesiumModel } from '../../interfaces/cesium/ingv-layers.js' ;
41- import type { ClippingChangeDetail , PositionChangeDetail } from '../ui/ngv-layer-details.js' ;
42+ import type { PositionChangeDetail } from '../ui/ngv-layer-details.js' ;
4243import { Task } from '@lit/task' ;
4344import { ControlAxis } from './controlAxis.js' ;
4445import type { ControlPickId } from './controlAxis.js' ;
@@ -50,9 +51,10 @@ export class NgvPluginCesiumModelInteract extends LitElement {
5051 @property ( { type : Object } ) tiles3dCollection : PrimitiveCollection ;
5152 @property ( { type : Object } ) dataSourceCollection : DataSourceCollection ;
5253 @property ( { type : Object } ) storeOptions ?: { localStoreKey : string ; indexDbName : string } ;
53- @property ( { type : Object } ) options ?: { listTitle : string } ;
54+ @property ( { type : Object } ) options ?: { listTitle : string ; showEditBtns ?: boolean } ;
5455
5556 @state ( ) private chosenModel : INGVCesiumModel | undefined ;
57+ @state ( ) private savedMatrix : Matrix4 | undefined ;
5658 @state ( ) private modelPosition : {
5759 longitude : number ; latitude : number ; height : number ;
5860 heading : number ; pitch : number ; roll : number ; scale : number ;
@@ -255,19 +257,29 @@ export class NgvPluginCesiumModelInteract extends LitElement {
255257 const model = this . pickModel ( evt . position ) ;
256258 if ( model ) {
257259 if ( model !== this . chosenModel ) {
258- this . chosenModel = model ;
259- this . modelPosition = this . extractModelPosition ( model ) ;
260- this . control ?. show ( model ) ;
261- this . _startContinuousRender ( ) ;
260+ this . selectModel ( model ) ;
262261 }
263262 } else {
264- this . chosenModel = undefined ;
265- this . modelPosition = undefined ;
266- this . control ?. hide ( ) ;
267- this . _stopContinuousRender ( ) ;
263+ this . deselectModel ( ) ;
268264 }
269265 }
270266
267+ private selectModel ( model : INGVCesiumModel ) : void {
268+ this . chosenModel = model ;
269+ this . savedMatrix = Matrix4 . clone ( model . modelMatrix , new Matrix4 ( ) ) ;
270+ this . modelPosition = this . extractModelPosition ( model ) ;
271+ this . control ?. show ( model ) ;
272+ this . _startContinuousRender ( ) ;
273+ }
274+
275+ private deselectModel ( ) : void {
276+ this . chosenModel = undefined ;
277+ this . savedMatrix = undefined ;
278+ this . modelPosition = undefined ;
279+ this . control ?. hide ( ) ;
280+ this . _stopContinuousRender ( ) ;
281+ }
282+
271283 private _unlistenPostRender : Event . RemoveCallback | undefined ;
272284 private _startContinuousRender ( ) : void {
273285 if ( this . _unlistenPostRender ) return ;
@@ -338,20 +350,10 @@ export class NgvPluginCesiumModelInteract extends LitElement {
338350 < ngv-layer-details
339351 .layer ="${ {
340352 name : this . chosenModel . id . name ,
341- clippingOptions : {
342- terrainClipping : this . chosenModel . id . terrainClipping ,
343- tilesClipping : this . chosenModel . id . tilesClipping ,
344- } ,
345353 position : this . modelPosition ,
346354 } } "
347355 .showDone =${ true }
348- @clippingChange =${ ( evt : { detail : ClippingChangeDetail } ) => {
349- if ( typeof evt . detail . terrainClipping === 'boolean' )
350- this . chosenModel . id . terrainClipping = evt . detail . terrainClipping ;
351- if ( typeof evt . detail . tilesClipping === 'boolean' )
352- this . chosenModel . id . tilesClipping = evt . detail . tilesClipping ;
353- updateModelClipping ( this . chosenModel , this . tiles3dCollection , this . viewer . scene . globe ) ;
354- } }
356+ .showCancel =${ true }
355357 @positionChange=${ ( evt : { detail : PositionChangeDetail } ) => {
356358 if ( ! this . chosenModel || ! this . modelPosition ) return ;
357359 const updated = { ...this . modelPosition , ...evt . detail } ;
@@ -378,10 +380,18 @@ export class NgvPluginCesiumModelInteract extends LitElement {
378380 this . viewer . scene . requestRender ( ) ;
379381 } }
380382 @done="${ ( ) => {
381- this . control ?. hide ( ) ;
382- this . _stopContinuousRender ( ) ;
383- this . chosenModel = undefined ;
384- this . modelPosition = undefined ;
383+ this . deselectModel ( ) ;
384+ this . onPrimitivesChanged ( ) ;
385+ } } "
386+ @cancel="${ ( ) => {
387+ if ( this . chosenModel && this . savedMatrix ) {
388+ Matrix4 . clone ( this . savedMatrix , this . chosenModel . modelMatrix ) ;
389+ if ( this . chosenModel . id . tilesClipping || this . chosenModel . id . terrainClipping ) {
390+ updateModelClipping ( this . chosenModel , this . tiles3dCollection , this . viewer . scene . globe ) ;
391+ }
392+ this . viewer . scene . requestRender ( ) ;
393+ }
394+ this . deselectModel ( ) ;
385395 this . onPrimitivesChanged ( ) ;
386396 } } "
387397 >
@@ -406,8 +416,21 @@ export class NgvPluginCesiumModelInteract extends LitElement {
406416 ${ this . options ?. listTitle }
407417 </ div >
408418 < ngv-layers-list
409- .options ="${ { showDeleteBtns : true , showZoomBtns : true } } "
419+ .options ="${ { showDeleteBtns : true , showZoomBtns : true , showEditBtns : this . options ?. showEditBtns , showAddClippingBtns : this . options ?. showEditBtns } } "
410420 .layers =${ this . models . map ( ( m ) => ( { name : m . id . name } ) ) }
421+ @addClipping ="${ ( evt : { detail : number } ) => {
422+ const model = this . primitiveCollection . get ( evt . detail ) as INGVCesiumModel ;
423+ if ( ! model ) return ;
424+ const positions = getModelFootprintPositions ( model ) ;
425+ this . dispatchEvent ( new CustomEvent ( 'modelAddClipping' , {
426+ detail : { positions, name : model . id . name } ,
427+ bubbles : true , composed : true ,
428+ } ) ) ;
429+ } } "
430+ @edit="${ ( evt : { detail : number } ) => {
431+ const model = this . primitiveCollection . get ( evt . detail ) as INGVCesiumModel ;
432+ if ( model ) this . selectModel ( model ) ;
433+ } } "
411434 @remove="${ ( evt : { detail : number } ) => {
412435 const model = this . primitiveCollection . get ( evt . detail ) as INGVCesiumModel ;
413436 if ( model ) this . primitiveCollection . remove ( model ) ;
0 commit comments