Skip to content

Instantly share code, notes, and snippets.

@sebmarkbage
Created November 15, 2010 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebmarkbage/700555 to your computer and use it in GitHub Desktop.
Save sebmarkbage/700555 to your computer and use it in GitHub Desktop.
var readSVG = function(text, doc){
var svg = doc.documentElement;
var w = +svg.getAttribute('width'), h = +svg.getAttribute('height');
w = 500;
h = 400;
var art = new ART(w, h);
art.element.setAttribute('viewBox', svg.getAttribute('viewBox'));
var root = new ART.Group().inject(art);
var node = svg;
var parent = root;
var count = 0;
treewalker: while (node){
var shape;
if (node.nodeType == 1){
if (node.nodeName == 'path'){
shape = new ART.Shape(node.getAttribute('d')).inject(parent);
} else if (node.nodeName == 'g'){
shape = new ART.Group().inject(parent);
}
if (shape && shape.fill && /land/.test(node.getAttribute('class'))){
shape.fill('#b9b9b9');
//shape.stroke('#ffffff');
}
}
if (node.firstChild){
node = node.firstChild;
if (shape) parent = shape;
} else {
while (!node.nextSibling){
node = node.parentNode;
if (!node || node == svg) break treewalker;
if (node.nodeName == 'path' || node.nodeName =='g') parent = parent.container;
}
node = node.nextSibling;
}
if (count++ > 10000) break;
}
};
new Request.XML({ url: 'BlankMap.svg', onSuccess: readSVG }).get();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment