Php Openseadragon imagetoViewport
我使用选择插件获得一个rect:Php Openseadragon imagetoViewport,php,mysql,css,openseadragon,Php,Mysql,Css,Openseadragon,我使用选择插件获得一个rect: selection =viewer.selection({ onSelection: function(rect) { console.log(rect.x); console.log(rect.y); console.log(rect.width); console.log(rect.height); var elt = document.createElement("di
selection =viewer.selection({
onSelection: function(rect) {
console.log(rect.x);
console.log(rect.y);
console.log(rect.width);
console.log(rect.height);
var elt = document.createElement("div");
elt.id = "runtime-overlay";
elt.className = "highlight";
viewer.addOverlay({
element: elt,
location: viewer.viewport.imageToViewportRectangle(rect)
});
input = "rect_x="+rect.x+"&rect_y="+rect.y+"&rect_w="+rect.width+"&rect_h="+rect.height+"&plink=<?=$plink?>&case_id=<?=$case_id?>&mode=add";
$.ajax({
url : "handlers/H_AnnotationHandler.php",
data : input,
type : "post",
dataType : "json",
success : function(response) {
if (!response.error)
alert("success");
else
alert("failed");
}
});
}
});
selection=viewer.selection({
onSelection:函数(rect){
console.log(rect.x);
console.log(rect.y);
控制台日志(垂直宽度);
控制台日志(垂直高度);
var elt=document.createElement(“div”);
elt.id=“运行时覆盖”;
elt.className=“突出显示”;
viewer.addOverlay({
要素:英语教学,
位置:viewer.viewport.imageToViewportRectangle(rect)
});
input=“rect_x=“+rect.x+”&rect_y=“+rect.y+”&rect_w=“+rect.width+”&rect_h=“+rect.height+”&plink=&case_id=&mode=add”;
$.ajax({
url:“handlers/H_AnnotationHandler.php”,
数据:输入,
类型:“post”,
数据类型:“json”,
成功:功能(响应){
如果(!response.error)
警惕(“成功”);
其他的
警报(“失败”);
}
});
}
});
我通过H_AnnotationHandler.php将rect存储在mysql中。之后,当我尝试像这样使用这些数据时:
$.ajax({
url : "handlers/H_AnnotationHandler.php",
data : "case_id=<?=$case_id?>&plink=<?=$plink?>&mode=get",
type : "post",
dataType : "json",
success : function (response) {
if (!response.error) {
for (var i = 0; i < response.annots.length; i++) {
var elt = document.createElement("div");
elt.id = "runtime-overlay" + i;
elt.className = "highlight";
viewer.addOverlay({
element: elt,
location : viewer.viewport.imageToViewportRectangle(parseInt(response.annots[i].rect_x), parseInt(response.annots[i].rect_y), parseInt(response.annots[i].rect_w), parseInt(response.annots[i].rect_h))
});
}
}
}
});
$.ajax({
url:“handlers/H_AnnotationHandler.php”,
数据:“案例id=&plink=&mode=get”,
类型:“post”,
数据类型:“json”,
成功:功能(响应){
如果(!response.error){
对于(var i=0;i
它创建了一个运行时覆盖分区,但左、上、高和宽似乎都是错误的。(27094e+04等)
注意:我确信,sql数据是正确的。我在拍摄前比较了它。您确定正确检索了矩形坐标吗?ajax请求的类型不应该是“get”而不是“post”吗?是的,我添加了setTimeout 3秒。它起作用了。我认为在页面加载时,查看器对象在一段时间内仍然为空。Ha,在这种情况下,您可以像这样侦听查看器
open
事件:viewer.addHandler('open',function(){$.ajax(…);})代码>@avandecreme非常感谢你!是否确实正确检索矩形坐标?ajax请求的类型不应该是“get”而不是“post”吗?是的,我添加了setTimeout 3秒。它起作用了。我认为在页面加载时,查看器对象在一段时间内仍然为空。Ha,在这种情况下,您可以像这样侦听查看器open
事件:viewer.addHandler('open',function(){$.ajax(…);})代码>@avandecreme非常感谢你!