javascript - SVGPanZoom 干扰动态 foreignObject 内容
问题描述
我想在我的 svg 地图上选择用户可以编写一些简单的文本。我想使用 foreignObject 和输入类型文本来做到这一点。
<img id ="text" src="slike/crtanje/text.svg" onclick="writeText()">
function writeText() {
var draw = karta.select("#wrap")
.on("mousedown", mousedown)
.on("mouseup", mouseup);
function mousedown() {
var m = d3.mouse(this);
draw.append("foreignObject")
.attr("xhtml", "http://www.w3.org/2000/svg")
.attr("x", m[0])
.attr("y", m[1])
.attr("width", "200")
.attr("height", "100")
.attr("class", "forin")
.append("xhtml:input")
.attr("xmlns", "http://www.w3.org/1999/xhtml")
.attr("type", "text" )
.attr("id", "text");
}
function mouseup () {
draw.on("mousedown", null);
}
}
问题是当我包含用于基本缩放/平移地图功能的 SVGPanZoom 库时(https://github.com/ariutta/svg-pan-zoom),它不起作用。我是 svg 的新手,如果有任何建议,我将不胜感激。我也尝试使用 contenteditable = "true" 但我再次面临与图书馆相同的问题。
svg.addEventListener("load", function(){
htmlSVG = document.getElementById("hrzup").contentDocument;
svgd3 = d3.select(htmlSVG);
karta = svgd3.select("#karta");
$(document).ready(function () {
panZoom = svgPanZoom("#hrzup", {
controlIconsEnabled: true,
contain: true,
fit: 1,
center: 1,
dblClickZoomEnabled: false,
minZoom: 0.1,
panEnabled: true,
})
});
}, false);
解决方案
推荐阅读
- python - 如何使用 python 从 spark 数据框中获取交叉表的行百分比?
- parameters - chectl server:deploy --platform minikube error required parameter body
- html - 反应式表单:在某些控件上用不同的功能替换回车键提交
- reactjs - 如何在 typescript 3 项目中使用 typescript 4 包?
- mysql - 连接两个 mySQL 表并使用唯一值进行汇总
- kubernetes - Kops 无法编辑节点实例类型
- azure-devops - Azure DevOps Pipeline - 服务连接权限
- objective-c - PHFetchOption 键的 NSPredicate 语法
- javascript - 我可以告诉汇总不要最小化它生成的代码吗?
- javascript - 如何在单击选择器之前在引导日期选择器中设置默认日期 10 年后