gpt4 book ai didi

OpenSeaDragon doesnt display a slide(OpenSeaDragon不显示幻灯片)

转载 作者:bug小助手 更新时间:2023-10-22 17:34:22 25 4
gpt4 key购买 nike



I don’t understand what the problem is, OpenSeaDragon doesn’t display the slide that I take from the API to the screen.

我不明白问题是什么,OpenSeaDragon没有在屏幕上显示我从API获取的幻灯片。


Here is a full code

这是完整的代码


import '../../../App.css'
import { useParams } from "react-router-dom";
import { useState, useEffect,useRef } from "react";
import OpenSeadragon from "openseadragon";


function CaseImage(){
const { id } = useParams();
const viewerRef = useRef(null);



const [imageSize, setImageSize] = useState(null)


useEffect(()=>{
fetch(`http://localhost/api/case/slide/GetDimensions?file_id=${id}`)
.then((response) => response.json())
.then((result) =>setImageSize(result.data))
},[id])


useEffect(() => {
if (imageSize && viewerRef.current) {
const viewer = OpenSeadragon({
id: 'openseadragon-viewer',
prefixUrl: '',
constrainDuringPan: true,
tileSources: {
getTileUrl: function (level, x, y) {
return "http://localhost/api/case/slide/GetTile/" + id + "/" +
level + "/" + x + "_" + y;
},
zoomPerScroll: 2,
overlap: 10,
height: imageSize.height,
width: imageSize.width,
tileSize: 256,
minLevel: 8,

},
zoomInButton: 'zoom-in',
zoomOutButton: 'zoom-out',
homeButton: 'home',
fullPageButton: 'full-page',
nextButton: 'next',
previousButton: 'previous',
});

viewerRef.current = viewer;
}

return () => {
if (viewerRef.current) {
viewerRef.current.destroy();
}
};
}, [imageSize, id]);

return(
<>

<div id="openseadragon-viewer" style={{ height: "700px", width: '100%' }}></div>

<div id="openseadragon-buttons" className="Panel">
<button id="zoom-in">Zoom In</button>
<button id="zoom-out">Zoom Out</button>
<button id="home">Home</button>
<button id="full-page">Full Page</button>
</div>
</>
)
}

export default CaseImage



I tried to give a straight direct like this

我试着直接这样说


http://localhost/api/case/slide/GetTile/397a03fc-6ebe-4278-ae86-7be34a5b9034/8/0_0

http://localhost/api/case/slide/GetTile/397a03fc-6ebe-4278-ae86-7be34a5b9034/8/0_0


instead of this
http://localhost/api/case/slide/GetTile/" + id + "/" +
level + "/" + x + "_" + y


but it didnt help

但是没有帮助


更多回答

Do you have an error related to this in the console?

控制台中是否存在与此相关的错误?

Hello, there are no errors in the console

你好,控制台中没有错误

You are sure of uploading the image through this link. To be sure, open this link in a new tab.

您确信可以通过此链接上传图像。要确定,请在新选项卡中打开此链接。

yes, i am sure d

是的,我确信d

It sure looks like it should work! There are all sorts of things you can do to debug... Add a console.log to make sure the viewer is being created. Take a look at the network tab of the developer tools to see if it's attempting to load in any image. Try a simple image first: openseadragon.github.io/examples/tilesource-image I'm noticing there's no extension on your URL... I don't think that should be a problem, but I guess you could try adding an extension. One unrelated thing: zoomPerScroll shouldn't be part of the tile source; move it out to the main options.

它看起来确实应该工作!你可以做各种各样的事情来调试。。。添加console.log以确保正在创建查看器。看看开发人员工具的网络选项卡,看看它是否试图加载到任何图像中。先尝试一个简单的图像:openseadragon.github.io/examples/tilesource-image我注意到你的URL上没有扩展。。。我认为这不应该是个问题,但我想你可以尝试添加一个扩展。一件无关的事情:zoomPerScroll不应该是tile源的一部分;将其移至主要选项。

优秀答案推荐

I believe the problem is that your CaseImage component is probably mounted twice. This can happen for various reasons, e.g. if React StrictMode is on. So the viewer is constructed and then immediately destructed at the end of the first mount.

我认为问题在于您的CaseImage组件可能安装了两次。这种情况可能由于各种原因而发生,例如,如果React StrictMode处于打开状态。因此,查看器被构造,然后在第一次装载结束时立即被销毁。


If you set viewerRef.current to null after destruction, the viewer will be reconstructed on the second call, and this might be enough.

如果在销毁后将viewerRef.current设置为null,则查看器将在第二次调用时重建,这可能就足够了。


However, a better approach (which avoids the double construction) would be to create the viewer as a response to the <div> going into or out of the DOM. One way to achieve this is (approximately)

然而,更好的方法(避免双重构造)是创建查看器,作为对<div>进入或离开DOM的响应。实现这一点的一种方法是(近似)


const setRef = useCallback((element: HTMLDivElement | null) => {
if (viewerRef.current) {
... <destruct old>
viewerRef.current = null; // not strictly necessary
}
if (element) {
... <create viewer on element>
viewerRef.current = viewer;
}
}, []);
...
return <div ref={setRef} {...etc}></div>


更多回答

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com