esm7 / obsidian-map-view

Interactive map view for Obsidian.md
MIT License
546 stars 25 forks source link

reading dataview-generated inline links does not work #204

Open johnrobertcobbold opened 9 months ago

johnrobertcobbold commented 9 months ago

Hello,

First of all thank you so much for this plugin, I am just starting diving into obsidian and the plugin really adds an indispensable geo dimension which is very valuable.

Where I can indeed make standard geo location links be recognized and have the Interactive Map View follow them, it does not seem to work if I have those links generated by dataview. Here is an example which hopefully would fetch all notes from the "Locations" folder and use their location frontmatter to generate inline geo links which would then be recognized by the Map View. A geo link is successfully generated and I can click on it to open the map, but the Map View is not doing its job

dataviewjs

const query = `
LIST
    "[location](geo:"+file.frontmatter.location[0]+","+file.frontmatter.location[1]+")"
FROM "Locations"

`;

dv.execute(query)
esm7 commented 9 months ago

First of all, thank you for the kind words! To some extent, the fact geo links are generated in the dataviewjs blocks is a bug or an unintended feature :sweat_smile: There is a Markdown post processor that Map View installs and recognizes the link although they are not "truly" present in the file. However, when the main map view transverses your notes, the geolinks are not really there. To mitigate this, Map View would need to use the Dataview API and execute (then probably cache the results of) these queries. I am not sure what are the performance implications of doing this for a large number of notes when they are searched for geolinks. Integration with Dataview is something I've been wanting to do for a long time, it's definitely in the roadmap, I just can't point out a timeline yet. (Some developer who's interested in investigating this and can push it forward will surely help!) BTW, for general knowledge, what is the use case for which you are generating inline geolinks inside a query that seems to take locations from other notes? Seems like you are using the location field of other notes in this query, which Map View can display directly. (And actually, seems like showing them as part of the note with the query, makes an opening to duplicating them many times)

johnrobertcobbold commented 9 months ago

Thanks for the comprehensive answer! My use case is the following (this is my first day using Obsidian so hopefully I will not say silly things)

I created a folder called Location where I aim to create a note for each meaningful location. Each note has its location field with its coordinates. For example, let's say two notes:

Note1: Cafe Alpha Note: Location Beta

Moving forward, when I am taking notes, I thought about being able to quickly to link to a location by typing something like:

Meeting at [[Cafe Alpha]] which allows the use of the auto-complete (i.e. typing [[Caf..]] suggests the Cafe Alpha note which is perfect).

I was then hoping to then add something along the line of the following at the top/bottom of a note - and hopefully a template which is something that I still to dive into -


dataviewjs
const query = `
TABLE without ID 
    "["+file.name+"](geo:"+file.frontmatter.location[0]+","+file.frontmatter.location[1]+")"
FROM "Locations"
WHERE regextest(this.file.name, file.inlinks.filename)
`;

dv.execute(query)

...with the hope that this would automatically generate a list of inline geo link(s) which would then be picked up by the Interactive View Map so that I can open such a note and see the location on the map.

esm7 commented 9 months ago

Creating a note for each meaningful location is a great way to go (I do that too for very often), with the auto-complete and everything. However, sounds to me like you can accomplish what you're looking for without DataviewJS. Just create an embedded map as part of your template, use the $filename$ parameter (see here ), with a query similar to the example given there that uses linkedfrom:, and you're good to go.

johnrobertcobbold commented 9 months ago

Glad that we share the same view on having one note for meaningful locations! Yes, you are right, it does pretty much achieve the same result @esm7 , thank you, that's how I will use your amazing plugin for now! Here is still some feedback with the aim of further improving things :)

You are obviously right that there would be some integration to go over though, as introduced on this page: https://blacksmithgu.github.io/obsidian-dataview/resources/develop-against-dataview/

Again, I just installed Obsidian so please take my feeedback with a grain of salt. On the other hand, thanks again for having set up this plugin, I see it as a must have.

esm7 commented 9 months ago

Can you elaborate about your interactive map view not getting populated? Basically the embedded map uses the exact same data flow and code, so if one works the other should work as well. How are you opening the map (i.e. are you possibly opening it with some query that hides some of the markers)?