diff --git a/src/app/OlMap/Controls/BaseLayers.tsx b/src/app/OlMap/Controls/BaseLayers.tsx index 7f17bb1..03f2a76 100644 --- a/src/app/OlMap/Controls/BaseLayers.tsx +++ b/src/app/OlMap/Controls/BaseLayers.tsx @@ -179,7 +179,7 @@ const BaseLayers: React.FC = () => { }; return ( -
+
{ const map = useMap(); const [zoomLevel, setZoomLevel] = useState(0); const [coordinates, setCoordinates] = useState<[number, number]>([0, 0]); + const scaleLineRef = useRef(null); useEffect(() => { if (!map) return; @@ -28,19 +30,58 @@ const Scale: React.FC = () => { // Initialize values updateZoomLevel(); + // ScaleLine control + const scaleControl = new ScaleLine({ + target: scaleLineRef.current || undefined, + units: "metric", + bar: false, + steps: 4, + text: true, + minWidth: 64, + }); + map.addControl(scaleControl); + return () => { map.un("moveend", updateZoomLevel); map.un("pointermove", updateCoordinates); + map.removeControl(scaleControl); }; }, [map]); return ( -
-
缩放: {zoomLevel.toFixed(1)}
-
- 坐标: {coordinates[0]}, {coordinates[1]} + <> + +
+
+
+
+ 缩放: {zoomLevel.toFixed(1)} +
+
+
+ 坐标: {coordinates[0]}, {coordinates[1]} +
-
+ ); }; diff --git a/src/app/OlMap/Controls/Zoom.tsx b/src/app/OlMap/Controls/Zoom.tsx index 7059a7d..e857abb 100644 --- a/src/app/OlMap/Controls/Zoom.tsx +++ b/src/app/OlMap/Controls/Zoom.tsx @@ -30,7 +30,7 @@ const Zoom: React.FC = () => { }; return ( -
+