Skip to content

Commit

Permalink
feat: add interpolate function (#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
jansule authored Nov 29, 2024
1 parent 18e9fd5 commit 6567d8b
Show file tree
Hide file tree
Showing 9 changed files with 265 additions and 70 deletions.
8 changes: 4 additions & 4 deletions data/mapbox/color_rgba.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { MbStyle } from '../../src/MapboxStyleParser';

const circleSimpleCircle: MbStyle = {
const colorRgba: MbStyle = {
version: 8,
name: 'Simple Circle',
name: 'Color RGBA',
sources: {
testsource: {
type: 'vector'
}
},
layers: [
{
id: 'Simple Circle',
id: 'Color RGBA',
source: 'testsource',
'source-layer': 'foo',
type: 'circle',
Expand All @@ -27,4 +27,4 @@ const circleSimpleCircle: MbStyle = {
]
};

export default circleSimpleCircle;
export default colorRgba;
37 changes: 37 additions & 0 deletions data/mapbox/expression_interpolate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { MbStyle } from '../../src/MapboxStyleParser';

const expressionInterpolate: MbStyle = {
version: 8,
name: 'Expression Interpolate',
sources: {
testsource: {
type: 'vector'
}
},
layers: [
{
id: 'earthquake_circle',
type: 'circle',
source: 'testsource',
'source-layer': 'foo',
paint: {
'circle-color': '#000000',
'circle-opacity': 0.6,
'circle-radius': [
'interpolate',
['linear'],
['get', 'population'],
12,
2,
15,
4,
19,
35
]
}
}
]
};

export default expressionInterpolate;
49 changes: 49 additions & 0 deletions data/mapbox_metadata/expression_interpolate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { MbStyle } from '../../src/MapboxStyleParser';

const expression_case: MbStyle = {
version: 8,
name: 'Expression Interpolate',
sources: {
testsource: {
type: 'vector'
}
},
layers: [
{
id: 'r0_sy0_st0',
source: 'testsource',
'source-layer': 'foo',
type: 'circle',
paint: {
'circle-color': '#000000',
'circle-opacity': 0.6,
'circle-radius': [
'interpolate',
['linear'],
['get', 'population'],
12,
2,
15,
4,
19,
35
]
}
}
],
metadata: {
'geostyler:ref': {
rules: [{
name: 'earthquake_circle',
symbolizers: [
[
'r0_sy0_st0'
]
]
}]
}
}
};

export default expression_case;
30 changes: 15 additions & 15 deletions data/styles/color_rgba.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { Style } from 'geostyler-style';

const circleSimpleCircle: Style = {
name: 'Simple Circle',
const colorRgba: Style = {
name: 'Color RGBA',
rules: [{
name: 'Simple Circle',
name: 'Color RGBA',
symbolizers: [{
kind: 'Mark',
wellKnownName: 'circle',
color: '#000000',
strokeColor: {
name: 'case',
args: [{
case: {
name: 'lessThan',
args: [{
name: 'property',
args: ['mag']
}, 2]
},
value: '#ff0000'
},
'#00ff00'
args: [
'#00ff00', {
case: {
name: 'lessThan',
args: [{
name: 'property',
args: ['mag']
}, 2]
},
value: '#ff0000'
}
]
}
}]
Expand All @@ -42,4 +42,4 @@ const circleSimpleCircle: Style = {
}
};

export default circleSimpleCircle;
export default colorRgba;
5 changes: 2 additions & 3 deletions data/styles/gs_expression_case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const gs_expression_case: Style = {
wellKnownName: 'circle',
color: {
name: 'case',
args: [{
args: ['#e31a1c', {
case: {
name: 'lessThan',
args: [{
Expand Down Expand Up @@ -80,8 +80,7 @@ const gs_expression_case: Style = {
}]
},
value:'#fc4e2a'
},
'#e31a1c']
}]
},
radius: 12,
fillOpacity: 0.6
Expand Down
36 changes: 18 additions & 18 deletions data/styles/gs_expression_decisions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const gs_expression_decisions: Style = {
color: {
name: 'case',
args: [
'#000000',
{
case: {
name: 'not',
Expand All @@ -23,8 +24,7 @@ const gs_expression_decisions: Style = {
}]
},
value: '#FFFFFF'
},
'#000000'
}
]
}
}]
Expand All @@ -36,6 +36,7 @@ const gs_expression_decisions: Style = {
color: {
name: 'case',
args: [
'#000000',
{
case: {
name: 'notEqualTo',
Expand All @@ -45,8 +46,7 @@ const gs_expression_decisions: Style = {
}, 1]
},
value: '#FFFFFF'
},
'#000000'
}
]
}
}]
Expand All @@ -58,6 +58,7 @@ const gs_expression_decisions: Style = {
color: {
name: 'case',
args: [
'#000000',
{
case: {
name: 'lessThan',
Expand All @@ -67,8 +68,7 @@ const gs_expression_decisions: Style = {
}, 1]
},
value: '#FFFFFF'
},
'#000000'
}
]
}
}]
Expand All @@ -80,6 +80,7 @@ const gs_expression_decisions: Style = {
color: {
name: 'case',
args: [
'#000000',
{
case: {
name: 'lessThanOrEqualTo',
Expand All @@ -89,8 +90,7 @@ const gs_expression_decisions: Style = {
}, 1]
},
value: '#FFFFFF'
},
'#000000'
}
]
}
}]
Expand All @@ -102,6 +102,7 @@ const gs_expression_decisions: Style = {
color: {
name: 'case',
args: [
'#000000',
{
case: {
name: 'equalTo',
Expand All @@ -111,8 +112,7 @@ const gs_expression_decisions: Style = {
}, 1]
},
value: '#FFFFFF'
},
'#000000'
}
]
}
}]
Expand All @@ -124,6 +124,7 @@ const gs_expression_decisions: Style = {
color: {
name: 'case',
args: [
'#000000',
{
case: {
name: 'greaterThan',
Expand All @@ -133,8 +134,7 @@ const gs_expression_decisions: Style = {
}, 1]
},
value: '#FFFFFF'
},
'#000000'
}
]
}
}]
Expand All @@ -146,6 +146,7 @@ const gs_expression_decisions: Style = {
color: {
name: 'case',
args: [
'#000000',
{
case: {
name: 'greaterThanOrEqualTo',
Expand All @@ -155,8 +156,7 @@ const gs_expression_decisions: Style = {
}, 1]
},
value: '#FFFFFF'
},
'#000000'
}
]
}
}]
Expand All @@ -168,6 +168,7 @@ const gs_expression_decisions: Style = {
color: {
name: 'case',
args: [
'#000000',
{
case: {
name: 'all',
Expand All @@ -189,8 +190,7 @@ const gs_expression_decisions: Style = {
]
},
value: '#FFFFFF'
},
'#000000'
}
]
}
}]
Expand All @@ -202,6 +202,7 @@ const gs_expression_decisions: Style = {
color: {
name: 'case',
args: [
'#000000',
{
case: {
name: 'any',
Expand All @@ -223,8 +224,7 @@ const gs_expression_decisions: Style = {
]
},
value: '#FFFFFF'
},
'#000000'
}
]
}
}]
Expand Down
50 changes: 50 additions & 0 deletions data/styles/gs_expression_interpolate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { Style } from 'geostyler-style';

const gsExpressionInterpolate: Style = {
name: 'Expression Interpolate',
rules: [{
name: 'earthquake_circle',
symbolizers: [{
kind: 'Mark',
wellKnownName: 'circle',
color: '#000000',
fillOpacity: 0.6,
radius: {
name: 'interpolate',
args: [{
name: 'linear'
}, {
name: 'property',
args: ['population']
}, {
stop: 12,
value: 2
}, {
stop: 15,
value: 4
}, {
stop: 19,
value: 35
}]
}
}]
}],
metadata: {
'mapbox:ref': {
sources: {
testsource: {
type: 'vector'
}
},
sourceMapping: {
testsource: [0]
},
sourceLayerMapping: {
foo: [0]
}
}
}
};

export default gsExpressionInterpolate;
Loading

0 comments on commit 6567d8b

Please sign in to comment.