* selectPhoto * Pass falsy values to deselect the layer and photo. * @param {string} layerID? - The layerID to select * @param {string} photoID? - The photoID to select
(layerID = null, photoID = null)
| 415 | * @param {string} photoID? - The photoID to select |
| 416 | */ |
| 417 | selectPhoto(layerID = null, photoID = null) { |
| 418 | const context = this.context; |
| 419 | const map = context.systems.map; |
| 420 | const scene = context.systems.gfx.scene; |
| 421 | |
| 422 | const didChange = (this._currPhotoLayerID !== layerID || this._currPhotoID !== photoID); |
| 423 | |
| 424 | // If we're selecting a photo then make sure its layer is enabled too. |
| 425 | if (this.photoLayerIDs.includes(layerID) && !this.isLayerEnabled(layerID)) { |
| 426 | scene.enableLayers(layerID); |
| 427 | return; // exit to avoid infinite loop, we will be right back in here via `_layerchange` handler. |
| 428 | } |
| 429 | |
| 430 | // Clear out any existing selection.. |
| 431 | this._currPhotoLayerID = null; |
| 432 | this._currPhotoID = null; |
| 433 | scene.clearClass('selectphoto'); |
| 434 | |
| 435 | // Apply the new selection.. |
| 436 | if (photoID && this.photoLayerIDs.includes(layerID)) { |
| 437 | const service = context.services[layerID]; |
| 438 | if (!service) return; |
| 439 | |
| 440 | this._currPhotoLayerID = layerID; |
| 441 | this._currPhotoID = photoID; |
| 442 | scene.setClass('selectphoto', layerID, photoID); |
| 443 | |
| 444 | // Try to show the viewer with the image selected.. |
| 445 | service.selectImageAsync(photoID) |
| 446 | .then(photo => { |
| 447 | if (!photo) return; |
| 448 | if (photo.id !== this._currPhotoID) return; // exit if something else is now selected |
| 449 | if (this._currDetectionID) return; // don't adjust the map if a detection is already selected |
| 450 | |
| 451 | if (didChange) { |
| 452 | map.centerEase(photo.loc); |
| 453 | } |
| 454 | }) |
| 455 | .then(() => this.showViewer()); |
| 456 | } |
| 457 | |
| 458 | this._photoChanged(); |
| 459 | } |
| 460 | |
| 461 | |
| 462 | /** |
no test coverage detected