diff --git a/src/pages/[organization]/[slug].tsx b/src/pages/[organization]/[slug].tsx
index dc7d74a..1822829 100644
--- a/src/pages/[organization]/[slug].tsx
+++ b/src/pages/[organization]/[slug].tsx
@@ -9,19 +9,35 @@ import toast, { Toaster } from "react-hot-toast";
import { BsCalendar2DateFill } from "react-icons/bs";
import { FaQq, FaTwitter, FaWeibo } from "react-icons/fa";
import { HiOutlineHome, HiOutlineMail } from "react-icons/hi";
+import { VscLoading } from "react-icons/vsc";
import { IoLocation } from "react-icons/io5";
import { SiBilibili } from "react-icons/si";
+import { RiErrorWarningLine } from "react-icons/ri";
import { TbArrowsRightLeft } from "react-icons/tb";
import { FaPaw } from "react-icons/fa";
import Link from "next/link";
import { EventStatus, EventStatusSchema } from "@/types/event";
import { sendTrack } from "@/utils/track";
import { getEventCoverUrl, imageUrl } from "@/utils/imageLoader";
+import Script from "next/script";
const xata = new XataClient();
+const MapLoadingStatus = {
+ Idle: "idle",
+ Loading: "loading",
+ Finished: "finished",
+ Error: "error",
+};
+
export default function EventDetail({ event }: { event: Event }) {
const [isWiderImage, setIsWiderImage] = useState(true);
+ const [mapLoadingStatus, setMapLoadingStatus] = useState(() => {
+ if (event.addressLat && event.addressLon) {
+ return MapLoadingStatus.Loading;
+ }
+ return MapLoadingStatus.Idle;
+ });
const calcImageRatio = useCallback(() => {
if (!event.coverUrl) return;
@@ -37,10 +53,70 @@ export default function EventDetail({ event }: { event: Event }) {
}, [calcImageRatio]);
const finalEventCoverImage = getEventCoverUrl(event);
+ const initMap = () => {
+ if (!window.TMap) throw new Error("TMap is not loaded");
+ setMapLoadingStatus(MapLoadingStatus.Loading);
+ const center = new window.TMap.LatLng(event.addressLat, event.addressLon);
+ //定义map变量,调用 TMap.Map() 构造函数创建地图
+
+ try {
+ const map = new window.TMap.Map(
+ document.getElementById("event-map-container"),
+ {
+ center: center, //设置地图中心点坐标
+ zoom: 17.2, //设置地图缩放级别
+ pitch: 43.5, //设置俯仰角
+ rotation: 45, //设置地图旋转角度
+ }
+ );
+
+ map.on("tilesloaded", function () {
+ setMapLoadingStatus(MapLoadingStatus.Finished);
+ });
+
+ new window.TMap.MultiMarker({
+ id: "marker-layer", //图层id
+ map: map,
+ styles: {
+ //点标注的相关样式
+ marker: new window.TMap.MarkerStyle({
+ width: 25,
+ height: 35,
+ anchor: { x: 16, y: 32 },
+ }),
+ },
+ geometries: [
+ {
+ //点标注数据数组
+ id: "demo",
+ styleId: "marker",
+ position: new window.TMap.LatLng(
+ event.addressLat,
+ event.addressLon
+ ),
+ properties: {
+ title: "marker",
+ },
+ },
+ ],
+ });
+ } catch (error) {
+ console.error(error);
+ setMapLoadingStatus(MapLoadingStatus.Error);
+ }
+ };
return (
<>
+