Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next #43

Merged
merged 2 commits into from
Jun 18, 2020
Merged

Next #43

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 @@ -61,7 +61,7 @@ <h4>{{'igo.geo.importExportForm.exportNoLayersExportable' | translate}}</h4>
formControlName="format"
placeholder="{{'igo.geo.importExportForm.exportFormatPlaceholder' | translate}}">
<mat-option *ngFor="let format of (formats$ | async) | keyvalue " [value]="format.key">
{{format.value}}
{{'igo.geo.export.format.' + format.value | translate}}
</mat-option>
</mat-select>
</mat-form-field>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ export class ImportExportComponent implements OnDestroy, OnInit {
return formats
.filter(format => {
if (
format.toUpperCase() === ExportFormat.CSV.toUpperCase() ||
format.toUpperCase() === ExportFormat.CSVcomma.toUpperCase() ||
format.toUpperCase() === ExportFormat.CSVsemicolon.toUpperCase() ||
format.toUpperCase() === ExportFormat.GML.toUpperCase() ||
format.toUpperCase() === ExportFormat.GPX.toUpperCase() ||
format.toUpperCase() === ExportFormat.GeoJSON.toUpperCase() ||
Expand All @@ -330,8 +331,12 @@ export class ImportExportComponent implements OnDestroy, OnInit {
}
})
.map(format => {
if (format.toUpperCase() === ExportFormat.CSV.toUpperCase()) {
format = ExportFormat.CSV;
if (format.toUpperCase() === ExportFormat.CSVcomma.toUpperCase()) {
format = ExportFormat.CSVcomma;
return format;
}
if (format.toUpperCase() === ExportFormat.CSVsemicolon.toUpperCase()) {
format = ExportFormat.CSVsemicolon;
return format;
}
if (format.toUpperCase() === ExportFormat.GML.toUpperCase()) {
Expand Down
42 changes: 32 additions & 10 deletions packages/geo/src/lib/import-export/shared/export.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export class ExportService {
GPX: 'gpx',
KML: 'kml',
Shapefile: 'ESRI Shapefile',
CSV: 'CSV'
CSVcomma: 'CSVcomma',
CSVsemicolon: 'CSVsemicolon'
};

static noOgreFallbacks = ['GML', 'GPX', 'KML'];
Expand All @@ -33,7 +34,9 @@ export class ExportService {

constructor(private config: ConfigService) {
this.ogreUrl = this.config.getConfig('importExport.url');
const gpxAggregateInComment = this.config.getConfig('importExport.gpxAggregateInComment');
const gpxAggregateInComment = this.config.getConfig(
'importExport.gpxAggregateInComment'
);
if (gpxAggregateInComment !== undefined) {
this.aggregateInComment = gpxAggregateInComment;
}
Expand All @@ -59,7 +62,8 @@ export class ExportService {

private generateFeature(
olFeatures: OlFeature[],
format: ExportFormat): OlFeature[] {
format: ExportFormat
): OlFeature[] {
if (format === ExportFormat.GPX && this.aggregateInComment) {
return this.generateAggratedFeature(olFeatures);
}
Expand Down Expand Up @@ -187,12 +191,15 @@ export class ExportService {
projectionIn: string,
projectionOut: string
) {
const featuresText = new olformat.GeoJSON().writeFeatures(olFeatures, {
dataProjection: projectionOut,
featureProjection: projectionIn,
featureType: 'feature',
featureNS: 'http://example.com/feature'
});
const featuresText: string = new olformat.GeoJSON().writeFeatures(
olFeatures,
{
dataProjection: projectionOut,
featureProjection: projectionIn,
featureType: 'feature',
featureNS: 'http://example.com/feature'
}
);

const url = `${this.ogreUrl}/convertJson`;
const form = document.createElement('form');
Expand All @@ -201,9 +208,18 @@ export class ExportService {
form.setAttribute('method', 'post');
form.setAttribute('target', '_blank');
form.setAttribute('action', url);

form.acceptCharset = 'UTF-8';
form.enctype = 'application/x-www-form-urlencoded; charset=utf-8;';

if (format === 'CSVsemicolon') {
const options = document.createElement('input');
options.setAttribute('type', 'hidden');
options.setAttribute('name', 'lco');
options.setAttribute('value', 'SEPARATOR=SEMICOLON');
form.appendChild(options);
}

const geojsonField = document.createElement('input');
geojsonField.setAttribute('type', 'hidden');
geojsonField.setAttribute('name', 'json');
Expand All @@ -215,14 +231,20 @@ export class ExportService {
format === 'Shapefile'
? `${title}.zip`
: `${title}.${format.toLowerCase()}`;
if (format === 'CSVcomma' || format === 'CSVsemicolon') {
outputName = `${title}.csv`;
}
outputName = outputName.replace(' ', '_');
outputName = outputName.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
outputNameField.setAttribute('type', 'hidden');
outputNameField.setAttribute('name', 'outputName');
outputNameField.setAttribute('value', outputName);
form.appendChild(outputNameField);

const ogreFormat = ExportService.ogreFormats[format];
let ogreFormat = ExportService.ogreFormats[format];
if (format === 'CSVcomma' || format === 'CSVsemicolon') {
ogreFormat = 'CSV';
}
const outputFormatField = document.createElement('input');
outputFormatField.setAttribute('type', 'hidden');
outputFormatField.setAttribute('name', 'format');
Expand Down
2 changes: 1 addition & 1 deletion packages/geo/src/lib/import-export/shared/export.type.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { strEnum } from '@igo2/utils';

export const ExportFormat = strEnum(['GeoJSON', 'GML', 'GPX', 'KML', 'Shapefile', 'CSV', 'URL']);
export const ExportFormat = strEnum(['GeoJSON', 'GML', 'GPX', 'KML', 'Shapefile', 'CSVcomma', 'CSVsemicolon', 'URL']);
export type ExportFormat = keyof typeof ExportFormat;
1 change: 1 addition & 0 deletions packages/geo/src/lib/layer/shared/layer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export class LayerService {
if (layerOptions.source instanceof ClusterDataSource) {
const serviceStyle = this.styleService;
const baseStyle = layerOptions.style;
layerOptions.clusterBaseStyle = baseStyle;
layerOptions.style = feature => {
return serviceStyle.createClusterStyle(
feature,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface VectorLayerOptions extends LayerOptions {
ol?: olLayerVector;
animation?: VectorAnimation;
styleByAttribute?: StyleByAttribute;
clusterBaseStyle?: { [key: string]: any } | olStyle | olStyle[];
clusterParam?: ClusterParam;
trackFeature?: string | number;
mapboxStyle ?: MapboxStyle;
Expand Down
9 changes: 9 additions & 0 deletions packages/geo/src/locale/en.geo.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@
"failed": {
"text": "Failed to export",
"title": "Failed to export features"
},
"format": {
"GeoJSON": "GeoJSON",
"GML": "GML",
"GPX": "GPX",
"KML": "KML",
"Shapefile": "Shapefile",
"CSVcomma": "CSV (comma delimited)",
"CSVsemicolon": "CSV (semicolon delimited)"
}
},
"importExportForm": {
Expand Down
9 changes: 9 additions & 0 deletions packages/geo/src/locale/fr.geo.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@
"failed": {
"text": "Impossible d’exporter, problème de donnée rencontré.",
"title": "Problème d’exportation"
},
"format": {
"GeoJSON": "GeoJSON",
"GML": "GML",
"GPX": "GPX",
"KML": "KML",
"Shapefile": "Shapefile",
"CSVcomma": "CSV (séparateur virgule)",
"CSVsemicolon": "CSV (séparateur point-virgule)"
}
},
"importExportForm": {
Expand Down