javalent / obsidian-leaflet

Adds interactive maps to Obsidian.md using Leaflet.js
468 stars 26 forks source link

šŸž Location in frontmatter cannot be parsed unless manually changed in an external program #431

Open rchaklashiya opened 6 months ago

rchaklashiya commented 6 months ago

Check for existing bug reports before submitting.

Expected Behavior

If I add a location to a note's frontmatter, let's say location: [x, y] where x and y are floating point numbers, and try to load the location in the map (using markerfile command), I should get the location marker at that point in the map.

Current behaviour

If I add a location to a note's frontmatter, let's say location: [x, y] where x and y are floating point numbers, and try to load the location in the map (using markerfile command), I instead get a "could not parse location" error popup. The map loads fine but the marker for the note that I was trying to parse doesn't show up at all. This was in my vault with a bazillion different notes and plugins in it. When I used a dummy vault with only one plugin (leaflet) and two notes (dummy-page and map) I could not get the map to load at all if I tried to load the page with the frontmatter coordinates using the markerfile command. It instead gave a different error, "Could not parse lattitude."

Digging deeper, it seems like obsidian will not allow that to be a property of a note. It will do one of two things to it:

  1. If editing in live preview mode, it will turn it into location: "[x, y]" or location: '[x,y]' (the quotation marks become a part of it)
  2. If editing in source mode, it will turn into three lines: location:
    • x
    • y

The only way I could get it to work was by leaving the note in live preview mode, opening the note in an external program, and manually changing it to [x, y] in there. HOWEVER, when I tried to automate this process (i.e. using python to automatically change all location notes from the above two formats to the [x, y] format) the automation succeeds but as soon as I try to check it onto the map it seems like obsidian itself checks the note and changes it to one of the two aforementioned formats, so it won't show up on the map.

So what this means is, there is no convenient way to parse location on different notes' frontmatter in obsidian. The only way to do it is to manually change it in a different app (e.g. notepad++) and be very careful not to open that note in obsidian source mode. Can't automate it, and can't edit it in obsidian.

Reproduction

  1. Have Leaflet plugin installed
  2. Create a new empty note where you put in a map (can just copy-paste a default from the instructions on the github, using openstreetmap as the layer), here is one example (that includes the line added from step 5):
    id: leaflet-map
    image: 
    height: 500px
    lat: 50
    long: 50
    minZoom: 1
    maxZoom: 10
    defaultZoom: 5
    unit: meters
    scale: 1
    marker: default
    darkMode: true
    markerFile: [[dummy-page]]
  3. Create a different empty note called "dummy-page" and add one property to it, "location", and attempt to add coordinates to it (e.g. [100,50])
  4. Go back to the note with the map and add a line "markerFile: [[dummy-page]]"
  5. You will find that obsidian leaflet cannot load the coordinates for that page as a marker

Which Operating Systems are you using?

Obsidian Version Check

1.5.3, installer version 1.4.16

Plugin Version

6.0.1

Confirmation

Possible solution

I think it should be a simple fix. Wherever in the plugin it tries to parse frontmatter for different notes, have it search for instances of "[x,y]" in addition to [x,y]. That's it. If there is a simple way to parse multiline, then also add in a parser for line 1: - x line 2: - y so that you get both possibilities. I know this can easily be done in python so hopefully it can easily be done in javascript too.

JulianBerkner commented 4 months ago

Hi, I had this problem too, but I could "fix" it by just changing the type of frontmatter to list: image Then click the location field and just add "lat" Enter "lon" Enter The "times" symbol (x) will be automatically added by Obsidian (when pressing Enter). If I open the markdown file in an external editor this is what I get:

---
location:
  - "50.954468"
  - "1.862801"
---

This works: image

Here is the snippet for the map, even though I dont think it really matters for this problem (and is more or less taken from the README):

id: leaflet-map
height: 1000px
lat: 45.815399
long: 15.966568
minZoom: 1
maxZoom: 15
defaultZoom: 6
unit: m
scale: 1
darkMode: false
markerTag:
  - [pnp, my_campaign, poi]
jordanmills commented 1 month ago

I just ran into this one soon.

What would be really great is if it could parse a value with a preceding name, like some others do: Houston, Texas [29, -95] That would let me (and maybe others) keep the same property values.