@team-geospan/structuresio 0.0.6 → 0.0.7
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/lib/geojson.js +43 -1
- package/package.json +3 -8
package/lib/geojson.js
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* Convert a StructuresJSON Structure or StructureCollection to GeoJSON
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
import { isCollection } from "./helpers
|
|
22
|
+
import { isCollection } from "./helpers";
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* simplifyRing converts a single surface ring and coverts it to a list
|
|
@@ -154,3 +154,45 @@ export const toLineStringGeoJSON = (collection) => {
|
|
|
154
154
|
features: allFeatures.flatMap((v) => v),
|
|
155
155
|
};
|
|
156
156
|
};
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Convert a single structure into a list of GeoJSON Features
|
|
160
|
+
* which have Point geometries for accessories.
|
|
161
|
+
*/
|
|
162
|
+
const structureAccessoriesToPointFeature = ({ points }) => {
|
|
163
|
+
const features = Object.keys(points)
|
|
164
|
+
// only convert the accessories to features
|
|
165
|
+
.filter((ea) => points[ea].kind == "accessory")
|
|
166
|
+
.map((pointId) => {
|
|
167
|
+
return {
|
|
168
|
+
type: "Feature",
|
|
169
|
+
properties: {
|
|
170
|
+
id: pointId,
|
|
171
|
+
layer: "accessories",
|
|
172
|
+
kind: "accessory",
|
|
173
|
+
color: points[pointId].color,
|
|
174
|
+
label: points[pointId].label,
|
|
175
|
+
},
|
|
176
|
+
geometry: {
|
|
177
|
+
type: "Point",
|
|
178
|
+
coordinates: points[pointId].coordinates,
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
});
|
|
182
|
+
return features;
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* @return A FeatureCollection of the accessories as GeoJSON Point.
|
|
187
|
+
*/
|
|
188
|
+
export const accessoriesToPointGeoJSON = (collection) => {
|
|
189
|
+
// handle either a collection or single structure
|
|
190
|
+
const allFeatures = isCollection(collection)
|
|
191
|
+
? collection.structures.map(structureAccessoriesToPointFeature)
|
|
192
|
+
: [structureAccessoriesToPointFeature(collection)];
|
|
193
|
+
|
|
194
|
+
return {
|
|
195
|
+
type: "FeatureCollection",
|
|
196
|
+
features: allFeatures.flatMap((v) => v),
|
|
197
|
+
};
|
|
198
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@team-geospan/structuresio",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "Collection of utilities for working with StructuresJSON",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -26,21 +26,16 @@
|
|
|
26
26
|
},
|
|
27
27
|
"extends": [
|
|
28
28
|
"eslint:recommended",
|
|
29
|
-
"plugin:prettier/recommended"
|
|
30
|
-
"plugin:import/recommended"
|
|
29
|
+
"plugin:prettier/recommended"
|
|
31
30
|
],
|
|
32
31
|
"rules": {
|
|
33
|
-
"prettier/prettier": "error"
|
|
34
|
-
"import/extensions": ["error", "always", {
|
|
35
|
-
"js": "always"
|
|
36
|
-
}]
|
|
32
|
+
"prettier/prettier": "error"
|
|
37
33
|
}
|
|
38
34
|
},
|
|
39
35
|
"devDependencies": {
|
|
40
36
|
"@vitest/coverage-v8": "^3.1.1",
|
|
41
37
|
"eslint": "^8.57.0",
|
|
42
38
|
"eslint-config-prettier": "^10.0.1",
|
|
43
|
-
"eslint-plugin-import": "^2.31.0",
|
|
44
39
|
"eslint-plugin-prettier": "^5.2.3",
|
|
45
40
|
"vitest": "^3.1.1"
|
|
46
41
|
},
|