1

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

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

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

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

4

1 回答 1

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,...

于 2016-02-02T20:48:57.317 回答