完善比例尺控件,调整控件位置
This commit is contained in:
@@ -179,7 +179,7 @@ const BaseLayers: React.FC = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="absolute right-17 bottom-8 z-1300">
|
<div className="absolute right-17 bottom-11 z-1300">
|
||||||
<div
|
<div
|
||||||
className="w-20 h-20 bg-white rounded-xl drop-shadow-xl shadow-black"
|
className="w-20 h-20 bg-white rounded-xl drop-shadow-xl shadow-black"
|
||||||
onMouseEnter={handleEnter}
|
onMouseEnter={handleEnter}
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState, useRef } from "react";
|
||||||
import { useMap } from "../MapComponent";
|
import { useMap } from "../MapComponent";
|
||||||
|
import { ScaleLine } from "ol/control";
|
||||||
|
|
||||||
const Scale: React.FC = () => {
|
const Scale: React.FC = () => {
|
||||||
const map = useMap();
|
const map = useMap();
|
||||||
const [zoomLevel, setZoomLevel] = useState(0);
|
const [zoomLevel, setZoomLevel] = useState(0);
|
||||||
const [coordinates, setCoordinates] = useState<[number, number]>([0, 0]);
|
const [coordinates, setCoordinates] = useState<[number, number]>([0, 0]);
|
||||||
|
const scaleLineRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!map) return;
|
if (!map) return;
|
||||||
@@ -28,19 +30,58 @@ const Scale: React.FC = () => {
|
|||||||
// Initialize values
|
// Initialize values
|
||||||
updateZoomLevel();
|
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 () => {
|
return () => {
|
||||||
map.un("moveend", updateZoomLevel);
|
map.un("moveend", updateZoomLevel);
|
||||||
map.un("pointermove", updateCoordinates);
|
map.un("pointermove", updateCoordinates);
|
||||||
|
map.removeControl(scaleControl);
|
||||||
};
|
};
|
||||||
}, [map]);
|
}, [map]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="absolute bottom-0 right-0 flex col-auto px-2 bg-white bg-opacity-70 text-black rounded-tl shadow-md text-sm z-1300">
|
<>
|
||||||
<div className="px-1">缩放: {zoomLevel.toFixed(1)}</div>
|
<style>
|
||||||
<div className="px-1">
|
{`
|
||||||
坐标: {coordinates[0]}, {coordinates[1]}
|
.custom-scale-line .ol-scale-line {
|
||||||
|
position: static;
|
||||||
|
background: transparent;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
.custom-scale-line .ol-scale-line-inner {
|
||||||
|
border: 1px solid #475569;
|
||||||
|
border-top: none;
|
||||||
|
color: #334155;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
font-weight: 600;
|
||||||
|
transition: all 0.3s;
|
||||||
|
}
|
||||||
|
`}
|
||||||
|
</style>
|
||||||
|
<div className="absolute bottom-0 right-0 flex items-center gap-2 px-3 py-1.5 bg-white/90 hover:bg-white rounded-tl-xl shadow-lg backdrop-blur-sm text-xs font-medium text-slate-700 z-1300 transition-all duration-300 pointer-events-auto">
|
||||||
|
<div
|
||||||
|
ref={scaleLineRef}
|
||||||
|
className="custom-scale-line flex items-center justify-center min-w-[60px]"
|
||||||
|
/>
|
||||||
|
<div className="h-3 w-px bg-slate-300 mx-1" />
|
||||||
|
<div className="min-w-[60px] text-center">
|
||||||
|
缩放: {zoomLevel.toFixed(1)}
|
||||||
|
</div>
|
||||||
|
<div className="h-3 w-px bg-slate-300 mx-1" />
|
||||||
|
<div className="tabular-nums min-w-[140px] text-center">
|
||||||
|
坐标: {coordinates[0]}, {coordinates[1]}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ const Zoom: React.FC = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="absolute right-4 bottom-8 z-1300">
|
<div className="absolute right-4 bottom-11 z-1300">
|
||||||
<div className="w-8 h-26 flex flex-col gap-2 items-center">
|
<div className="w-8 h-26 flex flex-col gap-2 items-center">
|
||||||
<div className="w-8 h-8 bg-gray-50 flex items-center justify-center rounded-xl drop-shadow-xl shadow-black">
|
<div className="w-8 h-8 bg-gray-50 flex items-center justify-center rounded-xl drop-shadow-xl shadow-black">
|
||||||
<button
|
<button
|
||||||
|
|||||||
Reference in New Issue
Block a user