map-ol-utils 0.0.36 → 0.0.37

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.
package/dist/index.cjs CHANGED
@@ -67,6 +67,7 @@ var __async = (__this, __arguments, generator) => {
67
67
  // src/index.ts
68
68
  var index_exports = {};
69
69
  __export(index_exports, {
70
+ GeometryType: () => GeometryType,
70
71
  activeFeatureByUid: () => activeFeatureByUid,
71
72
  addMassMarksLayer: () => addMassMarksLayer,
72
73
  appendFeaturesByLayer: () => appendFeaturesByLayer,
@@ -95,6 +96,16 @@ __export(index_exports, {
95
96
  });
96
97
  module.exports = __toCommonJS(index_exports);
97
98
 
99
+ // src/types.ts
100
+ var GeometryType = /* @__PURE__ */ ((GeometryType2) => {
101
+ GeometryType2["LineString"] = "LineString";
102
+ GeometryType2["MultiLineString"] = "MultiLineString";
103
+ GeometryType2["Polygon"] = "Polygon";
104
+ GeometryType2["MultiPolygon"] = "MultiPolygon";
105
+ GeometryType2["Invalid"] = "Invalid";
106
+ return GeometryType2;
107
+ })(GeometryType || {});
108
+
98
109
  // src/emitter.ts
99
110
  var import_mitt = __toESM(require("mitt"), 1);
100
111
  var emitter = (0, import_mitt.default)();
@@ -147,7 +158,7 @@ var resetActiveVector = () => {
147
158
  });
148
159
  };
149
160
  var assembleGeoJson = (dataList, config) => {
150
- const { key, isLine, needTransform = true } = config;
161
+ const { key, needTransform = true } = config;
151
162
  const tempList = [];
152
163
  dataList.forEach((item) => {
153
164
  try {
@@ -158,7 +169,7 @@ var assembleGeoJson = (dataList, config) => {
158
169
  properties: __spreadValues({}, item),
159
170
  geometry: {
160
171
  coordinates: pathArray,
161
- type: isLine ? "LineString" : "MultiPolygon"
172
+ type: determineGeometryType(pathArray)
162
173
  }
163
174
  });
164
175
  }
@@ -756,6 +767,54 @@ var getLayersDataList = () => {
756
767
  var _a;
757
768
  return ((_a = instance) == null ? void 0 : _a.getAllLayers().map((layer) => layer.get("_dataList") || []).flat(2)) || [];
758
769
  };
770
+ var determineGeometryType = (coordinates) => {
771
+ const getArrayDepth = (arr) => {
772
+ if (!Array.isArray(arr)) return 0;
773
+ return 1 + Math.max(...arr.map((item) => getArrayDepth(item)), 0);
774
+ };
775
+ const isClosedRing = (coords) => {
776
+ if (!Array.isArray(coords) || coords.length < 3) return false;
777
+ const first = coords[0];
778
+ const last = coords[coords.length - 1];
779
+ return first[0] === last[0] && first[1] === last[1];
780
+ };
781
+ const isValidCoordinate = (coord) => {
782
+ return Array.isArray(coord) && coord.length >= 2 && typeof coord[0] === "number" && typeof coord[1] === "number";
783
+ };
784
+ const isValidLineString = (coords) => {
785
+ return Array.isArray(coords) && coords.length >= 2 && coords.every(isValidCoordinate);
786
+ };
787
+ const isValidPolygon = (coords) => {
788
+ if (!Array.isArray(coords)) return false;
789
+ const rings = getArrayDepth(coords) === 2 ? [coords] : coords;
790
+ return rings.every(
791
+ (ring) => Array.isArray(ring) && ring.length >= 4 && isClosedRing(ring) && ring.every(isValidCoordinate)
792
+ );
793
+ };
794
+ const depth = getArrayDepth(coordinates);
795
+ try {
796
+ if (depth < 2 || !coordinates || coordinates.length === 0) {
797
+ return "Invalid" /* Invalid */;
798
+ } else if (depth === 2 && isValidLineString(coordinates)) {
799
+ return isClosedRing(coordinates) && coordinates.length >= 4 ? "Polygon" /* Polygon */ : "LineString" /* LineString */;
800
+ } else if (depth === 3 && Array.isArray(coordinates) && coordinates.every(isValidLineString)) {
801
+ if (isValidPolygon(coordinates)) {
802
+ return "Polygon" /* Polygon */;
803
+ } else if (coordinates.every((arr) => !isClosedRing(arr))) {
804
+ return "MultiLineString" /* MultiLineString */;
805
+ } else {
806
+ return "Invalid" /* Invalid */;
807
+ }
808
+ } else if (depth === 4 && Array.isArray(coordinates) && coordinates.every((rings) => isValidPolygon(rings))) {
809
+ return "MultiPolygon" /* MultiPolygon */;
810
+ } else {
811
+ return "Invalid" /* Invalid */;
812
+ }
813
+ } catch (error) {
814
+ console.error("Error analyzing coordinates:", error);
815
+ return "Invalid" /* Invalid */;
816
+ }
817
+ };
759
818
 
760
819
  // src/ogc-utils.ts
761
820
  var import_source3 = require("ol/source");
@@ -807,6 +866,7 @@ var createWmtsLayer = (serverUrl) => (config) => __async(void 0, null, function*
807
866
  });
808
867
  // Annotate the CommonJS export names for ESM import in node:
809
868
  0 && (module.exports = {
869
+ GeometryType,
810
870
  activeFeatureByUid,
811
871
  addMassMarksLayer,
812
872
  appendFeaturesByLayer,
package/dist/index.d.cts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Layer, Tile } from 'ol/layer';
2
2
  import { Map as Map$1, Feature } from 'ol';
3
3
  import { Source, XYZ, WMTS } from 'ol/source';
4
+ import { Coordinate } from 'ol/coordinate';
4
5
  import { Emitter, EventType } from 'mitt';
5
6
  import TileLayer from 'ol/layer/Tile';
6
7
  import * as ol_geom from 'ol/geom';
@@ -75,6 +76,14 @@ type WmtsSourceOptions = {
75
76
  layerName: string;
76
77
  matrixSet?: string;
77
78
  };
79
+ declare enum GeometryType {
80
+ LineString = "LineString",
81
+ MultiLineString = "MultiLineString",
82
+ Polygon = "Polygon",
83
+ MultiPolygon = "MultiPolygon",
84
+ Invalid = "Invalid"
85
+ }
86
+ type GeometryCoordinates = Coordinate[] | Coordinate[][] | Coordinate[][][];
78
87
 
79
88
  declare const emitter: Emitter<Record<EventType, any>>;
80
89
 
@@ -172,4 +181,4 @@ declare const addMassMarksLayer: (getImgUrlFn: GetImgUrlFn) => (dataList: never[
172
181
  */
173
182
  declare const updateMarksLayersByStatus: (checkedStatusList?: string[]) => MassData[];
174
183
 
175
- export { type CustomMap, type GetImgUrl, type GetImgUrlFn, type IconConfig, type MassData, type VectorConfig, type WmtsSourceOptions, activeFeatureByUid, addMassMarksLayer, appendFeaturesByLayer, buildMassMarksStyles, createAnimationMarker, createBaseLayer, createBusinessLayer, createMapInstance, createMapWorldLayer, createMassMarksLayer, createSelectByLayer, createVectorFaceLayer, createVectorLineLayer, createWmtsLayer, disposeMap, emitter, getLayersDataList, getMapInstance, instance, removeAllLayers, resetActiveFeature, resetActiveVector, resetMap, resetZoomAndCenter, updateMarksLayersByStatus };
184
+ export { type CustomMap, type GeometryCoordinates, GeometryType, type GetImgUrl, type GetImgUrlFn, type IconConfig, type MassData, type VectorConfig, type WmtsSourceOptions, activeFeatureByUid, addMassMarksLayer, appendFeaturesByLayer, buildMassMarksStyles, createAnimationMarker, createBaseLayer, createBusinessLayer, createMapInstance, createMapWorldLayer, createMassMarksLayer, createSelectByLayer, createVectorFaceLayer, createVectorLineLayer, createWmtsLayer, disposeMap, emitter, getLayersDataList, getMapInstance, instance, removeAllLayers, resetActiveFeature, resetActiveVector, resetMap, resetZoomAndCenter, updateMarksLayersByStatus };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Layer, Tile } from 'ol/layer';
2
2
  import { Map as Map$1, Feature } from 'ol';
3
3
  import { Source, XYZ, WMTS } from 'ol/source';
4
+ import { Coordinate } from 'ol/coordinate';
4
5
  import { Emitter, EventType } from 'mitt';
5
6
  import TileLayer from 'ol/layer/Tile';
6
7
  import * as ol_geom from 'ol/geom';
@@ -75,6 +76,14 @@ type WmtsSourceOptions = {
75
76
  layerName: string;
76
77
  matrixSet?: string;
77
78
  };
79
+ declare enum GeometryType {
80
+ LineString = "LineString",
81
+ MultiLineString = "MultiLineString",
82
+ Polygon = "Polygon",
83
+ MultiPolygon = "MultiPolygon",
84
+ Invalid = "Invalid"
85
+ }
86
+ type GeometryCoordinates = Coordinate[] | Coordinate[][] | Coordinate[][][];
78
87
 
79
88
  declare const emitter: Emitter<Record<EventType, any>>;
80
89
 
@@ -172,4 +181,4 @@ declare const addMassMarksLayer: (getImgUrlFn: GetImgUrlFn) => (dataList: never[
172
181
  */
173
182
  declare const updateMarksLayersByStatus: (checkedStatusList?: string[]) => MassData[];
174
183
 
175
- export { type CustomMap, type GetImgUrl, type GetImgUrlFn, type IconConfig, type MassData, type VectorConfig, type WmtsSourceOptions, activeFeatureByUid, addMassMarksLayer, appendFeaturesByLayer, buildMassMarksStyles, createAnimationMarker, createBaseLayer, createBusinessLayer, createMapInstance, createMapWorldLayer, createMassMarksLayer, createSelectByLayer, createVectorFaceLayer, createVectorLineLayer, createWmtsLayer, disposeMap, emitter, getLayersDataList, getMapInstance, instance, removeAllLayers, resetActiveFeature, resetActiveVector, resetMap, resetZoomAndCenter, updateMarksLayersByStatus };
184
+ export { type CustomMap, type GeometryCoordinates, GeometryType, type GetImgUrl, type GetImgUrlFn, type IconConfig, type MassData, type VectorConfig, type WmtsSourceOptions, activeFeatureByUid, addMassMarksLayer, appendFeaturesByLayer, buildMassMarksStyles, createAnimationMarker, createBaseLayer, createBusinessLayer, createMapInstance, createMapWorldLayer, createMassMarksLayer, createSelectByLayer, createVectorFaceLayer, createVectorLineLayer, createWmtsLayer, disposeMap, emitter, getLayersDataList, getMapInstance, instance, removeAllLayers, resetActiveFeature, resetActiveVector, resetMap, resetZoomAndCenter, updateMarksLayersByStatus };
package/dist/index.js CHANGED
@@ -38,6 +38,16 @@ var __async = (__this, __arguments, generator) => {
38
38
  });
39
39
  };
40
40
 
41
+ // src/types.ts
42
+ var GeometryType = /* @__PURE__ */ ((GeometryType2) => {
43
+ GeometryType2["LineString"] = "LineString";
44
+ GeometryType2["MultiLineString"] = "MultiLineString";
45
+ GeometryType2["Polygon"] = "Polygon";
46
+ GeometryType2["MultiPolygon"] = "MultiPolygon";
47
+ GeometryType2["Invalid"] = "Invalid";
48
+ return GeometryType2;
49
+ })(GeometryType || {});
50
+
41
51
  // src/emitter.ts
42
52
  import mitt from "mitt";
43
53
  var emitter = mitt();
@@ -90,7 +100,7 @@ var resetActiveVector = () => {
90
100
  });
91
101
  };
92
102
  var assembleGeoJson = (dataList, config) => {
93
- const { key, isLine, needTransform = true } = config;
103
+ const { key, needTransform = true } = config;
94
104
  const tempList = [];
95
105
  dataList.forEach((item) => {
96
106
  try {
@@ -101,7 +111,7 @@ var assembleGeoJson = (dataList, config) => {
101
111
  properties: __spreadValues({}, item),
102
112
  geometry: {
103
113
  coordinates: pathArray,
104
- type: isLine ? "LineString" : "MultiPolygon"
114
+ type: determineGeometryType(pathArray)
105
115
  }
106
116
  });
107
117
  }
@@ -699,6 +709,54 @@ var getLayersDataList = () => {
699
709
  var _a;
700
710
  return ((_a = instance) == null ? void 0 : _a.getAllLayers().map((layer) => layer.get("_dataList") || []).flat(2)) || [];
701
711
  };
712
+ var determineGeometryType = (coordinates) => {
713
+ const getArrayDepth = (arr) => {
714
+ if (!Array.isArray(arr)) return 0;
715
+ return 1 + Math.max(...arr.map((item) => getArrayDepth(item)), 0);
716
+ };
717
+ const isClosedRing = (coords) => {
718
+ if (!Array.isArray(coords) || coords.length < 3) return false;
719
+ const first = coords[0];
720
+ const last = coords[coords.length - 1];
721
+ return first[0] === last[0] && first[1] === last[1];
722
+ };
723
+ const isValidCoordinate = (coord) => {
724
+ return Array.isArray(coord) && coord.length >= 2 && typeof coord[0] === "number" && typeof coord[1] === "number";
725
+ };
726
+ const isValidLineString = (coords) => {
727
+ return Array.isArray(coords) && coords.length >= 2 && coords.every(isValidCoordinate);
728
+ };
729
+ const isValidPolygon = (coords) => {
730
+ if (!Array.isArray(coords)) return false;
731
+ const rings = getArrayDepth(coords) === 2 ? [coords] : coords;
732
+ return rings.every(
733
+ (ring) => Array.isArray(ring) && ring.length >= 4 && isClosedRing(ring) && ring.every(isValidCoordinate)
734
+ );
735
+ };
736
+ const depth = getArrayDepth(coordinates);
737
+ try {
738
+ if (depth < 2 || !coordinates || coordinates.length === 0) {
739
+ return "Invalid" /* Invalid */;
740
+ } else if (depth === 2 && isValidLineString(coordinates)) {
741
+ return isClosedRing(coordinates) && coordinates.length >= 4 ? "Polygon" /* Polygon */ : "LineString" /* LineString */;
742
+ } else if (depth === 3 && Array.isArray(coordinates) && coordinates.every(isValidLineString)) {
743
+ if (isValidPolygon(coordinates)) {
744
+ return "Polygon" /* Polygon */;
745
+ } else if (coordinates.every((arr) => !isClosedRing(arr))) {
746
+ return "MultiLineString" /* MultiLineString */;
747
+ } else {
748
+ return "Invalid" /* Invalid */;
749
+ }
750
+ } else if (depth === 4 && Array.isArray(coordinates) && coordinates.every((rings) => isValidPolygon(rings))) {
751
+ return "MultiPolygon" /* MultiPolygon */;
752
+ } else {
753
+ return "Invalid" /* Invalid */;
754
+ }
755
+ } catch (error) {
756
+ console.error("Error analyzing coordinates:", error);
757
+ return "Invalid" /* Invalid */;
758
+ }
759
+ };
702
760
 
703
761
  // src/ogc-utils.ts
704
762
  import { WMTS as WMTS2 } from "ol/source";
@@ -749,6 +807,7 @@ var createWmtsLayer = (serverUrl) => (config) => __async(void 0, null, function*
749
807
  });
750
808
  });
751
809
  export {
810
+ GeometryType,
752
811
  activeFeatureByUid,
753
812
  addMassMarksLayer,
754
813
  appendFeaturesByLayer,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "map-ol-utils",
3
- "version": "0.0.36",
3
+ "version": "0.0.37",
4
4
  "type": "module",
5
5
  "description": "Openlayers utils library",
6
6
  "files": [