Skip to content

Commit

Permalink
fix(export): export to latin1 with no latin1 equivalent characters (#…
Browse files Browse the repository at this point in the history
…1042)

* fix(export): export to latin1 with no latin1 equivalent characters

* lint

* wip

Co-authored-by: Pierre-Étienne Lord <[email protected]>
  • Loading branch information
pelord and Pierre-Étienne Lord authored May 24, 2022
1 parent ec0cae3 commit 9d9e8c6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
"typy": "^3.3.0",
"unorm": "^1.4.1",
"web-animations-js": "^2.3.2",
"windows-1252": "^3.0.4",
"zone.js": "~0.11.4"
},
"devDependencies": {
Expand Down
10 changes: 9 additions & 1 deletion packages/geo/src/lib/import-export/shared/export.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Observable, Observer } from 'rxjs';
import * as olformat from 'ol/format';
import OlFeature from 'ol/Feature';
import type { default as OlGeometry } from 'ol/geom/Geometry';
import {encode} from 'windows-1252';

import { ExportFormat, EncodingFormat } from './export.type';

Expand Down Expand Up @@ -168,7 +169,7 @@ export class ExportService {
projectionIn: string,
projectionOut: string
) {
const featuresText: string = new olformat.GeoJSON().writeFeatures(
let featuresText: string = new olformat.GeoJSON().writeFeatures(
olFeatures,
{
dataProjection: projectionOut,
Expand All @@ -189,6 +190,13 @@ export class ExportService {
form.enctype = 'application/x-www-form-urlencoded; charset=utf-8;';
} else if (encodingType === EncodingFormat.LATIN1) {
const enctype = 'ISO-8859-1';
const featuresJson = JSON.parse(featuresText);
featuresJson.features.map(f => {
const encodedProperties = String.fromCharCode
.apply(null, encode(JSON.stringify(f.properties), { mode: 'replacement' }));
f.properties = JSON.parse(encodedProperties);
});
featuresText = JSON.stringify(featuresJson);
const encoding = document.createElement('input');
encoding.setAttribute('type', 'hidden');
encoding.setAttribute('name', 'encoding');
Expand Down

0 comments on commit 9d9e8c6

Please sign in to comment.