Skip to content

Commit b5e68d5

Browse files
committed
add multilinestring support and release 0.0.3
1 parent da5aab9 commit b5e68d5

File tree

8 files changed

+1187
-1162
lines changed

8 files changed

+1187
-1162
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# v0.0.3
2+
- Add support for MultiLinestring
3+
- Rejigging bundling
4+
15
# v0.0.2
26
- Fix up handling of 0 values in attributes
37

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ This was cobbled together fairly quickly based on the [minimal documentation](ht
3838
- Inc MultiPolygon
3939
- Inc Polygon with holes
4040
- LineString
41+
- Inc MultiLineString
4142
- Point
4243
- Attributes
4344

4445
### To Do
4546
- MultiPoint (a sample service would be helpful)
46-
- MultiLineString (a sample service would be helpful)
4747
- Write proper tests
4848

4949

package.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
{
22
"name": "arcgis-pbf-parser",
3-
"version": "0.0.2",
3+
"version": "0.0.3",
44
"description": "A library for parsing the arcgis pbf format into geojson",
5-
"main": "dist/arcgis-pbf.js",
6-
"module": "dist/arcgis-pbf.esm.js",
5+
"main": "dist/arcgis-pbf.cjs",
6+
"module": "dist/arcgis-pbf.mjs",
77
"browser": "dist/arcgis-pbf.min.js",
8+
"type": "module",
9+
"exports": {
10+
".": {
11+
"require": "./dist/arcgis-pbf.cjs",
12+
"import": "./dist/arcgis-pbf.mjs"
13+
}
14+
},
815
"files": [
916
"dist"
1017
],

rollup.config.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,19 @@ const output = (input, file, format, plugins) => ({
99
file,
1010
format
1111
},
12-
external: ['pbf'],
1312
plugins
1413
})
1514

1615
export default [
17-
output('./src/main.js', './dist/arcgis-pbf.js', 'umd', [
18-
commonjs(),
19-
resolve()
16+
output('./src/main.js', './dist/arcgis-pbf.cjs', 'cjs', [
17+
commonjs()
2018
]),
2119
output('./src/main.js', './dist/arcgis-pbf.min.js', 'umd', [
2220
commonjs(),
2321
resolve(),
2422
terser()
2523
]),
26-
output('./src/main.js', './dist/arcgis-pbf.esm.js', 'esm', [
27-
commonjs(),
28-
resolve()
24+
output('./src/main.js', './dist/arcgis-pbf.mjs', 'esm', [
25+
commonjs()
2926
])
3027
]

src/main.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {FeatureCollectionPBuffer as EsriPbfBuffer} from './parser/PbfFeatureCollection'
1+
import {FeatureCollectionPBuffer as EsriPbfBuffer} from './parser/PbfFeatureCollection.js'
22
import Pbf from 'pbf'
33

44
export default function decode(featureCollectionBuffer) {
@@ -72,11 +72,28 @@ function createPoint (f, transform) {
7272
}
7373

7474
function createLine (f, transform) {
75-
const p = {
76-
type: 'LineString',
77-
coordinates: createLinearRing(f.geometry.coords, transform, 0, f.geometry.lengths[0] * 2)
75+
let l = null
76+
const lengths = f.geometry.lengths.length
77+
78+
if (lengths === 1) {
79+
l = {
80+
type: 'LineString',
81+
coordinates: createLinearRing(f.geometry.coords, transform, 0, f.geometry.lengths[0] * 2)
82+
}
83+
} else if (lengths > 1) {
84+
l = {
85+
type: 'MultiLineString',
86+
coordinates: []
87+
}
88+
let startPoint = 0
89+
for (let index = 0; index < lengths; index++) {
90+
const stopPoint = startPoint + (f.geometry.lengths[index] * 2)
91+
const line = createLinearRing(f.geometry.coords, transform, startPoint, stopPoint)
92+
l.coordinates.push(line)
93+
startPoint = stopPoint
94+
}
7895
}
79-
return p
96+
return l
8097
}
8198

8299
function createPolygon (f, transform) {

0 commit comments

Comments
 (0)