Dictionary SVG地图缩放保持图标和工具提示正常大小
我已经制作了一个SVG地图,该地图具有选择足球运动员并动态显示足球运动员所在俱乐部的功能。看见当你点击“Fussballer”,然后选择一个名称时,俱乐部的位置(足球图标)将显示在地图上。当您将鼠标悬停在图标上时,会显示一些信息Dictionary SVG地图缩放保持图标和工具提示正常大小,dictionary,svg,zooming,Dictionary,Svg,Zooming,我已经制作了一个SVG地图,该地图具有选择足球运动员并动态显示足球运动员所在俱乐部的功能。看见当你点击“Fussballer”,然后选择一个名称时,俱乐部的位置(足球图标)将显示在地图上。当您将鼠标悬停在图标上时,会显示一些信息 <h1>Demo for svg-pan-zoom: In-line SVG</h1> <div id="container" style="width: 400px; height: 300px; border:1px solid bla
<h1>Demo for svg-pan-zoom: In-line SVG</h1>
<div id="container" style="width: 400px; height: 300px; border:1px solid black;">
<svg xmlns="http://www.w3.org/2000/svg" style="width: 400px; height: 300px; "version="1.1" id="map-svg">
<g id="circle">
<circle cx="102" cy="197.5" r="20" stroke="black" stroke-width="0.1" fill="red" />
<g id="tooltip" opacity="0.7" transform="translate(20 20)">
<rect x="104" y="197.5" width="80" height="40" rx="5"/>
<text x="107" y="209.5">Test</text>
</g>
</g>
</svg>
</div>
<script>
function init() {
window.zoomTiger = svgPanZoom('#map-svg', {
zoomEnabled: true,
controlIconsEnabled: true,
fit: false,
center: true,
minZoom: 1,
maxZoom: 50,
zoomScaleSensitivity: 0.5,
onZoom: function(){
//in the following segment I tried with different values to counter the zoom and the transform of the tooltip, but honestly I have no clue!
var values = svgPanZoom('#map-svg');
var realZoom = values.getZoom();
var viewBox = values.getSizes();
var height = viewBox.viewBox.height;
var y = height/2;
var width = viewBox.viewBox.width;
var x = width/2;
var Zoom1 = 1.02/(realZoom+0.02);
x = (realZoom-1)*0.95*x + 20;
y = (realZoom-1)*0.85*y + 20;
document.getElementById("tooltip").setAttribute("transform", "scale(" + Zoom1 + ") translate(" + x + "," + y + ")");
},
});
};
init();
</script>
我的问题是,在放大/缩小(无比例)时,我想保持图标和工具提示未缩放。使文本和图标始终保持相同的大小。
对于缩放功能,我使用了库,它工作得很好
<h1>Demo for svg-pan-zoom: In-line SVG</h1>
<div id="container" style="width: 400px; height: 300px; border:1px solid black;">
<svg xmlns="http://www.w3.org/2000/svg" style="width: 400px; height: 300px; "version="1.1" id="map-svg">
<g id="circle">
<circle cx="102" cy="197.5" r="20" stroke="black" stroke-width="0.1" fill="red" />
<g id="tooltip" opacity="0.7" transform="translate(20 20)">
<rect x="104" y="197.5" width="80" height="40" rx="5"/>
<text x="107" y="209.5">Test</text>
</g>
</g>
</svg>
</div>
<script>
function init() {
window.zoomTiger = svgPanZoom('#map-svg', {
zoomEnabled: true,
controlIconsEnabled: true,
fit: false,
center: true,
minZoom: 1,
maxZoom: 50,
zoomScaleSensitivity: 0.5,
onZoom: function(){
//in the following segment I tried with different values to counter the zoom and the transform of the tooltip, but honestly I have no clue!
var values = svgPanZoom('#map-svg');
var realZoom = values.getZoom();
var viewBox = values.getSizes();
var height = viewBox.viewBox.height;
var y = height/2;
var width = viewBox.viewBox.width;
var x = width/2;
var Zoom1 = 1.02/(realZoom+0.02);
x = (realZoom-1)*0.95*x + 20;
y = (realZoom-1)*0.85*y + 20;
document.getElementById("tooltip").setAttribute("transform", "scale(" + Zoom1 + ") translate(" + x + "," + y + ")");
},
});
};
init();
</script>
调用onZoom方法时,我花了几天时间处理一些转换公式,但我无法正确地得到它。非常感谢你的帮助。(我知道也有D3库可以进行缩放,但如果可能,我希望保持svg平移缩放)
<h1>Demo for svg-pan-zoom: In-line SVG</h1>
<div id="container" style="width: 400px; height: 300px; border:1px solid black;">
<svg xmlns="http://www.w3.org/2000/svg" style="width: 400px; height: 300px; "version="1.1" id="map-svg">
<g id="circle">
<circle cx="102" cy="197.5" r="20" stroke="black" stroke-width="0.1" fill="red" />
<g id="tooltip" opacity="0.7" transform="translate(20 20)">
<rect x="104" y="197.5" width="80" height="40" rx="5"/>
<text x="107" y="209.5">Test</text>
</g>
</g>
</svg>
</div>
<script>
function init() {
window.zoomTiger = svgPanZoom('#map-svg', {
zoomEnabled: true,
controlIconsEnabled: true,
fit: false,
center: true,
minZoom: 1,
maxZoom: 50,
zoomScaleSensitivity: 0.5,
onZoom: function(){
//in the following segment I tried with different values to counter the zoom and the transform of the tooltip, but honestly I have no clue!
var values = svgPanZoom('#map-svg');
var realZoom = values.getZoom();
var viewBox = values.getSizes();
var height = viewBox.viewBox.height;
var y = height/2;
var width = viewBox.viewBox.width;
var x = width/2;
var Zoom1 = 1.02/(realZoom+0.02);
x = (realZoom-1)*0.95*x + 20;
y = (realZoom-1)*0.85*y + 20;
document.getElementById("tooltip").setAttribute("transform", "scale(" + Zoom1 + ") translate(" + x + "," + y + ")");
},
});
};
init();
</script>
下面是一个简化的例子
<h1>Demo for svg-pan-zoom: In-line SVG</h1>
<div id="container" style="width: 400px; height: 300px; border:1px solid black;">
<svg xmlns="http://www.w3.org/2000/svg" style="width: 400px; height: 300px; "version="1.1" id="map-svg">
<g id="circle">
<circle cx="102" cy="197.5" r="20" stroke="black" stroke-width="0.1" fill="red" />
<g id="tooltip" opacity="0.7" transform="translate(20 20)">
<rect x="104" y="197.5" width="80" height="40" rx="5"/>
<text x="107" y="209.5">Test</text>
</g>
</g>
</svg>
</div>
<script>
function init() {
window.zoomTiger = svgPanZoom('#map-svg', {
zoomEnabled: true,
controlIconsEnabled: true,
fit: false,
center: true,
minZoom: 1,
maxZoom: 50,
zoomScaleSensitivity: 0.5,
onZoom: function(){
//in the following segment I tried with different values to counter the zoom and the transform of the tooltip, but honestly I have no clue!
var values = svgPanZoom('#map-svg');
var realZoom = values.getZoom();
var viewBox = values.getSizes();
var height = viewBox.viewBox.height;
var y = height/2;
var width = viewBox.viewBox.width;
var x = width/2;
var Zoom1 = 1.02/(realZoom+0.02);
x = (realZoom-1)*0.95*x + 20;
y = (realZoom-1)*0.85*y + 20;
document.getElementById("tooltip").setAttribute("transform", "scale(" + Zoom1 + ") translate(" + x + "," + y + ")");
},
});
};
init();
</script>
我希望无论缩放如何,工具提示和其中的文本都保持相同的大小和位置
<h1>Demo for svg-pan-zoom: In-line SVG</h1>
<div id="container" style="width: 400px; height: 300px; border:1px solid black;">
<svg xmlns="http://www.w3.org/2000/svg" style="width: 400px; height: 300px; "version="1.1" id="map-svg">
<g id="circle">
<circle cx="102" cy="197.5" r="20" stroke="black" stroke-width="0.1" fill="red" />
<g id="tooltip" opacity="0.7" transform="translate(20 20)">
<rect x="104" y="197.5" width="80" height="40" rx="5"/>
<text x="107" y="209.5">Test</text>
</g>
</g>
</svg>
</div>
<script>
function init() {
window.zoomTiger = svgPanZoom('#map-svg', {
zoomEnabled: true,
controlIconsEnabled: true,
fit: false,
center: true,
minZoom: 1,
maxZoom: 50,
zoomScaleSensitivity: 0.5,
onZoom: function(){
//in the following segment I tried with different values to counter the zoom and the transform of the tooltip, but honestly I have no clue!
var values = svgPanZoom('#map-svg');
var realZoom = values.getZoom();
var viewBox = values.getSizes();
var height = viewBox.viewBox.height;
var y = height/2;
var width = viewBox.viewBox.width;
var x = width/2;
var Zoom1 = 1.02/(realZoom+0.02);
x = (realZoom-1)*0.95*x + 20;
y = (realZoom-1)*0.85*y + 20;
document.getElementById("tooltip").setAttribute("transform", "scale(" + Zoom1 + ") translate(" + x + "," + y + ")");
},
});
};
init();
</script>
<h1>Demo for svg-pan-zoom: In-line SVG</h1>
<div id="container" style="width: 400px; height: 300px; border:1px solid black;">
<svg xmlns="http://www.w3.org/2000/svg" style="width: 400px; height: 300px; "version="1.1" id="map-svg">
<g id="circle">
<circle cx="102" cy="197.5" r="20" stroke="black" stroke-width="0.1" fill="red" />
<g id="tooltip" opacity="0.7" transform="translate(20 20)">
<rect x="104" y="197.5" width="80" height="40" rx="5"/>
<text x="107" y="209.5">Test</text>
</g>
</g>
</svg>
</div>
<script>
function init() {
window.zoomTiger = svgPanZoom('#map-svg', {
zoomEnabled: true,
controlIconsEnabled: true,
fit: false,
center: true,
minZoom: 1,
maxZoom: 50,
zoomScaleSensitivity: 0.5,
onZoom: function(){
//in the following segment I tried with different values to counter the zoom and the transform of the tooltip, but honestly I have no clue!
var values = svgPanZoom('#map-svg');
var realZoom = values.getZoom();
var viewBox = values.getSizes();
var height = viewBox.viewBox.height;
var y = height/2;
var width = viewBox.viewBox.width;
var x = width/2;
var Zoom1 = 1.02/(realZoom+0.02);
x = (realZoom-1)*0.95*x + 20;
y = (realZoom-1)*0.85*y + 20;
document.getElementById("tooltip").setAttribute("transform", "scale(" + Zoom1 + ") translate(" + x + "," + y + ")");
},
});
};
init();
</script>
<h1>Demo for svg-pan-zoom: In-line SVG</h1>
<div id="container" style="width: 400px; height: 300px; border:1px solid black;">
<svg xmlns="http://www.w3.org/2000/svg" style="width: 400px; height: 300px; "version="1.1" id="map-svg">
<g id="circle">
<circle cx="102" cy="197.5" r="20" stroke="black" stroke-width="0.1" fill="red" />
<g id="tooltip" opacity="0.7" transform="translate(20 20)">
<rect x="104" y="197.5" width="80" height="40" rx="5"/>
<text x="107" y="209.5">Test</text>
</g>
</g>
</svg>
</div>
<script>
function init() {
window.zoomTiger = svgPanZoom('#map-svg', {
zoomEnabled: true,
controlIconsEnabled: true,
fit: false,
center: true,
minZoom: 1,
maxZoom: 50,
zoomScaleSensitivity: 0.5,
onZoom: function(){
//in the following segment I tried with different values to counter the zoom and the transform of the tooltip, but honestly I have no clue!
var values = svgPanZoom('#map-svg');
var realZoom = values.getZoom();
var viewBox = values.getSizes();
var height = viewBox.viewBox.height;
var y = height/2;
var width = viewBox.viewBox.width;
var x = width/2;
var Zoom1 = 1.02/(realZoom+0.02);
x = (realZoom-1)*0.95*x + 20;
y = (realZoom-1)*0.85*y + 20;
document.getElementById("tooltip").setAttribute("transform", "scale(" + Zoom1 + ") translate(" + x + "," + y + ")");
},
});
};
init();
</script>
<h1>Demo for svg-pan-zoom: In-line SVG</h1>
<div id="container" style="width: 400px; height: 300px; border:1px solid black;">
<svg xmlns="http://www.w3.org/2000/svg" style="width: 400px; height: 300px; "version="1.1" id="map-svg">
<g id="circle">
<circle cx="102" cy="197.5" r="20" stroke="black" stroke-width="0.1" fill="red" />
<g id="tooltip" opacity="0.7" transform="translate(20 20)">
<rect x="104" y="197.5" width="80" height="40" rx="5"/>
<text x="107" y="209.5">Test</text>
</g>
</g>
</svg>
</div>
<script>
function init() {
window.zoomTiger = svgPanZoom('#map-svg', {
zoomEnabled: true,
controlIconsEnabled: true,
fit: false,
center: true,
minZoom: 1,
maxZoom: 50,
zoomScaleSensitivity: 0.5,
onZoom: function(){
//in the following segment I tried with different values to counter the zoom and the transform of the tooltip, but honestly I have no clue!
var values = svgPanZoom('#map-svg');
var realZoom = values.getZoom();
var viewBox = values.getSizes();
var height = viewBox.viewBox.height;
var y = height/2;
var width = viewBox.viewBox.width;
var x = width/2;
var Zoom1 = 1.02/(realZoom+0.02);
x = (realZoom-1)*0.95*x + 20;
y = (realZoom-1)*0.85*y + 20;
document.getElementById("tooltip").setAttribute("transform", "scale(" + Zoom1 + ") translate(" + x + "," + y + ")");
},
});
};
init();
</script>
svg平移缩放演示:内嵌svg
试验
函数init(){
window.zoomTiger=svgPanZoom(“#映射svg”{
可缩放:对,
ControlIConseabled:正确,
fit:false,
中:是的,
minZoom:1,
maxZoom:50,
动物过敏性:0.5,
onZoom:function(){
//在下面的部分中,我尝试使用不同的值来对抗工具提示的缩放和变换,但老实说,我没有任何线索!
var values=svgPanZoom(“#映射svg”);
var realZoom=values.getZoom();
var viewBox=values.getSizes();
var height=viewBox.viewBox.height;
变量y=高度/2;
var width=viewBox.viewBox.width;
var x=宽度/2;
var Zoom1=1.02/(realZoom+0.02);
x=(realZoom-1)*0.95*x+20;
y=(realZoom-1)*0.85*y+20;
document.getElementById(“工具提示”).setAttribute(“转换”、“缩放”(+Zoom1+))转换(“+x+”,“+y+”));
},
});
};
init();
<h1>Demo for svg-pan-zoom: In-line SVG</h1>
<div id="container" style="width: 400px; height: 300px; border:1px solid black;">
<svg xmlns="http://www.w3.org/2000/svg" style="width: 400px; height: 300px; "version="1.1" id="map-svg">
<g id="circle">
<circle cx="102" cy="197.5" r="20" stroke="black" stroke-width="0.1" fill="red" />
<g id="tooltip" opacity="0.7" transform="translate(20 20)">
<rect x="104" y="197.5" width="80" height="40" rx="5"/>
<text x="107" y="209.5">Test</text>
</g>
</g>
</svg>
</div>
<script>
function init() {
window.zoomTiger = svgPanZoom('#map-svg', {
zoomEnabled: true,
controlIconsEnabled: true,
fit: false,
center: true,
minZoom: 1,
maxZoom: 50,
zoomScaleSensitivity: 0.5,
onZoom: function(){
//in the following segment I tried with different values to counter the zoom and the transform of the tooltip, but honestly I have no clue!
var values = svgPanZoom('#map-svg');
var realZoom = values.getZoom();
var viewBox = values.getSizes();
var height = viewBox.viewBox.height;
var y = height/2;
var width = viewBox.viewBox.width;
var x = width/2;
var Zoom1 = 1.02/(realZoom+0.02);
x = (realZoom-1)*0.95*x + 20;
y = (realZoom-1)*0.85*y + 20;
document.getElementById("tooltip").setAttribute("transform", "scale(" + Zoom1 + ") translate(" + x + "," + y + ")");
},
});
};
init();
</script>
我几天前更新了我的帖子…谢谢你的输入。我几天前更新了我的帖子…谢谢你的输入。
<h1>Demo for svg-pan-zoom: In-line SVG</h1>
<div id="container" style="width: 400px; height: 300px; border:1px solid black;">
<svg xmlns="http://www.w3.org/2000/svg" style="width: 400px; height: 300px; "version="1.1" id="map-svg">
<g id="circle">
<circle cx="102" cy="197.5" r="20" stroke="black" stroke-width="0.1" fill="red" />
<g id="tooltip" opacity="0.7" transform="translate(20 20)">
<rect x="104" y="197.5" width="80" height="40" rx="5"/>
<text x="107" y="209.5">Test</text>
</g>
</g>
</svg>
</div>
<script>
function init() {
window.zoomTiger = svgPanZoom('#map-svg', {
zoomEnabled: true,
controlIconsEnabled: true,
fit: false,
center: true,
minZoom: 1,
maxZoom: 50,
zoomScaleSensitivity: 0.5,
onZoom: function(){
//in the following segment I tried with different values to counter the zoom and the transform of the tooltip, but honestly I have no clue!
var values = svgPanZoom('#map-svg');
var realZoom = values.getZoom();
var viewBox = values.getSizes();
var height = viewBox.viewBox.height;
var y = height/2;
var width = viewBox.viewBox.width;
var x = width/2;
var Zoom1 = 1.02/(realZoom+0.02);
x = (realZoom-1)*0.95*x + 20;
y = (realZoom-1)*0.85*y + 20;
document.getElementById("tooltip").setAttribute("transform", "scale(" + Zoom1 + ") translate(" + x + "," + y + ")");
},
});
};
init();
</script>