@theseam/ui-common 0.3.1 → 0.3.4

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.
Files changed (100) hide show
  1. package/bundles/theseam-ui-common-dynamic.umd.js +1 -0
  2. package/bundles/theseam-ui-common-dynamic.umd.js.map +1 -1
  3. package/bundles/theseam-ui-common-form-field.umd.js +1 -1
  4. package/bundles/theseam-ui-common-form-field.umd.js.map +1 -1
  5. package/bundles/theseam-ui-common-google-maps.umd.js +2202 -0
  6. package/bundles/theseam-ui-common-google-maps.umd.js.map +1 -0
  7. package/bundles/theseam-ui-common-menu.umd.js +1 -0
  8. package/bundles/theseam-ui-common-menu.umd.js.map +1 -1
  9. package/bundles/theseam-ui-common-modal.umd.js +21 -1
  10. package/bundles/theseam-ui-common-modal.umd.js.map +1 -1
  11. package/bundles/theseam-ui-common-utils.umd.js +610 -136
  12. package/bundles/theseam-ui-common-utils.umd.js.map +1 -1
  13. package/bundles/theseam-ui-common-widget.umd.js +3 -1
  14. package/bundles/theseam-ui-common-widget.umd.js.map +1 -1
  15. package/esm2015/dynamic/evaluators/jexl-evaluator/jexl-evaluator.js +2 -1
  16. package/esm2015/form-field/input.directive.js +2 -2
  17. package/esm2015/google-maps/google-maps/google-maps.component.js +261 -0
  18. package/esm2015/google-maps/google-maps-contextmenu.js +113 -0
  19. package/esm2015/google-maps/google-maps-controls.service.js +70 -0
  20. package/esm2015/google-maps/google-maps-feature-helpers.js +177 -0
  21. package/esm2015/google-maps/google-maps-places-autocomplete/google-maps-places-autocomplete.component.js +195 -0
  22. package/esm2015/google-maps/google-maps-places-autocomplete/google-maps-places-autocomplete.directive.js +163 -0
  23. package/esm2015/google-maps/google-maps-recenter-button-control/google-maps-recenter-button-control.component.js +57 -0
  24. package/esm2015/google-maps/google-maps-upload-button-control/google-maps-upload-button-control.component.js +119 -0
  25. package/esm2015/google-maps/google-maps.module.js +45 -0
  26. package/esm2015/google-maps/google-maps.service.js +344 -0
  27. package/esm2015/google-maps/map-control.component.js +65 -0
  28. package/esm2015/google-maps/map-controls-service.js +4 -0
  29. package/esm2015/google-maps/map-file-drop/map-file-drop.component.js +135 -0
  30. package/esm2015/google-maps/map-value-manager.service.js +46 -0
  31. package/esm2015/google-maps/public-api.js +14 -0
  32. package/esm2015/google-maps/theseam-ui-common-google-maps.js +6 -0
  33. package/esm2015/menu/menu-toggle.directive.js +2 -1
  34. package/esm2015/modal/modal-ref.js +22 -2
  35. package/esm2015/utils/geo-json/coerce-feature-collection.js +44 -0
  36. package/esm2015/utils/geo-json/geo-json-to-area.js +11 -0
  37. package/esm2015/utils/geo-json/is-feature-collection.validator.js +21 -0
  38. package/esm2015/utils/geo-json/is-only-geometry-types.js +23 -0
  39. package/esm2015/utils/geo-json/is-only-geometry-types.validator.js +32 -0
  40. package/esm2015/utils/geo-json/merge-polygons.js +35 -0
  41. package/esm2015/utils/geo-json/no-inner-rings.validator.js +63 -0
  42. package/esm2015/utils/geo-json/no-kinks.validator.js +39 -0
  43. package/esm2015/utils/geo-json/read-geo-file.js +99 -0
  44. package/esm2015/utils/geo-json/split-multi-polygons.js +29 -0
  45. package/esm2015/utils/is-null-or-undefined.js +1 -1
  46. package/esm2015/utils/public-api.js +11 -1
  47. package/esm2015/widget/widget-content-components/widget-tile/widget-tile.component.js +4 -2
  48. package/fesm2015/theseam-ui-common-dynamic.js +1 -0
  49. package/fesm2015/theseam-ui-common-dynamic.js.map +1 -1
  50. package/fesm2015/theseam-ui-common-form-field.js +1 -1
  51. package/fesm2015/theseam-ui-common-form-field.js.map +1 -1
  52. package/fesm2015/theseam-ui-common-google-maps.js +1729 -0
  53. package/fesm2015/theseam-ui-common-google-maps.js.map +1 -0
  54. package/fesm2015/theseam-ui-common-menu.js +1 -0
  55. package/fesm2015/theseam-ui-common-menu.js.map +1 -1
  56. package/fesm2015/theseam-ui-common-modal.js +21 -1
  57. package/fesm2015/theseam-ui-common-modal.js.map +1 -1
  58. package/fesm2015/theseam-ui-common-utils.js +477 -94
  59. package/fesm2015/theseam-ui-common-utils.js.map +1 -1
  60. package/fesm2015/theseam-ui-common-widget.js +3 -1
  61. package/fesm2015/theseam-ui-common-widget.js.map +1 -1
  62. package/form-field/theseam-ui-common-form-field.metadata.json +1 -1
  63. package/google-maps/google-maps/google-maps.component.d.ts +89 -0
  64. package/google-maps/google-maps-contextmenu.d.ts +15 -0
  65. package/google-maps/google-maps-controls.service.d.ts +23 -0
  66. package/google-maps/google-maps-feature-helpers.d.ts +37 -0
  67. package/google-maps/google-maps-places-autocomplete/google-maps-places-autocomplete.component.d.ts +104 -0
  68. package/google-maps/google-maps-places-autocomplete/google-maps-places-autocomplete.directive.d.ts +80 -0
  69. package/google-maps/google-maps-recenter-button-control/google-maps-recenter-button-control.component.d.ts +21 -0
  70. package/google-maps/google-maps-upload-button-control/google-maps-upload-button-control.component.d.ts +34 -0
  71. package/google-maps/google-maps.module.d.ts +2 -0
  72. package/google-maps/google-maps.service.d.ts +53 -0
  73. package/google-maps/map-control.component.d.ts +20 -0
  74. package/google-maps/map-controls-service.d.ts +13 -0
  75. package/google-maps/map-file-drop/map-file-drop.component.d.ts +34 -0
  76. package/google-maps/map-value-manager.service.d.ts +18 -0
  77. package/google-maps/package.json +11 -0
  78. package/google-maps/public-api.d.ts +13 -0
  79. package/google-maps/theseam-ui-common-google-maps.d.ts +5 -0
  80. package/google-maps/theseam-ui-common-google-maps.metadata.json +1 -0
  81. package/modal/modal-ref.d.ts +1 -0
  82. package/modal/theseam-ui-common-modal.metadata.json +1 -1
  83. package/package.json +17 -10
  84. package/utils/geo-json/coerce-feature-collection.d.ts +2 -0
  85. package/utils/geo-json/geo-json-to-area.d.ts +6 -0
  86. package/utils/geo-json/is-feature-collection.validator.d.ts +3 -0
  87. package/utils/geo-json/is-only-geometry-types.d.ts +5 -0
  88. package/utils/geo-json/is-only-geometry-types.validator.d.ts +4 -0
  89. package/utils/geo-json/merge-polygons.d.ts +9 -0
  90. package/utils/geo-json/no-inner-rings.validator.d.ts +10 -0
  91. package/utils/geo-json/no-kinks.validator.d.ts +3 -0
  92. package/utils/geo-json/read-geo-file.d.ts +7 -0
  93. package/utils/geo-json/split-multi-polygons.d.ts +8 -0
  94. package/utils/is-null-or-undefined.d.ts +1 -1
  95. package/utils/public-api.d.ts +10 -0
  96. package/utils/theseam-ui-common-utils.metadata.json +1 -1
  97. package/widget/styles/_variables.scss +1 -0
  98. package/widget/theseam-ui-common-widget.metadata.json +1 -1
  99. package/widget/widget-content-components/widget-tile/widget-tile.component.d.ts +2 -0
  100. package/widget/widget-content-components/widget-tile/widget-tile.component.scss +1 -1
