Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ const FILE_INPUT_PROPS = {
};

const OPTIONS = {
importSelect: ['coordinateSeparator', 'decimalSeparator'],
importCheckbox: ['prefixId' /*, 'axisFlip' */],
exportSelect: ['decimalCount', 'decimalSeparator', 'coordinateSeparator', 'lineSeparator'],
exportCheckbox: ['prefixId', 'axisFlip', 'writeHeader', 'writeLineEndings', 'writeCardinals'],
options: {...SEPARATORS, decimalCount: DECIMAL, unit: DEGREE }
...SEPARATORS,
decimalCount: DECIMAL,
unit: DEGREE
};

const Content = styled.div`
Expand All @@ -41,42 +39,57 @@ const showDegreeUnit = srs => {
return isDegreeSystem(srs);
};

const CheckboxOption = ({id, checked, onChange, controller}) => (
// locPath is used if options.[id] loc doesn't exist
const CheckboxOption = ({id, values, onChange, controller, locPath}) => (
<Wrapper>
<Checkbox checked={checked} onChange={evt => onChange(id, evt.target.checked)}>
<Message messageKey={`fileSettings.options.${id}`} />
<Checkbox checked={values[id]} onChange={evt => onChange(id, evt.target.checked)}>
<Message messageKey={`fileSettings.options.${locPath || id}`} />
</Checkbox>
<span onClick={() => controller.showInfo(id)}>
<InfoIcon title={<Message messageKey={`infoPopup.${id}.title`}/>}/>
</span>
</Wrapper>
);

const SelectOption = ({id, value, onChange, controller}) =>
<LabeledSelect localize mandatory label={`fileSettings.options.${id}`} info={id} value={value} options={OPTIONS.options[id]} onChange={value => onChange(id, value)} controller={controller}/>

const SelectOption = ({id, values, onChange, controller, mandatory = true}) =>
<LabeledSelect localize mandatory={mandatory} label={`fileSettings.options.${id}`} info={id} value={values[id]} options={OPTIONS[id]} onChange={value => onChange(id, value)} controller={controller}/>

export const ImportFile = ({ import: values, inputSrs, files, fileContents, controller }) => {
const onChange = (key, value) => controller.setFileSetting('import', key, value);
return (
<Content>
<FileInput mandatory onFiles={controller.setFiles} files={files} { ...FILE_INPUT_PROPS } />
<LabeledInput number min={0} label='fileSettings.options.headerLineCount' value={values.headerLineCount} onChange={value => onChange('headerLineCount', value)} controller={controller}/>
{ OPTIONS.importSelect.map(id => <SelectOption key={id} id={id} controller={controller} onChange={onChange} value={values[id]}/>)}
{ showDegreeUnit(inputSrs) && <SelectOption id='unit' controller={controller} onChange={onChange} value={values.unit}/> }
{ OPTIONS.importCheckbox.map(id => <CheckboxOption key={id} id={id} controller={controller} onChange={onChange} checked={values[id]}/>)}
<SelectOption id='coordinateSeparator' controller={controller} onChange={onChange} values={values}/>
<SelectOption id='decimalSeparator' controller={controller} onChange={onChange} values={values}/>
{ showDegreeUnit(inputSrs) && <SelectOption id='unit' mandatory={isDegreeSystem(inputSrs)} controller={controller} onChange={onChange} values={values}/> }
<CheckboxOption id='prefixId' locPath='prefixes.input' controller={controller} onChange={onChange} values={values}/>
<FilePreview fileContents={fileContents} dataFormat={values.unit} />
</Content>
);
};

export const ExportFile = ({ export: values, outputSrs, controller }) => {
export const ExportFile = ({ export: values, outputSrs, controller, fileContents }) => {
const onChange = (key, value) => controller.setFileSetting('export', key, value);
const { lineEndings = [], headerLines = [] , prefixColCount } = fileContents || {};
const prefixIdLocPath = prefixColCount > 0 ? 'prefixes.fromFile' : 'prefixes.generate'; // or prefixes.length > 0
const hasLineEndings = lineEndings.length > 0;
const hasHeaders = headerLines.length > 0;
return (
<Content>
<LabeledInput label='fileSettings.export.fileName' value={values.fileName} onChange={evt => onChange('fileName', evt.target.value)} controller={controller}/>
{ showDegreeUnit(outputSrs) && <SelectOption id='unit' controller={controller} onChange={onChange} value={values.unit}/> }
{ OPTIONS.exportSelect.map(id => <SelectOption key={id} id={id} controller={controller} onChange={onChange} value={values[id]}/>)}
{ OPTIONS.exportCheckbox.map(id => <CheckboxOption key={id} id={id} controller={controller} onChange={onChange} checked={values[id]}/>)}
<LabeledInput label='fileSettings.options.fileName' value={values.fileName} onChange={evt => onChange('fileName', evt.target.value)} controller={controller}/>
<SelectOption id='coordinateSeparator' controller={controller} onChange={onChange} values={values}/>
<SelectOption id='decimalSeparator' controller={controller} onChange={onChange} values={values}/>
<SelectOption id='decimalCount' controller={controller} onChange={onChange} values={values}/>
{ showDegreeUnit(outputSrs) && <SelectOption id='unit' controller={controller} onChange={onChange} values={values}/> }
<SelectOption id='lineSeparator' controller={controller} onChange={onChange} values={values}/>
<CheckboxOption id='createHeader' controller={controller} onChange={onChange} values={values}/>
{ hasHeaders && <CheckboxOption id='writeHeaders' controller={controller} onChange={onChange} values={values}/> }
<CheckboxOption id='prefixId' locPath={prefixIdLocPath} controller={controller} onChange={onChange} values={values}/>
<CheckboxOption id='axisFlip' controller={controller} onChange={onChange} values={values}/>
<CheckboxOption id='writeCardinals' controller={controller} onChange={onChange} values={values}/>
{ hasLineEndings && <CheckboxOption id='writeLineEndings' controller={controller} onChange={onChange} values={values}/> }
</Content>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const getLocalized = options => options.map(opt => opt.label ? opt : ({ ...opt,

const Info = ({ info, controller }) => (
<span onClick={() => controller.showInfo(info)}>
<InfoIcon space={false} title={<Message messageKey={`infoPopup.${info}.title`}/>}/>
<InfoIcon space={false} title={<Message messageKey={`infoPopup.${info}.info`}/>}/>
</span>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ export const MapSelect = ({ controller }) => {
const [value, setValue] = useState(MAP.ADD);
const onRadio = value => {
setValue(value);
controller.onAction(value);
controller.setMapSelectionMode(value);
};
const options = Object.values(MAP).map(value => ({ value, label: <Message messageKey={`mapMarkers.select.${value}`} bundleKey={BUNDLE} />}));
const options = [
{ value: MAP.ADD, label: <Message messageKey='mapMarkers.select.add' bundleKey={BUNDLE} /> },
{ value: MAP.REMOVE, label: <Message messageKey='mapMarkers.select.remove' bundleKey={BUNDLE} /> }
];
return (
<Content>
<Message messageKey='mapMarkers.select.info' bundleKey={BUNDLE} />
Expand Down
26 changes: 19 additions & 7 deletions bundles/paikkatietoikkuna/coordinatetransformation/constants.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
export const BUNDLE = 'coordinatetransformation';
export const WATCH_JOB = 'CoordinateTransformJob';
export const WATCH_URL = '/coordinatetransform/watch/';
export const WATCH_JOB = 'CoordinateTransformJob'; // deprecated
export const WATCH_URL = '/coordinatetransform/watch/'; // deprecated
export const ID_PREFIX = 'coord_marker_';
export const SOURCE = ['table', 'file', 'map']; // deprecated
export const LON_AXES = ['E', 'φ', 'X'];
export const LON_AXES = ['E', 'λ', 'X'];
export const LAN_AXES = ['N', 'φ', 'Y'];

export const HOUR_TO_MIN = 60; // MIN_TO_SEC
export const HOUR_TO_SEC = 3600;
// 2 * pi =~ 6.283185307179586476925286766559
const PI2 = Math.PI * 2;
export const DEC_TO_GRAD = 10 / 9;
export const DEC_TO_RAD = PI2 / 360;

export const MAP = {
ADD: 'add',
REMOVE: 'remove'
REMOVE: 'remove',
STORE: 'store',
POPUP: 'showPopup',
SHOW: 'showOnMap'
};

export const ACTIONS = {
Expand Down Expand Up @@ -43,6 +54,7 @@ export const FILE_DEFAULTS = {
lineSeparator: '\r\n'
}
};

// const closestZoom = 6;

export const SEPARATORS = {
Expand Down Expand Up @@ -71,9 +83,9 @@ export const DECIMAL = [
];

export const DEGREE = [
{ loc: 'fileSettings.options.degreeFormat.degree', value: 'degree', decimals: 8 },
{ loc: 'fileSettings.options.degreeFormat.gradian', value: 'gradian', decimals: 8 },
{ loc: 'fileSettings.options.degreeFormat.radian', value: 'radian', decimals: 10 },
{ loc: 'fileSettings.options.degrees.degree', value: 'degree', decimals: 8 },
{ loc: 'fileSettings.options.degrees.gradian', value: 'gradian', decimals: 8 },
{ loc: 'fileSettings.options.degrees.radian', value: 'radian', decimals: 10 },
{ label: 'DD', value: 'DD', decimals: 8 },
{ label: 'DD MM', value: 'DD MM', decimals: 6 },
{ label: 'DD MM SS', value: 'DD MM SS', decimals: 4 },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DEGREE } from '../constants';
import { DEGREE, HOUR_TO_MIN, HOUR_TO_SEC, DEC_TO_GRAD, DEC_TO_RAD } from '../constants';

export const parseFile = (file) => {
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -54,8 +54,6 @@ export const parseFileContents = (lines = [], delimiter = ';', headerLineCount =

return {
delimiter,
// TODO: we don't need this when we don't send the file to backend
delimiterValueForBackend: delimiter,
decimalSeparator,
prefixColCount,
data,
Expand All @@ -66,22 +64,15 @@ export const parseFileContents = (lines = [], delimiter = ';', headerLineCount =
};
};

const HOUR_TO_MIN = 60;
const HOUR_TO_SEC = 3600;
// 2 * pi =~ 6.283185307179586476925286766559
const PI2 = Math.PI * 2;
const DEC_TO_GRAD = 10 / 9;
const DEC_TO_RAD = PI2 / 360;

// https://github.com/nls-oskari/kartta.paikkatietoikkuna.fi/blob/master/service-coordtransform/src/main/java/fi/nls/paikkatietoikkuna/coordtransform/CoordTransService.java#L25-L26
export const parseValue = (value, format = 'default') => {
export const parseValue = (value, format = 'metric') => {
if (typeof value === 'undefined') {
return NaN;
}
const asNumber = parseFloat(value);
const unitItem = DEGREE.find(unit => unit.value === format);
if (!unitItem) {
return parseFloat(value);
return asNumber;
}
if (format === 'gradian') {
return asNumber / DEC_TO_GRAD;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import { SRS, SRS_H, SYSTEM } from '../constants';
import { SRS, SRS_H, SYSTEM, HOUR_TO_MIN, DEC_TO_GRAD, DEC_TO_RAD } from '../constants';
import { getDimension, isDegreeSystem, isLonFirst, getDecimalCount } from '../helper';

const HOUR_TO_MIN = 60;
// const HOUR_TO_SEC = 3600;
// 2 * pi =~ 6.283185307179586476925286766559
const PI2 = Math.PI * 2;
const DEC_TO_GRAD = 10 / 9;
const DEC_TO_RAD = PI2 / 360;

const CRS = 'Coordinate Reference System';

const toDegree = (coord, unit, decimals, isLon) => {
const toDegree = (coord, unit, decimals) => { //, isLon)
if (unit === 'DD' || unit === 'degree') {
// TODO: prefix 0 ??
return coord.toFixed(decimals);
Expand All @@ -26,7 +19,8 @@ const toDegree = (coord, unit, decimals, isLon) => {
const separator = unit.includes(' ') ? ' ' : '';
const d = Math.floor(coord);
const m = (coord - d) * HOUR_TO_MIN;
const dd = isLon && d < 100 ? '0' + d : d.toString();
const dd = d < 10 ? '0' + d : d.toString();
// const dd = isLon && d < 100 ? '0' + d : d.toString();
let mm = m.toFixed(decimals);
if (m < 10) {
mm = '0' + mm;
Expand Down Expand Up @@ -107,7 +101,7 @@ const getFileContent = ({
}).join(lineSeparator);
};

const createHeader = (srs, height, axisFlip, decimalUnit) => {
const createSrsHeader = (srs, height, axisFlip, decimalUnit) => {
// name for KKJ (no need to localize zones)
const { name, label = name, axes = [], system } = SRS.find(s => s.value === srs) || {};
const { unit: systemUnit } = SYSTEM.find(s => s.value === system) || {};
Expand All @@ -124,17 +118,15 @@ const createHeader = (srs, height, axisFlip, decimalUnit) => {

export const exportStateToFile = (state) => {
const { outputSrs, outputHeightSrs, fileContents } = state;
const { fileName, lineSeparator, writeHeader, axisFlip, unit } = state.export;
const { fileName, lineSeparator, createHeader, writeHeaders, axisFlip, unit } = state.export;

const content = [];
if (writeHeader) {
const { headerLines = [] } = fileContents || {};
if (headerLines.length) {
headerLines.forEach(header => content.push(header));
} else {
const header = createHeader(outputSrs, outputHeightSrs, axisFlip, unit);
content.push(header);
}
if (createHeader) {
const header = createSrsHeader(outputSrs, outputHeightSrs, axisFlip, unit);
content.push(header);
}
if (writeHeaders) {
fileContents?.headerLines?.forEach(header => content.push(header));
}
const text = getFileContent(state);
content.push(text);
Expand Down
Loading
Loading