Skip to content

Commit f53ff2c

Browse files
committed
add debugging
1 parent 34d8725 commit f53ff2c

File tree

2 files changed

+59
-7
lines changed

2 files changed

+59
-7
lines changed

bundles/paikkatietoikkuna/coordinatetransformation/handler/ViewHandler.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { showFilePopup } from '../view/FilePopup';
44
import { showConfirmPopup } from '../view/ConfirmPopup';
55
import { showClipboardPopup } from '../view/ClipboardPopup';
66
import { showMapSelectPopup, showMapPreviewPopup } from '../view/MapPopup';
7-
import { SOURCE, MAP, WATCH_JOB, WATCH_URL, FILE_DEFAULTS, ACTIONS, PAGINATION } from '../constants';
8-
import { stateToPTIArray, stateToTransformRequest, stateToKomuRequest, parseKomuResponse, validateFileSettings, validateTransform, validateCoordinate, parseCoordinateValue, is3DSystem, getDimension, getLabelForMarker } from '../helper';
7+
import { SOURCE, MAP, WATCH_JOB, WATCH_URL, FILE_DEFAULTS, ACTIONS, PAGINATION, SRS } from '../constants';
8+
import { stateToPTIArray, stateToTransformRequest, stateToKomuRequest, parseKomuResponse, validateFileSettings, validateTransform, validateCoordinate, parseCoordinateValue, is3DSystem, getDimension, getLabelForMarker, getCoordinatesExtent } from '../helper';
99
import { parseFile, parseFileContents, parseValue } from './FileParser';
1010
import { exportStateToFile } from './FileWriter';
1111

@@ -45,6 +45,7 @@ class UIHandler extends StateHandler {
4545
this.baseUrl = conf.url;
4646
this.transformFunction = this.getTransformFunction(conf);
4747
Oskari.urls.set(WATCH_JOB, WATCH_URL);
48+
this.log = Oskari.log('CoordTransHandler');
4849
}
4950

5051
getTransformFunction ({ url, contentType }) {
@@ -184,8 +185,8 @@ class UIHandler extends StateHandler {
184185
.map(([x, y, z]) => ({ x, y, z }));
185186
this.addSourceToState('clipboard');
186187
this.updateState({ coordinates, transformed: false });
187-
} catch {
188-
// TODO: error handling
188+
} catch (err) {
189+
this.log.debug(err);
189190
Messaging.error(this.loc('transform.errors.paste'));
190191
}
191192
}
@@ -299,7 +300,7 @@ class UIHandler extends StateHandler {
299300
import: newSettings // { ...settings, ...contents.settings }
300301
});
301302
}).catch(err => {
302-
console.log(err);
303+
this.log.debug(err);
303304
Messaging.error(this.log('transform.errors.import'));
304305
});
305306
}
@@ -517,9 +518,21 @@ class UIHandler extends StateHandler {
517518
this.showConfirmTransform(warnings);
518519
return;
519520
}
521+
if (this.log.isDebug()) {
522+
this.debugTransform();
523+
}
520524
this.transformFunction();
521525
}
522526

527+
debugTransform () {
528+
const { inputSrs, coordinates } = this.getState();
529+
const { bounds = [] } = SRS.find(s => s.value === inputSrs) || {};
530+
const info = getCoordinatesExtent(coordinates, inputSrs);
531+
this.log.debug('Projected bounds for:', inputSrs, bounds);
532+
Object.keys(info).forEach(key => this.log.debug(key, '=>', info[key]));
533+
}
534+
535+
523536
importFileContentsToInputTable () {
524537
const errors = validateFileSettings(this.getState(), 'import');
525538
if (errors.length) {
@@ -549,7 +562,7 @@ class UIHandler extends StateHandler {
549562
try {
550563
exportStateToFile(state);
551564
} catch (err) {
552-
console.log(err);
565+
this.log.debug(err);
553566
Messaging.error(this.loc('transform.errors.export'));
554567
}
555568
this.updateState({ loading: false });
@@ -702,7 +715,6 @@ class UIHandler extends StateHandler {
702715
showResponseError (response) {
703716
const { error, info } = response || {};
704717
const key = info?.errorKey || error?.errorKey || 'generic';
705-
Oskari.log('CoordTransHandler').error(error);
706718
Messaging.error(this.loc(`transform.errors.${key}`));
707719
this.updateState({ loading: false });
708720
}

bundles/paikkatietoikkuna/coordinatetransformation/helper.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,46 @@ export const getLabelForMarker = (coord, srs) => {
209209
*/
210210
};
211211

212+
// Added for debugging
213+
export const getCoordinatesExtent = (coordinates, srs) => {
214+
if (!coordinates.length) {
215+
return {};
216+
}
217+
const swap = !isLonFirst(srs);
218+
let minX = Infinity;
219+
let maxX = -Infinity;
220+
let minY = Infinity;
221+
let maxY = -Infinity;
222+
coordinates.forEach(({ x, y }, i) => {
223+
const coord = swap ? [y, x] : [x, y];
224+
if (coord.some(c => typeof c !== 'number' || isNaN(c))) {
225+
Oskari.log('CoordTransHelper').warn('Invalid coord:', coord, 'at:', i);
226+
return;
227+
}
228+
if (coord[0] < minX) {
229+
minX = coord[0];
230+
}
231+
if (coord[0] > maxX) {
232+
maxX = coord[0];
233+
}
234+
if (coord[1] < minY) {
235+
minY = coord[1];
236+
}
237+
if (coord[1] > maxY) {
238+
maxY = coord[1];
239+
}
240+
});
241+
// wkt: left-bottom counterclockwise closed
242+
return {
243+
extent: [minX, minY, maxX, maxY],
244+
bbox: { left: minX, bottom: minY, right: maxX, top: maxY },
245+
min: { x: swap ? minY : minX, y: swap ? minX : minY},
246+
max: { x: swap ? maxY : maxX, y: swap ? maxX : maxY},
247+
wkt: `POLYGON ((${minX} ${minY}, ${maxX} ${minY}, ${maxX} ${maxY}, ${minX} ${maxY}, ${minX} ${minY}))`
248+
};
249+
// Oskari.getSandbox().postRequestByName('MapModulePlugin.AddFeaturesToMapRequest', [wkt, { layerId: 'komu', centerTo: true }]);
250+
};
251+
212252
export const coordinateToMarker = (coord, isNew) => {
213253
const { colors, ...props } = MARKER;
214254
const { x, y, label } = coord;

0 commit comments

Comments
 (0)