@@ -1,12 +1,15 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('rxjs/operators'), require('rxjs'), require('@marklb/file-type')) :
3
- typeof define === 'function' && define.amd ? define('@theseam/ui-common/utils', ['exports', 'rxjs/operators', 'rxjs', '@marklb/file-type'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.theseam = global.theseam || {}, global.theseam["ui-common"] = global.theseam["ui-common"] || {}, global.theseam["ui-common"].utils = {}), global.rxjs.operators, global.rxjs, global.fileType));
5
- })(this, (function (exports, operators, rxjs, fileType) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('rxjs/operators'), require('rxjs'), require('@turf/area'), require('@turf/helpers'), require('@turf/kinks'), require('@angular/core'), require('@marklb/file-type'), require('shpjs')) :
3
+ typeof define === 'function' && define.amd ? define('@theseam/ui-common/utils', ['exports', 'rxjs/operators', 'rxjs', '@turf/area', '@turf/helpers', '@turf/kinks', '@angular/core', '@marklb/file-type', 'shpjs'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.theseam = global.theseam || {}, global.theseam["ui-common"] = global.theseam["ui-common"] || {}, global.theseam["ui-common"].utils = {}), global.rxjs.operators, global.rxjs, global.area, global.helpers, global.kinks, global.ng.core, global.fileType, global.shp));
5
+ })(this, (function (exports, operators, rxjs, area, helpers, kinks, core, fileType, shp) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
9
+ var area__default = /*#__PURE__*/_interopDefaultLegacy(area);
10
+ var kinks__default = /*#__PURE__*/_interopDefaultLegacy(kinks);
9
11
  var fileType__default = /*#__PURE__*/_interopDefaultLegacy(fileType);
12
+ var shp__default = /*#__PURE__*/_interopDefaultLegacy(shp);
10
13
 
11
14
  /**
12
15
  *
@@ -315,6 +318,80 @@
315
318
  return activatedRoute.snapshot.url.length === 0;
316
319
  }
317
320
 
321
+ // TODO: Make this more thorough and maybe error on unrecognized.
322
+ function coerceFeatureCollection(value) {
323
+ return parseValue(value);
324
+ }
325
+ /**
326
+ * Parses the value to a FeatureCollection object or null if it is not a
327
+ * FeatureCollection.
328
+ */
329
+ function parseValue(value) {
330
+ var _value = parseStringValue(value);
331
+ if (isFeatureCollectionValue(_value)) {
332
+ return _value;
333
+ }
334
+ return null;
335
+ }
336
+ /**
337
+ * Tries to parse the value to an object, in case the value is a stringified
338
+ * json.
339
+ */
340
+ function parseStringValue(value) {
341
+ if (typeof value === 'string') {
342
+ try {
343
+ return JSON.parse(value);
344
+ }
345
+ catch (_a) {
346
+ return null;
347
+ }
348
+ }
349
+ return value;
350
+ }
351
+ /**
352
+ * Checks if the value is a FeatureCollection.
353
+ *
354
+ * NOTE: This is not a thorough FeatureCollection check. It only checks that the
355
+ * value is an object resembling a GeoJSON.FeatureCollection, enough for the
356
+ * validator.
357
+ */
358
+ function isFeatureCollectionValue(value) {
359
+ if (value === undefined || value === null) {
360
+ return false;
361
+ }
362
+ return value.type === 'FeatureCollection' && Array.isArray(value.features);
363
+ }
364
+
365
+ /**
366
+ *
367
+ */
368
+ function geoJsonToArea(geoJson, units) {
369
+ if (units === void 0) { units = 'acres'; }
370
+ var area_mSqr = area__default["default"](geoJson);
371
+ var acres = helpers.convertArea(area_mSqr, 'meters', units);
372
+ return acres;
373
+ }
374
+
375
+ var IS_FEATURE_COLLECTION_VALIDATOR_NAME = 'is-feature-collection';
376
+ function isFeatureCollectionValidator() {
377
+ return function (control) {
378
+ var _a;
379
+ // Don't need to validate if there isn't a value. Use `Validators.required` for that.
380
+ if (isEmptyInputValue(control.value)) {
381
+ return null; // don't validate empty values to allow optional controls
382
+ }
383
+ var value = coerceFeatureCollection(control.value);
384
+ if (value === null) {
385
+ return _a = {},
386
+ _a[IS_FEATURE_COLLECTION_VALIDATOR_NAME] = {
387
+ reason: "Must be a FeatureCollection.",
388
+ },
389
+ _a;
390
+ }
391
+ return null;
392
+ };
393
+ }
394
+
318
395
  /*! *****************************************************************************
319
396
  Copyright (c) Microsoft Corporation.
320
397
 
@@ -633,6 +710,521 @@
633
710
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
634
711
  }
635
712
 
713
+ /**
714
+ * Returns true if the GeoJSON is only specifies geometries.
715
+ */
716
+ function isOnlyGeometryTypes(featureCollection, types) {
717
+ var e_1, _a;
718
+ if (types.length === 0) {
719
+ if (featureCollection.features.length > 0) {
720
+ // If no types are specified then there can't be any specified types found.
721
+ return false;
722
+ }
723
+ else {
724
+ // If no types are specified and there are no features then there is
725
+ // nothing to say a specified type isn't found.
726
+ return true;
727
+ }
728
+ }
729
+ try {
730
+ for (var _b = __values(featureCollection.features), _c = _b.next(); !_c.done; _c = _b.next()) {
731
+ var f = _c.value;
732
+ if (types.indexOf(f.geometry.type) === -1) {
733
+ return false;
734
+ }
735
+ }
736
+ }
737
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
738
+ finally {
739
+ try {
740
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
741
+ }
742
+ finally { if (e_1) throw e_1.error; }
743
+ }
744
+ return true;
745
+ }
746
+
747
+ var IS_ONLY_GEOMETRY_TYPES_VALIDATOR_NAME = 'is-only-geometry-types';
748
+ function isOnlyGeometryTypesValidator(types) {
749
+ return function (control) {
750
+ var _a;
751
+ // Don't need to validate if there isn't a value. Use `Validators.required` for that.
752
+ if (isEmptyInputValue(control.value)) {
753
+ return null; // don't validate empty values to allow optional controls
754
+ }
755
+ var value = coerceFeatureCollection(control.value);
756
+ if (value === null) {
757
+ // If there isn't a FeatureCollection then there is nothing to validate.
758
+ // Use 'isFeatureCollection' to validate the value is a FeatureCollection.
759
+ return null;
760
+ }
761
+ if (!isOnlyGeometryTypes(value, types)) {
762
+ var typesNotAllowed = value.features
763
+ .map(function (f) { return f.geometry.type; })
764
+ .filter(function (t) { return types.indexOf(t) === -1; });
765
+ var distinctTypesNotAllowed = Array.from(new Set(typesNotAllowed));
766
+ return _a = {},
767
+ _a[IS_ONLY_GEOMETRY_TYPES_VALIDATOR_NAME] = {
768
+ reason: "Only geometry type" + (types.length === 1 ? '' : 's') + " " + types.join(', ') + " allowed.",
769
+ notAllowedGeometryTypesFound: distinctTypesNotAllowed,
770
+ },
771
+ _a;
772
+ }
773
+ return null;
774
+ };
775
+ }
776
+
777
+ /**
778
+ * Merge Polygon and MultiPolygon geometries into a single MultiPolygon. Any
779
+ * properties, other than 'coordinates', of the Polygons and MultiPolygons will
780
+ * be lost.
781
+ *
782
+ * NOTE: Polygons and MultPolygons in a GeometryCollection will not be merged.
783
+ */
784
+ function mergePolygons(featureCollection) {
785
+ var _a;
786
+ var multiPolygon = {
787
+ type: 'MultiPolygon',
788
+ coordinates: [],
789
+ };
790
+ for (var i = 0; i < featureCollection.features.length; i++) {
791
+ var f = featureCollection.features[i];
792
+ if (f.geometry.type === 'Polygon') {
793
+ multiPolygon.coordinates.push(f.geometry.coordinates);
794
+ featureCollection.features.splice(i, 1);
795
+ i--;
796
+ }
797
+ else if (f.geometry.type === 'MultiPolygon') {
798
+ (_a = multiPolygon.coordinates).push.apply(_a, __spreadArray([], __read(f.geometry.coordinates)));
799
+ featureCollection.features.splice(i, 1);
800
+ i--;
801
+ }
802
+ }
803
+ if (multiPolygon.coordinates.length > 0) {
804
+ var feature = {
805
+ type: 'Feature',
806
+ geometry: multiPolygon,
807
+ properties: {},
808
+ };
809
+ featureCollection.features.push(feature);
810
+ }
811
+ }
812
+
813
+ var NO_INNER_RINGS_VALIDATOR_NAME = 'no-inner-rings';
814
+ /**
815
+ * Validates that a FeatureCollection does not contain any Polygon with inner
816
+ * rings("holes").
817
+ *
818
+ * NOTE: Only considers Polygon and MultiPolygon. Does not consider
819
+ * GeometryCollection.
820
+ */
821
+ function noInnerRingsValidator() {
822
+ return function (control) {
823
+ var _a;
824
+ // Don't need to validate if there isn't a value. Use `Validators.required` for that.
825
+ if (isEmptyInputValue(control.value)) {
826
+ return null; // don't validate empty values to allow optional controls
827
+ }
828
+ var value = coerceFeatureCollection(control.value);
829
+ if (value === null) {
830
+ // If there isn't a FeatureCollection then there is nothing to validate.
831
+ // Use 'isFeatureCollection' to validate the value is a FeatureCollection.
832
+ return null;
833
+ }
834
+ if (hasInnerRing(value)) {
835
+ return _a = {},
836
+ _a[NO_INNER_RINGS_VALIDATOR_NAME] = {
837
+ reason: "A shape cannot have an inner ring."
838
+ },
839
+ _a;
840
+ }
841
+ return null;
842
+ };
843
+ }
844
+ /**
845
+ * Checks if a FeatureCollection contains any geometries with an inner
846
+ * ring("hole").
847
+ *
848
+ * NOTE: Does not consider GeometryCollection.
849
+ */
850
+ function hasInnerRing(featureCollection) {
851
+ var e_1, _a, e_2, _b;
852
+ try {
853
+ for (var _c = __values(featureCollection.features), _d = _c.next(); !_d.done; _d = _c.next()) {
854
+ var f = _d.value;
855
+ // The spec says the right-hand rule must be followed, but also specifies
856
+ // that tools should not reject polygons that do not follow the right-hand
857
+ // rule. It does specify that the first ring must be the exterior ring and
858
+ // the others must be the interior. So, this should be safe to just check
859
+ // if there are multiple rings, instead of checking their winding orders.
860
+ //
861
+ // Polygon spec: https://datatracker.ietf.org/doc/html/rfc7946#section-3.1.6
862
+ if (f.geometry.type === 'Polygon') {
863
+ if (f.geometry.coordinates.length > 1) {
864
+ return true;
865
+ }
866
+ }
867
+ else if (f.geometry.type === 'MultiPolygon') {
868
+ try {
869
+ for (var _e = (e_2 = void 0, __values(f.geometry.coordinates)), _f = _e.next(); !_f.done; _f = _e.next()) {
870
+ var coords = _f.value;
871
+ if (coords.length > 1) {
872
+ return true;
873
+ }
874
+ }
875
+ }
876
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
877
+ finally {
878
+ try {
879
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
880
+ }
881
+ finally { if (e_2) throw e_2.error; }
882
+ }
883
+ }
884
+ }
885
+ }
886
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
887
+ finally {
888
+ try {
889
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
890
+ }
891
+ finally { if (e_1) throw e_1.error; }
892
+ }
893
+ return false;
894
+ }
895
+
896
+ var kinkableGeometryTypes = ['LineString', 'MultiLineString', 'MultiPolygon', 'Polygon'];
897
+ var NO_KINKS_VALIDATOR_NAME = 'no-kinks';
898
+ function noKinksValidator() {
899
+ return function (control) {
900
+ var e_1, _a, _b;
901
+ // Don't need to validate if there isn't a value. Use `Validators.required` for that.
902
+ if (isEmptyInputValue(control.value)) {
903
+ return null; // don't validate empty values to allow optional controls
904
+ }
905
+ var value = coerceFeatureCollection(control.value);
906
+ if (value === null) {
907
+ return null;
908
+ }
909
+ var kinksFound = [];
910
+ try {
911
+ for (var _c = __values(value.features), _d = _c.next(); !_d.done; _d = _c.next()) {
912
+ var f = _d.value;
913
+ if (kinkableGeometryTypes.indexOf(f.geometry.type) !== -1) {
914
+ var _kinks = kinks__default["default"](f);
915
+ if (_kinks.features.length > 0) {
916
+ kinksFound.push({
917
+ feature: f,
918
+ kinks: _kinks,
919
+ });
920
+ }
921
+ }
922
+ }
923
+ }
924
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
925
+ finally {
926
+ try {
927
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
928
+ }
929
+ finally { if (e_1) throw e_1.error; }
930
+ }
931
+ if (kinksFound.length > 0) {
932
+ return _b = {},
933
+ _b[NO_KINKS_VALIDATOR_NAME] = {
934
+ reason: 'Paths should not intersect themself.',
935
+ featuresWithKink: kinksFound,
936
+ },
937
+ _b;
938
+ }
939
+ return null;
940
+ };
941
+ }
942
+
943
+ // import { Buffer } from 'buffer/'
944
+ var Buffer$1 = require('buffer/').Buffer;
945
+ function readFileAsync(file) {
946
+ return new Promise(function (resolve, reject) {
947
+ var reader = new FileReader();
948
+ reader.onload = function () {
949
+ resolve(reader.result);
950
+ };
951
+ reader.readAsArrayBuffer(file);
952
+ });
953
+ }
954
+ function readFileAsDataUrlAsync(file) {
955
+ return __awaiter(this, void 0, void 0, function () {
956
+ return __generator(this, function (_a) {
957
+ return [2 /*return*/, new Promise(function (resolve, reject) {
958
+ var reader = new FileReader();
959
+ reader.onload = function () {
960
+ resolve(reader.result);
961
+ };
962
+ reader.readAsDataURL(file);
963
+ })];
964
+ });
965
+ });
966
+ }
967
+ function fileBufferToBlob(fileBuffer, defaultMime) {
968
+ if (defaultMime === void 0) { defaultMime = 'application/octet-stream'; }
969
+ return __awaiter(this, void 0, void 0, function () {
970
+ var fType, mime, blob;
971
+ return __generator(this, function (_a) {
972
+ fType = fileType__default["default"](fileBuffer);
973
+ mime = (fType) ? fType.mime : defaultMime;
974
+ blob = new Blob([fileBuffer], { type: mime });
975
+ return [2 /*return*/, blob];
976
+ });
977
+ });
978
+ }
979
+ function fileBufferToObjectUrl(fileBuffer, defaultMime) {
980
+ if (defaultMime === void 0) { defaultMime = 'application/octet-stream'; }
981
+ return __awaiter(this, void 0, void 0, function () {
982
+ var file, fileURL;
983
+ return __generator(this, function (_a) {
984
+ switch (_a.label) {
985
+ case 0: return [4 /*yield*/, fileBufferToBlob(fileBuffer, defaultMime)];
986
+ case 1:
987
+ file = _a.sent();
988
+ fileURL = URL.createObjectURL(file);
989
+ return [2 /*return*/, fileURL];
990
+ }
991
+ });
992
+ });
993
+ }
994
+ function fileDataFromBuffer(fileBuffer, defaultMime) {
995
+ if (defaultMime === void 0) { defaultMime = 'application/octet-stream'; }
996
+ return __awaiter(this, void 0, void 0, function () {
997
+ var _fileBuffer, fType, ext, mime, blob, fileData;
998
+ return __generator(this, function (_a) {
999
+ _fileBuffer = Buffer$1.from(fileBuffer);
1000
+ fType = fileType__default["default"](_fileBuffer);
1001
+ ext = fType && fType.ext || undefined;
1002
+ mime = fType ? fType.mime : defaultMime;
1003
+ blob = new Blob([_fileBuffer], { type: mime });
1004
+ fileData = { ext: ext, mime: mime, blob: blob };
1005
+ return [2 /*return*/, fileData];
1006
+ });
1007
+ });
1008
+ }
1009
+ function openBlob(blob, target, filename) {
1010
+ // NOTE: IE and MSEdge do not allow Blob resources as a source for
1011
+ // tabs or iframes. msSaveOrOpenBlob is used as a workaround. I
1012
+ // haven't been able to find a way to just open the Blob file in
1013
+ // another tab yet for IE or MSEdge.
1014
+ if (window.navigator.msSaveOrOpenBlob) {
1015
+ window.navigator.msSaveOrOpenBlob(blob, filename);
1016
+ }
1017
+ else {
1018
+ var url = URL.createObjectURL(blob);
1019
+ var win = window.open(url, target);
1020
+ // TODO: Consider if always setting opener to null is to restrictive
1021
+ // if (win && target && target.toLowerCase() === '_blank') {
1022
+ // win.opener = null
1023
+ // }
1024
+ }
1025
+ }
1026
+
1027
+ /** Returns object without property */
1028
+ function withoutProperty(obj, propName) {
1029
+ var _a = obj, _b = propName, _ = _a[_b], without = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
1030
+ return without;
1031
+ }
1032
+ /** Returns object without properties */
1033
+ function withoutProperties(obj, propNames) {
1034
+ var e_1, _c;
1035
+ var without = obj;
1036
+ try {
1037
+ for (var propNames_1 = __values(propNames), propNames_1_1 = propNames_1.next(); !propNames_1_1.done; propNames_1_1 = propNames_1.next()) {
1038
+ var propName = propNames_1_1.value;
1039
+ without = withoutProperty(without, propName);
1040
+ }
1041
+ }
1042
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1043
+ finally {
1044
+ try {
1045
+ if (propNames_1_1 && !propNames_1_1.done && (_c = propNames_1.return)) _c.call(propNames_1);
1046
+ }
1047
+ finally { if (e_1) throw e_1.error; }
1048
+ }
1049
+ return without;
1050
+ }
1051
+ /** Delete property of object */
1052
+ function deleteProperty(obj, propName) {
1053
+ if (obj.hasOwnProperty(propName)) {
1054
+ delete obj[propName];
1055
+ }
1056
+ }
1057
+ /** Delete properties of object */
1058
+ function deleteProperties(obj, propNames) {
1059
+ var e_2, _c;
1060
+ try {
1061
+ for (var propNames_2 = __values(propNames), propNames_2_1 = propNames_2.next(); !propNames_2_1.done; propNames_2_1 = propNames_2.next()) {
1062
+ var propName = propNames_2_1.value;
1063
+ deleteProperty(obj, propName);
1064
+ }
1065
+ }
1066
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
1067
+ finally {
1068
+ try {
1069
+ if (propNames_2_1 && !propNames_2_1.done && (_c = propNames_2.return)) _c.call(propNames_2);
1070
+ }
1071
+ finally { if (e_2) throw e_2.error; }
1072
+ }
1073
+ }
1074
+
1075
+ var Buffer = require('buffer/').Buffer;
1076
+ /**
1077
+ * Reads a File, or buffer of file content, in GeoJSON or ESRI Shapefile format
1078
+ * and returns a GeoJSON `FeatureCollection`.
1079
+ */
1080
+ function readGeoFile(fileOrBuffer) {
1081
+ var _a;
1082
+ return __awaiter(this, void 0, void 0, function () {
1083
+ var buffer, e_1;
1084
+ return __generator(this, function (_b) {
1085
+ switch (_b.label) {
1086
+ case 0: return [4 /*yield*/, coerceFileOrBufferToBuffer(fileOrBuffer)];
1087
+ case 1:
1088
+ buffer = _b.sent();
1089
+ if (!isShpFile(buffer)) return [3 /*break*/, 3];
1090
+ return [4 /*yield*/, parseShpFile(buffer)];
1091
+ case 2: return [2 /*return*/, _b.sent()];
1092
+ case 3:
1093
+ if (!(((_a = fileType__default["default"](buffer)) === null || _a === void 0 ? void 0 : _a.mime) === 'application/zip')) return [3 /*break*/, 7];
1094
+ _b.label = 4;
1095
+ case 4:
1096
+ _b.trys.push([4, 6, , 7]);
1097
+ return [4 /*yield*/, parseShpZip(buffer)];
1098
+ case 5: return [2 /*return*/, _b.sent()];
1099
+ case 6:
1100
+ e_1 = _b.sent();
1101
+ // NOTE: If 'shpjs' updates or we switch to a fork, where it doesn't use
1102
+ // node buffers, then we can remove this rethrow.
1103
+ if (core.isDevMode()) {
1104
+ if (e_1.message === 'nodebuffer is not supported by this platform') {
1105
+ console.warn('Try adding Buffer polyfill.\n' +
1106
+ 'Install: npm install buffer\n' +
1107
+ 'Add `global.Buffer = global.Buffer || require(\'buffer\').Buffer` to "src/polyfills.ts"');
1108
+ }
1109
+ }
1110
+ throw e_1;
1111
+ case 7: return [2 /*return*/, parseGeoJson(buffer)];
1112
+ }
1113
+ });
1114
+ });
1115
+ }
1116
+ function coerceFileOrBufferToBuffer(fileOrBuffer) {
1117
+ return __awaiter(this, void 0, void 0, function () {
1118
+ var arrBuf;
1119
+ return __generator(this, function (_b) {
1120
+ switch (_b.label) {
1121
+ case 0:
1122
+ if (!(fileOrBuffer instanceof File)) return [3 /*break*/, 2];
1123
+ return [4 /*yield*/, readFileAsync(fileOrBuffer)];
1124
+ case 1:
1125
+ arrBuf = _b.sent();
1126
+ return [2 /*return*/, Buffer.from(arrBuf)];
1127
+ case 2: return [2 /*return*/, Buffer.from(fileOrBuffer)];
1128
+ }
1129
+ });
1130
+ });
1131
+ }
1132
+ // NOTE: Our current version of file-type does not detect shp files. We can
1133
+ // remove this function when file-types is upgraded.
1134
+ function isShpFile(buffer) {
1135
+ var header = [0x27, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
1136
+ var offset = 2;
1137
+ if (buffer.length < (header.length + offset)) {
1138
+ return false;
1139
+ }
1140
+ for (var i = 0; i < header.length; i++) {
1141
+ if (header[i] !== buffer[i + offset]) {
1142
+ return false;
1143
+ }
1144
+ }
1145
+ return true;
1146
+ }
1147
+ function parseShpFile(buffer) {
1148
+ return __awaiter(this, void 0, void 0, function () {
1149
+ var geometries, featCollection;
1150
+ return __generator(this, function (_b) {
1151
+ switch (_b.label) {
1152
+ case 0: return [4 /*yield*/, shp__default["default"].parseShp(buffer, undefined)];
1153
+ case 1:
1154
+ geometries = _b.sent();
1155
+ featCollection = {
1156
+ type: 'FeatureCollection',
1157
+ features: geometries.map(function (geom) { return ({
1158
+ type: 'Feature',
1159
+ geometry: geom,
1160
+ properties: {}
1161
+ }); })
1162
+ };
1163
+ return [2 /*return*/, featCollection];
1164
+ }
1165
+ });
1166
+ });
1167
+ }
1168
+ function parseShpZip(buffer) {
1169
+ return __awaiter(this, void 0, void 0, function () {
1170
+ var featCollection;
1171
+ return __generator(this, function (_b) {
1172
+ switch (_b.label) {
1173
+ case 0: return [4 /*yield*/, shp__default["default"].parseZip(buffer, undefined)];
1174
+ case 1:
1175
+ featCollection = _b.sent();
1176
+ if (Array.isArray(featCollection)) {
1177
+ if (featCollection.length === 0) {
1178
+ throw Error("Shape data not found.");
1179
+ }
1180
+ else if (featCollection.length > 1) {
1181
+ throw Error("Multiple shape files not supported.");
1182
+ }
1183
+ featCollection = featCollection[0];
1184
+ }
1185
+ return [2 /*return*/, withoutProperty(featCollection, 'fileName')];
1186
+ }
1187
+ });
1188
+ });
1189
+ }
1190
+ function parseGeoJson(buffer) {
1191
+ var json = JSON.parse(buffer.toString());
1192
+ if ((json === null || json === void 0 ? void 0 : json.type) === 'FeatureCollection' && Array.isArray(json === null || json === void 0 ? void 0 : json.features)) {
1193
+ return json;
1194
+ }
1195
+ throw Error("Unable to parse as GeoJSON.");
1196
+ }
1197
+
1198
+ /**
1199
+ * Split all MultiPolygon into Polygon. Any properties, other than
1200
+ * 'coordinates', of the MultiPolygons will be lost.
1201
+ *
1202
+ * NOTE: MultiPolygons in a GeometryCollection will not be split.
1203
+ */
1204
+ function splitMultiPolygons(featureCollection) {
1205
+ var _a;
1206
+ for (var i = 0; i < featureCollection.features.length; i++) {
1207
+ if (featureCollection.features[i]) {
1208
+ var geometry = featureCollection.features[i].geometry;
1209
+ if (geometry.type === 'MultiPolygon') {
1210
+ var features = splitMultPolygon(geometry).map(function (p) { return ({
1211
+ type: 'Feature',
1212
+ geometry: p,
1213
+ properties: {},
1214
+ }); });
1215
+ (_a = featureCollection.features).splice.apply(_a, __spreadArray([i, 1], __read(features)));
1216
+ i += Math.max(features.length - 1, 0);
1217
+ }
1218
+ }
1219
+ }
1220
+ }
1221
+ function splitMultPolygon(multiPolygon) {
1222
+ return multiPolygon.coordinates.map(function (c) { return ({
1223
+ type: 'Polygon',
1224
+ coordinates: c,
1225
+ }); });
1226
+ }
1227
+
636
1228
  // Based on source: https://github.com/sindresorhus/array-move/blob/main/index.js
637
1229
  /**
638
1230
  Moves the item to the new position in the input array. Useful for huge arrays
@@ -767,138 +1359,6 @@
767
1359
  });
768
1360
  }
769
1361
 
770
- /** Returns object without property */
771
- function withoutProperty(obj, propName) {
772
- var _a = obj, _b = propName, _ = _a[_b], without = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
773
- return without;
774
- }
775
- /** Returns object without properties */
776
- function withoutProperties(obj, propNames) {
777
- var e_1, _c;
778
- var without = obj;
779
- try {
780
- for (var propNames_1 = __values(propNames), propNames_1_1 = propNames_1.next(); !propNames_1_1.done; propNames_1_1 = propNames_1.next()) {
781
- var propName = propNames_1_1.value;
782
- without = withoutProperty(without, propName);
783
- }
784
- }
785
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
786
- finally {
787
- try {
788
- if (propNames_1_1 && !propNames_1_1.done && (_c = propNames_1.return)) _c.call(propNames_1);
789
- }
790
- finally { if (e_1) throw e_1.error; }
791
- }
792
- return without;
793
- }
794
- /** Delete property of object */
795
- function deleteProperty(obj, propName) {
796
- if (obj.hasOwnProperty(propName)) {
797
- delete obj[propName];
798
- }
799
- }
800
- /** Delete properties of object */
801
- function deleteProperties(obj, propNames) {
802
- var e_2, _c;
803
- try {
804
- for (var propNames_2 = __values(propNames), propNames_2_1 = propNames_2.next(); !propNames_2_1.done; propNames_2_1 = propNames_2.next()) {
805
- var propName = propNames_2_1.value;
806
- deleteProperty(obj, propName);
807
- }
808
- }
809
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
810
- finally {
811
- try {
812
- if (propNames_2_1 && !propNames_2_1.done && (_c = propNames_2.return)) _c.call(propNames_2);
813
- }
814
- finally { if (e_2) throw e_2.error; }
815
- }
816
- }
817
-
818
- // import { Buffer } from 'buffer/'
819
- var Buffer = require('buffer/').Buffer;
820
- function readFileAsync(file) {
821
- return new Promise(function (resolve, reject) {
822
- var reader = new FileReader();
823
- reader.onload = function () {
824
- resolve(reader.result);
825
- };
826
- reader.readAsArrayBuffer(file);
827
- });
828
- }
829
- function readFileAsDataUrlAsync(file) {
830
- return __awaiter(this, void 0, void 0, function () {
831
- return __generator(this, function (_a) {
832
- return [2 /*return*/, new Promise(function (resolve, reject) {
833
- var reader = new FileReader();
834
- reader.onload = function () {
835
- resolve(reader.result);
836
- };
837
- reader.readAsDataURL(file);
838
- })];
839
- });
840
- });
841
- }
842
- function fileBufferToBlob(fileBuffer, defaultMime) {
843
- if (defaultMime === void 0) { defaultMime = 'application/octet-stream'; }
844
- return __awaiter(this, void 0, void 0, function () {
845
- var fType, mime, blob;
846
- return __generator(this, function (_a) {
847
- fType = fileType__default["default"](fileBuffer);
848
- mime = (fType) ? fType.mime : defaultMime;
849
- blob = new Blob([fileBuffer], { type: mime });
850
- return [2 /*return*/, blob];
851
- });
852
- });
853
- }
854
- function fileBufferToObjectUrl(fileBuffer, defaultMime) {
855
- if (defaultMime === void 0) { defaultMime = 'application/octet-stream'; }
856
- return __awaiter(this, void 0, void 0, function () {
857
- var file, fileURL;
858
- return __generator(this, function (_a) {
859
- switch (_a.label) {
860
- case 0: return [4 /*yield*/, fileBufferToBlob(fileBuffer, defaultMime)];
861
- case 1:
862
- file = _a.sent();
863
- fileURL = URL.createObjectURL(file);
864
- return [2 /*return*/, fileURL];
865
- }
866
- });
867
- });
868
- }
869
- function fileDataFromBuffer(fileBuffer, defaultMime) {
870
- if (defaultMime === void 0) { defaultMime = 'application/octet-stream'; }
871
- return __awaiter(this, void 0, void 0, function () {
872
- var _fileBuffer, fType, ext, mime, blob, fileData;
873
- return __generator(this, function (_a) {
874
- _fileBuffer = Buffer.from(fileBuffer);
875
- fType = fileType__default["default"](_fileBuffer);
876
- ext = fType && fType.ext || undefined;
877
- mime = fType ? fType.mime : defaultMime;
878
- blob = new Blob([_fileBuffer], { type: mime });
879
- fileData = { ext: ext, mime: mime, blob: blob };
880
- return [2 /*return*/, fileData];
881
- });
882
- });
883
- }
884
- function openBlob(blob, target, filename) {
885
- // NOTE: IE and MSEdge do not allow Blob resources as a source for
886
- // tabs or iframes. msSaveOrOpenBlob is used as a workaround. I
887
- // haven't been able to find a way to just open the Blob file in
888
- // another tab yet for IE or MSEdge.
889
- if (window.navigator.msSaveOrOpenBlob) {
890
- window.navigator.msSaveOrOpenBlob(blob, filename);
891
- }
892
- else {
893
- var url = URL.createObjectURL(blob);
894
- var win = window.open(url, target);
895
- // TODO: Consider if always setting opener to null is to restrictive
896
- // if (win && target && target.toLowerCase() === '_blank') {
897
- // win.opener = null
898
- // }
899
- }
900
- }
901
-
902
1362
  function notNullOrUndefined(value) {
903
1363
  return value !== null && value !== undefined;
904
1364
  }
@@ -1276,12 +1736,17 @@
1276
1736
  * Generated bundle index. Do not edit.
1277
1737
  */
1278
1738
 
1739
+ exports.IS_FEATURE_COLLECTION_VALIDATOR_NAME = IS_FEATURE_COLLECTION_VALIDATOR_NAME;
1740
+ exports.IS_ONLY_GEOMETRY_TYPES_VALIDATOR_NAME = IS_ONLY_GEOMETRY_TYPES_VALIDATOR_NAME;
1741
+ exports.NO_INNER_RINGS_VALIDATOR_NAME = NO_INNER_RINGS_VALIDATOR_NAME;
1742
+ exports.NO_KINKS_VALIDATOR_NAME = NO_KINKS_VALIDATOR_NAME;
1279
1743
  exports.PollingTickerOptions = PollingTickerOptions;
1280
1744
  exports.Refreshable = Refreshable;
1281
1745
  exports.activatedRoutesWithDataProperty = activatedRoutesWithDataProperty;
1282
1746
  exports.arrayMoveImmutable = arrayMoveImmutable;
1283
1747
  exports.arrayMoveMutable = arrayMoveMutable;
1284
1748
  exports.calcPercentage = calcPercentage;
1749
+ exports.coerceFeatureCollection = coerceFeatureCollection;
1285
1750
  exports.createPadding = createPadding;
1286
1751
  exports.deleteProperties = deleteProperties;
1287
1752
  exports.deleteProperty = deleteProperty;
@@ -1289,6 +1754,7 @@
1289
1754
  exports.fileBufferToObjectUrl = fileBufferToObjectUrl;
1290
1755
  exports.fileDataFromBuffer = fileDataFromBuffer;
1291
1756
  exports.fractionalDigitsCount = fractionalDigitsCount;
1757
+ exports.geoJsonToArea = geoJsonToArea;
1292
1758
  exports.getAttribute = getAttribute;
1293
1759
  exports.getClosestWidgetCdkDrag = getClosestWidgetCdkDrag;
1294
1760
  exports.getControlName = getControlName;
@@ -1299,12 +1765,18 @@
1299
1765
  exports.isAbsoluteUrl = isAbsoluteUrl;
1300
1766
  exports.isEmptyInputValue = isEmptyInputValue;
1301
1767
  exports.isEmptyUrlRoute = isEmptyUrlRoute;
1768
+ exports.isFeatureCollectionValidator = isFeatureCollectionValidator;
1302
1769
  exports.isNullOrUndefined = isNullOrUndefined;
1303
1770
  exports.isNumeric = isNumeric;
1771
+ exports.isOnlyGeometryTypes = isOnlyGeometryTypes;
1772
+ exports.isOnlyGeometryTypesValidator = isOnlyGeometryTypesValidator;
1304
1773
  exports.leafChildRoute = leafChildRoute;
1305
1774
  exports.loadStyle = loadStyle;
1306
1775
  exports.loadStyleSheet = loadStyleSheet;
1307
1776
  exports.mapEach = mapEach;
1777
+ exports.mergePolygons = mergePolygons;
1778
+ exports.noInnerRingsValidator = noInnerRingsValidator;
1779
+ exports.noKinksValidator = noKinksValidator;
1308
1780
  exports.notNullOrUndefined = notNullOrUndefined;
1309
1781
  exports.observeControlIsDifferent = observeControlIsDifferent;
1310
1782
  exports.observeControlStatus = observeControlStatus;
@@ -1319,8 +1791,10 @@
1319
1791
  exports.pollingTicker = pollingTicker;
1320
1792
  exports.readFileAsDataUrlAsync = readFileAsDataUrlAsync;
1321
1793
  exports.readFileAsync = readFileAsync;
1794
+ exports.readGeoFile = readGeoFile;
1322
1795
  exports.routeSnapshotPathFull = routeSnapshotPathFull;
1323
1796
  exports.routeSnapshotPathRelative = routeSnapshotPathRelative;
1797
+ exports.splitMultiPolygons = splitMultiPolygons;
1324
1798
  exports.subscriberCount = subscriberCount;
1325
1799
  exports.tapFirst = tapFirst;
1326
1800
  exports.toggleAttribute = toggleAttribute;