Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

无法获取window.bmapgl #308

Open
Allen-Bayern opened this issue Jun 29, 2023 · 1 comment
Open

无法获取window.bmapgl #308

Allen-Bayern opened this issue Jun 29, 2023 · 1 comment

Comments

@Allen-Bayern
Copy link

RT

import React, { useState, useEffect } from 'react';
import { APILoader } from '@uiw/react-baidu-map';
import { WaterMark } from 'antd-mobile';
import './_style.scss';
import { BoxMap } from '@/components';

export default function MapPage() {
    const AK = 'AK';

    useEffect(() => {
        console.log(window);
        console.log(window?.BMapGL);
    }, []);

    // 获取userName以用于水印
    const [userName] = useState('duxiaoman');

    return (
        <div
            className="map-page"
            style={{ width: '100%', height: '100vh', overflow: 'hidden' }}
        >
            <APILoader
                akay={AK}
                type="webgl"
            >
                <BoxMap></BoxMap>
            </APILoader>

            {/* 水印组件 */}
            <WaterMark content={userName} />
        </div>
    );
}

在打印第一个window时可以看到BmapGL挂到window上了,第二个会直接打出undefined。求教各位大神是怎么回事

@jaywcjlove
Copy link
Member

@Allen-Bayern 如果使用 BmapGL 可以使用百度官方 react 组件 https://lbsyun.baidu.com/solutions/reactBmapDoc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants