Skip to content

Commit a055c11

Browse files
authored
Merge pull request #462 from jansule/fix-mapbox
fix: reading mapbox styles
2 parents 443bd15 + 61efff0 commit a055c11

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

src/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,14 @@ async function writeFile(
202202
: await promises.readFile(sourceFile, 'utf-8');
203203

204204
// If no sourceParser is set, just parse it as JSON - it should already be in geostyler format.
205-
// LyrxParser expects a JSON object as input, so we need to parse it as an extra step.
206-
if (!sourceParser || sourceParser instanceof LyrxParser || sourceParser instanceof OlFlatStyleParser) {
205+
// LyrxParser, OlFlatStyleParser and MapboxParser expect a JSON object as input,
206+
// so we need to parse it as an extra step.
207+
if (
208+
!sourceParser
209+
|| sourceParser instanceof LyrxParser
210+
|| sourceParser instanceof OlFlatStyleParser
211+
|| sourceParser instanceof MapboxParser
212+
) {
207213
inputFileData = JSON.parse(inputFileData);
208214
}
209215

test.cjs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,15 @@ function runAllTests() {
105105
success = false;
106106
}
107107

108+
// test mapbox style to geostyler
109+
outputFile = 'output.json';
110+
args = ['start', '--', '-s', 'mapbox', '-o', outputFile, 'testdata/point_simple.mapbox'];
111+
runTest(args, outputFile);
112+
113+
if (checkFileCreated(outputFile) === false) {
114+
success = false;
115+
}
116+
108117
// test folder output
109118
args = ['start', '--', '-s', 'sld', '-t', 'qgis', '-o', './output-bulk', 'testdata/sld'];
110119
runTest(args, outputFile);
@@ -152,10 +161,10 @@ function runAllTests() {
152161

153162
// Test the parseOptions functions.
154163
if (!parseOptionsTest() || !parseEmptyOptionsTest()) {
155-
console.log('Parser options tests failed');
164+
console.log('\n\n\nParser options tests failed');
156165
success = false;
157166
} else {
158-
console.log('Parser options tests ok');
167+
console.log('\n\n\nParser options tests ok');
159168
}
160169

161170
return success;

testdata/point_simple.mapbox

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"version": 8,
3+
"name": "Simple Point",
4+
"layers": [
5+
{
6+
"type": "circle",
7+
"paint": {
8+
"circle-radius": 3,
9+
"circle-color": "#FF0000",
10+
"circle-opacity": 0.5,
11+
"circle-stroke-color": "#0000FF",
12+
"circle-stroke-opacity": 0.7
13+
},
14+
"id": "r0_sy0_st0"
15+
}
16+
],
17+
"sources": {}
18+
}

0 commit comments

Comments
 (0)