Obsidian Leaflet

repository·main·Indexed 20 days ago

https://github.com/javalent/obsidian-leaflet

An Obsidian.md plugin that integrates Leaflet.js to provide interactive maps within notes using specialized code blocks. It supports custom tile servers, GeoJSON and GPX file loading, image overlays, and markers linked to notes, external URLs, or Obsidian commands. Users can define map coordinates, zoom levels, and markers via YAML configuration in code blocks or note frontmatter.

Tokens
18.4K
Snippets
60
Records
89
Agent score
72%

What's inside obsidian-leaflet

  1. Automatically Assign Marker Types via Associated Tags

    main

    The plugin can automatically determine a marker type for a note based on its tags.

    Logic Flow:

    1. The plugin searches for a note using markerFile, markerFolder, or markerTag.
    2. It first checks the note's frontmatter for a mapmarker parameter to determine the marker type.
    3. If mapmarker is not set, the plugin searches the note's tags against the list of Associated Tags defined for each marker type.
    4. The search follows the order in which the marker types were defined.
  2. Integrate with Initiative Tracker

    main

    If the Initiative Tracker plugin is installed, Obsidian Leaflet can sync combat maps with active combat sessions.

    Features:

    • Automatic Markers: Combat maps automatically load active creatures from the current Initiative Tracker session as markers.
    • Syncing: The map state stays synchronized with the Initiative Tracker; markers are added or removed as creatures are added or removed from combat.
    • Customization: You can set default marker types for PCs and NPCs, or specify unique marker types for individual creatures.
  3. Generate overlays from note frontmatter

    main

    You can automate overlay creation using note metadata:

    Using mapoverlay

    If you use markerFile, markerFolder, or markerTag to pull markers from notes, the plugin will also look for a mapoverlay parameter in those notes' frontmatter. It uses the same syntax as the manual overlay parameter.

    Using overlayTag

    You can tell the map to look for a specific tag in your notes' frontmatter to generate an overlay.

    Example Configuration:

    overlayTag: nearby

    Note Frontmatter:

    nearby: 50 km
  4. Understand Map IDs requirement

    main

    As of version 3.0.0, every map requires a unique id.

    If you are upgrading an older note that uses an old map block, the plugin will warn you that an ID is required. Once you assign an ID to the map, the plugin will attempt to associate your existing marker data with the new map ID.

    Note: Upon the first update to 3.0.0, a backup of your marker data is created automatically to prevent data loss during migration.

  5. Define Local Marker Types via markers.json

    main
    To make specific marker types available to all notes within a directory, create a markers.json file in that directory. The file should contain an array of Icon objects. This allows for directory-specific marker definitions that are shared across all notes in that folder.
  6. Using wildcards in translation strings

    main

    Localization strings may contain wildcards (e.g., %1) used to inject dynamic data into the translated text. This allows for proper placement of variables and support for different plural syntaxes in different languages.

    Example: Loading Obsidian Leaflet v%1 — The plugin replaces %1 with the current version number.

  7. Use Associated Tags for Automatic Marker Assignment

    main

    The plugin can automatically assign marker types to notes based on their tags.

    Logic Flow:

    1. The plugin first checks the note's frontmatter for the mapmarker parameter. If present, this takes precedence.
    2. If mapmarker is not set, the plugin searches the note's tags to find a match with a defined marker type.
    3. If multiple tags match, the plugin uses the marker type associated with the tag that appears first in the marker type's definition order.
  8. Set initial zoom level and zoom tags

    main

    The initial zoom level can be set using the defaultZoom parameter. The value must be a number between minZoom and maxZoom. If the value is outside this range, it will be clamped to the nearest boundary.

    Using Zoom Tags with Coordinates If you use a note for coordinates, you can read the initial zoom level from that note's frontmatter using a zoomTag. For example, if a note has:

    ---
    location: [-36, 89]
    nearby: 100 mi
    ---

    You can define the map block as:

    ```leaflet
    coordinates: [[Note With Frontmatter]]
    zoomTag: nearby
    The map will interpret `nearby` (100 mi) and set the zoom level to the one closest to displaying a 100-mile radius (depending on `minZoom`, `maxZoom`, and `zoomDelta`).
    
  9. Configure real-world tile servers

    main

    If no image parameter is provided, the plugin creates a real-world map. By default, it uses OpenStreetMap. You can use tileServer or tileOverlay to add other tile servers.

    • tileServer: Adds the server as a switchable layer.
    • tileOverlay: Adds the server as an overlay on top of the base map. Append |on to make it enabled by default.
    • osmLayer: false: Use this to disable the default OpenStreetMap layer if you are providing a custom tileServer.

    Syntax: tileServer: <domain>|<alias (optional)> or a list of servers.

    Example with multiple servers:

    ```leaflet
    tileServer:
    - https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png|Dark
    - https://tiles.wmflabs.org/hillshading/{z}/{x}/{y}.png|Hills
    
    ```leaflet
    tileServer: https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png|Dark|on
  10. Manage markers and marker links

    main

    Markers can be added by right-clicking on the map. They are persistent and tied to the map's id.

    Marker Links Markers can link to:

    • Notes: Enter the note name, header (Note#Header), or block. For duplicate names, use the full path.
    • External Websites: Enter the URL.
    • Obsidian Commands: Use the full command name from the Command Palette. To use this, use commandMarker: instead of marker: in your code block.

    Marker Zoom Breakpoints You can set breakpoints so markers appear or disappear based on the current zoom level. This can be done via the right-click menu or in the code block.

    Batch Editing Since version 3.9.0, you can use the batch edit button on the map to open a modal and edit all variable markers at once.