maplibre-gl-geo-editor 0.7.2 → 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";
@@ -18540,6 +18543,10 @@ class GeoEditor {
18540
18543
  import("@geoman-io/maplibre-geoman-free").then(({ Geoman }) => {
18541
18544
  if (this.map && !this.geoman) {
18542
18545
  const geoman = new Geoman(this.map);
18546
+ geoman.addControls = async () => {
18547
+ };
18548
+ geoman.removeControls = () => {
18549
+ };
18543
18550
  this.setGeoman(geoman);
18544
18551
  }
18545
18552
  }).catch(() => {
@@ -20660,13 +20667,13 @@ class GeoEditor {
20660
20667
  const file = input.files?.[0];
20661
20668
  if (!file) return;
20662
20669
  const reader = new FileReader();
20663
- reader.onload = (e) => {
20670
+ reader.onload = async (e) => {
20664
20671
  try {
20665
20672
  const content = e.target?.result;
20666
20673
  const geoJson = JSON.parse(content);
20667
- this.loadGeoJson(geoJson, file.name);
20674
+ await this.loadGeoJson(geoJson, file.name);
20668
20675
  } catch (error) {
20669
- console.error("GeoEditor: Failed to parse GeoJSON file:", error);
20676
+ console.error("GeoEditor: Failed to load GeoJSON file:", error);
20670
20677
  const errorInfo = {
20671
20678
  filename: file.name,
20672
20679
  message: error instanceof Error ? error.message : String(error),
@@ -20679,17 +20686,31 @@ class GeoEditor {
20679
20686
  input.value = "";
20680
20687
  }
20681
20688
  /**
20682
- * 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
+ *
20683
20697
  * @param geoJson - FeatureCollection or Feature to load
20684
20698
  * @param filename - Optional filename for logging
20685
20699
  * @returns Result of the load operation
20686
20700
  */
20687
- loadGeoJson(geoJson, filename = "loaded.geojson") {
20701
+ async loadGeoJson(geoJson, filename = "loaded.geojson") {
20688
20702
  if (!this.geoman) {
20689
20703
  throw new Error("Geoman not initialized");
20690
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
+ }
20691
20712
  try {
20692
- this.geoman.features.deleteAll();
20713
+ await this.geoman.features.deleteAll();
20693
20714
  } catch {
20694
20715
  this.geoman.features.forEach((fd) => {
20695
20716
  try {
@@ -20710,10 +20731,12 @@ class GeoEditor {
20710
20731
  } else {
20711
20732
  throw new Error("Invalid GeoJSON: expected Feature or FeatureCollection");
20712
20733
  }
20713
- const importResult = this.geoman.features.importGeoJson(featureCollection2);
20734
+ const importResult = await this.geoman.features.importGeoJson(
20735
+ featureCollection2
20736
+ );
20714
20737
  const result = {
20715
20738
  features: featureCollection2.features,
20716
- count: importResult.success,
20739
+ count: resolveImportedCount(importResult, featureCollection2.features.length),
20717
20740
  filename
20718
20741
  };
20719
20742
  if (this.options.fitBoundsOnLoad && featureCollection2.features.length > 0) {
@@ -21591,4 +21614,4 @@ exports.safeUnion = safeUnion;
21591
21614
  exports.selectFeaturesWithinLasso = selectFeaturesWithinLasso;
21592
21615
  exports.toSelectedFeatures = toSelectedFeatures;
21593
21616
  exports.toggleInSelection = toggleInSelection;
21594
- //# sourceMappingURL=geo-editor-DJ3r15Lv.cjs.map
21617
+ //# sourceMappingURL=geo-editor-DDTgH2JC.cjs.map