Indentation ?

This commit is contained in:
Eric van der Vlist 2022-12-21 18:54:56 +01:00
parent 07a7df9089
commit 6702bf8dc4
1 changed files with 62 additions and 36 deletions

View File

@ -1,17 +1,18 @@
import { Grid, IconButton } from '@suid/material'; import { Grid, IconButton } from "@suid/material";
import { Feature } from 'ol'; import { Feature } from "ol";
import { Geometry } from 'ol/geom'; import { Geometry } from "ol/geom";
import { Component, createSignal, For, Show } from 'solid-js'; import { getLength } from "ol/sphere";
import { useI18n } from '@solid-primitives/i18n'; import { Component, createSignal, For, Show } from "solid-js";
import EditIcon from '@suid/icons-material/Edit'; import { useI18n } from "@solid-primitives/i18n";
import { Paper, Stack } from '@suid/material'; import EditIcon from "@suid/icons-material/Edit";
import styled from '@suid/material/styles/styled'; import { Paper, Stack } from "@suid/material";
import Dialog from '../dialog'; import styled from "@suid/material/styles/styled";
import Dialog from "../dialog";
const Item = styled(Paper)(({ theme }) => ({ const Item = styled(Paper)(({ theme }) => ({
...theme.typography.body2, ...theme.typography.body2,
padding: theme.spacing(1), padding: theme.spacing(1),
textAlign: 'center', textAlign: "center",
color: theme.palette.text.secondary, color: theme.palette.text.secondary,
})); }));
@ -23,20 +24,24 @@ export const clickHandler = (event: any) => {
const pixel = [event.originalEvent.x, event.originalEvent.y]; const pixel = [event.originalEvent.x, event.originalEvent.y];
const features = event.map.getFeaturesAtPixel(pixel, { hitTolerance: 30 }); const features = event.map.getFeaturesAtPixel(pixel, { hitTolerance: 30 });
console.log({ console.log({
caller: '<Infos/> / clickHandler', caller: "<Infos/> / clickHandler",
event, event,
features, features,
}); });
selectedFeatures.map((feature) => feature.set('isSelected', false)); selectedFeatures.map((feature) => feature.set("isSelected", false));
selectedFeatures = features; selectedFeatures = features;
features.map((feature: Feature<Geometry>) => { features.map((feature: Feature<Geometry>) => {
const id = feature.get('id'); const id = feature.get("id");
feature.set('isSelected', true); feature.set("isSelected", true);
// const geometry = feature.getGeometry();
// const length = getLength(geometry, { projection: "EPSG:4326" });
console.log({ console.log({
caller: '<Infos/> / clickHandler / feature', caller: "<Infos/> / clickHandler / feature",
event, event,
feature, feature,
id, id,
// geometry,
// length,
}); });
}); });
if (features.length > 0) { if (features.length > 0) {
@ -50,33 +55,54 @@ const Infos: Component<{}> = (props) => {
setOpen(false); setOpen(false);
}; };
const formatLength = (length: number) => {
if (length > 1000) {
const l = length / 1000;
return ` ${l.toLocaleString(undefined, {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
})} km`;
}
return ` ${length.toLocaleString(undefined, {
minimumFractionDigits: 0,
maximumFractionDigits: 0,
})} m`;
};
return ( return (
<Dialog closeHandler={handleClick} open={open()} title={t('nearby')}> <Dialog closeHandler={handleClick} open={open()} title={t("nearby")}>
<Stack <Stack
spacing={1} spacing={1}
direction='column' direction="column"
alignItems='center' alignItems="center"
sx={{ width: 'calc(100% - 5px)' }} sx={{ width: "calc(100% - 5px)" }}
> >
<For each={selectedFeatures}> <For each={selectedFeatures}>
{(feature) => ( {(feature) => {
<Item sx={{ width: 'calc(100% - 1px)' }}> const geometry = feature.getGeometry();
<Grid container spacing={2} alignItems='center'> const length = geometry
<Grid item xs={11}> ? getLength(geometry, { projection: "EPSG:4326" })
{feature.get('getTitle') : undefined;
? feature.get('getTitle')() return (
: t(feature.get('type'))} <Item sx={{ width: "calc(100% - 1px)" }}>
<Grid container spacing={2} alignItems="center">
<Grid item xs={11}>
{feature.get("getTitle")
? feature.get("getTitle")()
: t(feature.get("type"))}
{length ? formatLength(length) : ""}
</Grid>
<Grid item xs={1} sx={{ paddingLeft: "0px" }}>
<Show when={feature.get("edit")}>
<IconButton onClick={feature.get("edit")}>
<EditIcon />
</IconButton>
</Show>
</Grid>
</Grid> </Grid>
<Grid item xs={1} sx={{ paddingLeft: '0px' }}> </Item>
<Show when={feature.get('edit')}> );
<IconButton onClick={feature.get('edit')}> }}
<EditIcon />
</IconButton>
</Show>
</Grid>
</Grid>
</Item>
)}
</For> </For>
</Stack> </Stack>
</Dialog> </Dialog>