Я хочу дать существующее число из базы данных, внутри функции и поместить его в качестве значения в context.drawImage, я действительно не знаю, как это объяснить, поэтому, пожалуйста, взгляните на код, тогда он будет более ясно
"this is what i have tried to do"
"data = DataBaseService"
x:IArea;
floors: IFloor;
areas:IArea;
constructor(public data: DatabaseService, public activatedRoute: ActivatedRoute, public navCtrl: NavController, public route: Router, public service: DatabaseService) {
this.id = this.activatedRoute.snapshot.params['id'];
this.data.GetSingleFloor(this.id).subscribe((floor) => {
console.log(floor);
this.floors = floor;
},
(error : HttpErrorResponse) =>{
this.route.navigate(['/pagenotfound'])
})
this.data.GetArea().subscribe((area) => {
console.log(area);
this.areas = area;
this.x.startX = area.startX
this.draw(this.floors.blueprint, this.x);
})
}
draw(image:string, coordinateX:IArea){
this.canvas.width = 626;
this.canvas.height = 434;
this.context.fillRect(0, 0, this.canvas.width, this.canvas.height);
this.mapSprite.src = image;
/* "http://antyradar.info/wp-content/uploads/commercial-tumilty-design-commercial-floor-plans.jpg" */
this.Sprite.src = "https://www.lasvegas-waterdelivery.com/wp-content/uploads/2016/07/5gal-cropped.png"
this.context.drawImage(this.mapSprite, 0, 0, 626, 434)
this.context.drawImage(this.Sprite, coordinateX.startX, 161, 12, 20);
this.context.drawImage(this.Sprite, 342, 262, 12, 20);
}
________________________________________________________________
"original code"
constructor(public data: DatabaseService, public activatedRoute: ActivatedRoute, public navCtrl: NavController, public route: Router, public service: DatabaseService) {
this.id = this.activatedRoute.snapshot.params['id'];
this.data.GetSingleFloor(this.id).subscribe((floor) => {
console.log(floor);
this.floors = floor;
this.draw(this.floors.blueprint);
},
(error : HttpErrorResponse) =>{
this.route.navigate(['/pagenotfound'])
})
this.data.GetArea().subscribe((area) => {
console.log(area);
this.areas = area;
})
}
draw(image:string){
this.canvas.width = 626;
this.canvas.height = 434;
this.context.fillRect(0, 0, this.canvas.width, this.canvas.height);
this.mapSprite.src = image;
/* "http://antyradar.info/wp-content/uploads/commercial-tumilty-design-commercial-floor-plans.jpg" */
this.Sprite.src = "https://www.lasvegas-waterdelivery.com/wp-content/uploads/2016/07/5gal-cropped.png"
this.context.drawImage(this.mapSprite, 0, 0, 626, 434)
this.context.drawImage(this.Sprite, 220, 161, 12, 20);
this.context.drawImage(this.Sprite, 342, 262, 12, 20);
}
Я ожидаю, что координата X будет иметь значение startX базы данных, но это дает мне свойство startX undefined
введите описание изображения здесь