Skip to content

Commit aa45a34

Browse files
committed
feat: add mapnik parser
1 parent 601d973 commit aa45a34

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

package-lock.json

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"geostyler-mapfile-parser": "^4.0.1",
7272
"geostyler-qgis-parser": "^4.0.0",
7373
"geostyler-sld-parser": "^7.1.0",
74+
"@koordinates/geostyler-mapnik-parser": "^0.1.1",
7475
"geostyler-style": "^9.2.0",
7576
"gradient-string": "^2.0.2",
7677
"minimist": "^1.2.8",

src/index.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import QGISParser from 'geostyler-qgis-parser';
55
import MapfileParser from 'geostyler-mapfile-parser';
66
import MapboxParser from 'geostyler-mapbox-parser';
77
import LyrxParser from 'geostyler-lyrx-parser';
8+
import { MapnikStyleParser } from '@koordinates/geostyler-mapnik-parser';
89

910
import {
1011
existsSync,
@@ -49,6 +50,22 @@ const getParserFromFormat = (inputString: string): StyleParser | undefined => {
4950
case 'qgis':
5051
case 'qml':
5152
return new QGISParser();
53+
case 'mapnik':
54+
return new MapnikStyleParser({
55+
output: {
56+
includeMap: false,
57+
wellKnownBasePath: 'icons',
58+
style: {
59+
name: 'style',
60+
},
61+
symbolizers: {
62+
MarkersSymbolizer: {
63+
'allow-overlap': 'true',
64+
},
65+
},
66+
},
67+
}) as StyleParser<any>;
68+
5269
case 'geostyler':
5370
return undefined;
5471
default:
@@ -65,7 +82,7 @@ const getFormatFromFilename = (fileName: string): string | undefined => {
6582
return undefined;
6683
}
6784
fileEnding = fileEnding.toLowerCase();
68-
if (['lyrx', 'mapbox', 'map', 'sld', 'qml', 'geostyler'].includes(fileEnding)) {
85+
if (['lyrx', 'mapbox', 'map', 'sld', 'qml', 'mapnik', 'geostyler'].includes(fileEnding)) {
6986
return fileEnding;
7087
}
7188
return undefined;
@@ -88,7 +105,7 @@ const getExtensionFromFormat = (format: string): string => {
88105
};
89106

90107
const tryRemoveExtension = (fileName: string): string => {
91-
const possibleExtensions = ['js', 'ts', 'mapbox', 'map', 'sld', 'qml', 'lyrx'];
108+
const possibleExtensions = ['js', 'ts', 'mapbox', 'map', 'sld', 'qml', 'lyrx', 'mapnik'];
92109
const splittedFileName = fileName.split('.');
93110
const sourceFileExtension = splittedFileName.pop();
94111
if (sourceFileExtension && possibleExtensions.includes(sourceFileExtension.toLowerCase())) {
@@ -154,6 +171,11 @@ function collectPaths(basePath: string, isFile: boolean): string[] {
154171
}
155172

156173
function handleResult(result: ReadStyleResult | WriteStyleResult, parser: StyleParser, stage: 'Source' | 'Target') {
174+
if (parser instanceof MapnikStyleParser) {
175+
// MapnikStyleParser uses an older StyleParser interface, I haven't brought it up to date.
176+
return result;
177+
}
178+
157179
const { output, errors, warnings, unsupportedProperties } = result;
158180
if (errors && errors.length > 0) {
159181
throw errors;

0 commit comments

Comments
 (0)