Autosize both sprites (fixes #1116)

This commit is contained in:
John Firebaugh
2013-03-22 16:22:18 -07:00
parent 25f22bc3f3
commit 1c3b817b89
+18 -20
View File
@@ -5,6 +5,17 @@ iD.svg.Surface = function() {
});
}
function autosize(image) {
var img = document.createElement('img');
img.src = image.attr('xlink:href');
img.onload = function() {
image.attr({
width: img.width,
height: img.height
});
};
}
function sprites(stylesheetName, selectorRegexp) {
var sprites = [];
@@ -90,12 +101,9 @@ iD.svg.Surface = function() {
.attr('height', function(d) { return d; });
defs.append('image')
.attr({
id: 'sprite',
width: 460,
height: 320,
'xlink:href': 'img/sprite.png'
});
.attr('id', 'sprite')
.attr('xlink:href', 'img/sprite.png')
.call(autosize);
defs.selectAll()
.data(sprites("app.css", /^\.(icon-operation-[a-z0-9-]+)$/))
@@ -104,20 +112,10 @@ iD.svg.Surface = function() {
.attr('transform', function(d) { return "translate(" + d.x + "," + d.y + ")"; })
.attr('xlink:href', '#sprite');
var image = defs.append('image')
.attr({
id: 'maki-sprite',
'xlink:href': 'img/feature-icons.png'
});
var img = document.createElement('img');
img.src = 'img/feature-icons.png';
img.onload = function() {
image.attr({
width: img.width,
height: img.height
});
};
defs.append('image')
.attr('id', 'maki-sprite')
.attr('xlink:href', 'img/feature-icons.png')
.call(autosize);
defs.selectAll()
.data(sprites("feature-icons.css", /^\.(feature-[a-z0-9-]+-(12|18))$/))