javascript - 如何将谷歌地图标记固定在地图中心?
问题描述
我npm install --save google-map-react
用来显示谷歌地图,这AnyReactComponent
是标记。我已经给出了fixed
位置和inset-0
标记,但是当我开始拖动地图时,它不会停留在地图的中心,当我结束拖动时,固定位置就会起作用。我想要的是当用户开始拖动地图时,图钉应该只停留在中心。
<div
className="mx-auto max-w-2xl relative"
style={{ height: "100vh", width: "100%" }}
>
<GoogleMapReact
bootstrapURLKeys={{ key: process.env.REACT_APP_GOOGLE_KEY }}
defaultCenter={userInfo.center}
defaultZoom={userInfo.zoom}
onChange={(e) => updateMap(e)}
>
<AnyReactComponent
lat={updatedPosition.lat}
lng={updatedPosition.lng}
text="My Marker"
/>
</GoogleMapReact>
</div>
任何反应组件
const AnyReactComponent = ({ text }) => {
return (
<div className="bg-white sticky transform inset-0 z-50 ">
<svg
xmlns="http://www.w3.org/2000/svg"
className="h-6 w-6"
viewBox="0 0 20 20"
fill="#FFF"
>
<path
fillRule="evenodd"
d="M5.05 4.05a7 7 0 119.9 9.9L10 18.9l-4.95-4.95a7 7 0 010-9.9zM10 11a2 2 0 100-4 2 2 0 000 4z"
clipRule="evenodd"
/>
</svg>
<span className="text-xl text-white">{text}</span>
</div>
);
};
解决方案
推荐阅读
- templates - TYPO3:替换变量中的字符串
- java - 提取 3 个子字符串并创建 Animal 对象
- r - 如何将矢量存储在R中的数据框中
- ffmpeg - 如何让 Gstreamer 只返回关键帧?
- git - 如果远程处于特定提交上,是否可以仅 git force push?
- python-3.x - 安装 Tensorflow GPU - 找不到 libcublas.so.9.0,即使它存在且在路径中
- maven - Maven Netbeans 中的实现依赖
- c# - 获取响应广播的设备的 IP 地址
- android - Android Studio 预览版不显示布局
- wpf - WPF 按钮样式不适用于第二个按钮