Skip to content

Commit

Permalink
fix: PBF json (#945)
Browse files Browse the repository at this point in the history
* fix: pbf encoding
  • Loading branch information
rgwozdz authored Mar 6, 2024
1 parent cb8f7b9 commit cebed95
Show file tree
Hide file tree
Showing 20 changed files with 303 additions and 165 deletions.
5 changes: 5 additions & 0 deletions .changeset/wise-cooks-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@koopjs/featureserver": patch
---

- changes to JSON specification sent to PBF encoder
62 changes: 62 additions & 0 deletions demo/provider-data/points-id-string.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"type": "FeatureCollection",
"metadata": {
"idField": "id",
"fields": [
{ "name": "timestamp", "type": "Date" },
{ "name": "id", "type": "String" },
{ "name": "label", "type": "String" },
{ "name": "category", "type": "String" }
]
},
"features": [
{
"type": "Feature",
"properties": {
"id": "aaa",
"timestamp": "2023-04-10T16:15:30.000Z",
"label": "White Leg",
"category": "pinto"
},
"geometry": {
"type": "Point",
"coordinates": [
-80,
25
]
}
},
{
"type": "Feature",
"properties": {
"id": "bbb",
"timestamp": "2020-04-12T16:15:30.000Z",
"label": "Fireman",
"category": "pinto"
},
"geometry": {
"type": "Point",
"coordinates": [
-120,
45
]
}
},
{
"type": "Feature",
"properties": {
"id": "ccc",
"timestamp": "2015-04-11T16:15:30.000Z",
"label": "Workhorse",
"category": "draft"
},
"geometry": {
"type": "Point",
"coordinates": [
-100,
40
]
}
}
]
}
14 changes: 7 additions & 7 deletions packages/featureserver/coverage-unit.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions packages/featureserver/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 18 additions & 25 deletions packages/featureserver/src/helpers/feature-layer-metadata.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
const _ = require('lodash');
const TableLayerMetadata = require('./table-layer-metadata');
const {
PointRenderer,
LineRenderer,
PolygonRenderer
} = require('./renderers');
const { PointRenderer, LineRenderer, PolygonRenderer } = require('./renderers');
const { calculateBounds } = require('@terraformer/spatial');
const logManager = require('../log-manager');
const getSpatialReference = require('./get-spatial-reference');
Expand All @@ -13,22 +9,20 @@ const normalizeExtent = require('./normalize-extent');
const defaults = require('../metadata-defaults');

class FeatureLayerMetadata extends TableLayerMetadata {
static create (geojson, options) {
const {
geojson: normalizedGeojson,
options: normalizedOptions
} = FeatureLayerMetadata.normalizeInput(geojson, options);
static create(geojson, options) {
const { geojson: normalizedGeojson, options: normalizedOptions } =
FeatureLayerMetadata.normalizeInput(geojson, options);
const layerMetadata = new FeatureLayerMetadata();
return layerMetadata.mixinOverrides(normalizedGeojson, normalizedOptions);
}

constructor () {
constructor() {
super();
Object.assign(this, defaults.featureLayerDefaults());
return this;
}

mixinOverrides (geojson = {}, options = {}) {
mixinOverrides(geojson = {}, options = {}) {
super.mixinOverrides(geojson, options);

const { renderer, extent, inputCrs, sourceSR, capabilities = {} } = options;
Expand All @@ -46,14 +40,14 @@ class FeatureLayerMetadata extends TableLayerMetadata {
return this;
}

_setExtent (geojson, options) {
_setExtent(geojson, options) {
const extent = getLayerExtent(geojson, options);
if (extent) {
this.extent = extent;
}
}

_setRenderer (renderer) {
_setRenderer(renderer) {
if (renderer) {
this.drawingInfo.renderer = renderer;
return;
Expand All @@ -68,24 +62,21 @@ class FeatureLayerMetadata extends TableLayerMetadata {
}
}

_setDirectOverrides (options) {
_setDirectOverrides(options) {
super._setDirectOverrides(options);
const {
minScale,
maxScale
} = options;
const { minScale, maxScale } = options;

_.merge(this, {
minScale,
maxScale
maxScale,
});
}
}

function getLayerExtent (geojson, options) {
function getLayerExtent(geojson, options) {
const spatialReference = getSpatialReference(geojson, options) || {
wkid: 4326,
latestWkid: 4326
latestWkid: 4326,
};

const { extent } = options;
Expand All @@ -97,7 +88,7 @@ function getLayerExtent (geojson, options) {
return calculateExtentFromFeatures(geojson, spatialReference);
}

function calculateExtentFromFeatures (geojson, spatialReference) {
function calculateExtentFromFeatures(geojson, spatialReference) {
if (!geojson.features || geojson.features.length === 0) {
return;
}
Expand All @@ -110,10 +101,12 @@ function calculateExtentFromFeatures (geojson, spatialReference) {
xmax,
ymin,
ymax,
spatialReference
spatialReference,
};
} catch (error) {
logManager.logger.debug(`Could not calculate extent from data: ${error.message}`);
logManager.logger.debug(
`Could not calculate extent from data: ${error.message}`,
);
}
}

Expand Down
20 changes: 14 additions & 6 deletions packages/featureserver/src/helpers/feature-layer-metadata.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ describe('FeatureLayerMetadata', () => {

featureLayerMetadata.should.deepEqual({
currentVersion: CURRENT_VERSION,
supportedPbfFeatureEncodings: 'esriDefault',
id: 0,
name: 'Not Set',
type: 'Feature Layer',
Expand Down Expand Up @@ -180,6 +181,7 @@ describe('FeatureLayerMetadata', () => {

featureLayerMetadata.should.deepEqual({
currentVersion: CURRENT_VERSION,
supportedPbfFeatureEncodings: 'esriDefault',
id: 0,
name: 'Not Set',
type: 'Feature Layer',
Expand Down Expand Up @@ -299,7 +301,7 @@ describe('FeatureLayerMetadata', () => {
renderer: {
type: 'simple',
symbol: {
color: [45, 172, 128, 161],
color: [247, 150, 70, 161],
outline: {
color: [190, 190, 190, 105],
width: 0.5,
Expand Down Expand Up @@ -348,6 +350,7 @@ describe('FeatureLayerMetadata', () => {
);
featureLayerMetadata.should.deepEqual({
currentVersion: CURRENT_VERSION,
supportedPbfFeatureEncodings: 'esriDefault',
id: 0,
name: 'Not Set',
type: 'Feature Layer',
Expand Down Expand Up @@ -467,7 +470,7 @@ describe('FeatureLayerMetadata', () => {
renderer: {
type: 'simple',
symbol: {
color: [45, 172, 128, 161],
color: [247, 150, 70, 161],
outline: {
color: [190, 190, 190, 105],
width: 0.5,
Expand Down Expand Up @@ -508,6 +511,7 @@ describe('FeatureLayerMetadata', () => {

featureLayerMetadata.should.deepEqual({
currentVersion: CURRENT_VERSION,
supportedPbfFeatureEncodings: 'esriDefault',
id: 0,
name: 'Not Set',
type: 'Feature Layer',
Expand Down Expand Up @@ -627,7 +631,7 @@ describe('FeatureLayerMetadata', () => {
renderer: {
type: 'simple',
symbol: {
color: [45, 172, 128, 161],
color: [247, 150, 70, 161],
outline: {
color: [190, 190, 190, 105],
width: 0.5,
Expand Down Expand Up @@ -664,6 +668,7 @@ describe('FeatureLayerMetadata', () => {

featureLayerMetadata.should.deepEqual({
currentVersion: CURRENT_VERSION,
supportedPbfFeatureEncodings: 'esriDefault',
id: 0,
name: 'Not Set',
type: 'Feature Layer',
Expand Down Expand Up @@ -783,7 +788,7 @@ describe('FeatureLayerMetadata', () => {
renderer: {
type: 'simple',
symbol: {
color: [45, 172, 128, 161],
color: [247, 150, 70, 161],
outline: {
color: [190, 190, 190, 105],
width: 0.5,
Expand Down Expand Up @@ -826,6 +831,7 @@ describe('FeatureLayerMetadata', () => {

featureLayerMetadata.should.deepEqual({
currentVersion: CURRENT_VERSION,
supportedPbfFeatureEncodings: 'esriDefault',
id: 0,
name: 'Not Set',
type: 'Feature Layer',
Expand Down Expand Up @@ -967,6 +973,7 @@ describe('FeatureLayerMetadata', () => {

featureLayerMetadata.should.deepEqual({
currentVersion: CURRENT_VERSION,
supportedPbfFeatureEncodings: 'esriDefault',
id: 0,
name: 'Not Set',
type: 'Feature Layer',
Expand Down Expand Up @@ -1086,7 +1093,7 @@ describe('FeatureLayerMetadata', () => {
renderer: {
type: 'simple',
symbol: {
color: [45, 172, 128, 161],
color: [247, 150, 70, 161],
outline: {
color: [190, 190, 190, 105],
width: 0.5,
Expand Down Expand Up @@ -1134,6 +1141,7 @@ describe('FeatureLayerMetadata', () => {

featureLayerMetadata.should.deepEqual({
currentVersion: CURRENT_VERSION,
supportedPbfFeatureEncodings: 'esriDefault',
id: 99,
name: 'Not Set',
type: 'Feature Layer',
Expand Down Expand Up @@ -1253,7 +1261,7 @@ describe('FeatureLayerMetadata', () => {
renderer: {
type: 'simple',
symbol: {
color: [45, 172, 128, 161],
color: [247, 150, 70, 161],
outline: {
color: [190, 190, 190, 105],
width: 0.5,
Expand Down
6 changes: 3 additions & 3 deletions packages/featureserver/src/helpers/renderers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ class PointRenderer {
type: 'simple',
symbol: {
color: [
45,
172,
128,
247,
150,
70,
161
],
outline: {
Expand Down
6 changes: 3 additions & 3 deletions packages/featureserver/src/helpers/renderers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ describe('Renderers', () => {
type: 'simple',
symbol: {
color: [
45,
172,
128,
247,
150,
70,
161
],
outline: {
Expand Down
Loading

0 comments on commit cebed95

Please sign in to comment.