admin管理员组文章数量:1434954
I am trying to implement some kind of Zoom/Pan features to maps generated with the google geochart API. There are some scripts online to zoom/pan svg images, but I am not succeeding in implementing them to the SVGs that the geochart api generates.
I am trying the SVGPan library /
The code I'm using to append the script to the SVG is:
google.visualization.events.addListener(chart, 'ready', function () {
var script = document.createElementNS('', 'script');
script.setAttributeNS('', 'xlink:href', '.js');
var svg = document.getElementsByTagName('svg')[0];
svg.appendChild(script);
});
Here's the jsfiddle:
/
With Firebug I can see the script is beeing place on the svg, but nothing happens, it doesn't implement the features in the svg, as expected.
I am not sure if this line is correct, since I didn't find any example online:
var script = document.createElementNS('', 'script');
Am I doing something wrong, or what I'm trying to do will be impossible?
Thanks for you help! Cheers Carlos
I am trying to implement some kind of Zoom/Pan features to maps generated with the google geochart API. There are some scripts online to zoom/pan svg images, but I am not succeeding in implementing them to the SVGs that the geochart api generates.
I am trying the SVGPan library http://code.google./p/svgpan/
The code I'm using to append the script to the SVG is:
google.visualization.events.addListener(chart, 'ready', function () {
var script = document.createElementNS('http://www.w3/2000/svg', 'script');
script.setAttributeNS('http://www.w3/1999/xlink', 'xlink:href', 'http://www.cyberz/projects/SVGPan/SVGPan.js');
var svg = document.getElementsByTagName('svg')[0];
svg.appendChild(script);
});
Here's the jsfiddle:
http://jsfiddle/cmoreira/CetaA/
With Firebug I can see the script is beeing place on the svg, but nothing happens, it doesn't implement the features in the svg, as expected.
I am not sure if this line is correct, since I didn't find any example online:
var script = document.createElementNS('http://www.w3/2000/svg', 'script');
Am I doing something wrong, or what I'm trying to do will be impossible?
Thanks for you help! Cheers Carlos
Share Improve this question asked Nov 6, 2012 at 18:32 CMoreiraCMoreira 1,7081 gold badge12 silver badges27 bronze badges2 Answers
Reset to default 3After some experiments, I was able to find a simple solution and since there were not any valuable answers so far, I decided to share what I have so far.
I decided to do it with CSS, redrawing the map with different values on zoom in/out and hide the overflow with CSS.
Here's a working example:
http://jsfiddle/cmoreira/CCUpf/
CSS
#canvas {
width:400px;
height:300px;
overflow:hidden;
}
#visualization {
top:0px;
left:0px;
}
Zoom/Pan Javascript
function zoomin() {
mw = mw+50;
mh = mh+50;
x = x-25;
y = y-25;
document.getElementById('visualization').style.top = y +'px';
document.getElementById('visualization').style.left = x +'px';
drawVisualization(mw,mh);
}
function zoomout() {
if(mw > 600) {
mw = mw-50;
mh = mh-50;
x = x+25;
y = y+25;
document.getElementById('visualization').style.top = y +'px';
document.getElementById('visualization').style.left = x +'px';
drawVisualization(mw,mh);
}
}
function left() {
x = x-50;
document.getElementById('visualization').style.left = x +'px';
}
function right() {
x = x+50;
document.getElementById('visualization').style.left = x +'px';
}
function up() {
y = y-50;
document.getElementById('visualization').style.top = y +'px';
}
function down() {
y = y+50;
document.getElementById('visualization').style.top = y +'px';
}
I know this is a very poor zoom/pan feature for the google geochart API, but it's something, right?
Any improvements to this simple aproach would be weled. Thanks!
I would remend you to try jVectorMap instead. It has support for the zoom/pan with mouse or touch events.
本文标签: javascriptAppend ZoomPan Script to SVG From Google GeochartStack Overflow
版权声明:本文标题:javascript - Append ZoomPan Script to SVG From Google Geochart - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745637110a2667626.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论