diff --git a/src/pages/route-preview/Constants.ts b/src/pages/route-preview/Constants.ts index 0a0cf7d..a4b646f 100644 --- a/src/pages/route-preview/Constants.ts +++ b/src/pages/route-preview/Constants.ts @@ -3,7 +3,7 @@ export const PATH_WIDTH = 15; export const STATION_RADIUS = 20; export const STATION_OUTLINE_WIDTH = 10; export const SIGHT_SIZE = 60; -export const SCALE_FACTOR = 40; +export const SCALE_FACTOR = 50; export const BACKGROUND_COLOR = 0x111111; export const PATH_COLOR = 0xff4d4d; \ No newline at end of file diff --git a/src/pages/route-preview/InfiniteCanvas.tsx b/src/pages/route-preview/InfiniteCanvas.tsx index 6df05c5..63cd364 100644 --- a/src/pages/route-preview/InfiniteCanvas.tsx +++ b/src/pages/route-preview/InfiniteCanvas.tsx @@ -116,6 +116,11 @@ export function InfiniteCanvas({children} : Readonly<{children?: ReactNode}>) { setScale(newScale); }; + useEffect(() => { + applicationRef?.current?.getApplication()?.render(); + console.log(position, scale, rotation); + }, [position, scale, rotation]); + return ( diff --git a/src/pages/route-preview/MapDataContext.tsx b/src/pages/route-preview/MapDataContext.tsx index b8ea2ee..0ce7fde 100644 --- a/src/pages/route-preview/MapDataContext.tsx +++ b/src/pages/route-preview/MapDataContext.tsx @@ -1,11 +1,9 @@ -import { useCustom, useShow, useApiUrl } from "@refinedev/core"; +import { useCustom, useApiUrl } from "@refinedev/core"; import { useParams } from "react-router"; import { createContext, ReactNode, useContext, useEffect, useMemo, useState } from "react"; import { RouteData, SightData, StationData, StationPatchData } from "./types"; import { axiosInstance } from "../../providers/data"; - - const MapDataContext = createContext<{ originalRouteData?: RouteData, originalStationData?: StationData[], @@ -63,7 +61,7 @@ export function MapDataProvider({ children }: Readonly<{ children: ReactNode }>) }); const { data: stationQuery, isLoading: isStationLoading } = useCustom({ url: `${apiUrl}/route/${routeId}/station`, - method: 'get', + method: 'get' }); const { data: sightQuery, isLoading: isSightLoading } = useCustom({ url: `${apiUrl}/route/${routeId}/sight`, @@ -110,8 +108,7 @@ export function MapDataProvider({ children }: Readonly<{ children: ReactNode }>) } async function saveChanges() { - console.log("saveChanges", routeData); - const response = await axiosInstance.patch(`/route/${routeId}`, routeData); + await axiosInstance.patch(`/route/${routeId}`, routeData); saveStationChanges(); } diff --git a/src/pages/route-preview/RightSidebar.tsx b/src/pages/route-preview/RightSidebar.tsx index 38f589a..de193ce 100644 --- a/src/pages/route-preview/RightSidebar.tsx +++ b/src/pages/route-preview/RightSidebar.tsx @@ -2,7 +2,7 @@ import { Button, Stack, TextField, Typography } from "@mui/material"; import { useMapData } from "./MapDataContext"; import { useEffect, useState } from "react"; import { useTransform } from "./TransformContext"; -import { localToCoordinates } from "./utils"; +import { coordinatesToLocal, localToCoordinates } from "./utils"; export function RightSidebar() { const { routeData, setScaleRange, saveChanges, originalRouteData, setMapRotation, setMapCenter } = useMapData(); @@ -52,7 +52,8 @@ export function RightSidebar() { } function pan({x, y}: {x: number, y: number}) { - setTransform(x, y); + const coordinates = coordinatesToLocal(y,x); + setTransform(coordinates.x, coordinates.y); } if(!routeData) { diff --git a/src/pages/route-preview/Station.tsx b/src/pages/route-preview/Station.tsx index 64de524..ae06f2a 100644 --- a/src/pages/route-preview/Station.tsx +++ b/src/pages/route-preview/Station.tsx @@ -40,10 +40,6 @@ export function StationLabel({ const [startPosition, setStartPosition] = useState({ x: 0, y: 0 }); const [startMousePosition, setStartMousePosition] = useState({ x: 0, y: 0 }); - useEffect(() => { - console.log(position); - }, [position]); - if(!station) { console.error("station is null"); return null; @@ -64,8 +60,8 @@ export function StationLabel({ }; const handlePointerMove = (e: FederatedMouseEvent) => { if (!isDragging) return; - const dx = (e.globalX - startMousePosition.x) / scale; - const dy = (e.globalY - startMousePosition.y) / scale; + const dx = (e.globalX - startMousePosition.x); + const dy = (e.globalY - startMousePosition.y); const cos = Math.cos(rotation); const sin = Math.sin(rotation); const newPosition = { @@ -93,13 +89,17 @@ export function StationLabel({ onPointerUpOutside={handlePointerUp} width={48} height={48} - x={coordinates.x * UP_SCALE + position.x*scale} - y={coordinates.y * UP_SCALE + position.y*scale} + x={coordinates.x * UP_SCALE} + y={coordinates.y * UP_SCALE} rotation={-rotation} > { - if(!applicationRef?.current || isSetup) { + if(!applicationRef?.current?.getCanvas() || isSetup) { return; } @@ -111,7 +111,7 @@ export function RouteMap() { ); setIsSetup(true); } - }, [points, originalRouteData?.center_latitude, originalRouteData?.center_longitude, originalRouteData?.rotate, applicationRef?.current, isSetup]); + }, [points, originalRouteData?.center_latitude, originalRouteData?.center_longitude, originalRouteData?.rotate, applicationRef?.current?.getCanvas(), isSetup]); if (!routeData || !stationData || !sightData) { console.error("routeData, stationData or sightData is null"); diff --git a/src/pages/route-preview/utils.ts b/src/pages/route-preview/utils.ts index b7f8caa..161fd80 100644 --- a/src/pages/route-preview/utils.ts +++ b/src/pages/route-preview/utils.ts @@ -1,10 +1,9 @@ +// approximation export function coordinatesToLocal(longitude: number, latitude: number) { - return { x: latitude, y: -longitude*2 } - //return {x: longitude, y: latitude} } export function localToCoordinates(x: number, y: number) { @@ -12,5 +11,4 @@ export function localToCoordinates(x: number, y: number) { latitude: x, longitude: -y/2 } - // return {latitude: x, longitude: y} } \ No newline at end of file diff --git a/src/pages/sight/edit.tsx b/src/pages/sight/edit.tsx index 8c69c85..2b60192 100644 --- a/src/pages/sight/edit.tsx +++ b/src/pages/sight/edit.tsx @@ -444,8 +444,8 @@ export const SightEdit = observer(() => { onChange={(_, newValue) => setTabValue(newValue)} aria-label="basic tabs example" > - - + + @@ -594,20 +594,6 @@ export const SightEdit = observer(() => { name="coordinates" /> */} - - { display: "flex", flexDirection: "column", position: "fixed", - p: 2, + p: 0, height: "max-content", width: "30%", @@ -1172,7 +1158,6 @@ export const SightEdit = observer(() => { display: "flex", flexDirection: "column", flexGrow: 1, - gap: 2, }} > {!previewSelected && ( @@ -1192,7 +1177,6 @@ export const SightEdit = observer(() => { alt={mediaFile.filename} style={{ maxWidth: "100%", - height: "300px", objectFit: "contain", borderRadius: 8, }} @@ -1255,14 +1239,14 @@ export const SightEdit = observer(() => { { {previewSelected && @@ -1356,7 +1340,16 @@ export const SightEdit = observer(() => { {selectedArticle.heading} @@ -1366,6 +1359,7 @@ export const SightEdit = observer(() => { {selectedArticle.body} @@ -1374,47 +1368,50 @@ export const SightEdit = observer(() => { )} - - Привязанные статьи - - {linkedArticles.map((article, index) => ( - { - setSelectedArticleIndex(index); - setPreviewSelected(false); - }} - sx={{ - cursor: "pointer", - bgcolor: - selectedArticleIndex === index - ? "primary.main" - : "transparent", - color: - selectedArticleIndex === index - ? "white" - : "inherit", - p: 1, - borderRadius: 1, - }} - > - - {article.heading} - - - ))} + + {linkedArticles.map((article, index) => ( + { + setSelectedArticleIndex(index); + setPreviewSelected(false); + }} + sx={{ + cursor: "pointer", + bgcolor: "transparent", + color: "inherit", + textDecoration: + selectedArticleIndex === index ? + "underline" : "none", + p: 1, + borderRadius: 1, + }} + > + + {article.heading} + + + ))} + @@ -1446,6 +1443,21 @@ export const SightEdit = observer(() => { sx={{ flex: 1, display: "flex", flexDirection: "column" }} autoComplete="off" > + + + { {thumbnailPreview && ( + + + Адрес:{" "} + + + theme.palette.mode === "dark" ? "grey.300" : "grey.800", + }} + > + {`${addressContent}`} + +