Skip to content

Commit

Permalink
feat: add mapnik parser
Browse files Browse the repository at this point in the history
  • Loading branch information
olsen232 committed Dec 10, 2024
1 parent bc0cc03 commit e1c55c6
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
38 changes: 38 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"geostyler-mapfile-parser": "^4.0.1",
"geostyler-qgis-parser": "^3.0.0",
"geostyler-sld-parser": "^6.1.2",
"@koordinates/geostyler-mapnik-parser": "^0.1.1",
"geostyler-style": "^9.1.0",
"gradient-string": "^2.0.2",
"minimist": "^1.2.8",
Expand Down
26 changes: 24 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import QGISParser from 'geostyler-qgis-parser';
import MapfileParser from 'geostyler-mapfile-parser';
import MapboxParser from 'geostyler-mapbox-parser';
import LyrxParser from 'geostyler-lyrx-parser';
import { MapnikStyleParser } from '@koordinates/geostyler-mapnik-parser';

import {
existsSync,
Expand Down Expand Up @@ -48,6 +49,22 @@ const getParserFromFormat = (inputString: string): StyleParser | undefined => {
case 'qgis':
case 'qml':
return new QGISParser();
case 'mapnik':
return new MapnikStyleParser({
output: {
includeMap: false,
wellKnownBasePath: 'icons',
style: {
name: 'style',
},
symbolizers: {
MarkersSymbolizer: {
'allow-overlap': 'true',
},
},
},
}) as StyleParser<any>;

case 'geostyler':
return undefined;
default:
Expand All @@ -64,7 +81,7 @@ const getFormatFromFilename = (fileName: string): string | undefined => {
return undefined;
}
fileEnding = fileEnding.toLowerCase();
if (['lyrx', 'mapbox', 'map', 'sld', 'qml', 'geostyler'].includes(fileEnding)) {
if (['lyrx', 'mapbox', 'map', 'sld', 'qml', 'mapnik', 'geostyler'].includes(fileEnding)) {
return fileEnding;
}
return undefined;
Expand All @@ -87,7 +104,7 @@ const getExtensionFromFormat = (format: string): string => {
};

const tryRemoveExtension = (fileName: string): string => {
const possibleExtensions = ['js', 'ts', 'mapbox', 'map', 'sld', 'qml', 'lyrx'];
const possibleExtensions = ['js', 'ts', 'mapbox', 'map', 'sld', 'qml', 'lyrx', 'mapnik'];
const splittedFileName = fileName.split('.');
const sourceFileExtension = splittedFileName.pop();
if (sourceFileExtension && possibleExtensions.includes(sourceFileExtension.toLowerCase())) {
Expand Down Expand Up @@ -150,6 +167,11 @@ function collectPaths(basePath: string, isFile: boolean): string[] {
}

function handleResult(result: ReadStyleResult | WriteStyleResult, parser: StyleParser, stage: 'Source' | 'Target') {
if (parser instanceof MapnikStyleParser) {
// MapnikStyleParser uses an older StyleParser interface, I haven't brought it up to date.
return result;
}

const { output, errors, warnings, unsupportedProperties } = result;
if (errors && errors.length > 0) {
throw errors;
Expand Down

0 comments on commit e1c55c6

Please sign in to comment.