MCPcopy Create free account
hub / github.com/facebook/Rapid / selectDetection

Method selectDetection

modules/core/PhotoSystem.js:468–555  ·  view source on GitHub ↗

* selectDetection * Pass falsy values to deselect the layer and detection. * @param {string} layerID? - The layerID to select * @param {string} detectionID? - The detectionID to select

(layerID = null, detectionID = null)

Source from the content-addressed store, hash-verified

466 * @param {string} detectionID? - The detectionID to select
467 */
468 selectDetection(layerID = null, detectionID = null) {
469 const context = this.context;
470 const map = context.systems.map;
471 const scene = context.systems.gfx.scene;
472
473 // If we're selecting a detection then make sure its layer is enabled too.
474 if (this.detectionLayerIDs.includes(layerID) && !this.isLayerEnabled(layerID)) {
475 scene.enableLayers(layerID);
476 return; // exit to avoid infinite loop, we will be right back in here via `_layerchange` handler.
477 }
478
479 // Clear out any existing selection..
480 this._currDetectionLayerID = null;
481 this._currDetectionID = null;
482 scene.clearClass('selectdetection');
483 scene.clearClass('highlightphoto');
484
485 // Apply the new selection..
486 if (detectionID && this.detectionLayerIDs.includes(layerID)) {
487 const photoLayerID = layerID.split('-')[0]; // e.g. 'mapillary-signs' -> 'mapillary'
488 const service = context.services[photoLayerID];
489 if (!service) return;
490
491 this._currDetectionLayerID = layerID;
492 this._currDetectionID = detectionID;
493 scene.setClass('selectdetection', layerID, detectionID);
494
495 // Try to highlight any photos that show this detection,
496 // And try to select a photo in the viewer that shows it.
497 service.selectDetectionAsync(detectionID)
498 .then(detection => {
499 if (!detection) return;
500 if (detection.id !== this._currDetectionID) return; // exit if something else is now selected
501
502 // Handle the situation where we want to select a detection,
503 // but we haven't properly entered SelectMode yet.
504 // This can happen if the detection arrived in the URL hash.
505 if (!context.selectedData().has(detection.id)) {
506 const selection = new Map().set(detection.id, detection);
507 context.enter('select', { selection: selection });
508 return; // exit to avoid infinite loop - entering select mode will bring us right back in here.
509 }
510
511 // Highlight any images that show this detection..
512 const highlightPhotoIDs = (detection.images ?? []).map(image => image.id);
513 for (const photoID of highlightPhotoIDs) {
514 scene.setClass('highlightphoto', photoLayerID, photoID);
515 }
516
517 // Try to select a photo that shows this detection..
518 // - If the current photo already shows it, keep it selected
519 // - Otherwise choose the "best" photo suggested by the detection
520 // - Otherwise no selected photo.
521 let bestPhotoID;
522 if (this._currPhotoLayerID === photoLayerID && highlightPhotoIDs.includes(this._currPhotoID)) {
523 bestPhotoID = this._currPhotoID;
524 } else {
525 bestPhotoID = detection.bestImageID;

Callers 4

_hashchangeMethod · 0.95
_layerchangeMethod · 0.95
enterMethod · 0.80
exitMethod · 0.80

Calls 14

isLayerEnabledMethod · 0.95
selectPhotoMethod · 0.95
_photoChangedMethod · 0.95
enableLayersMethod · 0.80
splitMethod · 0.80
selectDetectionAsyncMethod · 0.80
getImageMethod · 0.80
trimmedExtentZoomMethod · 0.80
centerZoomEaseMethod · 0.80
centerMethod · 0.80
clearClassMethod · 0.45
setClassMethod · 0.45

Tested by

no test coverage detected