obsidian-maps

repository·master·Indexed 18 days ago

https://github.com/obsidianmd/obsidian-maps

A community plugin for Obsidian Bases that adds a map layout to visualize notes as interactive markers. It supports coordinate-based placement via note properties or Bases formulas, custom marker styling using Lucide icons and CSS colors, and configurable map backgrounds via OpenFreeMap or custom tile/style URLs. Features include a mobile-specific 'copy-current-location' command and a context menu for creating notes at specific coordinates.

Tokens
5.9K
Snippets
20
Records
30
Agent score
66%

What's inside obsidian-maps

  1. Configure Map view options

    master

    After setting up the Marker coordinates property in a Map view, you can use the following view options to customize the display:

    • Center coordinates: Set the initial map center.
    • Default zoom: Set the initial zoom level.
    • Zoom limits: Define the minimum and maximum zoom levels.
    • Marker icon/color: Choose specific properties to drive the icon and color of each marker.
  2. Configure basic map markers using note properties

    master

    To display markers on a map, use the Markers section within the Map view configuration menu (located in the top left corner of the base). Markers are driven by properties assigned directly to individual notes.

    Supported properties for marker styling include:

    • coordinates: Stored as latitude, longitude (e.g., 48.85837\n2.294481). You can obtain these by right-clicking a location on the map and selecting Copy coordinates.
    • icon: A string representing a name from the Lucide library.
    • color: A valid CSS value (e.g., hex, RGB, or named colors like red).
  3. Display notes on a map view

    master

    To show notes on a map, you must first add a coordinates property to your notes. The plugin supports both a single text property and a list property format.

    Once properties are added, create a Map view in an Obsidian Base and configure the Marker coordinates option to point to your chosen property. Markers will dynamically appear and update based on the view's active filters.

    # Option 1: Text property
    location: 34.13956, -118.38710
    
    # Option 2: List property
    location:
      - 34.13956
      - -118.38710
  4. Use the MapView context menu actions

    master

    Right-clicking on the map provides several context-aware actions:

    • New note: Creates a new file. If a coordinates property is configured in the Map View, the new note will be pre-filled with the clicked coordinates in the format [lat, lng].
    • Copy coordinates: Copies the formatted coordinates of the clicked location to the clipboard.
    • Set default center point: Updates the map's center configuration to the current clicked coordinates.
    • Set default zoom: Updates the map's defaultZoom configuration to the current zoom level (rounded to 1 decimal place).
  5. Configure map markers using note types and formulas

    master

    Instead of using properties from the individual note, you can derive marker icons and colors from the note's assigned type. This is done using Bases formula properties.

    To access properties from the first assigned type of a note, use the following formulas in the Properties configuration menu:

    To get the icon from the type:

    list(type)[0].asFile().properties.icon

    To get the color from the type:

    list(type)[0].asFile().properties.color
    // Get the icon from the type
    list(type)[0].asFile().properties.icon
    
    // Get the color from the type
    list(type)[0].asFile().properties.color
  6. Configure the map view with MapConfig

    master

    The MapConfig interface defines how the map and its markers are rendered. It maps specific Obsidian Bases properties to map features like coordinates, icons, and colors.

    Key configuration options include:

    • coordinatesProp: The BasesPropertyId used to retrieve latitude/longitude from entries.
    • markerIconProp: The BasesPropertyId used to retrieve icon names.
    • markerColorProp: The BasesPropertyId used to retrieve marker colors.
    • mapTiles and mapTilesDark: Arrays of tile set URLs for light and dark modes.
    • center: The initial [number, number] coordinates (latitude, longitude). Set to null to indicate no center is configured.
    export interface MapConfig {
    	coordinatesProp: BasesPropertyId | null;
    	markerIconProp: BasesPropertyId | null;
    	markerColorProp: BasesPropertyId | null;
    	mapHeight: number;
    	defaultZoom: number;
    	center: [number, number] | null;
    	maxZoom: number;
    	minZoom: number;
    	mapTiles: string[];
    	mapTilesDark: string[];
    	currentTileSetId: string | null;
    }
  7. Configure Map Backgrounds (TileSets)

    master

    The obsidian-maps plugin allows you to define custom background tile sets that can be used across all maps. These are managed via the MapSettingTab in the plugin settings.

    A TileSet consists of:

    • name: A descriptive name for the background (e.g., 'Terrain', 'Satellite').
    • lightTiles: The Tile URL or style URL used when Obsidian is in Light mode.
    • darkTiles: (Optional) The Tile URL or style URL used when Obsidian is in Dark mode. If omitted, the lightTiles URL will be used as a fallback.

    Example URLs provided in documentation:

    • Light mode: https://tiles.openfreemap.org/styles/bright
    • Dark mode: https://tiles.openfreemap.org/styles/dark
  8. Configure Map View settings

    master

    The MapView can be customized via several configuration keys. These settings control the map's appearance, center, zoom levels, and how markers are identified.

    Display Settings

    • center: A formula or string representing the default center coordinates (e.g., [latitude, longitude]).
    • defaultZoom: The initial zoom level (range: 1-18).
    • minZoom: The minimum allowed zoom level (range: 0-24).
    • maxZoom: The maximum allowed zoom level (range: 0-24).
    • mapHeight: The height of the map in pixels (used when the view is embedded).

    Marker Settings

    • coordinates: The property key used to extract coordinates from notes to place markers.
    • markerIcon: The property key used to extract custom icon names for markers.
    • markerColor: The property key used to extract custom color values for markers.

    Background Settings

    • mapTiles: An array of tile set URLs for light mode.
    • mapTilesDark: An array of tile set URLs for dark mode.
  9. Use default GEOLOCATION_OPTIONS

    master

    The GEOLOCATION_OPTIONS constant provides a recommended PositionOptions configuration for geolocation requests in Obsidian. It is designed to balance accuracy with battery/resource usage by allowing cached positions.

    export const GEOLOCATION_OPTIONS: PositionOptions = {
    	enableHighAccuracy: true,
    	timeout: 10000,
    	maximumAge: 5000
    };
  10. Get user-facing geolocation error messages

    master

    The geolocationErrorMessage(error) function converts a standard GeolocationPositionError into a human-readable string suitable for UI display. It maps the following error codes:

    • error.PERMISSION_DENIED $\rightarrow$ 'Location permission denied'
    • error.POSITION_UNAVAILABLE $\rightarrow$ 'Location information unavailable'
    • error.TIMEOUT $\rightarrow$ 'Location request timed out'
    • All other errors $\rightarrow$ 'Failed to get location'
    import { geolocationErrorMessage } from 'obsidian-maps/src/map/utils';
    
    // Assuming 'error' is a GeolocationPositionError caught from navigator.geolocation
    try {
      // ... geolocation logic
    } catch (error) {
      const message = geolocationErrorMessage(error);
      console.error(message);
    }