diff --git a/README.md b/README.md index a46b9a6..5f99be2 100644 --- a/README.md +++ b/README.md @@ -12,54 +12,12 @@ The endpoint MUST return a reference to a single image. --- -Mapbox Styles require the properties [`sources`](https://docs.mapbox.com/mapbox-gl-js/style-spec/#root-sources) (root property) and [`source`](https://docs.mapbox.com/mapbox-gl-js/style-spec/#layer-source) (layers property). geostyler-mapbox-parser only parses style related properties to keep a clear separation between style and data. Thus, `sources` and `source` have to be added to the created styleobject after parsing, manually. See code snippet below for an example implementation of a wrapper function. - -```javascript -/** - * Example wrapper function that maps a source to the corresponding - * layer based on layer id. Expects a mapper object with key value - * pairs in the format of "layerId:'sourceName'". -**/ -function wrapper(sources, mapper, style) { - if (typeof style === 'undefined') { - return; - } - if (typeof mapper === 'undefined') { - return style; - } - if (typeof sources === 'undefined') { - return style; - } - - style.sources = sources; - style.layers.forEach(l => { - l.source = mapper[l.id]; - }); - return style; -} - -// required mapper object where the key refers to the layer id -// and the value to the source name. -var mapper = { - "water": "mapbox-streets" -}; - -// mapbox sources object -var sources = { - "mapbox-streets": { - "type": "vector", - "url": "mapbox://mapbox.mapbox-streets-v6" - } -}; - -// mapbox style object -var mbStyle = { - version: 8, - layers: [...] -}; - -var wrappedStyle = wrapper(sources, mapper, style); -``` +Mapbox styles require the properties [`sources`](https://docs.mapbox.com/mapbox-gl-js/style-spec/#root-sources) (root property) +and [`source`](https://docs.mapbox.com/mapbox-gl-js/style-spec/#layer-source) (layers property). +In order to keep a clear separation between style and data, geostyler-mapbox-parser puts the source-related attributes into the metadata block of +a geostyler-style under `mapbox:ref`. There, the original sources object, as well as the mappings between layers and sources will be stored +(properties `sources`, `sourceMapping` and `layerSourceMapping`). Applications can then use these mappings for re-creating the same layer structure +using their map library of choice (e.g. OpenLayers, etc.). ### How to use diff --git a/data/mapbox/circle_simplecircle.ts b/data/mapbox/circle_simplecircle.ts index 3370bb5..55e8c03 100644 --- a/data/mapbox/circle_simplecircle.ts +++ b/data/mapbox/circle_simplecircle.ts @@ -1,11 +1,18 @@ import { MbStyle } from '../../src/MapboxStyleParser'; -const circleSimpleCircle: Omit = { +const circleSimpleCircle: MbStyle = { version: 8, name: 'Simple Circle', + sources: { + testsource: { + type: 'vector' + } + }, layers: [ { id: 'Simple Circle', + source: 'testsource', + 'source-layer': 'foo', type: 'circle', paint: { 'circle-color': '#000000', diff --git a/data/mapbox/expression_case.ts b/data/mapbox/expression_case.ts index a35bf26..b839d97 100644 --- a/data/mapbox/expression_case.ts +++ b/data/mapbox/expression_case.ts @@ -1,13 +1,20 @@ /* eslint-disable @typescript-eslint/naming-convention */ import { MbStyle } from '../../src/MapboxStyleParser'; -const expression_case: Omit = { +const expression_case: MbStyle = { version: 8, name: 'Expression Case', + sources: { + testsource: { + type: 'vector' + } + }, layers: [ { id: 'earthquake_circle', type: 'circle', + source: 'testsource', + 'source-layer': 'foo', paint: { 'circle-color': [ 'case', diff --git a/data/mapbox/expression_get.ts b/data/mapbox/expression_get.ts index 8373c92..8d1dcf0 100644 --- a/data/mapbox/expression_get.ts +++ b/data/mapbox/expression_get.ts @@ -1,12 +1,19 @@ /* eslint-disable @typescript-eslint/naming-convention */ import { MbStyle } from '../../src/MapboxStyleParser'; -const expression_get: Omit = { +const expression_get: MbStyle = { version: 8, name: 'Expression Get', + sources: { + testsource: { + type: 'vector' + } + }, layers: [ { id: 'Expression Get', + source: 'testsource', + 'source-layer': 'foo', type: 'circle', paint: { 'circle-color': '#000000', diff --git a/data/mapbox/fill_patternfill.ts b/data/mapbox/fill_patternfill.ts index 807c05a..9dd9bef 100644 --- a/data/mapbox/fill_patternfill.ts +++ b/data/mapbox/fill_patternfill.ts @@ -1,12 +1,19 @@ import { MbStyle } from '../../src/MapboxStyleParser'; -const fillSimpleFill: Omit = { +const fillSimpleFill: MbStyle = { version: 8, name: 'Pattern Fill', sprite: 'https://testurl.com', + sources: { + testsource: { + type: 'vector' + } + }, layers: [ { id: 'Pattern Fill', + source: 'testsource', + 'source-layer': 'foo', type: 'fill', paint: { 'fill-color': '#000000', diff --git a/data/mapbox/fill_simple_outline.ts b/data/mapbox/fill_simple_outline.ts index e2818f7..b44c1c0 100644 --- a/data/mapbox/fill_simple_outline.ts +++ b/data/mapbox/fill_simple_outline.ts @@ -1,11 +1,18 @@ import { MbStyle } from '../../src/MapboxStyleParser'; -const fillSimpleFillOutline: Omit = { +const fillSimpleFillOutline: MbStyle = { version: 8, name: 'Simple Fill With outline', + sources: { + testsource: { + type: 'vector' + } + }, layers: [{ id: 'r0_sy0_st0', type: 'fill', + source: 'testsource', + 'source-layer': 'foo', paint: { 'fill-color': '#ff0000' } @@ -13,6 +20,8 @@ const fillSimpleFillOutline: Omit = { { id: 'r0_sy0_st1', type: 'line', + source: 'testsource', + 'source-layer': 'foo', paint: { 'line-opacity': 0.5, 'line-color': '#00ff00', diff --git a/data/mapbox/fill_simplefill.ts b/data/mapbox/fill_simplefill.ts index 6f7a2e0..1fc0af8 100644 --- a/data/mapbox/fill_simplefill.ts +++ b/data/mapbox/fill_simplefill.ts @@ -1,12 +1,19 @@ import { MbStyle } from '../../src/MapboxStyleParser'; -const fillSimpleFill: Omit = { +const fillSimpleFill: MbStyle = { version: 8, name: 'Simple Fill', + sources: { + testsource: { + type: 'vector' + } + }, layers: [ { id: 'Simple Fill', type: 'fill', + source: 'testsource', + 'source-layer': 'foo', paint: { 'fill-color': '#000000', 'fill-opacity': 1 diff --git a/data/mapbox/icon_simpleicon.ts b/data/mapbox/icon_simpleicon.ts index 6d9759d..41463ca 100644 --- a/data/mapbox/icon_simpleicon.ts +++ b/data/mapbox/icon_simpleicon.ts @@ -1,13 +1,20 @@ import { MbStyle } from '../../src/MapboxStyleParser'; -const iconSimpleIcon: Omit = { +const iconSimpleIcon: MbStyle = { version: 8, name: 'Simple Icon', sprite: 'https://testurl.com', + sources: { + testsource: { + type: 'vector' + } + }, layers: [ { id: 'Simple Icon', type: 'symbol', + source: 'testsource', + 'source-layer': 'foo', layout: { 'icon-image': 'poi' } diff --git a/data/mapbox/icon_simpleicon_mapboxapi.ts b/data/mapbox/icon_simpleicon_mapboxapi.ts index d1e8f0c..967ae5b 100644 --- a/data/mapbox/icon_simpleicon_mapboxapi.ts +++ b/data/mapbox/icon_simpleicon_mapboxapi.ts @@ -1,12 +1,19 @@ import { MbStyle } from '../../src/MapboxStyleParser'; -const iconSimpleIcon: Omit = { +const iconSimpleIcon: MbStyle = { version: 8, name: 'Simple Icon', sprite: 'mapbox://sprites/mapbox/streets-v8', + sources: { + testsource: { + type: 'vector' + } + }, layers: [ { id: 'Simple Icon', + source: 'testsource', + 'source-layer': 'foo', type: 'symbol', layout: { 'icon-image': 'poi' diff --git a/data/mapbox/icontext_symbolizer.ts b/data/mapbox/icontext_symbolizer.ts index 4ff3423..539ec73 100644 --- a/data/mapbox/icontext_symbolizer.ts +++ b/data/mapbox/icontext_symbolizer.ts @@ -1,12 +1,19 @@ import { MbStyle } from '../../src/MapboxStyleParser'; -const iconTextSymbolizer: Omit = { +const iconTextSymbolizer: MbStyle = { version: 8, name: 'icontext symbolizer', sprite: 'https://testurl.com', + sources: { + testsource: { + type: 'vector' + } + }, layers: [ { type: 'symbol', + source: 'testsource', + 'source-layer': 'foo', paint: { 'text-color': 'rgba(45, 45, 45, 1)', }, diff --git a/data/mapbox/line_patternline.ts b/data/mapbox/line_patternline.ts index a193b81..65ecc69 100644 --- a/data/mapbox/line_patternline.ts +++ b/data/mapbox/line_patternline.ts @@ -1,13 +1,20 @@ import { MbStyle } from '../../src/MapboxStyleParser'; -const linePatternLine: Omit = { +const linePatternLine: MbStyle = { version: 8, name: 'Pattern Line', sprite: 'https://testurl.com', + sources: { + testsource: { + type: 'vector' + } + }, layers: [ { id: 'Pattern Line', type: 'line', + source: 'testsource', + 'source-layer': 'foo', paint: { 'line-color': '#000000', 'line-width': 3, diff --git a/data/mapbox/line_simpleline.ts b/data/mapbox/line_simpleline.ts index 29c6d7b..4f89b58 100644 --- a/data/mapbox/line_simpleline.ts +++ b/data/mapbox/line_simpleline.ts @@ -1,11 +1,18 @@ import { MbStyle } from '../../src/MapboxStyleParser'; -const lineSimpleLine: Omit = { +const lineSimpleLine: MbStyle = { version: 8, name: 'Simple Line', + sources: { + testsource: { + type: 'vector' + } + }, layers: [ { id: 'Simple Line', + source: 'testsource', + 'source-layer': 'foo', type: 'line', paint: { 'line-color': '#000000', diff --git a/data/mapbox/line_simpleline_basefilter.ts b/data/mapbox/line_simpleline_basefilter.ts index 69f9c64..f3f3eef 100644 --- a/data/mapbox/line_simpleline_basefilter.ts +++ b/data/mapbox/line_simpleline_basefilter.ts @@ -1,10 +1,17 @@ import { MbStyle } from '../../src/MapboxStyleParser'; -const lineSimpleLine: Omit = { +const lineSimpleLine: MbStyle = { version: 8, name: 'Small populated New Yorks', + sources: { + testsource: { + type: 'vector' + } + }, layers: [{ id: 'Small populated New Yorks', + source: 'testsource', + 'source-layer': 'foo', type: 'line', filter: ['all', ['==', 'NAME', 'New York'], diff --git a/data/mapbox/line_simpleline_expression.ts b/data/mapbox/line_simpleline_expression.ts index 9717aad..8393719 100644 --- a/data/mapbox/line_simpleline_expression.ts +++ b/data/mapbox/line_simpleline_expression.ts @@ -1,10 +1,17 @@ import { MbStyle } from '../../src/MapboxStyleParser'; -const lineSimpleLine: Omit = { +const lineSimpleLine: MbStyle = { version: 8, name: 'Simple Line Filter', + sources: { + testsource: { + type: 'vector' + } + }, layers: [{ id: 'Small populated New Yorks', + source: 'testsource', + 'source-layer': 'foo', type: 'line', paint: { 'line-color': '#FF0000', diff --git a/data/mapbox/line_simpleline_zoom.ts b/data/mapbox/line_simpleline_zoom.ts index 8d42289..45a63e3 100644 --- a/data/mapbox/line_simpleline_zoom.ts +++ b/data/mapbox/line_simpleline_zoom.ts @@ -1,10 +1,17 @@ import { MbStyle } from '../../src/MapboxStyleParser'; -const lineSimpleLine: Omit = { +const lineSimpleLine: MbStyle = { version: 8, name: 'Simple Line Filter', + sources: { + testsource: { + type: 'vector' + } + }, layers: [{ id: 'Small populated New Yorks', + source: 'testsource', + 'source-layer': 'foo', type: 'line', minzoom: 5.5, maxzoom: 10, diff --git a/data/mapbox/multi_rule_line_fill.ts b/data/mapbox/multi_rule_line_fill.ts index dbfd1a1..cd86b28 100644 --- a/data/mapbox/multi_rule_line_fill.ts +++ b/data/mapbox/multi_rule_line_fill.ts @@ -1,12 +1,19 @@ import { MbStyle } from '../../src/MapboxStyleParser'; -const multiRuleLineFill: Omit = { +const multiRuleLineFill: MbStyle = { version: 8, name: 'Rule Line Fill', + sources: { + testsource: { + type: 'vector' + } + }, layers: [ { id: 'Line Rule', type: 'line', + source: 'testsource', + 'source-layer': 'foo', paint: { 'line-color': '#000000', 'line-width': 3, @@ -19,6 +26,8 @@ const multiRuleLineFill: Omit = { }, { id: 'Fill Rule', type: 'fill', + source: 'testsource', + 'source-layer': 'foo', paint: { 'fill-color': '#000000', 'fill-opacity': 1 diff --git a/data/mapbox/multi_simpleline_simplefill.ts b/data/mapbox/multi_simpleline_simplefill.ts index 5da5a90..d489bc3 100644 --- a/data/mapbox/multi_simpleline_simplefill.ts +++ b/data/mapbox/multi_simpleline_simplefill.ts @@ -1,11 +1,18 @@ import { MbStyle } from '../../src/MapboxStyleParser'; -const multiSimpleLineSimpleFill: Omit = { +const multiSimpleLineSimpleFill: MbStyle = { version: 8, name: 'Simple Line Simple Fill', + sources: { + testsource: { + type: 'vector' + } + }, layers: [ { id: 'Simple Line Simple Fill', + source: 'testsource', + 'source-layer': 'foo', type: 'line', paint: { 'line-color': '#000000', @@ -18,6 +25,8 @@ const multiSimpleLineSimpleFill: Omit = { } }, { id: 'Simple Line Simple Fill', + source: 'testsource', + 'source-layer': 'foo', type: 'fill', paint: { 'fill-color': '#000000', diff --git a/data/mapbox/point_placeholderText.ts b/data/mapbox/point_placeholderText.ts index e59f9d7..e8e0f4b 100644 --- a/data/mapbox/point_placeholderText.ts +++ b/data/mapbox/point_placeholderText.ts @@ -1,12 +1,19 @@ import { MbStyle } from '../../src/MapboxStyleParser'; -const pointPlaceholderText: Omit = { +const pointPlaceholderText: MbStyle = { version: 8, name: 'Placeholder Text', + sources: { + testsource: { + type: 'vector' + } + }, layers: [ { id: 'Placeholder Text', type: 'symbol', + source: 'testsource', + 'source-layer': 'foo', layout: { 'text-field': ['format', 'Area: ', {}, diff --git a/data/mapbox/point_placeholderText_simple.ts b/data/mapbox/point_placeholderText_simple.ts index fdbc21a..d5345ce 100644 --- a/data/mapbox/point_placeholderText_simple.ts +++ b/data/mapbox/point_placeholderText_simple.ts @@ -1,11 +1,18 @@ import { MbStyle } from '../../src/MapboxStyleParser'; -const pointPlaceholderText: Omit = { +const pointPlaceholderText: MbStyle = { version: 8, name: 'Placeholder Text', + sources: { + testsource: { + type: 'vector' + } + }, layers: [ { id: 'Placeholder Text', + source: 'testsource', + 'source-layer': 'foo', type: 'symbol', layout: { 'text-field': '{River}' diff --git a/data/mapbox/point_simpletext.ts b/data/mapbox/point_simpletext.ts index 7aff41e..b22a277 100644 --- a/data/mapbox/point_simpletext.ts +++ b/data/mapbox/point_simpletext.ts @@ -1,12 +1,19 @@ import { MbStyle } from '../../src/MapboxStyleParser'; -const pointSimpleText: Omit = { +const pointSimpleText: MbStyle = { version: 8, name: 'Simple Text', + sources: { + testsource: { + type: 'vector' + } + }, layers: [ { id: 'Simple Text', type: 'symbol', + source: 'testsource', + 'source-layer': 'foo', layout: { 'text-field': 'River' }, diff --git a/data/mapbox/source_layer_mapping.ts b/data/mapbox/source_layer_mapping.ts new file mode 100644 index 0000000..9989d3c --- /dev/null +++ b/data/mapbox/source_layer_mapping.ts @@ -0,0 +1,43 @@ +import { MbStyle } from '../../src/MapboxStyleParser'; + +const sourceLayerMapping: MbStyle = { + version: 8, + name: 'SourceLayerMapping', + sources: { + first: { + type: 'vector' + } + }, + layers: [ + { + id: 'Simple Circle 1', + source: 'first', + 'source-layer': 'foo', + type: 'circle', + paint: { + 'circle-color': '#000000', + 'circle-radius': 5, + 'circle-opacity': 1, + 'circle-stroke-width': 2, + 'circle-stroke-color': '#FF0000', + 'circle-stroke-opacity': 0.5 + } + }, + { + id: 'Simple Circle 2', + source: 'first', + 'source-layer': 'bar', + type: 'circle', + paint: { + 'circle-color': '#000000', + 'circle-radius': 5, + 'circle-opacity': 1, + 'circle-stroke-width': 2, + 'circle-stroke-color': '#FF0000', + 'circle-stroke-opacity': 0.5 + } + } + ] +}; + +export default sourceLayerMapping; diff --git a/data/mapbox/source_mapping.ts b/data/mapbox/source_mapping.ts new file mode 100644 index 0000000..0beacc4 --- /dev/null +++ b/data/mapbox/source_mapping.ts @@ -0,0 +1,46 @@ +import { MbStyle } from '../../src/MapboxStyleParser'; + +const sourceMapping: MbStyle = { + version: 8, + name: 'SourceMapping', + sources: { + first: { + type: 'vector' + }, + second: { + type: 'vector' + } + }, + layers: [ + { + id: 'Simple Circle 1', + source: 'first', + 'source-layer': 'foo', + type: 'circle', + paint: { + 'circle-color': '#000000', + 'circle-radius': 5, + 'circle-opacity': 1, + 'circle-stroke-width': 2, + 'circle-stroke-color': '#FF0000', + 'circle-stroke-opacity': 0.5 + } + }, + { + id: 'Simple Circle 2', + source: 'second', + 'source-layer': 'foo', + type: 'circle', + paint: { + 'circle-color': '#000000', + 'circle-radius': 5, + 'circle-opacity': 1, + 'circle-stroke-width': 2, + 'circle-stroke-color': '#FF0000', + 'circle-stroke-opacity': 0.5 + } + } + ] +}; + +export default sourceMapping; diff --git a/data/mapbox_metadata/circle_simplecircle.ts b/data/mapbox_metadata/circle_simplecircle.ts index e84ce33..4978304 100644 --- a/data/mapbox_metadata/circle_simplecircle.ts +++ b/data/mapbox_metadata/circle_simplecircle.ts @@ -1,11 +1,18 @@ import { MbStyle } from '../../src/MapboxStyleParser'; -const circleSimpleCircle: Omit = { +const circleSimpleCircle: MbStyle = { version: 8, name: 'Simple Circle', + sources: { + testsource: { + type: 'vector' + } + }, layers: [ { id: 'r0_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'circle', paint: { 'circle-color': '#000000', diff --git a/data/mapbox_metadata/expression_case.ts b/data/mapbox_metadata/expression_case.ts index de9c076..eab7ddb 100644 --- a/data/mapbox_metadata/expression_case.ts +++ b/data/mapbox_metadata/expression_case.ts @@ -1,12 +1,19 @@ /* eslint-disable @typescript-eslint/naming-convention */ import { MbStyle } from '../../src/MapboxStyleParser'; -const expression_case: Omit = { +const expression_case: MbStyle = { version: 8, name: 'Expression Case', + sources: { + testsource: { + type: 'vector' + } + }, layers: [ { id: 'r0_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'circle', paint: { 'circle-color': [ diff --git a/data/mapbox_metadata/expression_decisions.ts b/data/mapbox_metadata/expression_decisions.ts index 94389ed..80a9543 100644 --- a/data/mapbox_metadata/expression_decisions.ts +++ b/data/mapbox_metadata/expression_decisions.ts @@ -1,12 +1,19 @@ /* eslint-disable @typescript-eslint/naming-convention */ import { MbStyle } from '../../src/MapboxStyleParser'; -const expression_decisions: Omit = { +const expression_decisions: MbStyle = { version: 8, name: 'Expression Decisions', + sources: { + testsource: { + type: 'vector' + } + }, layers: [ { id: 'r0_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'circle', paint: { 'circle-color': [ @@ -19,6 +26,8 @@ const expression_decisions: Omit = { }, { id: 'r1_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'circle', paint: { 'circle-color': [ @@ -31,6 +40,8 @@ const expression_decisions: Omit = { }, { id: 'r2_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'circle', paint: { 'circle-color': [ @@ -43,6 +54,8 @@ const expression_decisions: Omit = { }, { id: 'r3_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'circle', paint: { 'circle-color': [ @@ -55,6 +68,8 @@ const expression_decisions: Omit = { }, { id: 'r4_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'circle', paint: { 'circle-color': [ @@ -67,6 +82,8 @@ const expression_decisions: Omit = { }, { id: 'r5_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'circle', paint: { 'circle-color': [ @@ -79,6 +96,8 @@ const expression_decisions: Omit = { }, { id: 'r6_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'circle', paint: { 'circle-color': [ @@ -91,6 +110,8 @@ const expression_decisions: Omit = { }, { id: 'r7_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'circle', paint: { 'circle-color': [ @@ -106,6 +127,8 @@ const expression_decisions: Omit = { }, { id: 'r8_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'circle', paint: { 'circle-color': [ diff --git a/data/mapbox_metadata/expression_get.ts b/data/mapbox_metadata/expression_get.ts index c026638..837b441 100644 --- a/data/mapbox_metadata/expression_get.ts +++ b/data/mapbox_metadata/expression_get.ts @@ -1,12 +1,19 @@ /* eslint-disable @typescript-eslint/naming-convention */ import { MbStyle } from '../../src/MapboxStyleParser'; -const expression_get: Omit = { +const expression_get: MbStyle = { version: 8, name: 'Expression Get', + sources: { + testsource: { + type: 'vector' + } + }, layers: [ { id: 'r0_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'circle', paint: { 'circle-color': '#000000', diff --git a/data/mapbox_metadata/expression_lookup.ts b/data/mapbox_metadata/expression_lookup.ts index a7dc1ea..516c592 100644 --- a/data/mapbox_metadata/expression_lookup.ts +++ b/data/mapbox_metadata/expression_lookup.ts @@ -1,12 +1,19 @@ /* eslint-disable @typescript-eslint/naming-convention */ import { MbStyle } from '../../src/MapboxStyleParser'; -const expression_lookup: Omit = { +const expression_lookup: MbStyle = { version: 8, name: 'Expression Lookup', + sources: { + testsource: { + type: 'vector' + } + }, layers: [ { id: 'r0_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'circle', paint: { 'circle-radius': ['length', 'peter'] @@ -14,6 +21,8 @@ const expression_lookup: Omit = { }, { id: 'r1_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'symbol', layout: { 'text-field': ['slice', 'peter', 0, 2] diff --git a/data/mapbox_metadata/expression_math.ts b/data/mapbox_metadata/expression_math.ts index 506a634..b009295 100644 --- a/data/mapbox_metadata/expression_math.ts +++ b/data/mapbox_metadata/expression_math.ts @@ -1,12 +1,19 @@ /* eslint-disable @typescript-eslint/naming-convention */ import { MbStyle } from '../../src/MapboxStyleParser'; -const expression_math: Omit = { +const expression_math: MbStyle = { version: 8, name: 'Expression Math', + sources: { + testsource: { + type: 'vector' + } + }, layers: [ { id: 'r0_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'circle', paint: { 'circle-radius': ['+', 13, 3, 7] @@ -14,6 +21,8 @@ const expression_math: Omit = { }, { id: 'r1_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'circle', paint: { 'circle-radius': ['abs', -12] @@ -21,6 +30,8 @@ const expression_math: Omit = { }, { id: 'r2_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'circle', paint: { 'circle-radius': ['acos', 4] @@ -28,6 +39,8 @@ const expression_math: Omit = { }, { id: 'r3_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'circle', paint: { 'circle-radius': ['asin', 4] @@ -35,6 +48,8 @@ const expression_math: Omit = { }, { id: 'r4_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'circle', paint: { 'circle-radius': ['atan', 4] @@ -42,6 +57,8 @@ const expression_math: Omit = { }, { id: 'r5_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'circle', paint: { 'circle-radius': ['ceil', 3.4] @@ -49,6 +66,8 @@ const expression_math: Omit = { }, { id: 'r6_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'circle', paint: { 'circle-radius': ['cos', 3.4] @@ -56,6 +75,8 @@ const expression_math: Omit = { }, { id: 'r7_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'circle', paint: { 'circle-radius': ['/', 100, 2] @@ -63,6 +84,8 @@ const expression_math: Omit = { }, { id: 'r8_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'circle', paint: { 'circle-radius': ['e'] @@ -70,6 +93,8 @@ const expression_math: Omit = { }, { id: 'r9_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'circle', paint: { 'circle-radius': ['floor', 3.5] @@ -77,6 +102,8 @@ const expression_math: Omit = { }, { id: 'r10_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'circle', paint: { 'circle-radius': ['ln', 4.6] @@ -84,6 +111,8 @@ const expression_math: Omit = { }, { id: 'r11_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'circle', paint: { 'circle-radius': ['max', 13, 37, 0, 8, 15] @@ -91,6 +120,8 @@ const expression_math: Omit = { }, { id: 'r12_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'circle', paint: { 'circle-radius': ['min', 13, 37, 0, 8, 15] @@ -98,6 +129,8 @@ const expression_math: Omit = { }, { id: 'r13_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'circle', paint: { 'circle-radius': ['%', 3, 2] @@ -105,6 +138,8 @@ const expression_math: Omit = { }, { id: 'r14_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'circle', paint: { 'circle-radius': ['*', 2, 2.5, 10] @@ -112,6 +147,8 @@ const expression_math: Omit = { }, { id: 'r15_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'circle', paint: { 'circle-radius': ['pi'] @@ -119,6 +156,8 @@ const expression_math: Omit = { }, { id: 'r16_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'circle', paint: { 'circle-radius': ['^', 2, 4] @@ -126,6 +165,8 @@ const expression_math: Omit = { }, { id: 'r17_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'circle', paint: { 'circle-radius': ['round', 13.37] @@ -133,6 +174,8 @@ const expression_math: Omit = { }, { id: 'r18_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'circle', paint: { 'circle-radius': ['sin', 1] @@ -140,6 +183,8 @@ const expression_math: Omit = { }, { id: 'r19_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'circle', paint: { 'circle-radius': ['sqrt', 1] @@ -147,6 +192,8 @@ const expression_math: Omit = { }, { id: 'r20_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'circle', paint: { 'circle-radius': ['-', 5, 6] @@ -154,6 +201,8 @@ const expression_math: Omit = { }, { id: 'r21_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'circle', paint: { 'circle-radius': ['tan', 1] diff --git a/data/mapbox_metadata/expression_string.ts b/data/mapbox_metadata/expression_string.ts index 88610a1..8f29b0c 100644 --- a/data/mapbox_metadata/expression_string.ts +++ b/data/mapbox_metadata/expression_string.ts @@ -1,12 +1,19 @@ /* eslint-disable @typescript-eslint/naming-convention */ import { MbStyle } from '../../src/MapboxStyleParser'; -const expression_string: Omit = { +const expression_string: MbStyle = { version: 8, name: 'Expression String', + sources: { + testsource: { + type: 'vector' + } + }, layers: [ { id: 'r0_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'symbol', layout: { 'text-field': [ @@ -18,6 +25,8 @@ const expression_string: Omit = { } }, { id: 'r1_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'symbol', layout: { 'text-field': [ @@ -27,6 +36,8 @@ const expression_string: Omit = { } }, { id: 'r2_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'symbol', layout: { 'text-field': [ diff --git a/data/mapbox_metadata/fill_patternfill.ts b/data/mapbox_metadata/fill_patternfill.ts index 7c33d61..352ca16 100644 --- a/data/mapbox_metadata/fill_patternfill.ts +++ b/data/mapbox_metadata/fill_patternfill.ts @@ -1,12 +1,19 @@ import { MbStyle } from '../../src/MapboxStyleParser'; -const fillSimpleFill: Omit = { +const fillSimpleFill: MbStyle = { version: 8, name: 'Pattern Fill', sprite: 'https://testurl.com', + sources: { + testsource: { + type: 'vector' + } + }, layers: [ { id: 'r0_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'fill', paint: { 'fill-color': '#000000', diff --git a/data/mapbox_metadata/fill_simple_outline.ts b/data/mapbox_metadata/fill_simple_outline.ts index 643555d..ebc92f1 100644 --- a/data/mapbox_metadata/fill_simple_outline.ts +++ b/data/mapbox_metadata/fill_simple_outline.ts @@ -1,10 +1,17 @@ import { MbStyle } from '../../src/MapboxStyleParser'; -const fillSimpleFillOutline: Omit = { +const fillSimpleFillOutline: MbStyle = { version: 8, name: 'Simple Fill With outline', + sources: { + testsource: { + type: 'vector' + } + }, layers: [{ id: 'r0_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'fill', paint: { 'fill-color': '#ff0000' @@ -12,6 +19,8 @@ const fillSimpleFillOutline: Omit = { }, { id: 'r0_sy0_st1', + source: 'testsource', + 'source-layer': 'foo', type: 'line', paint: { 'line-opacity': 0.5, diff --git a/data/mapbox_metadata/fill_simplefill.ts b/data/mapbox_metadata/fill_simplefill.ts index 37a2a87..ed30054 100644 --- a/data/mapbox_metadata/fill_simplefill.ts +++ b/data/mapbox_metadata/fill_simplefill.ts @@ -1,11 +1,18 @@ import { MbStyle } from '../../src/MapboxStyleParser'; -const fillSimpleFill: Omit = { +const fillSimpleFill: MbStyle = { version: 8, name: 'Simple Fill', + sources: { + testsource: { + type: 'vector' + } + }, layers: [ { id: 'r0_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'fill', paint: { 'fill-color': '#000000', diff --git a/data/mapbox_metadata/icon_simpleicon.ts b/data/mapbox_metadata/icon_simpleicon.ts index ac647c1..391e9a8 100644 --- a/data/mapbox_metadata/icon_simpleicon.ts +++ b/data/mapbox_metadata/icon_simpleicon.ts @@ -1,12 +1,19 @@ import { MbStyle } from '../../src/MapboxStyleParser'; -const iconSimpleIcon: Omit = { +const iconSimpleIcon: MbStyle = { version: 8, name: 'Simple Icon', sprite: 'https://testurl.com', + sources: { + testsource: { + type: 'vector' + } + }, layers: [ { id: 'r0_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'symbol', layout: { 'icon-image': 'poi' diff --git a/data/mapbox_metadata/icon_simpleicon_mapboxapi.ts b/data/mapbox_metadata/icon_simpleicon_mapboxapi.ts index 4d70eb8..97e700b 100644 --- a/data/mapbox_metadata/icon_simpleicon_mapboxapi.ts +++ b/data/mapbox_metadata/icon_simpleicon_mapboxapi.ts @@ -1,12 +1,19 @@ import { MbStyle } from '../../src/MapboxStyleParser'; -const iconSimpleIcon: Omit = { +const iconSimpleIcon: MbStyle = { version: 8, name: 'Simple Icon', sprite: 'mapbox://sprites/mapbox/streets-v8', + sources: { + testsource: { + type: 'vector' + } + }, layers: [ { id: 'r0_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'symbol', layout: { 'icon-image': 'poi' diff --git a/data/mapbox_metadata/icontext_symbolizer.ts b/data/mapbox_metadata/icontext_symbolizer.ts index 7481fec..ee3d154 100644 --- a/data/mapbox_metadata/icontext_symbolizer.ts +++ b/data/mapbox_metadata/icontext_symbolizer.ts @@ -1,12 +1,19 @@ import { MbStyle } from '../../src/MapboxStyleParser'; -const iconTextSymbolizer: Omit = { +const iconTextSymbolizer: MbStyle = { version: 8, name: 'icontext symbolizer', sprite: 'https://testurl.com', + sources: { + testsource: { + type: 'vector' + } + }, layers: [ { type: 'symbol', + source: 'testsource', + 'source-layer': 'foo', paint: { 'text-color': 'rgba(45, 45, 45, 1)', }, diff --git a/data/mapbox_metadata/line_patternline.ts b/data/mapbox_metadata/line_patternline.ts index 09a5707..8808595 100644 --- a/data/mapbox_metadata/line_patternline.ts +++ b/data/mapbox_metadata/line_patternline.ts @@ -1,13 +1,20 @@ import { MbStyle } from '../../src/MapboxStyleParser'; -const linePatternLine: Omit = { +const linePatternLine: MbStyle = { version: 8, name: 'Pattern Line', sprite: 'https://testurl.com', + sources: { + testsource: { + type: 'vector' + } + }, layers: [ { id: 'r0_sy0_st0', type: 'line', + source: 'testsource', + 'source-layer': 'foo', paint: { 'line-color': '#000000', 'line-width': 3, diff --git a/data/mapbox_metadata/line_simpleline.ts b/data/mapbox_metadata/line_simpleline.ts index ee43e18..ae314ba 100644 --- a/data/mapbox_metadata/line_simpleline.ts +++ b/data/mapbox_metadata/line_simpleline.ts @@ -1,12 +1,19 @@ import { MbStyle } from '../../src/MapboxStyleParser'; -const lineSimpleLine: Omit = { +const lineSimpleLine: MbStyle = { version: 8, name: 'Simple Line', + sources: { + testsource: { + type: 'vector' + } + }, layers: [ { id: 'r0_sy0_st0', type: 'line', + source: 'testsource', + 'source-layer': 'foo', paint: { 'line-color': '#000000', 'line-width': 3, diff --git a/data/mapbox_metadata/line_simpleline_basefilter.ts b/data/mapbox_metadata/line_simpleline_basefilter.ts index ebf5c14..f971751 100644 --- a/data/mapbox_metadata/line_simpleline_basefilter.ts +++ b/data/mapbox_metadata/line_simpleline_basefilter.ts @@ -1,10 +1,17 @@ import { MbStyle } from '../../src/MapboxStyleParser'; -const lineSimpleLine: Omit = { +const lineSimpleLine: MbStyle = { version: 8, name: 'Small populated New Yorks', + sources: { + testsource: { + type: 'vector' + } + }, layers: [{ id: 'r0_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'line', filter: ['all', ['==', 'NAME', 'New York'], diff --git a/data/mapbox_metadata/line_simpleline_expression.ts b/data/mapbox_metadata/line_simpleline_expression.ts index 704983e..ea2af6f 100644 --- a/data/mapbox_metadata/line_simpleline_expression.ts +++ b/data/mapbox_metadata/line_simpleline_expression.ts @@ -1,10 +1,17 @@ import { MbStyle } from '../../src/MapboxStyleParser'; -const lineSimpleLine: Omit = { +const lineSimpleLine: MbStyle = { version: 8, name: 'Simple Line Filter', + sources: { + testsource: { + type: 'vector' + } + }, layers: [{ id: 'r0_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'line', paint: { 'line-color': '#FF0000', diff --git a/data/mapbox_metadata/line_simpleline_zoom.ts b/data/mapbox_metadata/line_simpleline_zoom.ts index 35334a0..6af96d4 100644 --- a/data/mapbox_metadata/line_simpleline_zoom.ts +++ b/data/mapbox_metadata/line_simpleline_zoom.ts @@ -1,10 +1,17 @@ import { MbStyle } from '../../src/MapboxStyleParser'; -const lineSimpleLine: Omit = { +const lineSimpleLine: MbStyle = { version: 8, name: 'Simple Line Filter', + sources: { + testsource: { + type: 'vector' + } + }, layers: [{ id: 'r0_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'line', minzoom: 5.5, maxzoom: 10, diff --git a/data/mapbox_metadata/multi_rule_line_fill.ts b/data/mapbox_metadata/multi_rule_line_fill.ts index d0a46ed..e48f019 100644 --- a/data/mapbox_metadata/multi_rule_line_fill.ts +++ b/data/mapbox_metadata/multi_rule_line_fill.ts @@ -1,11 +1,18 @@ import { MbStyle } from '../../src/MapboxStyleParser'; -const multiRuleLineFill: Omit = { +const multiRuleLineFill: MbStyle = { version: 8, name: 'Rule Line Fill', + sources: { + testsource: { + type: 'vector' + } + }, layers: [ { id: 'r0_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'line', paint: { 'line-color': '#000000', @@ -18,6 +25,8 @@ const multiRuleLineFill: Omit = { } }, { id: 'r1_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'fill', paint: { 'fill-color': '#000000', diff --git a/data/mapbox_metadata/multi_simpleline_simplefill.ts b/data/mapbox_metadata/multi_simpleline_simplefill.ts index b22272c..6f0c196 100644 --- a/data/mapbox_metadata/multi_simpleline_simplefill.ts +++ b/data/mapbox_metadata/multi_simpleline_simplefill.ts @@ -1,11 +1,18 @@ import { MbStyle } from '../../src/MapboxStyleParser'; -const multiSimpleLineSimpleFill: Omit = { +const multiSimpleLineSimpleFill: MbStyle = { version: 8, name: 'Simple Line Simple Fill', + sources: { + testsource: { + type: 'vector' + } + }, layers: [ { id: 'r0_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'line', paint: { 'line-color': '#000000', @@ -18,6 +25,8 @@ const multiSimpleLineSimpleFill: Omit = { } }, { id: 'r1_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'fill', paint: { 'fill-color': '#000000', diff --git a/data/mapbox_metadata/point_placeholderText.ts b/data/mapbox_metadata/point_placeholderText.ts index 3fda64a..6016a86 100644 --- a/data/mapbox_metadata/point_placeholderText.ts +++ b/data/mapbox_metadata/point_placeholderText.ts @@ -1,12 +1,19 @@ import { MbStyle } from '../../src/MapboxStyleParser'; -const pointPlaceholderText: Omit = { +const pointPlaceholderText: MbStyle = { version: 8, name: 'Placeholder Text', + sources: { + testsource: { + type: 'vector' + } + }, layers: [ { id: 'r0_sy0_st0', type: 'symbol', + source: 'testsource', + 'source-layer': 'foo', layout: { 'text-field': ['format', 'Area: ', {}, diff --git a/data/mapbox_metadata/point_placeholderText_simple.ts b/data/mapbox_metadata/point_placeholderText_simple.ts index 8a9c93c..e305038 100644 --- a/data/mapbox_metadata/point_placeholderText_simple.ts +++ b/data/mapbox_metadata/point_placeholderText_simple.ts @@ -1,11 +1,18 @@ import { MbStyle } from '../../src/MapboxStyleParser'; -const pointPlaceholderText: Omit = { +const pointPlaceholderText: MbStyle = { version: 8, name: 'Placeholder Text', + sources: { + testsource: { + type: 'vector' + } + }, layers: [ { id: 'r0_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'symbol', layout: { 'text-field': '{River}' diff --git a/data/mapbox_metadata/point_simpletext.ts b/data/mapbox_metadata/point_simpletext.ts index d6c92cc..0c3181a 100644 --- a/data/mapbox_metadata/point_simpletext.ts +++ b/data/mapbox_metadata/point_simpletext.ts @@ -1,11 +1,18 @@ import { MbStyle } from '../../src/MapboxStyleParser'; -const pointSimpleText: Omit = { +const pointSimpleText: MbStyle = { version: 8, name: 'Simple Text', + sources: { + testsource: { + type: 'vector' + } + }, layers: [ { id: 'r0_sy0_st0', + source: 'testsource', + 'source-layer': 'foo', type: 'symbol', layout: { 'text-field': 'River' diff --git a/data/mapbox_metadata/source_layer_mapping.ts b/data/mapbox_metadata/source_layer_mapping.ts new file mode 100644 index 0000000..af5ba22 --- /dev/null +++ b/data/mapbox_metadata/source_layer_mapping.ts @@ -0,0 +1,58 @@ +import { MbStyle } from '../../src/MapboxStyleParser'; + +const sourceLayerMapping: MbStyle = { + version: 8, + name: 'SourceLayerMapping', + sources: { + first: { + type: 'vector' + } + }, + layers: [ + { + id: 'r0_sy0_st0', + source: 'first', + 'source-layer': 'foo', + type: 'circle', + paint: { + 'circle-color': '#000000', + 'circle-radius': 5, + 'circle-opacity': 1, + 'circle-stroke-width': 2, + 'circle-stroke-color': '#FF0000', + 'circle-stroke-opacity': 0.5 + } + }, + { + id: 'r1_sy0_st0', + source: 'first', + 'source-layer': 'bar', + type: 'circle', + paint: { + 'circle-color': '#000000', + 'circle-radius': 5, + 'circle-opacity': 1, + 'circle-stroke-width': 2, + 'circle-stroke-color': '#FF0000', + 'circle-stroke-opacity': 0.5 + } + } + ], + metadata: { + 'geostyler:ref': { + rules: [{ + name: 'Simple Circle 1', + symbolizers: [[ + 'r0_sy0_st0' + ]] + }, { + name: 'Simple Circle 2', + symbolizers: [[ + 'r1_sy0_st0' + ]] + }] + } + } +}; + +export default sourceLayerMapping; diff --git a/data/mapbox_metadata/source_mapping.ts b/data/mapbox_metadata/source_mapping.ts new file mode 100644 index 0000000..5320d7a --- /dev/null +++ b/data/mapbox_metadata/source_mapping.ts @@ -0,0 +1,61 @@ +import { MbStyle } from '../../src/MapboxStyleParser'; + +const sourceMapping: MbStyle = { + version: 8, + name: 'SourceMapping', + sources: { + first: { + type: 'vector' + }, + second: { + type: 'vector' + } + }, + layers: [ + { + id: 'r0_sy0_st0', + source: 'first', + 'source-layer': 'foo', + type: 'circle', + paint: { + 'circle-color': '#000000', + 'circle-radius': 5, + 'circle-opacity': 1, + 'circle-stroke-width': 2, + 'circle-stroke-color': '#FF0000', + 'circle-stroke-opacity': 0.5 + } + }, + { + id: 'r1_sy0_st0', + source: 'second', + 'source-layer': 'foo', + type: 'circle', + paint: { + 'circle-color': '#000000', + 'circle-radius': 5, + 'circle-opacity': 1, + 'circle-stroke-width': 2, + 'circle-stroke-color': '#FF0000', + 'circle-stroke-opacity': 0.5 + } + } + ], + metadata: { + 'geostyler:ref': { + rules: [{ + name: 'Simple Circle 1', + symbolizers: [[ + 'r0_sy0_st0' + ]] + }, { + name: 'Simple Circle 2', + symbolizers: [[ + 'r1_sy0_st0' + ]] + }] + } + } +}; + +export default sourceMapping; diff --git a/data/styles/circle_simplecircle.ts b/data/styles/circle_simplecircle.ts index 3698a17..3baa7cc 100644 --- a/data/styles/circle_simplecircle.ts +++ b/data/styles/circle_simplecircle.ts @@ -14,7 +14,22 @@ const circleSimpleCircle: Style = { strokeColor: '#FF0000', strokeOpacity: 0.5 }] - }] + }], + metadata: { + 'mapbox:ref': { + sources: { + testsource: { + type: 'vector' + } + }, + sourceMapping: { + testsource: [0] + }, + sourceLayerMapping: { + foo: [0] + } + } + } }; export default circleSimpleCircle; diff --git a/data/styles/fill_patternfill.ts b/data/styles/fill_patternfill.ts index 4118b30..d8d364d 100644 --- a/data/styles/fill_patternfill.ts +++ b/data/styles/fill_patternfill.ts @@ -13,7 +13,22 @@ const fillPatternFill: Style = { image: '/sprites/?name=poi&baseurl=' + encodeURIComponent('https://testurl.com') } }] - }] + }], + metadata: { + 'mapbox:ref': { + sources: { + testsource: { + type: 'vector' + } + }, + sourceMapping: { + testsource: [0] + }, + sourceLayerMapping: { + foo: [0] + } + } + } }; export default fillPatternFill; diff --git a/data/styles/fill_simple_outline.ts b/data/styles/fill_simple_outline.ts index f365a26..7bafa7c 100644 --- a/data/styles/fill_simple_outline.ts +++ b/data/styles/fill_simple_outline.ts @@ -13,7 +13,22 @@ const fillSimpleFillOutline: Style = { outlineCap: 'butt', outlineJoin: 'round' }] - }] + }], + metadata: { + 'mapbox:ref': { + sources: { + testsource: { + type: 'vector' + } + }, + sourceMapping: { + testsource: [0] + }, + sourceLayerMapping: { + foo: [0] + } + } + } }; export default fillSimpleFillOutline; diff --git a/data/styles/fill_simplefill.ts b/data/styles/fill_simplefill.ts index 027cf9b..d0ea754 100644 --- a/data/styles/fill_simplefill.ts +++ b/data/styles/fill_simplefill.ts @@ -9,7 +9,22 @@ const fillSimpleFill: Style = { color: '#000000', opacity: 1 }] - }] + }], + metadata: { + 'mapbox:ref': { + sources: { + testsource: { + type: 'vector' + } + }, + sourceMapping: { + testsource: [0] + }, + sourceLayerMapping: { + foo: [0] + } + } + } }; export default fillSimpleFill; diff --git a/data/styles/gs_expression_case.ts b/data/styles/gs_expression_case.ts index 0c1fdbc..6ee46c4 100644 --- a/data/styles/gs_expression_case.ts +++ b/data/styles/gs_expression_case.ts @@ -86,7 +86,22 @@ const gs_expression_case: Style = { radius: 12, fillOpacity: 0.6 }] - }] + }], + metadata: { + 'mapbox:ref': { + sources: { + testsource: { + type: 'vector' + } + }, + sourceMapping: { + testsource: [0] + }, + sourceLayerMapping: { + foo: [0] + } + } + } }; export default gs_expression_case; diff --git a/data/styles/gs_expression_decisions.ts b/data/styles/gs_expression_decisions.ts index d716190..54d0659 100644 --- a/data/styles/gs_expression_decisions.ts +++ b/data/styles/gs_expression_decisions.ts @@ -228,7 +228,22 @@ const gs_expression_decisions: Style = { ] } }] - },] + }], + metadata: { + 'mapbox:ref': { + sources: { + testsource: { + type: 'vector' + } + }, + sourceMapping: { + testsource: [0, 1, 2, 3, 4, 5, 6, 7, 8] + }, + sourceLayerMapping: { + foo: [0, 1, 2, 3, 4, 5, 6, 7, 8] + } + } + } }; export default gs_expression_decisions; diff --git a/data/styles/gs_expression_lookup.ts b/data/styles/gs_expression_lookup.ts index 0b6a044..0473902 100644 --- a/data/styles/gs_expression_lookup.ts +++ b/data/styles/gs_expression_lookup.ts @@ -22,7 +22,22 @@ const gs_expression_lookup: Style = { args: ['peter', 0, 2] } }] - }] + }], + metadata: { + 'mapbox:ref': { + sources: { + testsource: { + type: 'vector' + } + }, + sourceMapping: { + testsource: [0, 1] + }, + sourceLayerMapping: { + foo: [0, 1] + } + } + } }; export default gs_expression_lookup; diff --git a/data/styles/gs_expression_math.ts b/data/styles/gs_expression_math.ts index be4e851..ce2b665 100644 --- a/data/styles/gs_expression_math.ts +++ b/data/styles/gs_expression_math.ts @@ -222,7 +222,22 @@ const gs_expression_math: Style = { args: [1] } }] - }] + }], + metadata: { + 'mapbox:ref': { + sources: { + testsource: { + type: 'vector' + } + }, + sourceMapping: { + testsource: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21] + }, + sourceLayerMapping: { + foo: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21] + } + } + } }; export default gs_expression_math; diff --git a/data/styles/gs_expression_property.ts b/data/styles/gs_expression_property.ts index 21c9fce..6716e80 100644 --- a/data/styles/gs_expression_property.ts +++ b/data/styles/gs_expression_property.ts @@ -21,7 +21,22 @@ const gs_expression_property: Style = { strokeColor: '#FF0000', strokeOpacity: 0.5 }] - }] + }], + metadata: { + 'mapbox:ref': { + sources: { + testsource: { + type: 'vector' + } + }, + sourceMapping: { + testsource: [0] + }, + sourceLayerMapping: { + foo: [0] + } + } + } }; export default gs_expression_property; diff --git a/data/styles/gs_expression_string.ts b/data/styles/gs_expression_string.ts index e057e3b..c60e7c1 100644 --- a/data/styles/gs_expression_string.ts +++ b/data/styles/gs_expression_string.ts @@ -30,7 +30,22 @@ const gs_expression_string: Style = { args: ['peter'] } }] - }] + }], + metadata: { + 'mapbox:ref': { + sources: { + testsource: { + type: 'vector' + } + }, + sourceMapping: { + testsource: [0, 1, 2] + }, + sourceLayerMapping: { + foo: [0, 1, 2] + } + } + } }; export default gs_expression_string; diff --git a/data/styles/icon_simpleicon.ts b/data/styles/icon_simpleicon.ts index 41df89a..589825e 100644 --- a/data/styles/icon_simpleicon.ts +++ b/data/styles/icon_simpleicon.ts @@ -8,7 +8,22 @@ const iconSimpleIcon: Style = { kind: 'Icon', image: '/sprites/?name=poi&baseurl=' + encodeURIComponent('https://testurl.com') }] - }] + }], + metadata: { + 'mapbox:ref': { + sources: { + testsource: { + type: 'vector' + } + }, + sourceMapping: { + testsource: [0] + }, + sourceLayerMapping: { + foo: [0] + } + } + } }; export default iconSimpleIcon; diff --git a/data/styles/icon_simpleicon_mapboxapi.ts b/data/styles/icon_simpleicon_mapboxapi.ts index 09f0adb..1fb28a0 100644 --- a/data/styles/icon_simpleicon_mapboxapi.ts +++ b/data/styles/icon_simpleicon_mapboxapi.ts @@ -8,7 +8,22 @@ const iconSimpleIcon: Style = { kind: 'Icon', image: '/sprites/?name=poi&baseurl=' + encodeURIComponent('https://api.mapbox.com/sprites/mapbox/streets-v8') }] - }] + }], + metadata: { + 'mapbox:ref': { + sources: { + testsource: { + type: 'vector' + } + }, + sourceMapping: { + testsource: [0] + }, + sourceLayerMapping: { + foo: [0] + } + } + } }; export default iconSimpleIcon; diff --git a/data/styles/line_patternline.ts b/data/styles/line_patternline.ts index 551c498..75125f3 100644 --- a/data/styles/line_patternline.ts +++ b/data/styles/line_patternline.ts @@ -16,7 +16,22 @@ const linePatternLine: Style = { image: '/sprites/?name=poi&baseurl=' + encodeURIComponent('https://testurl.com') } }] - }] + }], + metadata: { + 'mapbox:ref': { + sources: { + testsource: { + type: 'vector' + } + }, + sourceMapping: { + testsource: [0] + }, + sourceLayerMapping: { + foo: [0] + } + } + } }; export default linePatternLine; diff --git a/data/styles/line_simpleline.ts b/data/styles/line_simpleline.ts index d99d572..a0b9282 100644 --- a/data/styles/line_simpleline.ts +++ b/data/styles/line_simpleline.ts @@ -12,7 +12,22 @@ const lineSimpleLine: Style = { cap: 'round', join: 'miter' }] - }] + }], + metadata: { + 'mapbox:ref': { + sources: { + testsource: { + type: 'vector' + } + }, + sourceMapping: { + testsource: [0] + }, + sourceLayerMapping: { + foo: [0] + } + } + } }; export default lineSimpleLine; diff --git a/data/styles/line_simpleline_basefilter.ts b/data/styles/line_simpleline_basefilter.ts index e10523d..5198aa3 100644 --- a/data/styles/line_simpleline_basefilter.ts +++ b/data/styles/line_simpleline_basefilter.ts @@ -21,7 +21,22 @@ const lineSimpleLine: Style = { color: '#FF0000', width: 3 }] - }] + }], + metadata: { + 'mapbox:ref': { + sources: { + testsource: { + type: 'vector' + } + }, + sourceMapping: { + testsource: [0] + }, + sourceLayerMapping: { + foo: [0] + } + } + } }; export default lineSimpleLine; diff --git a/data/styles/line_simpleline_expression.ts b/data/styles/line_simpleline_expression.ts index 6e2ac9e..ae26c9e 100644 --- a/data/styles/line_simpleline_expression.ts +++ b/data/styles/line_simpleline_expression.ts @@ -12,7 +12,22 @@ const lineSimpleLine: Style = { name: 'random' } }] - }] + }], + metadata: { + 'mapbox:ref': { + sources: { + testsource: { + type: 'vector' + } + }, + sourceMapping: { + testsource: [0] + }, + sourceLayerMapping: { + foo: [0] + } + } + } }; export default lineSimpleLine; diff --git a/data/styles/line_simpleline_zoom.ts b/data/styles/line_simpleline_zoom.ts index 0737737..b1a4307 100644 --- a/data/styles/line_simpleline_zoom.ts +++ b/data/styles/line_simpleline_zoom.ts @@ -13,7 +13,22 @@ const lineSimpleLine: Style = { color: '#FF0000', width: 5 }] - }] + }], + metadata: { + 'mapbox:ref': { + sources: { + testsource: { + type: 'vector' + } + }, + sourceMapping: { + testsource: [0] + }, + sourceLayerMapping: { + foo: [0] + } + } + } }; export default lineSimpleLine; diff --git a/data/styles/multi_rule_line_fill.ts b/data/styles/multi_rule_line_fill.ts index 9ad49db..5182ed8 100644 --- a/data/styles/multi_rule_line_fill.ts +++ b/data/styles/multi_rule_line_fill.ts @@ -20,7 +20,22 @@ const multiRuleLineFill: Style = { color: '#000000', opacity: 1 }] - }] + }], + metadata: { + 'mapbox:ref': { + sources: { + testsource: { + type: 'vector' + } + }, + sourceMapping: { + testsource: [0, 1] + }, + sourceLayerMapping: { + foo: [0, 1] + } + } + } }; export default multiRuleLineFill; diff --git a/data/styles/multi_simpleline_simplefill.ts b/data/styles/multi_simpleline_simplefill.ts index 461c74e..a57a904 100644 --- a/data/styles/multi_simpleline_simplefill.ts +++ b/data/styles/multi_simpleline_simplefill.ts @@ -19,7 +19,22 @@ const multiSimpleLineSimpleFill: Style = { color: '#000000', opacity: 1 }] - }] + }], + metadata: { + 'mapbox:ref': { + sources: { + testsource: { + type: 'vector' + } + }, + sourceMapping: { + testsource: [0, 1] + }, + sourceLayerMapping: { + foo: [0, 1] + } + } + } }; export default multiSimpleLineSimpleFill; diff --git a/data/styles/point_placeholderText.ts b/data/styles/point_placeholderText.ts index e16d790..8875fa5 100644 --- a/data/styles/point_placeholderText.ts +++ b/data/styles/point_placeholderText.ts @@ -10,7 +10,22 @@ const pointPlaceholderText: Style = { color: '#000000', opacity: 1 }] - }] + }], + metadata: { + 'mapbox:ref': { + sources: { + testsource: { + type: 'vector' + } + }, + sourceMapping: { + testsource: [0] + }, + sourceLayerMapping: { + foo: [0] + } + } + } }; export default pointPlaceholderText; diff --git a/data/styles/point_placeholderText_simple.ts b/data/styles/point_placeholderText_simple.ts index 49c6493..80d764e 100644 --- a/data/styles/point_placeholderText_simple.ts +++ b/data/styles/point_placeholderText_simple.ts @@ -10,7 +10,22 @@ const pointPlaceholderText: Style = { color: '#000000', opacity: 1 }] - }] + }], + metadata: { + 'mapbox:ref': { + sources: { + testsource: { + type: 'vector' + } + }, + sourceMapping: { + testsource: [0] + }, + sourceLayerMapping: { + foo: [0] + } + } + } }; export default pointPlaceholderText; diff --git a/data/styles/point_simpletext.ts b/data/styles/point_simpletext.ts index cbe8c49..c69fd15 100644 --- a/data/styles/point_simpletext.ts +++ b/data/styles/point_simpletext.ts @@ -10,7 +10,22 @@ const pointSimpleText: Style = { color: '#000000', opacity: 1 }] - }] + }], + metadata: { + 'mapbox:ref': { + sources: { + testsource: { + type: 'vector' + } + }, + sourceMapping: { + testsource: [0] + }, + sourceLayerMapping: { + foo: [0] + } + } + } }; export default pointSimpleText; diff --git a/data/styles/source_layer_mapping.ts b/data/styles/source_layer_mapping.ts new file mode 100644 index 0000000..e625d02 --- /dev/null +++ b/data/styles/source_layer_mapping.ts @@ -0,0 +1,48 @@ +import { Style } from 'geostyler-style'; + +const sourceLayerMapping: Style = { + name: 'SourceLayerMapping', + rules: [{ + name: 'Simple Circle 1', + symbolizers: [{ + kind: 'Mark', + wellKnownName: 'circle', + color: '#000000', + radius: 5, + fillOpacity: 1, + strokeWidth: 2, + strokeColor: '#FF0000', + strokeOpacity: 0.5 + }] + }, { + name: 'Simple Circle 2', + symbolizers: [{ + kind: 'Mark', + wellKnownName: 'circle', + color: '#000000', + radius: 5, + fillOpacity: 1, + strokeWidth: 2, + strokeColor: '#FF0000', + strokeOpacity: 0.5 + }] + }], + metadata: { + 'mapbox:ref': { + sources: { + first: { + type: 'vector' + } + }, + sourceMapping: { + first: [0, 1] + }, + sourceLayerMapping: { + foo: [0], + bar: [1] + } + } + } +}; + +export default sourceLayerMapping; diff --git a/data/styles/source_mapping.ts b/data/styles/source_mapping.ts new file mode 100644 index 0000000..3676c9c --- /dev/null +++ b/data/styles/source_mapping.ts @@ -0,0 +1,51 @@ +import { Style } from 'geostyler-style'; + +const sourceMapping: Style = { + name: 'SourceMapping', + rules: [{ + name: 'Simple Circle 1', + symbolizers: [{ + kind: 'Mark', + wellKnownName: 'circle', + color: '#000000', + radius: 5, + fillOpacity: 1, + strokeWidth: 2, + strokeColor: '#FF0000', + strokeOpacity: 0.5 + }] + }, { + name: 'Simple Circle 2', + symbolizers: [{ + kind: 'Mark', + wellKnownName: 'circle', + color: '#000000', + radius: 5, + fillOpacity: 1, + strokeWidth: 2, + strokeColor: '#FF0000', + strokeOpacity: 0.5 + }] + }], + metadata: { + 'mapbox:ref': { + sources: { + first: { + type: 'vector' + }, + second: { + type: 'vector' + } + }, + sourceMapping: { + first: [0], + second: [1] + }, + sourceLayerMapping: { + foo: [0, 1] + } + } + } +}; + +export default sourceMapping; diff --git a/data/styles_metadata/icontext_symbolizer.ts b/data/styles_metadata/icontext_symbolizer.ts index 20f9f2e..b16d4e7 100644 --- a/data/styles_metadata/icontext_symbolizer.ts +++ b/data/styles_metadata/icontext_symbolizer.ts @@ -23,10 +23,21 @@ const iconTextSymbolizer: Style = { ], metadata: { 'mapbox:ref': { + sources: { + testsource: { + type: 'vector' + } + }, splitSymbolizers: [{ rule: 0, symbolizers: [0, 1] - }] + }], + sourceMapping: { + testsource: [0] + }, + sourceLayerMapping: { + foo: [0] + } } } }; diff --git a/src/MapboxStyleParser.spec.ts b/src/MapboxStyleParser.spec.ts index 2318734..395d9ed 100644 --- a/src/MapboxStyleParser.spec.ts +++ b/src/MapboxStyleParser.spec.ts @@ -51,6 +51,12 @@ import mb_point_placeholdertext_simple_metadata from '../data/mapbox_metadata/po import icontext_symbolizer_metadata from '../data/styles_metadata/icontext_symbolizer'; import mb_icontext_symbolizer from '../data/mapbox/icontext_symbolizer'; import mb_icontext_symbolizer_metadata from '../data/mapbox_metadata/icontext_symbolizer'; +import source_mapping from '../data/styles/source_mapping'; +import mb_source_mapping from '../data/mapbox/source_mapping'; +import mb_source_mapping_metadata from '../data/mapbox_metadata/source_mapping'; +import source_layer_mapping from '../data/styles/source_layer_mapping'; +import mb_source_layer_mapping from '../data/mapbox/source_layer_mapping'; +import mb_source_layer_mapping_metadata from '../data/mapbox_metadata/source_layer_mapping'; import { CustomLayerInterface } from 'mapbox-gl'; import { AnyLayer } from 'mapbox-gl'; @@ -195,6 +201,18 @@ describe('MapboxStyleParser implements StyleParser', () => { expect(geoStylerStyle).toBeDefined(); expect(geoStylerStyle).toEqual(icontext_symbolizer_metadata); }); + + it('can keep track of a mapbox style sources', async () => { + const { output: geoStylerStyle } = await styleParser.readStyle(mb_source_mapping); + expect(geoStylerStyle).toBeDefined(); + expect(geoStylerStyle).toEqual(source_mapping); + }); + + it('can keep track of a mapbox style layer source', async () => { + const { output: geostylerStyle } = await styleParser.readStyle(mb_source_layer_mapping); + expect(geostylerStyle).toBeDefined(); + expect(geostylerStyle).toEqual(source_layer_mapping); + }); }); describe('#writeStyle', () => { @@ -304,5 +322,17 @@ describe('MapboxStyleParser implements StyleParser', () => { expect(mbStyle).toBeDefined(); expect(mbStyle).toEqual(mb_icontext_symbolizer_metadata); }); + + it('can properly resolve the source mapping', async () => { + const { output: mbStyle } = await styleParser.writeStyle(source_mapping); + expect(mbStyle).toBeDefined(); + expect(mbStyle).toEqual(mb_source_mapping_metadata); + }); + + it('can properly resolve the source layer mapping', async () => { + const { output: mbStyle } = await styleParser.writeStyle(source_layer_mapping); + expect(mbStyle).toBeDefined(); + expect(mbStyle).toEqual(mb_source_layer_mapping_metadata); + }); }); }); diff --git a/src/MapboxStyleParser.ts b/src/MapboxStyleParser.ts index afbfefb..21797b5 100644 --- a/src/MapboxStyleParser.ts +++ b/src/MapboxStyleParser.ts @@ -48,7 +48,8 @@ import { SymbolPaint, Style as MapboxStyle, Sources, - Expression + Expression, + Layer } from 'mapbox-gl'; import { gs2mbExpression, mb2gsExpression } from './Expressions'; import { isBoolean, isString, isUndefined, omitBy, set } from 'lodash'; @@ -57,7 +58,7 @@ import { isBoolean, isString, isUndefined, omitBy, set } from 'lodash'; * The style representation of mapbox-gl but with optional sources, as these are * not required for reading the style and get stripped when writing. */ -export type MbStyle = Omit & { sources?: Sources }; +export type MbStyle = MapboxStyle; type NoneCustomLayer = Exclude; @@ -82,6 +83,13 @@ type MapboxRef = { rule: number; symbolizers: number[]; }[]; + sources: Sources; + sourceMapping?: { + [source: keyof Sources]: number[]; + }; + sourceLayerMapping?: { + [key: string]: number[]; + }; }; type SymbolType = { @@ -654,6 +662,8 @@ export class MapboxStyleParser implements StyleParser> const gsRules: Rule[] = []; const splitSymbolizers: MapboxRef['splitSymbolizers'] = []; const mapboxRef = structuredClone(mbRef); + const sourceMapping: MapboxRef['sourceMapping'] = {}; + const sourceLayerMapping: MapboxRef['sourceLayerMapping'] = {}; if (geoStylerRef) { geoStylerRef.rules.forEach((rule, ruleIndex) => { @@ -661,6 +671,8 @@ export class MapboxStyleParser implements StyleParser> let symbolizers: Symbolizer[] = []; let filter: Filter | undefined; let scaleDenominator: ScaleDenominator | undefined; + let source: Layer['source']; + let sourceLayer: Layer['source-layer']; rule.symbolizers?.forEach((layerIds, symbolizerIndex) => { const matchingLayers = layers.filter(layer => layerIds.includes(layer.id)); const flattenedSymbolizers = matchingLayers @@ -687,6 +699,21 @@ export class MapboxStyleParser implements StyleParser> matchingLayers[0].minzoom, matchingLayers[0].maxzoom, ); + source = matchingLayers[0].source; + sourceLayer = matchingLayers[0]['source-layer']; + + if (source && typeof source === 'string') { + if (!sourceMapping[source]) { + sourceMapping[source] = []; + } + sourceMapping[source].push(ruleIndex); + } + if (sourceLayer) { + if (!sourceLayerMapping[sourceLayer]) { + sourceLayerMapping[sourceLayer] = []; + } + sourceLayerMapping[sourceLayer].push(ruleIndex); + } } // TODO: care about layers not configured in the metadata // const noneMatchingLayes = layers.filter(layer => !layerIds.includes(layer.id)); @@ -718,6 +745,18 @@ export class MapboxStyleParser implements StyleParser> symbolizers }; gsRules.push(rule); + if (layer.source && typeof layer.source === 'string') { + if (!sourceMapping[layer.source]) { + sourceMapping[layer.source] = []; + } + sourceMapping[layer.source].push(gsRules.length - 1); + } + if (layer['source-layer']) { + if (!sourceLayerMapping[layer['source-layer']]) { + sourceLayerMapping[layer['source-layer']] = []; + } + sourceLayerMapping[layer['source-layer']].push(gsRules.length - 1); + } if (symbolizers.length > 1) { splitSymbolizers.push({ rule: gsRules.length - 1, @@ -730,6 +769,12 @@ export class MapboxStyleParser implements StyleParser> if (splitSymbolizers.length) { mapboxRef.splitSymbolizers = splitSymbolizers; } + if (Object.keys(sourceMapping).length) { + mapboxRef.sourceMapping = sourceMapping; + } + if (Object.keys(sourceLayerMapping).length) { + mapboxRef.sourceLayerMapping = sourceLayerMapping; + } return { rules: gsRules, @@ -747,7 +792,9 @@ export class MapboxStyleParser implements StyleParser> let style: Style = {} as Style; style.name = mapboxStyle.name || ''; style.rules = []; - let mapboxRef: MapboxRef = {}; + let mapboxRef: MapboxRef = { + sources: mapboxStyle.sources || {} + }; this.mbMetadata = mapboxStyle.metadata; if (mapboxStyle.sprite) { this.spriteBaseUrl = MapboxStyleUtil.getUrlForMbPlaceholder(mapboxStyle.sprite); @@ -763,11 +810,9 @@ export class MapboxStyleParser implements StyleParser> style.rules = style.rules.concat(rules); } - if (Object.keys(mapboxRef).length) { - style.metadata = { - 'mapbox:ref': mapboxRef - }; - } + style.metadata = { + 'mapbox:ref': mapboxRef + }; return style; } @@ -801,12 +846,12 @@ export class MapboxStyleParser implements StyleParser> * @param geoStylerStyle A GeoStylerStyle-Style * @return The Promise resolving with a GeoStylerStyle-WriteStyleResult */ - writeStyle(geoStylerStyle: Style): Promise>> { - return new Promise>>(resolve => { + writeStyle(geoStylerStyle: Style): Promise> { + return new Promise>(resolve => { const unsupportedProperties = this.checkForUnsupportedProperties(geoStylerStyle); try { const gsStyle = structuredClone(geoStylerStyle); - const output: Omit = this.geoStylerStyleToMapboxObject(gsStyle); + const output: MbStyle = this.geoStylerStyleToMapboxObject(gsStyle); resolve({ output, unsupportedProperties, @@ -826,12 +871,12 @@ export class MapboxStyleParser implements StyleParser> * @param geoStylerStyle A GeoStylerStyle-Style * @return A Mapbox Style object */ - geoStylerStyleToMapboxObject(geoStylerStyle: Style): Omit { + geoStylerStyleToMapboxObject(geoStylerStyle: Style): MbStyle { // Mapbox Style version const version = 8; const name = geoStylerStyle.name; - const metadata = geoStylerStyle.metadata?.['mapbox:ref']; - const {layers, geoStylerRef} = this.getMapboxLayersFromRules(geoStylerStyle.rules, metadata); + const mapboxRef = geoStylerStyle.metadata?.['mapbox:ref']; + const {layers, geoStylerRef} = this.getMapboxLayersFromRules(geoStylerStyle.rules, mapboxRef); const sprite = MapboxStyleUtil.getMbPlaceholderForUrl(this.spriteBaseUrl); let mapboxObject = omitBy({ @@ -839,7 +884,8 @@ export class MapboxStyleParser implements StyleParser> name, layers, sprite, - }, isUndefined) as Omit; + sources: mapboxRef?.sources || {} + }, isUndefined) as MbStyle; if (geoStylerRef){ mapboxObject = { @@ -934,6 +980,25 @@ export class MapboxStyleParser implements StyleParser> } lyrClone.id = `r${ruleIndex}_sy${symbolizerIndex}_st${styleIndex}`; + const sourceMapping = mapboxRef?.sourceMapping; + if (sourceMapping) { + const matchingSource = Object.keys(sourceMapping) + .filter(source => sourceMapping[source].includes(ruleIndex)) + .pop(); + if (matchingSource !== undefined) { + lyrClone.source = matchingSource; + } + } + const sourceLayerMapping = mapboxRef?.sourceLayerMapping; + if (sourceLayerMapping) { + const matchingSourceLayer = Object.keys(sourceLayerMapping) + .filter(sourceLayer => sourceLayerMapping[sourceLayer].includes(ruleIndex)) + .pop(); + if (matchingSourceLayer !== undefined) { + lyrClone['source-layer'] = matchingSourceLayer; + } + } + layers.push(omitBy(lyrClone, isUndefined) as NoneCustomLayer); let symbs = geoStylerRef.rules[ruleIndex].symbolizers;