maplibre-gl-geo-editor 0.7.3 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16191,6 +16191,9 @@ class HistoryManager {
16191
16191
  }
16192
16192
  }
16193
16193
  }
16194
+ function resolveImportedCount(result, fallback) {
16195
+ return result?.stats?.success ?? result?.success ?? fallback;
16196
+ }
16194
16197
  class CreateFeatureCommand {
16195
16198
  description;
16196
16199
  type = "create";
@@ -20664,13 +20667,13 @@ class GeoEditor {
20664
20667
  const file = input.files?.[0];
20665
20668
  if (!file) return;
20666
20669
  const reader = new FileReader();
20667
- reader.onload = (e) => {
20670
+ reader.onload = async (e) => {
20668
20671
  try {
20669
20672
  const content = e.target?.result;
20670
20673
  const geoJson = JSON.parse(content);
20671
- this.loadGeoJson(geoJson, file.name);
20674
+ await this.loadGeoJson(geoJson, file.name);
20672
20675
  } catch (error) {
20673
- console.error("GeoEditor: Failed to parse GeoJSON file:", error);
20676
+ console.error("GeoEditor: Failed to load GeoJSON file:", error);
20674
20677
  const errorInfo = {
20675
20678
  filename: file.name,
20676
20679
  message: error instanceof Error ? error.message : String(error),
@@ -20683,17 +20686,31 @@ class GeoEditor {
20683
20686
  input.value = "";
20684
20687
  }
20685
20688
  /**
20686
- * Load GeoJSON data into the editor
20689
+ * Load GeoJSON data into the editor.
20690
+ *
20691
+ * Resolves once geoman has finished importing the features. This is `async`
20692
+ * because geoman's `deleteAll` and `importGeoJson` are asynchronous in current
20693
+ * geoman releases: awaiting them prevents a reload from racing the previous
20694
+ * clear, and lets the returned `count` reflect the actual import result rather
20695
+ * than a not-yet-resolved promise.
20696
+ *
20687
20697
  * @param geoJson - FeatureCollection or Feature to load
20688
20698
  * @param filename - Optional filename for logging
20689
20699
  * @returns Result of the load operation
20690
20700
  */
20691
- loadGeoJson(geoJson, filename = "loaded.geojson") {
20701
+ async loadGeoJson(geoJson, filename = "loaded.geojson") {
20692
20702
  if (!this.geoman) {
20693
20703
  throw new Error("Geoman not initialized");
20694
20704
  }
20705
+ const geoman = this.geoman;
20706
+ if (geoman.loaded === false && typeof geoman.waitForGeomanLoaded === "function") {
20707
+ try {
20708
+ await geoman.waitForGeomanLoaded();
20709
+ } catch {
20710
+ }
20711
+ }
20695
20712
  try {
20696
- this.geoman.features.deleteAll();
20713
+ await this.geoman.features.deleteAll();
20697
20714
  } catch {
20698
20715
  this.geoman.features.forEach((fd) => {
20699
20716
  try {
@@ -20714,10 +20731,12 @@ class GeoEditor {
20714
20731
  } else {
20715
20732
  throw new Error("Invalid GeoJSON: expected Feature or FeatureCollection");
20716
20733
  }
20717
- const importResult = this.geoman.features.importGeoJson(featureCollection2);
20734
+ const importResult = await this.geoman.features.importGeoJson(
20735
+ featureCollection2
20736
+ );
20718
20737
  const result = {
20719
20738
  features: featureCollection2.features,
20720
- count: importResult.success,
20739
+ count: resolveImportedCount(importResult, featureCollection2.features.length),
20721
20740
  filename
20722
20741
  };
20723
20742
  if (this.options.fitBoundsOnLoad && featureCollection2.features.length > 0) {
@@ -21595,4 +21614,4 @@ exports.safeUnion = safeUnion;
21595
21614
  exports.selectFeaturesWithinLasso = selectFeaturesWithinLasso;
21596
21615
  exports.toSelectedFeatures = toSelectedFeatures;
21597
21616
  exports.toggleInSelection = toggleInSelection;
21598
- //# sourceMappingURL=geo-editor-DCRqA66U.cjs.map
21617
+ //# sourceMappingURL=geo-editor-DDTgH2JC.cjs.map