Skip to content

Commit

Permalink
Update layout in coordinates plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
sbk-linus committed Oct 16, 2019
1 parent 2a69b35 commit d43fcbf
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 67 deletions.
33 changes: 20 additions & 13 deletions new-client/src/plugins/coordinates/CoordinatesModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CoordinatesModel {

this.map.addLayer(this.vector);
this.coordinates = undefined;
this.transformedCoordinates = {};
this.transformedCoordinates = [];
}

get getMap() {
Expand Down Expand Up @@ -69,20 +69,27 @@ class CoordinatesModel {

presentCoordinates() {
var coordinates = this.coordinates;
var transformedCoordinates = {};
var transformedCoordinates = [];
var transformations = this.transformations;

transformations.map((transformation, i) => {
transformedCoordinates = {
coordinates: this.transform(coordinates, transformation.code) || "",
xtitle: transformation.xtitle || "",
ytitle: transformation.ytitle || ""
};

this.transformedCoordinates[i] = transformedCoordinates;

return transformedCoordinates;
});
if (transformations.length) {
transformations.map((transformation, i) => {
transformedCoordinates = {
code: transformation.code || "",
default: transformation.default || false,
hint: transformation.hint || "",
title: transformation.title || "",
xtitle: transformation.xtitle || "",
ytitle: transformation.ytitle || "",
inverseAxis: transformation.inverseAxis || false,
coordinates: this.transform(coordinates, transformation.code) || ""
};

this.transformedCoordinates[i] = transformedCoordinates;

return this.transformedCoordinates;
});
}

this.localObserver.publish(
"setTransformedCoordinates",
Expand Down
113 changes: 59 additions & 54 deletions new-client/src/plugins/coordinates/CoordinatesView.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import TableHead from "@material-ui/core/TableHead";
import TableRow from "@material-ui/core/TableRow";
import Paper from "@material-ui/core/Paper";
import Typography from "@material-ui/core/Typography";
import TextField from "@material-ui/core/TextField";

const styles = theme => ({
root: {
Expand All @@ -21,7 +22,12 @@ const styles = theme => ({
position: "unset"
}
},
table: {}
table: {},
textField: {
marginLeft: theme.spacing(1),
marginRight: theme.spacing(1),
marginTop: theme.spacing(2)
}
});

class CoordinatesView extends React.PureComponent {
Expand All @@ -34,8 +40,6 @@ class CoordinatesView extends React.PureComponent {
this.options = this.props.options;
this.localObserver = this.props.localObserver;

this.transformations = this.props.options.transformations;

this.localObserver.subscribe(
"setTransformedCoordinates",
transformedCoordinates => {
Expand All @@ -53,57 +57,58 @@ class CoordinatesView extends React.PureComponent {
}

renderProjections() {
if (this.transformations.length) {
return (
<>
{this.transformations.map((coordinates, i) => {
return (
<TableRow key={i}>
<TableCell>
<Typography variant="subtitle2" style={{ display: "block" }}>
{coordinates.title} ({coordinates.code})
</Typography>
</TableCell>
<TableCell>
<Typography style={{ display: "block" }}>
{coordinates.ytitle}:
{this.state.transformedCoordinates
? this.state.transformedCoordinates[i].coordinates[1]
: ""}
</Typography>
<Typography style={{ display: "block" }}>
{coordinates.xtitle}:
{this.state.transformedCoordinates
? this.state.transformedCoordinates[i].coordinates[0]
: ""}
</Typography>
</TableCell>
</TableRow>
);
})}
</>
);
} else {
return (
<>
<TableRow>
<TableCell>
<Typography variant="subtitle2" style={{ display: "block" }}>
Sweref 99 12 00
</Typography>
</TableCell>
<TableCell>
<Typography style={{ display: "block" }}>
N: {this.props.coordinates}
</Typography>
<Typography style={{ display: "block" }}>
E: {this.props.coordinates}
</Typography>
</TableCell>
</TableRow>
</>
);
}
const { classes } = this.props;

return (
<>
{this.state.transformedCoordinates
? this.state.transformedCoordinates.map((transformations, i) => {
return (
<TableRow key={i}>
<TableCell>
<Typography
variant="subtitle2"
style={{ display: "block" }}
>
{transformations.title}
</Typography>
<Typography
variant="subtitle2"
style={{ display: "block" }}
>
({transformations.code})
</Typography>
</TableCell>
<TableCell>
<TextField
label={transformations.ytitle}
className={classes.textField}
margin="dense"
variant="outlined"
value={
transformations.inverseAxis
? transformations.coordinates[0]
: transformations.coordinates[1]
}
/>
<TextField
label={transformations.xtitle}
className={classes.textField}
margin="dense"
variant="outlined"
value={
transformations.inverseAxis
? transformations.coordinates[1]
: transformations.coordinates[0]
}
/>
</TableCell>
</TableRow>
);
})
: null}
</>
);
}

render() {
Expand Down

1 comment on commit d43fcbf

@sbk-linus
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.