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

map4

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

testMap,default,57.820440822550445,96.86774253845215,,real,ID_f9fb79bb0b3b
testMap,default,54.85857210415401,71.64789676666261,,real,ID_aa3a896b798b

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:
files

# map one.md

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

Add some markers and drag them.

And finally create note for the dataview report:

# report.md
 
```dataviewjs

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", 
	        "Type", 
	        "Lat", 
	        "Long"
		],
            mapJsonObject.mapMarkers.flatMap(map => 
                map.markers.map(marker => [
                    map.id, // Map ID
                    marker.id, // Marker ID
                    marker.type,
                    marker.loc[0], // Lat
                    marker.loc[1], // Long
                ])
            )
        );

	
	} else {
    
		markersTable = dv.table(
	        ["Error"], 
	        [["Invalid JSON format - No mapMarkers property found"]]
		);
    
    }
    
} catch (error) {
    
    markersTable = dv.table(
	    ["Error"], 
	    [[`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.