esm7 / obsidian-map-view

Interactive map view for Obsidian.md

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Only show locations from current note in embedded map

ltroj opened this issue · comments

commented

Is there a way to write a query (maybe using path) that makes an embedded map show only the locations from the note it is embedded in?

90% of the time I simply want to add a map at the end of the note showing all inline geo-locations but that means to update the query to match the path of the current note everytime.

commented

See the suggestion here: #140
I believe that together with the Templater plugin, you can easily set up what you're looking for.

commented

Yes, that's certainly a workaround.

For future reference, here is the template which I use for now.

```mapview
{"name":"Default","mapZoom":8,"centerLat":38.58252615935333,"centerLng":-99.83745527819484,"query":"path:\"<% tp.file.path(true) %>\" ","chosenMapSource":0,"embeddedHeight":800}
```

In a future realease it would be nice to have the possibility to write a query like "query":"thisNote" to achieve the same result.

Thanks for helping out and this useful plugin in general!

commented

Thanks for sharing!
Whether Map View should implement this internally is something I'm in a dilemma about.
On one hand, this is surely a useful feature, and having it built into Map View would make it cleaner and in some edge cases also better (e.g. if you copy the snippet to a different note it would work as expected).
On the other hand, every extra new feature adds a bit more stuff to maintain from that point onward, while at the same time there is a plugin that specializes in perfecting 90% of this behavior (and provides a much richer syntax than what I'd probably take upon myself to maintain).
If while working with this workaround you reach useful insights, I'd love to hear.

commented

I understand and have no idea how difficult it is to implement a function like that.

The big issue I see with using templater is that the query is static after the template is inserted.
That means moving or even renaming the note breaks the map. Which is not obvious for inexperienced users and in general the expected/learned behaviour in Obsidian is that editing notes does not break things.

Also I think it's a quite natural and common use case to create a note with a few locations and show them in a map without collecting locations from other, unrelated notes. Personally I even thought that was the default use case for the plugin when I started using it. It was quite cumbersome at the beginning to learn how to query the current note.

But again, I understand your reasoning and really don't know how hard it is to maintain.

Would like to see support for this as well, as it seems to a very common use-case. As stated above, if note is renamed, the embedded map will break.

Using dataviewjs this can be achieved as follows...
This particular example expects location of the note to be set in front view to center the map around this location.

let self = dv.current();
let filePath = self.file.path;
let map = mapview {"name":"Default","embeddedHeight":400,"mapZoom":13,"centerLat":+self['location'][0]+,"centerLng": + self['location'][1] + ,"query": "path:\\" + filePath + \\"","chosenMapSource":0}\n;
dv.paragraph( '' + map + '');

commented

Added a $filename$ template parameter in the just-released version 4.0.0 🎈

A side effect of $filename$ (which makes sense based on your comments in the docs), is that map view seems to interpret the embedded code block as having changed, so the "Save" button is always displayed.

commented

That's a side effect I did not consider, and it sounds like enough of an annoyance to convince me to work on a more comprehensive implementation.