[英]Leaflet with degress and azimuth
I'm using react-leaflet and I need to plot a geographic coordinate, degrees and azimuth on the map, as in the image example, but I didn't find how to do it.我正在使用 react-leaflet,我需要在地图上绘制地理坐标、度数和方位角,如图像示例中所示,但我没有找到如何做。
I have the coordinate and the azimuth and I need to plot the same as it is in the image, with an opening of 90º.我有坐标和方位角,我需要绘制与图像中相同的图,开口为 90º。
UPDATE 1更新 1
const Map = ({ position, azimuth }) => {
const ICON = icon({
iconUrl: "images/antena.png",
iconSize: [120, 120],
});
let startAngle = (azimuth + 120 / 2 ) % 360;
let stopAngle = (azimuth - 120 / 2 ) % 360;
console.log(azimuth, startAngle, stopAngle)
return (
<MapContainer
style={{ height: "100%", minHeight: "100%" }}
zoom={15}
center={position}
scrollWheelZoom={true}
>
<TileLayer
attribution="aaaa"
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
<SemiCircle
position={position}
radius={1000}
startAngle={startAngle}
stopAngle={stopAngle}
opacity={0.5}
weight={1}
// smoothFactor={1}
/>
<PlotPolyline position={position} azimuth={azimuth} distance={1000} />
</MapContainer>
);
};
I managed to make the semicircle, but I'm wrong in the degree calculations, I think.我设法做了一个半圆,但我认为我在计算度数时错了。 Some semicircles are displayed correctly, with the proper opening and others are displayed wrong, see the images.一些半圆正确显示,开口正确,而其他半圆显示错误,请参见图像。
Example 1:示例 1:
Example 2, wrong:例2,错误:
You need to create a custom react-leaflet component to be able to use the plugin IvanSanchez mentioned.您需要创建一个自定义的 react-leaflet 组件才能使用 IvanSanchez 提到的插件。
All you need is the map reference and plugin's L.semiCircle to instantiate it.您只需要地图引用和插件的 L.semiCircle 来实例化它。
export default function Semicircle() {
const map = useMap();
useEffect(() => {
if (!map) return;
L.semiCircle([51.5, -0.09], {
radius: 500,
startAngle: 45,
stopAngle: 135
}).addTo(map);
}, [map]);
return null;
}
and then use it a chidl of MapContainer然后使用它作为 MapContainer 的 chidl
<MapContainer>
...
<Semicircle/>
</MapContainer>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.