Leaflet javascript

What I’m trying to do

Looking for a way to get marker positions after opening the note with the map embed in it and moving the markers around.

Has anyone tried it before?
Is it even possible?

Using obsidian-leaflet You can get the marker position with right click > Convert to code block


Also you can go to the plugin settings and click on “export market data” and you will get a CSV with:


I’m very sorry for not being clear. I only mentioned it in the title, but i want to know if its possible using a javascript codeblock like dataviewjs codeblock? I would like to automatically gather marker positions on clock of a button and use that data in my code.

You can access the data.json data with dataviewjs

Here’s an example:

Create a /maps folder in the vault to store all the maps data.

Go to settings > obsidian leafleft > default config directory and modify the folder to /maps

Now create two notes for the maps:

# map one.md

id: map-01
# map two.md
id: map-02

Add some markers and drag them.

And finally create note for the dataview report:

# report.md

const jsonFilePath = "/maps/plugins/obsidian-leaflet-plugin/data.json";
let markersTable;

try {

	const mapJsonString = await dv.io.load(jsonFilePath);
    const mapJsonObject = JSON.parse(mapJsonString);

    if (mapJsonObject.mapMarkers) {
		markersTable = dv.table(
	        "Map ID", 
	        "Marker ID", 
            mapJsonObject.mapMarkers.flatMap(map => 
                map.markers.map(marker => [
                    map.id, // Map ID
                    marker.id, // Marker ID
                    marker.loc[0], // Lat
                    marker.loc[1], // Long

	} else {
		markersTable = dv.table(
	        [["Invalid JSON format - No mapMarkers property found"]]
} catch (error) {
    markersTable = dv.table(
	    [[`Error parsing JSON: ${error.message}`]]



You will get a table like this one:

Here the files: maps.zip (2.1 KB)

1 Like

Wow, thank you so much <3

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.