mirror of
https://github.com/zadam/trilium.git
synced 2025-10-09 23:18:46 +08:00
chore(views/geomap): integrate touchbar
This commit is contained in:
parent
a4faaa406b
commit
229dd9cd18
2 changed files with 38 additions and 37 deletions
|
@ -25,7 +25,6 @@ export default class GeoMapTypeWidget extends TypeWidget {
|
||||||
|
|
||||||
private geoMapWidget: GeoMapWidget;
|
private geoMapWidget: GeoMapWidget;
|
||||||
private L!: Leaflet;
|
private L!: Leaflet;
|
||||||
private ignoreNextZoomEvent?: boolean;
|
|
||||||
|
|
||||||
static getType() {
|
static getType() {
|
||||||
return "geoMap";
|
return "geoMap";
|
||||||
|
@ -55,15 +54,7 @@ export default class GeoMapTypeWidget extends TypeWidget {
|
||||||
// map.invalidateSize();
|
// map.invalidateSize();
|
||||||
// }, 100);
|
// }, 100);
|
||||||
|
|
||||||
// if (hasTouchBar) {
|
|
||||||
// map.on("zoom", () => {
|
|
||||||
// if (!this.ignoreNextZoomEvent) {
|
|
||||||
// this.triggerCommand("refreshTouchBar");
|
|
||||||
// }
|
|
||||||
|
|
||||||
// this.ignoreNextZoomEvent = false;
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async doRefresh(note: FNote) {
|
async doRefresh(note: FNote) {
|
||||||
|
@ -91,30 +82,4 @@ export default class GeoMapTypeWidget extends TypeWidget {
|
||||||
// this.moveMarker(noteId, null);
|
// this.moveMarker(noteId, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
buildTouchBarCommand({ TouchBar }: CommandListenerData<"buildTouchBar">) {
|
|
||||||
const map = this.geoMapWidget.map;
|
|
||||||
const that = this;
|
|
||||||
if (!map) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
return [
|
|
||||||
new TouchBar.TouchBarSlider({
|
|
||||||
label: "Zoom",
|
|
||||||
value: map.getZoom(),
|
|
||||||
minValue: map.getMinZoom(),
|
|
||||||
maxValue: map.getMaxZoom(),
|
|
||||||
change(newValue) {
|
|
||||||
that.ignoreNextZoomEvent = true;
|
|
||||||
map.setZoom(newValue);
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
new TouchBar.TouchBarButton({
|
|
||||||
label: "New geo note",
|
|
||||||
click: () => this.triggerCommand("geoMapCreateChildNote", { ntxId: this.ntxId }),
|
|
||||||
enabled: (this._state === State.Normal)
|
|
||||||
})
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,10 +4,9 @@ import type { GPX, LatLng, LeafletMouseEvent, Map, Marker } from "leaflet";
|
||||||
import SpacedUpdate from "../../../services/spaced_update.js";
|
import SpacedUpdate from "../../../services/spaced_update.js";
|
||||||
import { t } from "../../../services/i18n.js";
|
import { t } from "../../../services/i18n.js";
|
||||||
import processNoteWithMarker, { processNoteWithGpxTrack } from "./markers.js";
|
import processNoteWithMarker, { processNoteWithGpxTrack } from "./markers.js";
|
||||||
import froca from "../../../services/froca.js";
|
|
||||||
import { hasTouchBar } from "../../../services/utils.js";
|
import { hasTouchBar } from "../../../services/utils.js";
|
||||||
import toast from "../../../services/toast.js";
|
import toast from "../../../services/toast.js";
|
||||||
import { EventData } from "../../../components/app_context.js";
|
import { CommandListenerData, EventData } from "../../../components/app_context.js";
|
||||||
import dialog from "../../../services/dialog.js";
|
import dialog from "../../../services/dialog.js";
|
||||||
import server from "../../../services/server.js";
|
import server from "../../../services/server.js";
|
||||||
import attributes from "../../../services/attributes.js";
|
import attributes from "../../../services/attributes.js";
|
||||||
|
@ -117,6 +116,7 @@ export default class GeoView extends ViewMode<MapData> {
|
||||||
private map?: Map;
|
private map?: Map;
|
||||||
private spacedUpdate: SpacedUpdate;
|
private spacedUpdate: SpacedUpdate;
|
||||||
private _state: State;
|
private _state: State;
|
||||||
|
private ignoreNextZoomEvent?: boolean;
|
||||||
|
|
||||||
private currentMarkerData: Record<string, Marker>;
|
private currentMarkerData: Record<string, Marker>;
|
||||||
private currentTrackData: Record<string, GPX>;
|
private currentTrackData: Record<string, GPX>;
|
||||||
|
@ -168,6 +168,16 @@ export default class GeoView extends ViewMode<MapData> {
|
||||||
map.on("click", (e) => this.#onMapClicked(e));
|
map.on("click", (e) => this.#onMapClicked(e));
|
||||||
|
|
||||||
this.#reloadMarkers();
|
this.#reloadMarkers();
|
||||||
|
|
||||||
|
if (hasTouchBar) {
|
||||||
|
map.on("zoom", () => {
|
||||||
|
if (!this.ignoreNextZoomEvent) {
|
||||||
|
this.triggerCommand("refreshTouchBar");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.ignoreNextZoomEvent = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async #restoreViewportAndZoom() {
|
async #restoreViewportAndZoom() {
|
||||||
|
@ -303,4 +313,30 @@ export default class GeoView extends ViewMode<MapData> {
|
||||||
this.#changeState(State.Normal);
|
this.#changeState(State.Normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buildTouchBarCommand({ TouchBar }: CommandListenerData<"buildTouchBar">) {
|
||||||
|
const map = this.map;
|
||||||
|
const that = this;
|
||||||
|
if (!map) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
new TouchBar.TouchBarSlider({
|
||||||
|
label: "Zoom",
|
||||||
|
value: map.getZoom(),
|
||||||
|
minValue: map.getMinZoom(),
|
||||||
|
maxValue: map.getMaxZoom(),
|
||||||
|
change(newValue) {
|
||||||
|
that.ignoreNextZoomEvent = true;
|
||||||
|
map.setZoom(newValue);
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new TouchBar.TouchBarButton({
|
||||||
|
label: "New geo note",
|
||||||
|
click: () => this.triggerCommand("geoMapCreateChildNote"),
|
||||||
|
enabled: (this._state === State.Normal)
|
||||||
|
})
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue