New Plugin: Obsidian Leaflet - Interactive maps in notes

Not through the plugin, but you can with a little bit of CSS. I think it’s a good idea to be able to set the size of the marker types you create, though, so I’ll create an issue on the repository to track this.

If you want to change all markers, you can do this:

.leaflet-div-icon > svg {
    width: 12px !important;
    height: 12px !important;
}

To change a specific type, target the Font Awesome Icon Class of that Marker Type:

.leaflet-div-icon > svg.fa-circle {
    width: 12px !important;
    height: 12px !important;
}

The markers are currently set to 25px x 25px, and if you make them not a square, they probably won’t center properly.

1 Like

Whenever I select this plugin in the settings it bring me a prompt to select a color of the marker and what ever I do I can’t select anything else in the menu.

Other than the bug, an idea can be adding a feature that marks lines, like rivers which are hard to spot on the maps.

And thanks for your efforts it is a really useful app.

Whenever I select this plugin in the settings it bring me a prompt to select a color of the marker and what ever I do I can’t select anything else in the menu.

Could you send me a screenshot of what you’re seeing? I can’t seem to replicate this issue.

Other than the bug, an idea can be adding a feature that marks lines, like rivers which are hard to spot on the maps.

This is not possible from my end. I could open up the option of choosing a different source for the map tiles (if creating a real-world map), where this kind of data may already exist.

1 Like

It shows up like this, and when I choose a color and click again on the menu it comes back again.

That looks like an older version of the plugin; could you try updating and seeing if the issue goes away?

1 Like

yes the update fixed it. My last update was couples of days ago so I was not thinking about that option at all.

1 Like

Hi everyone. Just released a big new update.

If you have maps that are defined with an id parameter, they will now fail to render. Sorry about this change, but requiring a map ID makes it much easier to store the data and get rid of it when it is no longer needed (stops accumulating indefinitely). This also allows you to easily render the same map in multiple notes - give them the same ID and the marker data will come over too.

3.0.0

New Features

  • Map IDs are now required.
    • A map that does not have an id will not render
    • The plugin will try to load previously defined marker data once an id has been given to the map.
    • This means marker definitions are no longer tied to maps - giving a map on a different note the same ID will load the same marker data
  • Marker data that is not associated with a file will now be deleted after 7 days to prevent data accumulation
  • Map data is now only saved if the map has defined markers
  • Image files can now be linked using an Obsidian wikilink (e.g., [[Image Name.jpg]])
  • New markerFile and markerFolder parameters in maps
    • markerFile will read a note file’s frontmatter and create a marker based on the marker and location tags
      • marker should be a defined marker type (will default to default if not provided)
      • location should be a array of [latitude, longitude]. If not provided, the marker will not be created
      • The marker link target will be set to the file
    • markerFolder will read all of the files in the folder, and try to parse the frontmatter as above.
  • Made display of marker link in tooltip consistent with Obsidian’s display style
  • Added data attributes to marker HTML element
    • data-type: marker type
    • data-link: marker link target, if any
    • data-mutable: whether marker data can be edited
    • data-type: marker type name (such as default)
  • Rendering improvements

Bug Fixes

  • Fixed issue where a new marker type’s Layer Icon setting was not respecting the default layer marker setting
  • Fixed issue where clicking a marker could open the context menu
  • Fixed issue where clicking a marker without a link could cause an error
  • Fixed issue with opening a marker link defined with alt-text
  • Fixed issue where resizing the leaf containing a map caused it to calculate marker positions incorrectly
  • Fixed issue where having the same map open in multiple windows was not adding markers correctly
  • Fixed issue where dragging a marker created on a map open in multiple views would not drag correctly on other maps
  • Fixed issue where turning the plugin off would leave map tiles in random locations on open notes
  • Fixed issue where showing the note preview of a note with a map that is already open in the workspace would cause the map to be disassociated
3 Likes

Wow! This is an incredibly useful update!

Especially

  • the reusability of maps using an ID, and not having to recreate its markers.
  • the markerFolder feature—allows using something like a “People” folder to be used for map data in a snap.
  • The CSV exported/imported is now much cleaner and doesn’t rely on (possibly changing) file and folder names anymore.

