chore(react/collections/geomap): clean up

This commit is contained in:
Elian Doran
2025-09-05 11:04:36 +03:00
parent 3d88b3c74b
commit cb53ff880d
3 changed files with 1 additions and 96 deletions

View File

@@ -93,7 +93,7 @@ export default function GeoView({ note, noteIds, viewConfig, saveConfig }: ViewM
const apiRef = useRef<MapApi>(null);
useNoteTreeDrag(containerRef, async (treeData, e) => {
const api = apiRef.current;
if (!note || !api) return;
if (!note || !api || isReadOnly) return;
const { noteId } = treeData[0];

View File

@@ -1,20 +0,0 @@
import { LatLng, LeafletMouseEvent } from "leaflet";
import attributes from "../../../services/attributes";
import { LOCATION_ATTRIBUTE } from "./index.js";
import dialog from "../../../services/dialog";
import server from "../../../services/server";
import { t } from "../../../services/i18n";
import type { Map } from "leaflet";
import type { DragData } from "../../note_tree.js";
import froca from "../../../services/froca.js";
import branches from "../../../services/branches.js";
export function setupDragging($container: JQuery<HTMLElement>, map: Map, mapNoteId: string) {
$container.on("drop", async (e) => {
try {
} catch (e) {
console.warn(e);
}
});
}

View File

@@ -17,41 +17,7 @@ import { DEFAULT_MAP_LAYER_NAME, MAP_LAYERS } from "./map_layer.js";
export default class GeoView extends ViewMode<MapData> {
private $root: JQuery<HTMLElement>;
private $container!: JQuery<HTMLElement>;
private map?: Map;
private spacedUpdate: SpacedUpdate;
private _state: State;
private ignoreNextZoomEvent?: boolean;
private currentMarkerData: Record<string, Marker>;
private currentTrackData: Record<string, GPX>;
constructor(args: ViewModeArgs) {
super(args, "geoMap");
this.$root = $(TPL);
this.$container = this.$root.find(".geo-map-container");
this.spacedUpdate = new SpacedUpdate(() => this.onSave(), 5_000);
this.currentMarkerData = {};
this.currentTrackData = {};
args.$parent.append(this.$root);
}
async #onMapInitialized() {
const map = this.map;
if (!map) {
throw new Error(t("geo-map.unable-to-load-map"));
}
const isEditable = !this.isReadOnly;
if (isEditable) {
setupDragging(this.$container, map, this.parentNote.noteId);
}
this.#reloadMarkers();
if (hasTouchBar) {
map.on("zoom", () => {
@@ -64,27 +30,6 @@ export default class GeoView extends ViewMode<MapData> {
}
}
async #reloadMarkers() {
if (!this.map) {
return;
}
// Delete all existing markers
for (const marker of Object.values(this.currentMarkerData)) {
marker.remove();
}
// Delete all existing tracks
for (const track of Object.values(this.currentTrackData)) {
track.remove();
}
// Add the new markers.
this.currentMarkerData = {};
const notes = await this.parentNote.getSubtreeNotes();
const draggable = !this.isReadOnly;
}
#changeState(newState: State) {
this._state = newState;
if (hasTouchBar) {
@@ -92,26 +37,6 @@ export default class GeoView extends ViewMode<MapData> {
}
}
async onEntitiesReloaded({ loadResults }: EventData<"entitiesReloaded">) {
// If any of the children branches are altered.
if (loadResults.getBranchRows().find((branch) => branch.parentNoteId === this.parentNote.noteId)) {
this.#reloadMarkers();
return;
}
// If any of note has its location attribute changed.
// TODO: Should probably filter by parent here as well.
const attributeRows = loadResults.getAttributeRows();
if (attributeRows.find((at) => [LOCATION_ATTRIBUTE, "color", "iconClass"].includes(at.name ?? ""))) {
this.#reloadMarkers();
}
// Full reload if map layer is changed.
if (loadResults.getAttributeRows().some(attr => (attr.name?.startsWith("map:") && attributes.isAffecting(attr, this.parentNote)))) {
return true;
}
}
buildTouchBarCommand({ TouchBar }: CommandListenerData<"buildTouchBar">) {
const map = this.map;
const that = this;