Skip to content

Commit

Permalink
3.3.0
Browse files Browse the repository at this point in the history
- Marker links may now be Obsidian commands (closes #35)
  • Loading branch information
valentine195 committed May 5, 2021
1 parent 05c416f commit f755662
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 13 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ Additionally, markers can be created by dragging a note from the file tree and d

Marker links can also be set to external websites. Clicking the marker will open the website.

#### Obsidian Commands as Links

Markers links can also be set to a defined Obsidian command from the command palette. This must be the full name of the command as it appears in the palette.

Setting a marker link to a command will execute the command when the marker is clicked.

### Markers Defined in the Code Block

Markers may be defined directly in the code block using the following syntax:
Expand Down
20 changes: 10 additions & 10 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"id": "obsidian-leaflet-plugin",
"name": "Obsidian Leaflet",
"description": "Create interactive maps inside your notes",
"version": "3.2.1",
"minAppVersion": "0.11.0",
"author": "Jeremy Valentine",
"repo": "valentine195/obsidian-leaflet-plugin",
"isDesktopOnly": true
}
{
"id": "obsidian-leaflet-plugin",
"name": "Obsidian Leaflet",
"description": "Create interactive maps inside your notes",
"version": "3.3.0",
"minAppVersion": "0.11.0",
"author": "Jeremy Valentine",
"repo": "valentine195/obsidian-leaflet-plugin",
"isDesktopOnly": true
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-leaflet-plugin",
"version": "3.2.1",
"version": "3.3.0",
"description": "Leaflet integration for Obsidian.md",
"main": "main.js",
"scripts": {
Expand Down
66 changes: 65 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
Menu,
MarkdownPostProcessorContext,
Vault,
TFolder
TFolder,
setIcon
} from "obsidian";
import { latLng, LeafletMouseEvent, Point } from "leaflet";
import { parse as parseCSV } from "papaparse";
Expand Down Expand Up @@ -892,6 +893,25 @@ export default class ObsidianLeaflet extends Plugin {

this.registerEvent(
map.on("marker-click", async (link: string, newWindow: boolean) => {
//@ts-expect-error
const commands = this.app.commands.listCommands();

if (
commands.find(
({ name }: { name: string }) =>
name.toLowerCase() === link.toLowerCase().trim()
)
) {
const command = commands.find(
({ name }: { name: string }) =>
name.toLowerCase() === link.toLowerCase().trim()
);

//@ts-expect-error
this.app.commands.executeCommandById(command.id);
return;
}

let internal = await this.app.metadataCache.getFirstLinkpathDest(
link.split(/(\^|\||#)/).shift(),
""
Expand Down Expand Up @@ -934,6 +954,50 @@ export default class ObsidianLeaflet extends Plugin {
map.on(
"marker-mouseover",
async (evt: L.LeafletMouseEvent, marker: LeafletMarker) => {
//@ts-expect-error
const commands = this.app.commands.listCommands();

if (
commands.find(
({ name }: { name: string }) =>
name.toLowerCase() ===
marker.link.toLowerCase().trim()
)
) {
const command = commands.find(
({ name }: { name: string }) =>
name.toLowerCase() ===
marker.link.toLowerCase().trim()
);

let el = evt.originalEvent.target as SVGElement;
const div = createDiv({
attr: {
style: "display: flex; align-items: center;"
}
});
setIcon(
div.createSpan({
attr: {
style:
"margin-right: 0.5em; display: flex; align-items: center;"
}
}),
"run-command"
);
div.createSpan({ text: command.name });
map.tooltip.setContent(div);
marker.leafletInstance
.bindTooltip(map.tooltip, {
offset: new Point(
0,
-1 * el.getBoundingClientRect().height
)
})
.openTooltip();
return;
}

let internal = await this.app.metadataCache.getFirstLinkpathDest(
marker.link.split(/(\^|\||#)/).shift(),
""
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"2.1.1": "0.11.0",
"3.0.0": "0.11.13",
"3.1.1": "0.11.13",
"3.2.1": "0.11.13"
"3.2.1": "0.11.13",
"3.3.0": "0.11.13"
}

0 comments on commit f755662

Please sign in to comment.