May I suggest 2 further things?

  1. Using marker from the YAML front matter might be slightly too ambiguous, how about maybe using mapmarker instead? Just in case some people already use marker for something?

  2. The folder feature is incredibly useful. But people might use location data that is scattered throughout the vault, instead of in one folder, but tagged. Could this be used for tags instead? Or maybe a new markerTags added?

    So people could easily “tag together” what they like displayed, as in, say:

    markerTags: #people, #locations
    

    or—technically even better—

    markerTags: [people, locations]
    

    Hint: If both markerFile/markerFolder plus markerTags are present, they should be logically ANDed, I think, so one wouldn’t get all tags from everywhere but only those entries that are in the specified files/folders AND have the specified tag(s). I.e., kinda filter: The more specific you get, the less results you get.

  3. Q: Are multiple markerFile and markerFolder entries allowed? Might be useful in some cases.

  4. Q: Do I understand correctly (from my testing) that specifying a markerFolder will automatically traverse all its subfolders? Like I give it markerFolder: People and actually have the folders People/Friends & Family and People/Business Contacts, will it include notes from both subfolders?


For those who like examples: I have a folder People/Friends & Family, all notes inside this folder have location: and marker: YAML front matter like so:

---
location: [51.133333,10.416667]
marker: Friends
---

and I’ve set up 3 marker types:

obsidian-leaflet-marker-types

Now, make a map:

id: Friends
markerFolder: People/Friends & Family
height: 500px
lat: 51.133333
long: 10.416667
minZoom: 1
maxZoom: 18
defaultZoom: 5

and presto! In a fraction of a second:

Impressive, isn’t it?

3 Likes
  1. Using marker from the YAML front matter might be slightly too ambiguous, how about maybe using mapmarker instead? Just in case some people already use marker for something?

Probably a good idea, I’ll update this in the next release.

  1. The folder feature is incredibly useful. But people might use location data that is scattered throughout the vault, instead of in one folder, but tagged . Could this be used for tags instead? Or maybe a new markerTags added?

markerTags: [people, locations]

So just to make sure I’m understanding the idea correctly: this would grab any notes in the vault with the #people and #locations tags?

  1. Q: Are multiple markerFile and markerFolder entries allowed? Might be useful in some cases.

Yes, you can have an arbitrary number of both. The more you add, the more the plugin will need to scan, though, so it could slow down rendering if a large number of folders or files is specified.

  1. Q: Do I understand correctly (from my testing) that specifying a markerFolder will automatically traverse all its subfolders? Like I give it markerFolder: People and actually have the folders People/Friends & Family and People/Business Contacts, will it include notes from both subfolders?

Correct, it is recursive all the way down. If you want to exclude folders, it would be necessary to set multiple markerFolder parameters.

Edit: Also, just curious if you’ve noticed if the maps render faster. I made some efficiency improvements.

2 Likes

Exactly. (Hope there is an API for that so it can reuse Obsidian’s built-in mechanisms. With 0.12, they’ve been talking about optimizations for large vaults, so maybe the internal search could be used for that?)

Plus everything I said in “Hint”. :wink: I’m only still wondering how to OR and AND tag searches. Maybe if multiple tags are given on one markerTags line as above, they must all be in the note (AND function), and if given on multiple lines, they’re ORed? As an example:

markerFolder: People and Locations
markerFolder: Interests/Maps of the World
markerTags: [people, friends]
markerTags: Paris

