Skip to content

Commit d92df41

Browse files
authored
fix: latidude and longitude can be set (closes #373) (#374)
1 parent a3c9fcb commit d92df41

File tree

3 files changed

+30
-33
lines changed

3 files changed

+30
-33
lines changed

src/l10n/locales/en.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ export default {
1313
"Could not parse GeoJSON file": "Could not parse GeoJSON file",
1414
"Could not parse overlay radius. Please make sure it is in the format `<length> <unit>`.":
1515
"Could not parse overlay radius. Please make sure it is in the format `<length> <unit>`.",
16-
"There was an error with the provided latitude and longitude. Using defaults.":
17-
"There was an error with the provided latitude and longitude. Using defaults.",
16+
"There was an error with the provided latitude. Using defaults.":
17+
"There was an error with the provided latitude. Using defaults.",
18+
"There was an error with the provided longitude. Using defaults.":
19+
"There was an error with the provided longitude. Using defaults.",
1820

1921
//loader.ts
2022
"There was an issue getting the image dimensions.":

src/l10n/locales/zh_CN.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ export default {
1313
"Could not parse GeoJSON file": "无法解析 GeoJSON 文件",
1414
"Could not parse overlay radius. Please make sure it is in the format `<length> <unit>`.":
1515
"无法解析覆盖半径. 请确保格式为 `<长度> <单位>`.",
16-
"There was an error with the provided latitude and longitude. Using defaults.":
16+
"There was an error with the provided latitude. Using defaults.":
17+
"提供的纬度和经度有误. 使用默认值.",
18+
"There was an error with the provided longitude. Using defaults.":
1719
"提供的纬度和经度有误. 使用默认值.",
1820

1921
//loader.ts

src/renderer/renderer.ts

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,7 @@ export class LeafletRenderer extends MarkdownRenderChild {
13511351
}> {
13521352
let latitude = lat;
13531353
let longitude = long;
1354-
let coords: [number, number] = [undefined, undefined];
1354+
const coords: [number, number] = [undefined, undefined];
13551355
let zoomDistance, file;
13561356
if (typeof coordinates == "string" && coordinates.length) {
13571357
file = this.plugin.app.metadataCache.getFirstLinkpathDest(
@@ -1375,39 +1375,32 @@ export class LeafletRenderer extends MarkdownRenderChild {
13751375
map.log(`Using supplied coordinates [${latitude}, ${longitude}]`);
13761376
}
13771377

1378-
let err: boolean = false;
1379-
const convertedLatitude = Number(`${latitude}`?.split("%").shift());
1380-
const convertedLongitude = Number(`${longitude}`?.split("%").shift());
1378+
let convertedLatitude: number;
1379+
let convertedLongitude: number;
1380+
13811381
try {
1382-
coords = [convertedLatitude, convertedLongitude];
1383-
} catch (e) {
1384-
err = true;
1382+
convertedLatitude = Number(`${latitude}`?.split("%", 1)[0]);
1383+
} catch (error) {
1384+
new Notice(t("There was an error with the provided latitude. Using default."));
13851385
}
1386-
1387-
if (
1388-
(!isNaN(convertedLatitude) || !isNaN(convertedLongitude)) &&
1389-
(err || isNaN(coords[0]) || isNaN(coords[1]))
1390-
) {
1391-
new Notice(
1392-
t(
1393-
"There was an error with the provided latitude and longitude. Using defaults."
1394-
)
1395-
);
1386+
if (!isNaN(convertedLatitude)) {
1387+
coords[0] = convertedLatitude;
1388+
} else if (map.type === "real") {
1389+
coords[0] = this.plugin.data.lat;
1390+
} else {
1391+
coords[0] = 50;
13961392
}
1397-
if (map.type != "real") {
1398-
if (!isNaN(convertedLatitude) || isNaN(coords[0])) {
1399-
coords[0] = 50;
1400-
}
1401-
if (!isNaN(convertedLongitude) || isNaN(coords[1])) {
1402-
coords[1] = 50;
1403-
}
1393+
try {
1394+
convertedLongitude = Number(`${longitude}`?.split("%", 1)[0]);
1395+
} catch (error) {
1396+
new Notice(t("There was an error with the provided longitude. Using default."));
1397+
}
1398+
if (!isNaN(convertedLongitude)) {
1399+
coords[1] = convertedLongitude;
1400+
} else if (map.type === "real") {
1401+
coords[1] = this.plugin.data.long;
14041402
} else {
1405-
if (!isNaN(convertedLatitude) || isNaN(coords[0])) {
1406-
coords[0] = this.plugin.data.lat;
1407-
}
1408-
if (!isNaN(convertedLongitude) || isNaN(coords[1])) {
1409-
coords[1] = this.plugin.data.long;
1410-
}
1403+
coords[1] = 50;
14111404
}
14121405

14131406
return { coords, zoomDistance, file };

0 commit comments

Comments
 (0)