Skip to content

Commit 11d3960

Browse files
committed
refactor(collections/map): remove namespaced types
1 parent d2cf843 commit 11d3960

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

apps/client/src/widgets/collections/geomap/ContextMenus.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { MapMouseEvent } from "maplibre-gl";
12
import { useCallback, useContext, useEffect } from "preact/hooks";
23

34
import appContext, { type CommandMappings } from "../../../components/app_context.js";
@@ -33,7 +34,7 @@ export default function ContextMenus({ note, isReadOnly }: { note: FNote, isRead
3334
useEffect(() => {
3435
if (!onContextMenu || !map) return;
3536

36-
const handler = (e: maplibregl.MapMouseEvent) => {
37+
const handler = (e: MapMouseEvent) => {
3738
e.preventDefault();
3839
onContextMenu(toMapLibreEvent(e));
3940
};

apps/client/src/widgets/collections/geomap/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import "./index.css";
22

3-
import type maplibregl from "maplibre-gl";
3+
import type { Map as MapLibreGL } from "maplibre-gl";
44
import { useCallback, useContext, useEffect, useMemo, useRef, useState } from "preact/hooks";
55

66
import appContext from "../../../components/app_context";
@@ -99,7 +99,7 @@ export default function GeoView({ note, noteIds, viewConfig, saveConfig }: ViewM
9999

100100
// Dragging
101101
const containerRef = useRef<HTMLDivElement>(null);
102-
const apiRef = useRef<maplibregl.Map | null>(null);
102+
const apiRef = useRef<MapLibreGL | null>(null);
103103
useNoteTreeDrag(containerRef, {
104104
dragEnabled: !isReadOnly,
105105
dragNotEnabledMessage: {
@@ -307,7 +307,7 @@ function buildIconHtml(bxIconClass: string, colorClass?: string, title?: string,
307307
return html;
308308
}
309309

310-
function GeoMapTouchBar({ state, map }: { state: State, map: maplibregl.Map | null | undefined }) {
310+
function GeoMapTouchBar({ state, map }: { state: State, map: MapLibreGL | null | undefined }) {
311311
const [ currentZoom, setCurrentZoom ] = useState<number>();
312312
const parentComponent = useContext(ParentComponent);
313313

apps/client/src/widgets/collections/geomap/marker.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import { Marker as MapLibreMarker } from "maplibre-gl";
12
import { useContext, useEffect, useRef } from "preact/hooks";
2-
import { ParentMap, GeoMouseEvent } from "./map";
3-
import maplibregl from "maplibre-gl";
3+
4+
import { GeoMouseEvent,ParentMap } from "./map";
45

56
export interface MarkerProps {
67
coordinates: [ number, number ];
@@ -16,7 +17,7 @@ export interface MarkerProps {
1617

1718
export default function Marker({ coordinates, iconHtml, iconSize, iconAnchor, draggable, onClick, onDragged, onMouseDown, onContextMenu }: MarkerProps) {
1819
const parentMap = useContext(ParentMap);
19-
const markerRef = useRef<maplibregl.Marker>(null);
20+
const markerRef = useRef<MapLibreMarker>(null);
2021

2122
useEffect(() => {
2223
if (!parentMap) return;
@@ -31,13 +32,13 @@ export default function Marker({ coordinates, iconHtml, iconSize, iconAnchor, dr
3132
el.style.height = `${iconSize[1]}px`;
3233
}
3334

34-
const newMarker = new maplibregl.Marker({
35+
const newMarker = new MapLibreMarker({
3536
element: el,
3637
draggable: !!draggable,
3738
anchor: "bottom"
3839
})
39-
.setLngLat([coordinates[1], coordinates[0]])
40-
.addTo(parentMap);
40+
.setLngLat([coordinates[1], coordinates[0]])
41+
.addTo(parentMap);
4142

4243
markerRef.current = newMarker;
4344

@@ -99,7 +100,7 @@ export function GpxTrack({ gpxXmlString, trackColor, startIconHtml, endIconHtml,
99100
useEffect(() => {
100101
if (!parentMap) return;
101102

102-
const markers: maplibregl.Marker[] = [];
103+
const markers: MapLibreMarker[] = [];
103104
const sourceId = `gpx-source-${Math.random().toString(36).slice(2)}`;
104105
const layerId = `gpx-layer-${sourceId}`;
105106

@@ -145,7 +146,7 @@ export function GpxTrack({ gpxXmlString, trackColor, startIconHtml, endIconHtml,
145146
const startEl = document.createElement("div");
146147
startEl.className = "geo-marker";
147148
startEl.innerHTML = startIconHtml;
148-
const startMarker = new maplibregl.Marker({ element: startEl, anchor: "bottom" })
149+
const startMarker = new MapLibreMarker({ element: startEl, anchor: "bottom" })
149150
.setLngLat(coordinates[0])
150151
.addTo(parentMap);
151152
markers.push(startMarker);
@@ -156,7 +157,7 @@ export function GpxTrack({ gpxXmlString, trackColor, startIconHtml, endIconHtml,
156157
const endEl = document.createElement("div");
157158
endEl.className = "geo-marker";
158159
endEl.innerHTML = endIconHtml;
159-
const endMarker = new maplibregl.Marker({ element: endEl, anchor: "bottom" })
160+
const endMarker = new MapLibreMarker({ element: endEl, anchor: "bottom" })
160161
.setLngLat(coordinates[coordinates.length - 1])
161162
.addTo(parentMap);
162163
markers.push(endMarker);
@@ -172,7 +173,7 @@ export function GpxTrack({ gpxXmlString, trackColor, startIconHtml, endIconHtml,
172173
const wptEl = document.createElement("div");
173174
wptEl.className = "geo-marker";
174175
wptEl.innerHTML = waypointIconHtml;
175-
const wptMarker = new maplibregl.Marker({ element: wptEl, anchor: "bottom" })
176+
const wptMarker = new MapLibreMarker({ element: wptEl, anchor: "bottom" })
176177
.setLngLat([lon, lat])
177178
.addTo(parentMap);
178179
markers.push(wptMarker);

0 commit comments

Comments
 (0)