chore: Remove here map
This commit is contained in:
parent
5fc844b911
commit
8c19f4de68
@ -1,13 +1,9 @@
|
|||||||
import { dedupe, removeUndefined } from "@snort/shared";
|
|
||||||
import { NostrLink, ReqFilter, RequestBuilder } from "@snort/system";
|
import { NostrLink, ReqFilter, RequestBuilder } from "@snort/system";
|
||||||
import { useRequestBuilder } from "@snort/system-react";
|
import { useRequestBuilder } from "@snort/system-react";
|
||||||
import Geohash from "latlon-geohash";
|
|
||||||
import { lazy, Suspense, useMemo } from "react";
|
import { lazy, Suspense, useMemo } from "react";
|
||||||
|
|
||||||
import { TimelineRenderer } from "@/Components/Feed/TimelineRenderer";
|
import { TimelineRenderer } from "@/Components/Feed/TimelineRenderer";
|
||||||
import { findTag } from "@/Utils";
|
|
||||||
const LazySimpleChart = lazy(async () => await import("@/Components/LineChart"));
|
const LazySimpleChart = lazy(async () => await import("@/Components/LineChart"));
|
||||||
const LazyMap = lazy(async () => await import("@/Components/HereMap"));
|
|
||||||
|
|
||||||
export function GenericFeed({ link }: { link: NostrLink }) {
|
export function GenericFeed({ link }: { link: NostrLink }) {
|
||||||
const reqs = JSON.parse(link.id) as Array<ReqFilter>;
|
const reqs = JSON.parse(link.id) as Array<ReqFilter>;
|
||||||
@ -23,26 +19,10 @@ export function GenericFeed({ link }: { link: NostrLink }) {
|
|||||||
|
|
||||||
const evs = useRequestBuilder(sub);
|
const evs = useRequestBuilder(sub);
|
||||||
|
|
||||||
const geoTags = dedupe(removeUndefined(evs.map(a => findTag(a, "g"))));
|
|
||||||
const isTempSensor = reqs[0].kinds?.includes(8001) && reqs[0].kinds.length === 1;
|
const isTempSensor = reqs[0].kinds?.includes(8001) && reqs[0].kinds.length === 1;
|
||||||
if (isTempSensor) {
|
if (isTempSensor) {
|
||||||
return (
|
return (
|
||||||
<div className="p flex flex-col gap-2">
|
<div className="p flex flex-col gap-2">
|
||||||
{geoTags.length > 0 && (
|
|
||||||
<Suspense>
|
|
||||||
<LazyMap
|
|
||||||
zoom={2}
|
|
||||||
center={{ lat: 30, lng: 0 }}
|
|
||||||
markers={geoTags.map(a => {
|
|
||||||
const pos = Geohash.decode(a);
|
|
||||||
return {
|
|
||||||
lat: pos.lat,
|
|
||||||
lng: pos.lon,
|
|
||||||
};
|
|
||||||
})}
|
|
||||||
/>
|
|
||||||
</Suspense>
|
|
||||||
)}
|
|
||||||
<Suspense>
|
<Suspense>
|
||||||
<LazySimpleChart
|
<LazySimpleChart
|
||||||
data={evs
|
data={evs
|
||||||
|
@ -1,55 +0,0 @@
|
|||||||
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
||||||
import H from "@here/maps-api-for-javascript";
|
|
||||||
import { useEffect, useRef } from "react";
|
|
||||||
|
|
||||||
export default function HereMap(props: {
|
|
||||||
zoom?: number;
|
|
||||||
markers?: Array<{ lat: number; lng: number }>;
|
|
||||||
center?: { lat: number; lng: number };
|
|
||||||
}) {
|
|
||||||
const mapRef = useRef(null);
|
|
||||||
const map = useRef<H.Map>(null);
|
|
||||||
const platform = useRef<H.service.Platform>(null);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!map.current) {
|
|
||||||
//@ts-expect-error
|
|
||||||
platform.current = new H.service.Platform({ apikey: "5uZZsWJdVyMSDTjjNJNyUgKq_bKv2rVVZWAXnfmgttQ" });
|
|
||||||
|
|
||||||
const rasterTileService = platform.current.getRasterTileService({
|
|
||||||
queryParams: {
|
|
||||||
style: "explore.night",
|
|
||||||
size: 512,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const rasterTileProvider = new H.service.rasterTile.Provider(rasterTileService);
|
|
||||||
const rasterTileLayer = new H.map.layer.TileLayer(rasterTileProvider);
|
|
||||||
|
|
||||||
const newMap = new H.Map(mapRef.current!, rasterTileLayer, {
|
|
||||||
engineType: H.Map.EngineType.WEBGL,
|
|
||||||
pixelRatio: window.devicePixelRatio,
|
|
||||||
center: props.center ?? { lat: 0, lng: 0 },
|
|
||||||
zoom: props.zoom ?? 2,
|
|
||||||
});
|
|
||||||
|
|
||||||
new H.mapevents.Behavior(new H.mapevents.MapEvents(newMap));
|
|
||||||
//@ts-expect-error
|
|
||||||
map.current = newMap;
|
|
||||||
}
|
|
||||||
}, [props]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (map.current) {
|
|
||||||
map.current.setCenter(props.center ?? { lat: 0, lng: 0 });
|
|
||||||
map.current.setZoom(props.zoom ?? 2);
|
|
||||||
map.current.removeObjects(map.current.getObjects());
|
|
||||||
for (const mrk of props.markers ?? []) {
|
|
||||||
const m = new H.map.Marker(mrk);
|
|
||||||
map.current.addObject(m);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, [map, props.center, props.zoom, props.markers]);
|
|
||||||
|
|
||||||
// Return a div element to hold the map
|
|
||||||
return <div style={{ width: "100%", height: "300px" }} className="rounded-xl overflow-hidden" ref={mapRef} />;
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user