would search for notes that

  • (are in the folders People and Locations OR Interests/Maps of the World), AND
  • ((contain both tags #people AND #friends), OR
  • the tag #Paris)

I added parentheses to make the logic clearer (I hope).

Only having

markerTags: Paris

or

markerTags: [Paris]

would search in the whole vault. Using the [Paris] syntax might be more logical here, because you can use a YAML set as an array, whilst markerTags: Paris would return a str (?). Also, markerTags is plural, to symbolize that more than one can be used.

I wonder if you have something in Obsidian’s API that gives you “tags in this note”, because tags can also appear as a subtag (cities/Paris) and within the note content (Talking about #Paris, we find that …).

What do you think? And would others deem this useful?

And yes, I think the maps rendered faster here. Although clicking on links that open a browser seems slower, but that may well be my system.

1 Like
  • (are in the folders People and Locations OR Interests/Maps of the World), AND
  • ((contain both tags #people AND #friends), OR
  • the tag #Paris)

This makes sense to me. Should be easy enough to slot into the existing logic looking through the files for frontmatter.

What do you think? And would others deem this useful?

More options for people is never a bad thing!

1 Like

Hi, If I want to drag backgroud when i zoom picture, what can i do?

Now , i can’t drag picuture located in the local to shift vision

Looking forward to your reply!

You should definitely be able to drag a local image around when zoomed into the map.

If you are zoomed out (grey border around the image), the plugin will keep the image centered.

Could you send me a screen recording of what’s happening?

thank for you reply~

That is solved now :rofl:

It could be problem of software

1 Like

Just released version 3.1.0.

  1. Using marker from the YAML front matter might be slightly too ambiguous, how about maybe using mapmarker instead? Just in case some people already use marker for something?

This change has been implemented, but marker will still work for a bit. You’ll get a warning about it, though.

The folder feature is incredibly useful. But people might use location data that is scattered throughout the vault, instead of in one folder, but tagged . Could this be used for tags instead? Or maybe a new markerTags added?

markerTag parameter added. Documentation for it is here, but it works exactly as your idea:

markerTag: #people, #location

will return notes that are tagged with BOTH.

markerTag: #people
markerTag: #location

will return notes tagged with EITHER.

Specifying both markerTag and markerFolder will limit it to notes in the folder tagged with specified tags.

1 Like

Works like a beaut! And fast. Thank you, much appreciated!

Seems you made the better decision re tags. I was thinking to leave the # out but you left it in, so one gets the tag suggestion box.

For others:

  • Just remember that you won’t find tags like #family/kids when specifying only #kids. This is like Obsidian behaves, so probably a good thing.
  • Also remember this will pick up tags from both the YAML front matter and the content.

In the docs, you say:

If you have the Dataview plugin installed, markers may also be created from tags using the following syntax:

markerTag: #<tag>, #<tag>, ...

Does this mean it has to be enabled, i.e. you use parts of it?


Upon doing a quick test, I found that when adding a new (test) map to an existing map note, the first map lost all its markers? My mistake?

First map in the note (losing its markers):

id: Friends
markerFolder: People/Friends & Family
markerFolder: +Inbox
height: 500px
lat: 51.133333
long: 10.416667
minZoom: 1
maxZoom: 18
defaultZoom: 5

Second (test) map in this note (working):

id: Test
markerFolder: People/Friends & Family
markerTag: #family 
markerTag: #friends, #test 
height: 500px
lat: 51.133333
long: 10.416667
minZoom: 1
maxZoom: 18
defaultZoom: 5

EDIT: Deleting the second map and closing/reopening the note (to circumvent caching) didn’t bring back the markers on the first map.

See also: 3.1.0: Two maps in one note: first loses markers? · Issue #36 · javalent/obsidian-leaflet · GitHub

Does this mean it has to be enabled, i.e. you use parts of it?

Correct, it uses the Dataview etags cache. From what I can tell, there isn’t a map of files ↔ tags in the Obsidian API, and rather than duplicate his caching efforts, I’m just re-using it.

Eventually I’ll move the file and folder loading over to that cache too, if it is available.

Upon doing a quick test, I found that when adding a new (test) map to an existing map note, the first map lost all its markers? My mistake?

Interesting, I’ll try to reproduce this and hunt down what’s happening.

Thanks for checking.

Re Dataview: Hmm. I’m a great fan of re-usage, but needing to install Dataview just for finding tags? My gut feeling says the Obsidian API should have tag searching built-in, which would probably even be compatible with 0.12’s “large vault” changes. Can’t you use maybe the TagCache from CachedMetadata or something like this?

Just wildly guessing, without having inspected the code.

Any devs wishing to chime in, please?

Yeah, I agree re: requiring a separate plugin.

The exposed API hooks for getting a CachedMetadata object returns the CachedMetadata for a specific file or path (see here or here). It’s very possible I’m overlooking a way to get the cache for everything, though, and I’m certainly no expert.

Everything = all files in vault?

If so, maybe linkpath or path can take an empty string (like in Dataview’s from clause)?

Let’s see if any devs find this and can comment …