Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悶 Location in frontmatter cannot be parsed unless manually changed in an external program #431

Open
3 of 7 tasks
rchaklashiya opened this issue Dec 29, 2023 · 1 comment

Comments

@rchaklashiya
Copy link

rchaklashiya commented Dec 29, 2023

Check for existing bug reports before submitting.

  • I searched for existing Bug Reports and found no similar reports.

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]]
  1. 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])
  2. Go back to the note with the map and add a line "markerFile: [[dummy-page]]"
  3. You will find that obsidian leaflet cannot load the coordinates for that page as a marker

Which Operating Systems are you using?

  • Android
  • iPhone/iPad
  • Linux
  • macOS
  • Windows

Obsidian Version Check

1.5.3, installer version 1.4.16

Plugin Version

6.0.1

Confirmation

  • I have disabled all other plugins and the issue still persists.

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.

@rchaklashiya rchaklashiya changed the title 馃悶 Location of frontmatter cannot be parsed unless manually changed in an external program 馃悶 Location in frontmatter cannot be parsed unless manually changed in an external program Dec 29, 2023
@JulianBerkner
Copy link

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]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants