Skip to content

Commit

Permalink
add multilinestring support and release 0.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanwins committed Jul 26, 2022
1 parent da5aab9 commit b5e68d5
Show file tree
Hide file tree
Showing 8 changed files with 1,187 additions and 1,162 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v0.0.3
- Add support for MultiLinestring
- Rejigging bundling

# v0.0.2
- Fix up handling of 0 values in attributes

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ This was cobbled together fairly quickly based on the [minimal documentation](ht
- Inc MultiPolygon
- Inc Polygon with holes
- LineString
- Inc MultiLineString
- Point
- Attributes

### To Do
- MultiPoint (a sample service would be helpful)
- MultiLineString (a sample service would be helpful)
- Write proper tests


Expand Down
13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
{
"name": "arcgis-pbf-parser",
"version": "0.0.2",
"version": "0.0.3",
"description": "A library for parsing the arcgis pbf format into geojson",
"main": "dist/arcgis-pbf.js",
"module": "dist/arcgis-pbf.esm.js",
"main": "dist/arcgis-pbf.cjs",
"module": "dist/arcgis-pbf.mjs",
"browser": "dist/arcgis-pbf.min.js",
"type": "module",
"exports": {
".": {
"require": "./dist/arcgis-pbf.cjs",
"import": "./dist/arcgis-pbf.mjs"
}
},
"files": [
"dist"
],
Expand Down
11 changes: 4 additions & 7 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,19 @@ const output = (input, file, format, plugins) => ({
file,
format
},
external: ['pbf'],
plugins
})

export default [
output('./src/main.js', './dist/arcgis-pbf.js', 'umd', [
commonjs(),
resolve()
output('./src/main.js', './dist/arcgis-pbf.cjs', 'cjs', [
commonjs()
]),
output('./src/main.js', './dist/arcgis-pbf.min.js', 'umd', [
commonjs(),
resolve(),
terser()
]),
output('./src/main.js', './dist/arcgis-pbf.esm.js', 'esm', [
commonjs(),
resolve()
output('./src/main.js', './dist/arcgis-pbf.mjs', 'esm', [
commonjs()
])
]
27 changes: 22 additions & 5 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {FeatureCollectionPBuffer as EsriPbfBuffer} from './parser/PbfFeatureCollection'
import {FeatureCollectionPBuffer as EsriPbfBuffer} from './parser/PbfFeatureCollection.js'
import Pbf from 'pbf'

export default function decode(featureCollectionBuffer) {
Expand Down Expand Up @@ -72,11 +72,28 @@ function createPoint (f, transform) {
}

function createLine (f, transform) {
const p = {
type: 'LineString',
coordinates: createLinearRing(f.geometry.coords, transform, 0, f.geometry.lengths[0] * 2)
let l = null
const lengths = f.geometry.lengths.length

if (lengths === 1) {
l = {
type: 'LineString',
coordinates: createLinearRing(f.geometry.coords, transform, 0, f.geometry.lengths[0] * 2)
}
} else if (lengths > 1) {
l = {
type: 'MultiLineString',
coordinates: []
}
let startPoint = 0
for (let index = 0; index < lengths; index++) {
const stopPoint = startPoint + (f.geometry.lengths[index] * 2)
const line = createLinearRing(f.geometry.coords, transform, startPoint, stopPoint)
l.coordinates.push(line)
startPoint = stopPoint
}
}
return p
return l
}

function createPolygon (f, transform) {
Expand Down
Loading

0 comments on commit b5e68d5

Please sign in to comment.