Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

_loadImage() to public #31

Open
kochax opened this issue Aug 13, 2018 · 8 comments
Open

_loadImage() to public #31

kochax opened this issue Aug 13, 2018 · 8 comments
Assignees
Labels
bug next hotfix A bugfix update which helps the current codebase

Comments

@kochax
Copy link

kochax commented Aug 13, 2018

Would be nice to have a possibility to load image after the canvas is initialized. One of these options would be good to have:

  1. canvasWhiteboardComp.imageUrl = image;
    canvasWhiteboardComp.loadImage();
    
  2. or simply
    canvasWhiteboardComp.loadImage(image);

@Peshou
Copy link
Collaborator

Peshou commented Aug 13, 2018

Hi @kochax,

I am not really sure how you intend to use this functionality.

The _loadImage is private and it's executed whenever the imageUrl is changed (in the ngOnChanges method). This is why the image will always be redrawn if changed (along with some missing updates) and there would be no need to call this method manually.

If you could perhaps explain me your use case, we may be able to work out some alternative, but for now i do not think there will be any need to allow access to this method.

Best,
Stefan

@kochax
Copy link
Author

kochax commented Aug 13, 2018

@Peshou Thank you for the fast response.

I just can confirm that there is ngOnChanges check for image url changes, but logs that I have put, never occurs.

image

Simply calling _loadImage worked fine:

this.canvasWhiteboard.imageUrl = someBase64;
this.canvasWhiteboard['_loadImage()']; // :)

Without the second line, does not work.

@Peshou
Copy link
Collaborator

Peshou commented Aug 13, 2018

Okay let me look into this since it may be some kind of bug if the method is not being invoked

@Peshou
Copy link
Collaborator

Peshou commented Aug 13, 2018

Could you try to edit the canvas component directly or make a canvas options object which is linked to the component itself?

Example:

 <canvas-whiteboard [imageUrl]="someBase64">
    </canvas-whiteboard>

Or

 <canvas-whiteboard [options]="options">
    </canvas-whiteboard>
options: CanvasWhiteboardOptions = {
};

then somewhere in the code

this.options.imageUrl=someBase64;

Your issue seems to occur when manually changing the input value without letting angular check for changes. Because of this, thengOnChanges method won't register input changes so the redraw code won't execute. I think the second solution with the options object should help you with your issue and it should be a bit cleaner for other inputs you may wish to change.

@kochax
Copy link
Author

kochax commented Aug 13, 2018

The example I posted, was directly editing of canvasComponent instance property, the solution that you proposed also didn`t work for me. Here is the example:

<canvas-whiteboard #canvasWhiteboard [options]="canvasOptions" (onBatchUpdate)="onCanvasDraw($event)"></canvas-whiteboard>

Options:

this.canvasOptions = { strokeColor: 'rgb(255, 255, 255)', lineWidth: 5, drawButtonEnabled: false, clearButtonEnabled: false, undoButtonEnabled: false, redoButtonEnabled: false, saveDataButtonEnabled: false, colorPickerEnabled: false, shouldDownloadDrawing: false, startingColor: 'transparent', drawingEnabled: false, showStrokeColorPicker: false, showFillColorPicker: false, shapeSelectorEnabled: false, showShapeSelector: false } as CanvasWhiteboardOptions;

And somewhere in the code:

this.canvasOptions.imageUrl = base64;

Nothing happened. I have tried to subscribe to onImageLoaded event before changing of the URL (also with callback), nothing resolved

@Peshou
Copy link
Collaborator

Peshou commented Aug 13, 2018

Okay, thanks, this is an issue and should be handled accordingly, since this is the correct way to change the imageUrl.

I will update the library with a patch version v2.0.4 and you should be able to have this functionality available.

In the meantime, I think that you can work out your problem by directly accessing the imageUrl input in the canvas without using the options object.

this.imageUrl = base64;
<canvas-whiteboard #canvasWhiteboard [imageUrl]="imageUrl" (onBatchUpdate)="onCanvasDraw($event)"></canvas-whiteboard>

Thanks for the observation and help. I will try to attend to this as soon as possible.

Best,
Stefan

@Peshou Peshou closed this as completed Aug 13, 2018
@Peshou Peshou reopened this Aug 13, 2018
@Peshou Peshou self-assigned this Aug 13, 2018
@Peshou Peshou added bug next hotfix A bugfix update which helps the current codebase labels Aug 13, 2018
@kochax
Copy link
Author

kochax commented Aug 14, 2018

I can live with that :)
Thank you for being ready to help,

Best Regards,
Jovan

@Peshou
Copy link
Collaborator

Peshou commented Aug 15, 2018

Yeah, and until I roll this fix out, you should download the 2.0.3 version of the canvas that I released today so that you can get the fix for the flicker that appears when you draw on a canvas with an image as background.

I'll try to tend to your issue really soon.

Best Regards,
Stefan

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug next hotfix A bugfix update which helps the current codebase
Projects
None yet
Development

No branches or pull requests

2 participants