将sourceCrossOrigin设置为所有图片

时间:2016-01-31 11:36:34

标签: cors gojs

我正在使用Gojs 1.5.2。 我在S3的画布上加载图片。桶有CORS。

当我使用Diagram.makeImageData()时,我得到白色空白而不是我的图片。 这在此解释 - makeImageData

解决方案是使用sourceCrossOrigin匿名,这似乎有用。

有没有办法在一个地方为所有我的Picture类定义sourceCrossOrigin而不是每一个?

1 个答案:

答案 0 :(得分:0)

许多示例使用称为textStyle()之类的函数来确保TextBlock都具有一致的属性集。有关示例,请参阅OrgChartEditor中的代码。

// This function provides a common style for most of the TextBlocks.
// Some of these values may be overridden in a particular TextBlock.
function textStyle() {
  return { font: "9pt  Segoe UI,sans-serif", stroke: "white" };
}

然后像这样使用它:

...
$(go.TextBlock, textStyle(),
  { row: 2, column: 0 },
  new go.Binding("text", "key", function(v) {return "ID: " + v;})),
$(go.TextBlock, textStyle(),
  { row: 2, column: 3, },
  new go.Binding("text", "parent", function(v) {return "Boss: " + v;})),
$(go.TextBlock, textStyle(),  // the comments
  {
...

或者,您可以覆盖图片。这是一个例子:

function CustomPicture() {
  go.Picture.call(this);
  this.sourceCrossOrigin = function() { return 'anonymous' };
}
go.Diagram.inherit(CustomPicture, go.Picture);

然后在任何地方使用$(CustomPicture,...而不是$(go.Picture,...