Skip to content

Commit

Permalink
fix: latidude and longitude can be set (closes #373) (#374)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sirs0ri authored Apr 29, 2023
1 parent a3c9fcb commit d92df41
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 33 deletions.
6 changes: 4 additions & 2 deletions src/l10n/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ export default {
"Could not parse GeoJSON file": "Could not parse GeoJSON file",
"Could not parse overlay radius. Please make sure it is in the format `<length> <unit>`.":
"Could not parse overlay radius. Please make sure it is in the format `<length> <unit>`.",
"There was an error with the provided latitude and longitude. Using defaults.":
"There was an error with the provided latitude and longitude. Using defaults.",
"There was an error with the provided latitude. Using defaults.":
"There was an error with the provided latitude. Using defaults.",
"There was an error with the provided longitude. Using defaults.":
"There was an error with the provided longitude. Using defaults.",

//loader.ts
"There was an issue getting the image dimensions.":
Expand Down
4 changes: 3 additions & 1 deletion src/l10n/locales/zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export default {
"Could not parse GeoJSON file": "无法解析 GeoJSON 文件",
"Could not parse overlay radius. Please make sure it is in the format `<length> <unit>`.":
"无法解析覆盖半径. 请确保格式为 `<长度> <单位>`.",
"There was an error with the provided latitude and longitude. Using defaults.":
"There was an error with the provided latitude. Using defaults.":
"提供的纬度和经度有误. 使用默认值.",
"There was an error with the provided longitude. Using defaults.":
"提供的纬度和经度有误. 使用默认值.",

//loader.ts
Expand Down
53 changes: 23 additions & 30 deletions src/renderer/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,7 @@ export class LeafletRenderer extends MarkdownRenderChild {
}> {
let latitude = lat;
let longitude = long;
let coords: [number, number] = [undefined, undefined];
const coords: [number, number] = [undefined, undefined];
let zoomDistance, file;
if (typeof coordinates == "string" && coordinates.length) {
file = this.plugin.app.metadataCache.getFirstLinkpathDest(
Expand All @@ -1375,39 +1375,32 @@ export class LeafletRenderer extends MarkdownRenderChild {
map.log(`Using supplied coordinates [${latitude}, ${longitude}]`);
}

let err: boolean = false;
const convertedLatitude = Number(`${latitude}`?.split("%").shift());
const convertedLongitude = Number(`${longitude}`?.split("%").shift());
let convertedLatitude: number;
let convertedLongitude: number;

try {
coords = [convertedLatitude, convertedLongitude];
} catch (e) {
err = true;
convertedLatitude = Number(`${latitude}`?.split("%", 1)[0]);
} catch (error) {
new Notice(t("There was an error with the provided latitude. Using default."));
}

if (
(!isNaN(convertedLatitude) || !isNaN(convertedLongitude)) &&
(err || isNaN(coords[0]) || isNaN(coords[1]))
) {
new Notice(
t(
"There was an error with the provided latitude and longitude. Using defaults."
)
);
if (!isNaN(convertedLatitude)) {
coords[0] = convertedLatitude;
} else if (map.type === "real") {
coords[0] = this.plugin.data.lat;
} else {
coords[0] = 50;
}
if (map.type != "real") {
if (!isNaN(convertedLatitude) || isNaN(coords[0])) {
coords[0] = 50;
}
if (!isNaN(convertedLongitude) || isNaN(coords[1])) {
coords[1] = 50;
}
try {
convertedLongitude = Number(`${longitude}`?.split("%", 1)[0]);
} catch (error) {
new Notice(t("There was an error with the provided longitude. Using default."));
}
if (!isNaN(convertedLongitude)) {
coords[1] = convertedLongitude;
} else if (map.type === "real") {
coords[1] = this.plugin.data.long;
} else {
if (!isNaN(convertedLatitude) || isNaN(coords[0])) {
coords[0] = this.plugin.data.lat;
}
if (!isNaN(convertedLongitude) || isNaN(coords[1])) {
coords[1] = this.plugin.data.long;
}
coords[1] = 50;
}

return { coords, zoomDistance, file };
Expand Down

0 comments on commit d92df41

Please sign in to comment.