diff --git a/packages/geo/src/lib/import-export/shared/export.service.ts b/packages/geo/src/lib/import-export/shared/export.service.ts index d81e70f975..5089a4f04b 100644 --- a/packages/geo/src/lib/import-export/shared/export.service.ts +++ b/packages/geo/src/lib/import-export/shared/export.service.ts @@ -16,6 +16,8 @@ import { } from './export.errors'; import { EncodingFormat, ExportFormat } from './export.type'; +const SHAPEFILE_FIELD_MAX_LENGHT = 255; + @Injectable({ providedIn: 'root' }) @@ -78,9 +80,16 @@ export class ExportService { } return olFeatures.map((olFeature: OlFeature) => { - const keys = olFeature + let keys = olFeature .getKeys() .filter((key: string) => !key.startsWith(excludePrefix)); + + if (format === ExportFormat.Shapefile && olFeature.get('_style')) { + const style = JSON.stringify(olFeature.get('_style')); + if (style.length > SHAPEFILE_FIELD_MAX_LENGHT) + keys = keys.filter((key) => key !== '_style'); + } + const properties = keys.reduce( (acc: object, key: string) => { acc[key] = olFeature.get(key); diff --git a/packages/geo/src/lib/style/shared/feature/feature-style.ts b/packages/geo/src/lib/style/shared/feature/feature-style.ts index 01c27c1e74..78479b3d90 100644 --- a/packages/geo/src/lib/style/shared/feature/feature-style.ts +++ b/packages/geo/src/lib/style/shared/feature/feature-style.ts @@ -1,3 +1,5 @@ +import { isValidJSON } from '@igo2/utils'; + import olFeature from 'ol/Feature'; import * as olGeom from 'ol/geom'; import type { default as OlGeometry } from 'ol/geom/Geometry'; @@ -21,7 +23,7 @@ export function featureRandomStyleFunction(): ( }); return (olFeature: olFeature, resolution: number) => { const customStyle = olFeature.get('_style'); - if (customStyle) { + if (customStyle && isValidJSON(customStyle)) { if ( customStyle.circle && olFeature.get('rad') && diff --git a/packages/utils/src/lib/file.ts b/packages/utils/src/lib/file.ts index 8d170f3cd9..a727c7e428 100644 --- a/packages/utils/src/lib/file.ts +++ b/packages/utils/src/lib/file.ts @@ -32,3 +32,16 @@ export function downloadFromUri(uri: string, fileName: string) { document.body.removeChild(element); } + +/** + * Validate if string is valid json object + * @param jsonString + * @return boolean + */ +export function isValidJSON(jsonString: string): boolean { + try { + return JSON.parse(jsonString) && !!jsonString; + } catch (e) { + return false; + } +}