最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Append ZoomPan Script to SVG From Google Geochart - Stack Overflow

matteradmin7PV0评论

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 badges
Add a ment  | 

2 Answers 2

Reset to default 3

After 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.

Post a comment

comment list (0)

  1. No comments so far