@equinor/videx-3d
    Preparing search index...

    Function useAnnotations

    • This hook allow you to add annotations to an exisiting AnnotationsLayer. A scope is a user defined string, which should uniquely tie the added anotations to your component. If your annotations belong to a specific wellbore, the wellbore name or id would work well as a scope.

      A single function addAnnotations is returned, which you can call from within a useEffect hook to set annotations. Annotations must be an array of AnnotationProps. The addAnnotations function will return a dispose function when invoked, which you should call within the effect dispose function.

      Parameters

      • layer: string
      • scope: string

      Returns { addAnnotations: (annotations: AnnotationProps[]) => (() => void) | undefined }

      const { addAnnotations } = useAnnotations('casings', scope)
      

      Note that annotation positions needs to be in world space. You can optionally provide a matrixWorld to the annotation props that can be used to transform the local postion to world position. In the components using annotations, this is done by rendering a "dummy" Object3D and passing its matrixWorld instance to the annotation props.

      useEffect(() => {
      let dispose: (() => void) | null = null
      if (generator && id) {
      const v = new Vector3()
      generator(id).then(response => {
      if (response && positionRef.current) {
      response.forEach((d, i) => {
      v.set(...d.position)
      positionRef.current.localToWorld(v)
      d.position = v.toArray()
      d.id = i.toString()
      })
      dispose = addAnnotations(response || [])
      }
      })
      }

      return () => {
      if (dispose) dispose()
      }
      }, [addAnnotations, id, generator, positionRef])