features: getCleanedFeatures()

in modules/editor/src/lib/importer.ts [114:146]


        features: getCleanedFeatures(parsed),
      };
    } catch (err) {
      validationErrors.push('Error parsing GeoJSON');
      validationErrors.push(err.toString());
    }
  } else if (shouldTryKml(data)) {
    // Parse as KML
    const xml = new DOMParser().parseFromString(data, 'text/xml');

    try {
      const parsed = kml(xml);

      /*
      TODO: Revisit using loaders.gl/kml for this later
      const parsed_ = parseSync(data, KMLasGeoJsonLoader);
      // This is changing the coordinates to floats, because in loaders.gl/kml 2.1.1 they are returned as strings.
      const parsed = {
        ...parsed_,
        features: parsed_.features.map(f => ({
          ...f,
          geometry: {
            ...f.geometry,
            coordinates: f.geometry.coordinates.map(coords => coords.map(triple => triple.map(s => Number.parseFloat(s))))
          }
        }))
      };
      */
      const isFeature = parsed && parsed.type === 'Feature';
      const isFeatureCollectionWithFeatures =
        parsed && parsed.type === 'FeatureCollection' && parsed.features.length > 0;
      const isValid = isFeature || isFeatureCollectionWithFeatures;
      if (isValid) {