diff --git a/packages/geo/src/lib/import-export/import-export/import-export.component.ts b/packages/geo/src/lib/import-export/import-export/import-export.component.ts index 20b4c62dc0..2e678317d4 100644 --- a/packages/geo/src/lib/import-export/import-export/import-export.component.ts +++ b/packages/geo/src/lib/import-export/import-export/import-export.component.ts @@ -573,6 +573,7 @@ export class ImportExportComponent implements OnDestroy, OnInit { previousFeature.get('_featureStore').layer.options.title) { const titleEmptyRows = this.createTitleEmptyRows(previousFeature, currentFeature); featuresCSV.push(titleEmptyRows[2]); + featuresCSV.push(titleEmptyRows[0]); featuresCSV.push(titleEmptyRows[1]); } } else { @@ -632,23 +633,70 @@ export class ImportExportComponent implements OnDestroy, OnInit { } private createTitleEmptyRows(previousFeature, currentFeature) { - const titleRow = previousFeature.clone(); - const titleRowWithArrow = previousFeature.clone(); - const emptyRow = previousFeature.clone(); + const titleRow = currentFeature.clone(); + const headerRow = currentFeature.clone(); + const emptyRow = currentFeature.clone(); const previousFeatureKeys: Array = previousFeature.getKeys(); - const firstKey: string = previousFeatureKeys[1]; - previousFeatureKeys.forEach(key => { - if (key === firstKey) { + let firstKeyPrevious: string = ''; + for (const key in previousFeatureKeys) { + if (previousFeatureKeys[key] !== 'geometry') { + firstKeyPrevious = previousFeatureKeys[key]; + break; + } + } + + const currentFeatureKeys: Array = currentFeature.getKeys(); + let firstKeyCurrent: string = ''; + for (const key in currentFeatureKeys) { + if (currentFeatureKeys[key] !== 'geometry') { + firstKeyCurrent = currentFeatureKeys[key]; + break; + } + } + const allKeys: Array = currentFeature.getKeys(); + previousFeatureKeys.forEach(previousKey => { + if (allKeys.includes(previousKey) && previousKey !== firstKeyPrevious) { + allKeys.push(previousKey); + } + }); + allKeys.unshift(firstKeyPrevious); + + let firstKeyAll: string = ''; + for (const key in allKeys) { + if (allKeys[key] !== 'geometry') { + firstKeyAll = allKeys[key]; + break; + } + } + allKeys.forEach(key => { + const sameKeys: boolean = previousFeatureKeys.length === currentFeatureKeys.length && + previousFeatureKeys.every((value, index) => value === currentFeatureKeys[index]); + if (key === firstKeyAll && !sameKeys) { + titleRow.set(key, currentFeature.get('_featureStore').layer.options.title + " ===============>", true); + headerRow.set(key, key, true); + emptyRow.unset(key, true); + } else if (key === firstKeyAll && sameKeys) { + titleRow.set(key, currentFeature.get('_featureStore').layer.options.title, true); + headerRow.set(key, key, true); + emptyRow.unset(key, true); + } else if (key === firstKeyCurrent) { titleRow.set(key, currentFeature.get('_featureStore').layer.options.title, true); - titleRowWithArrow.set(key, currentFeature.get('_featureStore').layer.options.title + " ===================>", true); + headerRow.set(key, key, true); + emptyRow.unset(key, true); + } else if (key !== 'geometry') { + titleRow.unset(key, true); + headerRow.set(key, key, true); emptyRow.unset(key, true); } else { titleRow.unset(key, true); - titleRowWithArrow.unset(key, true); emptyRow.unset(key, true); } + + if (!(currentFeatureKeys.includes(key))) { + headerRow.unset(key, true); + } }); - const titleEmptyRows = [titleRow, titleRowWithArrow, emptyRow]; + const titleEmptyRows = [titleRow, headerRow, emptyRow]; return titleEmptyRows; }