export function loadAMap() {
    return new Promise((resolve, reject) => {
        if (window.AMap) return resolve();

        // 确保AMapLoader存在
        if (!window.AMapLoader) {
            return reject(new Error("AMapLoader未正确加载"));
        }

        window.AMapLoader.load({
            key: "848ab05db2a57a7782c153119f50dcef",
            version: "2.0",
        })
            .then((AMap) => {
                window.AMap = AMap;
                console.log("AMap初始化完成", AMap);
                resolve();
            })
            .catch((err) => {
                console.error("AMap加载失败:", err);
                reject(new Error("地图加载失败，请检查网络连接"));
            });
    });
};