@h4wldev/react-naver-maps
Version:
React Navermaps API integration for modern development.
57 lines (55 loc) • 1.52 kB
JavaScript
import {
loadScript
} from "./chunk-F6WKUPXL.mjs";
// src/load-navermaps-script.tsx
import { useEffect, useState } from "react";
import { jsx } from "react/jsx-runtime";
function loadNavermapsScript(options) {
const url = makeUrl(options);
const promise = loadScript(url).then(() => {
const navermaps = window.naver.maps;
if (navermaps.jsContentLoaded) {
return navermaps;
}
return new Promise((resolve) => {
navermaps.onJSContentLoaded = () => {
resolve(navermaps);
};
});
});
return promise;
}
function makeUrl(options) {
const submodules = options.submodules;
let clientIdQuery = null;
["ncpClientId", "ncpKeyId", "govClientId", "finClientId"].forEach((key) => {
if (key in options) {
clientIdQuery = `${key}=${options[key]}`;
}
});
if (!clientIdQuery) {
throw new Error("react-naver-maps: ncpClientId, govClientId or finClientId is required");
}
let url = `https://oapi.map.naver.com/openapi/v3/maps.js?${clientIdQuery}`;
if (submodules) {
url += `&submodules=${submodules.join(",")}`;
}
return url;
}
function LoadNavermapsScript({
children: Children,
...options
}) {
const [navermaps, setNavermaps] = useState();
useEffect(() => {
loadNavermapsScript(options).then((maps) => {
setNavermaps(maps);
});
}, []);
return navermaps && Children ? /* @__PURE__ */ jsx(Children, {}) : null;
}
export {
loadNavermapsScript,
LoadNavermapsScript
};
//# sourceMappingURL=chunk-HSCTNOCJ.mjs.map