uiwjs / react-baidu-map

基于 React 封装的百度地图组件,支持 React Hook,帮助你轻松的接入地图到 React 项目中。
https://uiwjs.github.io/react-baidu-map
MIT License
222 stars 22 forks source link

请问,我用官网提供的demo放到我的项目中地图首次加载不出来,第二次打开才能显示,这个是什么原因呢? #93

Closed fekevin closed 3 years ago

fekevin commented 3 years ago

import { useRef, useEffect, useState } from 'react' import { Map, APILoader, useMap } from '@uiw/react-baidu-map' import React from 'react' const Example = () => { const divElm = useRef() const [zoom, setZoom] = useState(15) const { setContainer, map, center, setCenter, setAutoLocalCity } = useMap({ enableScrollWheelZoom: true, // 启用滚轮放大缩小,默认禁用 center: '北京', widget: ['GeolocationControl', 'NavigationControl'] }) useEffect(() => { if (divElm.current && !map) { setContainer(divElm.current) } }) useEffect(() => { if (map) { // 启用滚轮放大缩小,默认禁用 map.setZoom(zoom) } }, [zoom, map]) return ( <> <div style={{ width: '100%', height: '300px' }}>

        </div>
    </>
)

} export default Example

fekevin commented 3 years ago

已解决

maimai123 commented 3 years ago

已解决

我也有这个问题哎,第一次进来地图不显示,第二次进来就好了,请问是版本几修复了呢

maimai123 commented 3 years ago

已解决

我也有这个问题哎,第一次进来地图不显示,第二次进来就好了,请问是版本几修复了呢