So i'm working on developing a map with svg and I wanted to be able to on user input zoom into a predefined area within my svg( a state or country ). I found a tutorial that does exactly this as well as animates it, which is here: https://css-tricks.com/interactive-data-visualization-animating-viewbox/ Also their codepen is here: https://codepen.io/sdras/pen/512230ed732f9b963ad3e50c8d4dcbb8
Now I'm having problems replicating this with my own svg. When I tell it to zoom into a certain area it will zoom into another area. I've tried copying the exact structure of their code with no success. I'm starting to think that the error is within my SVG itself.
HTML:
<svg id="foo" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 1440 776">
Then too much code to copy and paste here.
SASS:
html
body
svg
width: 100vw
height: 100vh
JQuery:
var test = document.getElementById("_x32_");
console.log(test);
var s = test.getBBox();
//check the console for the SVGRect object
console.log( s );
//we store the values from the object as our new viewBox string
var newView = "" + s.x + " " + s.y + " " + s.width + " " + s.height;
console.log(newView);
//we then set the new viewBox string as the viewBox attribute on the SVG
var foo = document.getElementById("foo");
console.log(foo);
//foo.setAttribute("viewBox", newView);
The CodePen is here: https://codepen.io/mat148/pen/xqWMXR