@loaders.gl/gis 3.1.3 → 4.0.0-alpha.5
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/bundle.js +2 -2
- package/dist/bundle.js.map +1 -0
- package/dist/index.js +6 -18
- package/dist/index.js.map +1 -0
- package/dist/lib/binary-to-geojson.js +242 -201
- package/dist/lib/binary-to-geojson.js.map +1 -0
- package/dist/lib/extract-geometry-info.js +102 -93
- package/dist/lib/extract-geometry-info.js.map +1 -0
- package/dist/lib/flat-geojson-to-binary-types.js +2 -2
- package/dist/{es5/lib → lib}/flat-geojson-to-binary-types.js.map +0 -0
- package/dist/lib/flat-geojson-to-binary.js +309 -345
- package/dist/lib/flat-geojson-to-binary.js.map +1 -0
- package/dist/lib/geojson-to-binary.js +20 -23
- package/dist/lib/geojson-to-binary.js.map +1 -0
- package/dist/lib/geojson-to-flat-geojson.js +104 -116
- package/dist/lib/geojson-to-flat-geojson.js.map +1 -0
- package/dist/lib/transform.js +42 -51
- package/dist/lib/transform.js.map +1 -0
- package/package.json +6 -6
- package/dist/es5/bundle.js +0 -7
- package/dist/es5/bundle.js.map +0 -1
- package/dist/es5/index.js +0 -64
- package/dist/es5/index.js.map +0 -1
- package/dist/es5/lib/binary-to-geojson.js +0 -330
- package/dist/es5/lib/binary-to-geojson.js.map +0 -1
- package/dist/es5/lib/extract-geometry-info.js +0 -204
- package/dist/es5/lib/extract-geometry-info.js.map +0 -1
- package/dist/es5/lib/flat-geojson-to-binary-types.js +0 -2
- package/dist/es5/lib/flat-geojson-to-binary.js +0 -397
- package/dist/es5/lib/flat-geojson-to-binary.js.map +0 -1
- package/dist/es5/lib/geojson-to-binary.js +0 -30
- package/dist/es5/lib/geojson-to-binary.js.map +0 -1
- package/dist/es5/lib/geojson-to-flat-geojson.js +0 -169
- package/dist/es5/lib/geojson-to-flat-geojson.js.map +0 -1
- package/dist/es5/lib/transform.js +0 -73
- package/dist/es5/lib/transform.js.map +0 -1
- package/dist/esm/bundle.js +0 -5
- package/dist/esm/bundle.js.map +0 -1
- package/dist/esm/index.js +0 -6
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/lib/binary-to-geojson.js +0 -274
- package/dist/esm/lib/binary-to-geojson.js.map +0 -1
- package/dist/esm/lib/extract-geometry-info.js +0 -105
- package/dist/esm/lib/extract-geometry-info.js.map +0 -1
- package/dist/esm/lib/flat-geojson-to-binary-types.js +0 -2
- package/dist/esm/lib/flat-geojson-to-binary-types.js.map +0 -1
- package/dist/esm/lib/flat-geojson-to-binary.js +0 -339
- package/dist/esm/lib/flat-geojson-to-binary.js.map +0 -1
- package/dist/esm/lib/geojson-to-binary.js +0 -21
- package/dist/esm/lib/geojson-to-binary.js.map +0 -1
- package/dist/esm/lib/geojson-to-flat-geojson.js +0 -116
- package/dist/esm/lib/geojson-to-flat-geojson.js.map +0 -1
- package/dist/esm/lib/transform.js +0 -50
- package/dist/esm/lib/transform.js.map +0 -1
|
@@ -1,375 +1,339 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
* data format detais
|
|
13
|
-
*
|
|
14
|
-
* @param features
|
|
15
|
-
* @param geometryInfo
|
|
16
|
-
* @param options
|
|
17
|
-
* @returns filled arrays
|
|
18
|
-
*/
|
|
19
|
-
function flatGeojsonToBinary(features, geometryInfo, options) {
|
|
20
|
-
const propArrayTypes = extractNumericPropTypes(features);
|
|
21
|
-
const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
|
|
22
|
-
return fillArrays(features, {
|
|
23
|
-
propArrayTypes,
|
|
24
|
-
...geometryInfo
|
|
25
|
-
}, {
|
|
26
|
-
numericPropKeys: (options && options.numericPropKeys) || numericPropKeys,
|
|
27
|
-
PositionDataType: options ? options.PositionDataType : Float32Array
|
|
28
|
-
});
|
|
1
|
+
import { earcut } from '@math.gl/polygon';
|
|
2
|
+
export function flatGeojsonToBinary(features, geometryInfo, options) {
|
|
3
|
+
const propArrayTypes = extractNumericPropTypes(features);
|
|
4
|
+
const numericPropKeys = Object.keys(propArrayTypes).filter(k => propArrayTypes[k] !== Array);
|
|
5
|
+
return fillArrays(features, {
|
|
6
|
+
propArrayTypes,
|
|
7
|
+
...geometryInfo
|
|
8
|
+
}, {
|
|
9
|
+
numericPropKeys: options && options.numericPropKeys || numericPropKeys,
|
|
10
|
+
PositionDataType: options ? options.PositionDataType : Float32Array
|
|
11
|
+
});
|
|
29
12
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
extractNumericPropTypes
|
|
13
|
+
export const TEST_EXPORTS = {
|
|
14
|
+
extractNumericPropTypes
|
|
33
15
|
};
|
|
34
|
-
|
|
35
|
-
* Extracts properties that are always numeric
|
|
36
|
-
*
|
|
37
|
-
* @param features
|
|
38
|
-
* @returns object with numeric types
|
|
39
|
-
*/
|
|
16
|
+
|
|
40
17
|
function extractNumericPropTypes(features) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const val = feature.properties[key];
|
|
50
|
-
propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
18
|
+
const propArrayTypes = {};
|
|
19
|
+
|
|
20
|
+
for (const feature of features) {
|
|
21
|
+
if (feature.properties) {
|
|
22
|
+
for (const key in feature.properties) {
|
|
23
|
+
const val = feature.properties[key];
|
|
24
|
+
propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);
|
|
25
|
+
}
|
|
53
26
|
}
|
|
54
|
-
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return propArrayTypes;
|
|
55
30
|
}
|
|
56
|
-
|
|
57
|
-
* Fills coordinates into pre-allocated typed arrays
|
|
58
|
-
*
|
|
59
|
-
* @param features
|
|
60
|
-
* @param geometryInfo
|
|
61
|
-
* @param options
|
|
62
|
-
* @returns an accessor object with value and size keys
|
|
63
|
-
*/
|
|
64
|
-
// eslint-disable-next-line complexity
|
|
31
|
+
|
|
65
32
|
function fillArrays(features, geometryInfo, options) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
33
|
+
const {
|
|
34
|
+
pointPositionsCount,
|
|
35
|
+
pointFeaturesCount,
|
|
36
|
+
linePositionsCount,
|
|
37
|
+
linePathsCount,
|
|
38
|
+
lineFeaturesCount,
|
|
39
|
+
polygonPositionsCount,
|
|
40
|
+
polygonObjectsCount,
|
|
41
|
+
polygonRingsCount,
|
|
42
|
+
polygonFeaturesCount,
|
|
43
|
+
propArrayTypes,
|
|
44
|
+
coordLength
|
|
45
|
+
} = geometryInfo;
|
|
46
|
+
const {
|
|
47
|
+
numericPropKeys = [],
|
|
48
|
+
PositionDataType = Float32Array
|
|
49
|
+
} = options;
|
|
50
|
+
const hasGlobalId = features[0] && 'id' in features[0];
|
|
51
|
+
const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
|
|
52
|
+
const points = {
|
|
53
|
+
type: 'Point',
|
|
54
|
+
positions: new PositionDataType(pointPositionsCount * coordLength),
|
|
55
|
+
globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
|
|
56
|
+
featureIds: pointFeaturesCount > 65535 ? new Uint32Array(pointPositionsCount) : new Uint16Array(pointPositionsCount),
|
|
57
|
+
numericProps: {},
|
|
58
|
+
properties: [],
|
|
59
|
+
fields: []
|
|
60
|
+
};
|
|
61
|
+
const lines = {
|
|
62
|
+
type: 'LineString',
|
|
63
|
+
pathIndices: linePositionsCount > 65535 ? new Uint32Array(linePathsCount + 1) : new Uint16Array(linePathsCount + 1),
|
|
64
|
+
positions: new PositionDataType(linePositionsCount * coordLength),
|
|
65
|
+
globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),
|
|
66
|
+
featureIds: lineFeaturesCount > 65535 ? new Uint32Array(linePositionsCount) : new Uint16Array(linePositionsCount),
|
|
67
|
+
numericProps: {},
|
|
68
|
+
properties: [],
|
|
69
|
+
fields: []
|
|
70
|
+
};
|
|
71
|
+
const polygons = {
|
|
72
|
+
type: 'Polygon',
|
|
73
|
+
polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1),
|
|
74
|
+
primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1),
|
|
75
|
+
positions: new PositionDataType(polygonPositionsCount * coordLength),
|
|
76
|
+
triangles: [],
|
|
77
|
+
globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),
|
|
78
|
+
featureIds: polygonFeaturesCount > 65535 ? new Uint32Array(polygonPositionsCount) : new Uint16Array(polygonPositionsCount),
|
|
79
|
+
numericProps: {},
|
|
80
|
+
properties: [],
|
|
81
|
+
fields: []
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
for (const object of [points, lines, polygons]) {
|
|
85
|
+
for (const propName of numericPropKeys) {
|
|
86
|
+
const T = propArrayTypes[propName];
|
|
87
|
+
object.numericProps[propName] = new T(object.positions.length / coordLength);
|
|
121
88
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
lines.pathIndices[linePathsCount] = linePositionsCount;
|
|
92
|
+
polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;
|
|
93
|
+
polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;
|
|
94
|
+
const indexMap = {
|
|
95
|
+
pointPosition: 0,
|
|
96
|
+
pointFeature: 0,
|
|
97
|
+
linePosition: 0,
|
|
98
|
+
linePath: 0,
|
|
99
|
+
lineFeature: 0,
|
|
100
|
+
polygonPosition: 0,
|
|
101
|
+
polygonObject: 0,
|
|
102
|
+
polygonRing: 0,
|
|
103
|
+
polygonFeature: 0,
|
|
104
|
+
feature: 0
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
for (const feature of features) {
|
|
108
|
+
const geometry = feature.geometry;
|
|
109
|
+
const properties = feature.properties || {};
|
|
110
|
+
|
|
111
|
+
switch (geometry.type) {
|
|
112
|
+
case 'Point':
|
|
113
|
+
handlePoint(geometry, points, indexMap, coordLength, properties);
|
|
114
|
+
points.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
115
|
+
|
|
116
|
+
if (hasGlobalId) {
|
|
117
|
+
points.fields.push({
|
|
118
|
+
id: feature.id
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
indexMap.pointFeature++;
|
|
123
|
+
break;
|
|
124
|
+
|
|
125
|
+
case 'LineString':
|
|
126
|
+
handleLineString(geometry, lines, indexMap, coordLength, properties);
|
|
127
|
+
lines.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
128
|
+
|
|
129
|
+
if (hasGlobalId) {
|
|
130
|
+
lines.fields.push({
|
|
131
|
+
id: feature.id
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
indexMap.lineFeature++;
|
|
136
|
+
break;
|
|
137
|
+
|
|
138
|
+
case 'Polygon':
|
|
139
|
+
handlePolygon(geometry, polygons, indexMap, coordLength, properties);
|
|
140
|
+
polygons.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
141
|
+
|
|
142
|
+
if (hasGlobalId) {
|
|
143
|
+
polygons.fields.push({
|
|
144
|
+
id: feature.id
|
|
145
|
+
});
|
|
168
146
|
}
|
|
169
|
-
|
|
147
|
+
|
|
148
|
+
indexMap.polygonFeature++;
|
|
149
|
+
break;
|
|
150
|
+
|
|
151
|
+
default:
|
|
152
|
+
throw new Error('Invalid geometry type');
|
|
170
153
|
}
|
|
171
|
-
|
|
172
|
-
|
|
154
|
+
|
|
155
|
+
indexMap.feature++;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return makeAccessorObjects(points, lines, polygons, coordLength);
|
|
173
159
|
}
|
|
174
|
-
|
|
175
|
-
* Fills (Multi)Point coordinates into points object of arrays
|
|
176
|
-
*
|
|
177
|
-
* @param geometry
|
|
178
|
-
* @param points
|
|
179
|
-
* @param indexMap
|
|
180
|
-
* @param coordLength
|
|
181
|
-
* @param properties
|
|
182
|
-
*/
|
|
160
|
+
|
|
183
161
|
function handlePoint(geometry, points, indexMap, coordLength, properties) {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
162
|
+
points.positions.set(geometry.data, indexMap.pointPosition * coordLength);
|
|
163
|
+
const nPositions = geometry.data.length / coordLength;
|
|
164
|
+
fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);
|
|
165
|
+
points.globalFeatureIds.fill(indexMap.feature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
|
|
166
|
+
points.featureIds.fill(indexMap.pointFeature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
|
|
167
|
+
indexMap.pointPosition += nPositions;
|
|
190
168
|
}
|
|
191
|
-
|
|
192
|
-
* Fills (Multi)LineString coordinates into lines object of arrays
|
|
193
|
-
*
|
|
194
|
-
* @param geometry
|
|
195
|
-
* @param lines
|
|
196
|
-
* @param indexMap
|
|
197
|
-
* @param coordLength
|
|
198
|
-
* @param properties
|
|
199
|
-
*/
|
|
169
|
+
|
|
200
170
|
function handleLineString(geometry, lines, indexMap, coordLength, properties) {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;
|
|
214
|
-
indexMap.linePosition += (end - start) / coordLength;
|
|
215
|
-
}
|
|
171
|
+
lines.positions.set(geometry.data, indexMap.linePosition * coordLength);
|
|
172
|
+
const nPositions = geometry.data.length / coordLength;
|
|
173
|
+
fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
|
|
174
|
+
lines.globalFeatureIds.fill(indexMap.feature, indexMap.linePosition, indexMap.linePosition + nPositions);
|
|
175
|
+
lines.featureIds.fill(indexMap.lineFeature, indexMap.linePosition, indexMap.linePosition + nPositions);
|
|
176
|
+
|
|
177
|
+
for (let i = 0, il = geometry.indices.length; i < il; ++i) {
|
|
178
|
+
const start = geometry.indices[i];
|
|
179
|
+
const end = i === il - 1 ? geometry.data.length : geometry.indices[i + 1];
|
|
180
|
+
lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;
|
|
181
|
+
indexMap.linePosition += (end - start) / coordLength;
|
|
182
|
+
}
|
|
216
183
|
}
|
|
217
|
-
|
|
218
|
-
* Fills (Multi)Polygon coordinates into polygons object of arrays
|
|
219
|
-
*
|
|
220
|
-
* @param geometry
|
|
221
|
-
* @param polygons
|
|
222
|
-
* @param indexMap
|
|
223
|
-
* @param coordLength
|
|
224
|
-
* @param properties
|
|
225
|
-
*/
|
|
184
|
+
|
|
226
185
|
function handlePolygon(geometry, polygons, indexMap, coordLength, properties) {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
: nextIndices[0] // start of first line in nextIndices
|
|
246
|
-
: indices[i + 1]; // start index for next line
|
|
247
|
-
polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
|
|
248
|
-
indexMap.polygonPosition += (end - start) / coordLength;
|
|
249
|
-
}
|
|
250
|
-
const endPosition = indexMap.polygonPosition;
|
|
251
|
-
triangulatePolygon(polygons, areas, indices, { startPosition, endPosition, coordLength });
|
|
186
|
+
polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);
|
|
187
|
+
const nPositions = geometry.data.length / coordLength;
|
|
188
|
+
fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
|
|
189
|
+
polygons.globalFeatureIds.fill(indexMap.feature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
|
|
190
|
+
polygons.featureIds.fill(indexMap.polygonFeature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
|
|
191
|
+
|
|
192
|
+
for (let l = 0, ll = geometry.indices.length; l < ll; ++l) {
|
|
193
|
+
const startPosition = indexMap.polygonPosition;
|
|
194
|
+
polygons.polygonIndices[indexMap.polygonObject++] = startPosition;
|
|
195
|
+
const areas = geometry.areas[l];
|
|
196
|
+
const indices = geometry.indices[l];
|
|
197
|
+
const nextIndices = geometry.indices[l + 1];
|
|
198
|
+
|
|
199
|
+
for (let i = 0, il = indices.length; i < il; ++i) {
|
|
200
|
+
const start = indices[i];
|
|
201
|
+
const end = i === il - 1 ? nextIndices === undefined ? geometry.data.length : nextIndices[0] : indices[i + 1];
|
|
202
|
+
polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
|
|
203
|
+
indexMap.polygonPosition += (end - start) / coordLength;
|
|
252
204
|
}
|
|
205
|
+
|
|
206
|
+
const endPosition = indexMap.polygonPosition;
|
|
207
|
+
triangulatePolygon(polygons, areas, indices, {
|
|
208
|
+
startPosition,
|
|
209
|
+
endPosition,
|
|
210
|
+
coordLength
|
|
211
|
+
});
|
|
212
|
+
}
|
|
253
213
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
*
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
// Compute triangulation
|
|
271
|
-
const triangles = (0, polygon_1.earcut)(polygonPositions, holes, coordLength, areas);
|
|
272
|
-
// Indices returned by triangulation are relative to start
|
|
273
|
-
// of polygon, so we need to offset
|
|
274
|
-
for (let t = 0, tl = triangles.length; t < tl; ++t) {
|
|
275
|
-
polygons.triangles.push(startPosition + triangles[t]);
|
|
276
|
-
}
|
|
214
|
+
|
|
215
|
+
function triangulatePolygon(polygons, areas, indices, {
|
|
216
|
+
startPosition,
|
|
217
|
+
endPosition,
|
|
218
|
+
coordLength
|
|
219
|
+
}) {
|
|
220
|
+
const start = startPosition * coordLength;
|
|
221
|
+
const end = endPosition * coordLength;
|
|
222
|
+
const polygonPositions = polygons.positions.subarray(start, end);
|
|
223
|
+
const offset = indices[0];
|
|
224
|
+
const holes = indices.slice(1).map(n => (n - offset) / coordLength);
|
|
225
|
+
const triangles = earcut(polygonPositions, holes, coordLength, areas);
|
|
226
|
+
|
|
227
|
+
for (let t = 0, tl = triangles.length; t < tl; ++t) {
|
|
228
|
+
polygons.triangles.push(startPosition + triangles[t]);
|
|
229
|
+
}
|
|
277
230
|
}
|
|
278
|
-
|
|
279
|
-
* Wraps an object containing array into accessors
|
|
280
|
-
*
|
|
281
|
-
* @param obj
|
|
282
|
-
* @param size
|
|
283
|
-
*/
|
|
231
|
+
|
|
284
232
|
function wrapProps(obj, size) {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
233
|
+
const returnObj = {};
|
|
234
|
+
|
|
235
|
+
for (const key in obj) {
|
|
236
|
+
returnObj[key] = {
|
|
237
|
+
value: obj[key],
|
|
238
|
+
size
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return returnObj;
|
|
290
243
|
}
|
|
291
|
-
|
|
292
|
-
* Wrap each array in an accessor object with value and size keys
|
|
293
|
-
*
|
|
294
|
-
* @param points
|
|
295
|
-
* @param lines
|
|
296
|
-
* @param polygons
|
|
297
|
-
* @param coordLength
|
|
298
|
-
* @returns object
|
|
299
|
-
*/
|
|
244
|
+
|
|
300
245
|
function makeAccessorObjects(points, lines, polygons, coordLength) {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
246
|
+
return {
|
|
247
|
+
points: { ...points,
|
|
248
|
+
positions: {
|
|
249
|
+
value: points.positions,
|
|
250
|
+
size: coordLength
|
|
251
|
+
},
|
|
252
|
+
globalFeatureIds: {
|
|
253
|
+
value: points.globalFeatureIds,
|
|
254
|
+
size: 1
|
|
255
|
+
},
|
|
256
|
+
featureIds: {
|
|
257
|
+
value: points.featureIds,
|
|
258
|
+
size: 1
|
|
259
|
+
},
|
|
260
|
+
numericProps: wrapProps(points.numericProps, 1)
|
|
261
|
+
},
|
|
262
|
+
lines: { ...lines,
|
|
263
|
+
positions: {
|
|
264
|
+
value: lines.positions,
|
|
265
|
+
size: coordLength
|
|
266
|
+
},
|
|
267
|
+
pathIndices: {
|
|
268
|
+
value: lines.pathIndices,
|
|
269
|
+
size: 1
|
|
270
|
+
},
|
|
271
|
+
globalFeatureIds: {
|
|
272
|
+
value: lines.globalFeatureIds,
|
|
273
|
+
size: 1
|
|
274
|
+
},
|
|
275
|
+
featureIds: {
|
|
276
|
+
value: lines.featureIds,
|
|
277
|
+
size: 1
|
|
278
|
+
},
|
|
279
|
+
numericProps: wrapProps(lines.numericProps, 1)
|
|
280
|
+
},
|
|
281
|
+
polygons: { ...polygons,
|
|
282
|
+
positions: {
|
|
283
|
+
value: polygons.positions,
|
|
284
|
+
size: coordLength
|
|
285
|
+
},
|
|
286
|
+
polygonIndices: {
|
|
287
|
+
value: polygons.polygonIndices,
|
|
288
|
+
size: 1
|
|
289
|
+
},
|
|
290
|
+
primitivePolygonIndices: {
|
|
291
|
+
value: polygons.primitivePolygonIndices,
|
|
292
|
+
size: 1
|
|
293
|
+
},
|
|
294
|
+
triangles: {
|
|
295
|
+
value: new Uint32Array(polygons.triangles),
|
|
296
|
+
size: 1
|
|
297
|
+
},
|
|
298
|
+
globalFeatureIds: {
|
|
299
|
+
value: polygons.globalFeatureIds,
|
|
300
|
+
size: 1
|
|
301
|
+
},
|
|
302
|
+
featureIds: {
|
|
303
|
+
value: polygons.featureIds,
|
|
304
|
+
size: 1
|
|
305
|
+
},
|
|
306
|
+
numericProps: wrapProps(polygons.numericProps, 1)
|
|
307
|
+
}
|
|
308
|
+
};
|
|
328
309
|
}
|
|
329
|
-
|
|
330
|
-
* Add numeric properties to object
|
|
331
|
-
*
|
|
332
|
-
* @param object
|
|
333
|
-
* @param properties
|
|
334
|
-
* @param index
|
|
335
|
-
* @param length
|
|
336
|
-
*/
|
|
310
|
+
|
|
337
311
|
function fillNumericProperties(object, properties, index, length) {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
}
|
|
312
|
+
for (const numericPropName in object.numericProps) {
|
|
313
|
+
if (numericPropName in properties) {
|
|
314
|
+
const value = properties[numericPropName];
|
|
315
|
+
object.numericProps[numericPropName].fill(value, index, index + length);
|
|
343
316
|
}
|
|
317
|
+
}
|
|
344
318
|
}
|
|
345
|
-
|
|
346
|
-
* Keep string properties in object
|
|
347
|
-
*
|
|
348
|
-
* @param properties
|
|
349
|
-
* @param numericKeys
|
|
350
|
-
* @returns object
|
|
351
|
-
*/
|
|
319
|
+
|
|
352
320
|
function keepStringProperties(properties, numericKeys) {
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
321
|
+
const props = {};
|
|
322
|
+
|
|
323
|
+
for (const key in properties) {
|
|
324
|
+
if (!numericKeys.includes(key)) {
|
|
325
|
+
props[key] = properties[key];
|
|
358
326
|
}
|
|
359
|
-
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
return props;
|
|
360
330
|
}
|
|
361
|
-
|
|
362
|
-
*
|
|
363
|
-
* Deduce correct array constructor to use for a given value
|
|
364
|
-
*
|
|
365
|
-
* @param x value to test
|
|
366
|
-
* @param constructor previous constructor deduced
|
|
367
|
-
* @returns PropArrayConstructor
|
|
368
|
-
*/
|
|
331
|
+
|
|
369
332
|
function deduceArrayType(x, constructor) {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
333
|
+
if (constructor === Array || !Number.isFinite(x)) {
|
|
334
|
+
return Array;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
return constructor === Float64Array || Math.fround(x) !== x ? Float64Array : Float32Array;
|
|
375
338
|
}
|
|
339
|
+
//# sourceMappingURL=flat-geojson-to-binary.js.map
|