Created
November 15, 2010 16:32
-
-
Save sebmarkbage/700555 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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