geostyler
Version:
Framework for styling geodata
112 lines (111 loc) • 2.83 kB
JavaScript
import { jsx as s, jsxs as U } from "react/jsx-runtime";
import p from "react";
import { Select as S, Modal as g } from "antd";
import { UploadButton as c } from "../../UploadButton/UploadButton.js";
import { WfsParserInput as x } from "../WfsParserInput/WfsParserInput.js";
import { useGeoStylerLocale as G } from "../../../context/GeoStylerContext/GeoStylerContext.js";
const I = S.Option, J = ({
parsers: f,
uploadButtonProps: d,
onDataRead: l = () => {
}
}) => {
const h = G("DataLoader"), [D, i] = p.useState(!1), [t, P] = p.useState(), u = (e) => {
if (!t)
return;
const r = e.file, a = new FileReader();
a.readAsText(r), a.onload = () => {
const o = a.result.toString();
t.readData(JSON.parse(o)).then((n) => {
l(n), e.onSuccess(n);
}).catch((n) => {
e.onError(n, "Upload failed. Invalid Data.");
});
};
}, v = (e) => {
if (!t)
return;
const r = e.file, a = new FileReader();
a.readAsArrayBuffer(r), a.onload = () => {
t.readData(a.result).then((o) => {
l(o), e.onSuccess(o);
}).catch((o) => {
e.onError(o, "Upload failed. Invalid Data.");
});
};
}, w = (e) => {
t && t.readData({
...e,
srsName: "EPSG:4326"
}).then((r) => {
l(r), i(!1);
});
}, A = f.map(
(e) => /* @__PURE__ */ s(I, { value: e.title, children: e.title }, e.title)
), F = (e) => {
const r = f.find((a) => a.title === e);
r && (P(r), i(r.title === "WFS Data Parser"));
}, m = () => {
i(!1);
}, N = () => {
if (t)
switch (t.title) {
case "GeoJSON Data Parser":
return /* @__PURE__ */ s(
c,
{
customRequest: u,
...d
}
);
case "Shapefile Data Parser":
return /* @__PURE__ */ s(
c,
{
customRequest: v,
...d
}
);
case "WFS Data Parser":
return /* @__PURE__ */ s(
g,
{
className: "wfs-parser-modal",
title: t.title,
open: D,
onCancel: m,
onOk: m,
children: /* @__PURE__ */ s(
x,
{
onClick: w
}
)
}
);
default:
return /* @__PURE__ */ s(
c,
{
customRequest: u
}
);
}
return null;
};
return /* @__PURE__ */ U("div", { className: t ? "gs-dataloader-right" : "", children: [
h.label,
/* @__PURE__ */ s(
S,
{
style: { width: 300 },
onSelect: F,
children: A
}
),
N()
] });
};
export {
J as DataLoader
};