Ich benutze Angular2 und HTML5 Canvas. Basierend auf json zur Verfügung gestellt, möchte ich mehrere divs mit Canvas-Bereich in ihnen erstellen.Dynamisch mehrere Leinwand Bereich basierend auf JSON
Dies ist, wie mein divs mit Canvas-Bereich (HTML CODE)
<div class="masterpage" *ngFor="let x of masterPages" draggable [dragScope]="'masterpage'" [dragData]="x">
<canvas #myCanvas width="105" height="149" style="background:lightgray;"></canvas>
</div>
.ts Code
ngAfterViewInit() {
let canvas = this.myCanvas.nativeElement;
this.context = canvas.getContext("2d");
this.tick(this.masterPages);
}
tick(masterPages) {
var ctx = this.context;
ctx.clearRect(0, 0, 150, 150);
for (let j = 0; j < this.masterPages[this.count].areas.length; j++) {
ctx.fillStyle = this.masterPages[this.count].areas[j].type;
ctx.fillRect(masterPages[this.count].areas[j].x/2, masterPages[this.count].areas[j].y/2, masterPages[this.count].areas[j].width/2, masterPages[this.count].areas[j].height/2);
}
this.count = this.count + 1;
}
unten ist mein json beid Leinwand
masterPages = [{
areas: [
{
type: "FlowArea",
width: "183.0",
x: "12.0",
y: "40.0",
id: "FAR.1",
height: "237.0"
},
{
type: "StaticArea",
width: "210.0",
x: "0.0",
y: "7.0",
id: "SAR.2",
height: "25.0"
},
{
type: "StaticArea",
width: "210.0",
x: "0.0",
y: "282.0",
id: "SAR.1",
height: "15.0"
},
{
type: "StaticArea",
width: "2.0",
x: "6.0",
y: "26.0",
id: "SAR.3",
height: "256.0"
}
]
},
{
areas: [
{
type: "FlowArea",
width: "183.0",
x: "12.0",
y: "13.25",
id: "FAR.1",
height: "265.0"
},
{
type: "StaticArea",
width: "210.0",
x: "0.0",
y: "282.0",
id: "SAR.1",
height: "15.0"
}
]
}
];
nach json erzeugen sollte einige Formen haben, aber in meinem Fall kommt zweite Leinwand leer
Danke .. Für mich gearbeitet – dsnr