问题
I'm wondering about the behavior of {Shape}.attr("fill","url({image.path})")
.
when applying a fill image to a shape:
public class AppMapCanvas extends Raphael {
public AppMapCanvas(int width, int height) {
super(width, height);
this.hCenter = width / 2;
this.vCenter = height / 2;
...
Rect rect = this.new Rect(hCenter, vCenter, 144, 40, 4);
rect.attr("fill", "url('../images/app-module-1-bg.png')"); // <--
...
}
}
The background image seem to teal accross the canvas behind the shape, thus gets weird positioning (an illustration snapshot is enclosed - i marked the original image borders in red).

This seem to resolve itself in the presence of an animation along a path (a mere path.M(0,0)
is sufficiant).
How can i position the fill-image properly in the first place?
回答1:
The proper way to do this from what I can understand would be to use an SVG pattern declaration to specify the portion and position of the image you would want to use. Then you would use that pattern to fill the rectangle element. Unfortunately, the Raphael javascript library doesn't have support for patterns... so there's no direct way to use an image to fill a rectangle.
来源:https://stackoverflow.com/questions/4769538/raphael-gwt-fill-image-of-a-shape-rect-appears-offset-how-to-resolve-this