javalent / obsidian-leaflet

Adds interactive maps to Obsidian.md using Leaflet.js
481 stars 29 forks source link

[Bug] Can't center a map on [0, 0] #362

Closed Sirs0ri closed 1 year ago

Sirs0ri commented 1 year ago

In the yaml-settings of a map, it's not possible to center it on the LatLong [0, 0]. Doing so will cause leaflet to use the default coordinates as configured in the settings. A workaround is to enter the coordinates as strings, see below:

Example code:

This should produce a map of the South Atlantic Ocean near Africa's west-coast, but shows Indianapolis instead:

id: test
lat: 0
long: 0

This config will produce the desired result:

id: test
lat: "0"
long: "0"

Obsidian Version: 1.1.16 Leaflet Version: 5.2.6

Potential fix

The issue is caused by a couple of boolean comparisons (starting here) on the supplied lat/long that should probably just be replaced with undefined checks?

For example:

if (!latitude || isNaN(coords[0])) {
    coords[0] = this.plugin.data.lat;
}

should be turned into:

if (latitude == null || isNaN(coords[0])) {
    coords[0] = this.plugin.data.lat;
}

If that's all it would take, I'm happy to open a PR, but I'm not sure I missed something else since this codebase is quite extensive! :D

sigrunixia commented 1 year ago

This should be completed @Sirs0ri. If there appears to be an issue regarding this functionality, then feel free to create a new thread. :)