Skip to content

Commit 505e3b2

Browse files
committed
fix: Fixes some instances where custom marker images were not resized
1 parent a0ccafc commit 505e3b2

File tree

2 files changed

+15
-24
lines changed

2 files changed

+15
-24
lines changed

src/modals/settings.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -173,23 +173,18 @@ export class CreateMarkerModal extends Modal {
173173
var image = new Image();
174174
image.onload = () => {
175175
this.canvas = iconDisplay.createEl("canvas");
176-
this.canvas.style.width = "100%";
177-
this.canvas.style.height = "100%";
178-
this.canvas.width = this.canvas.offsetWidth;
179-
this.canvas.height = this.canvas.offsetHeight;
176+
const max_size = 24;
180177
let width = image.width,
181178
height = image.height;
182-
if (width < height) {
183-
if (width > this.canvas.width) {
184-
height *= this.canvas.width / width;
185-
width = this.canvas.width;
186-
}
187-
} else {
188-
if (height > this.canvas.height) {
189-
width *= this.canvas.height / height;
190-
height = this.canvas.height;
191-
}
179+
if (width > height && width > max_size) {
180+
height *= max_size / width;
181+
width = max_size;
182+
} else if (height > width && height > max_size) {
183+
width *= max_size / height;
184+
height = max_size;
192185
}
186+
this.canvas.width = width;
187+
this.canvas.height = height;
193188
this.canvas
194189
.getContext("2d")
195190
.drawImage(image, 0, 0, width, height);

src/settings/settings.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,12 @@ export class ObsidianLeafletSettingTab extends PluginSettingTab {
175175
max_size = 24;
176176
let width = image.width,
177177
height = image.height;
178-
if (width > height) {
179-
if (width > max_size) {
180-
height *= max_size / width;
181-
width = max_size;
182-
}
183-
} else {
184-
if (height > max_size) {
185-
width *= max_size / height;
186-
height = max_size;
187-
}
178+
if (width > height && width > max_size) {
179+
height *= max_size / width;
180+
width = max_size;
181+
} else if (height > width && height > max_size) {
182+
width *= max_size / height;
183+
height = max_size;
188184
}
189185
canvas.width = width;
190186
canvas.height = height;

0 commit comments

Comments
 (0)