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

[Bug] Long Script Blocking time when adding data with WKT #2058

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 11 additions & 20 deletions src/layers/src/geojson-layer/geojson-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,11 @@ export function getGeojsonDataMaps(dataContainer: any, getFeature: GetFeature):
const feature = parseGeoJsonRawFeature(getFeature({index}));

if (feature && feature.geometry && acceptableTypes.includes(feature.geometry.type)) {
const cleaned = {
...feature,
// store index of the data in feature properties
properties: {
...feature.properties,
index
}
};
const cleaned = Object.assign({}, feature);

// store index of the data in feature properties
cleaned.properties = Object.assign({}, feature.properties || {});
cleaned.properties.index = index;
dataToFeature[index] = cleaned;
} else {
dataToFeature[index] = null;
Expand All @@ -120,24 +116,19 @@ export function getGeojsonDataMaps(dataContainer: any, getFeature: GetFeature):
*/
export function parseGeometryFromString(geoString: string): Feature | null {
let parsedGeo;

// try parse as geojson string
// {"type":"Polygon","coordinates":[[[-74.158491,40.83594]]]}
try {
parsedGeo = JSON.parse(geoString);
} catch (e) {
// keep trying to parse
}

// try parse as wkt
if (!parsedGeo) {
if (geoString.length && /[A-Z]/.test(geoString[0])) {
try {
parsedGeo = wktParser(geoString);
} catch (e) {
return null;
}
} else {
try {
parsedGeo = JSON.parse(geoString);
} catch (e) {
return null;
}
}

if (!parsedGeo) {
return null;
}
Expand Down