Skip to content

Commit

Permalink
Restructuring of functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
mholthausen committed May 7, 2021
1 parent 9e1a9a5 commit 8900ca0
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 21 deletions.
47 changes: 44 additions & 3 deletions data/mapfiles/point_symbol_style_in_label.map
Expand Up @@ -16,13 +16,54 @@ LAYER
FONT "ptsansbold"
TYPE truetype
STYLE
SYMBOL "simple_point_symbol_svg"
SYMBOL "simple_point_1_symbol_svg"
END
STYLE
SYMBOL "simple_point_2_symbol_svg"
END
END
END
CLASS
MAXSCALEDENOM 25000
LABEL
SIZE 5.644432194046306
COLOR "#ffffff"
TEXT '[ref]'
PARTIALS false
FONT "ptsansbold"
TYPE truetype
STYLE
SYMBOL "simple_point_2_symbol_svg"
END
END
END
CLASS
MAXSCALEDENOM 20000
LABEL
SIZE 4.644432194046306
COLOR "#ffffff"
TEXT '[ref]'
PARTIALS false
FONT "ptsansbold"
TYPE truetype
STYLE
SYMBOL "simple_point_3_symbol_svg"
END
END
END
END
SYMBOL
NAME simple_point_symbol_svg
IMAGE "simple_point_symbol.svg"
NAME simple_point_1_symbol_svg
IMAGE "simple_point_1_symbol.svg"
TYPE svg
END
SYMBOL
NAME simple_point_2_symbol_svg
IMAGE "simple_point_2_symbol.svg"
TYPE svg
END
SYMBOL
NAME simple_point_3_symbol_svg
IMAGE "simple_point_3_symbol.svg"
TYPE svg
END
32 changes: 30 additions & 2 deletions data/styles/point_symbol_style_in_label.ts
Expand Up @@ -8,7 +8,8 @@ const pointSymbolStyle: Style = [
name: '',
scaleDenominator: { max: 35000 },
symbolizers: [
{ kind: 'Icon', image: 'simple_point_symbol.svg' },
{ kind: 'Icon', image: 'simple_point_1_symbol.svg' },
{ kind: 'Icon', image: 'simple_point_2_symbol.svg' },
{
kind: 'Text',
label: '{{ref}}',
Expand All @@ -17,9 +18,36 @@ const pointSymbolStyle: Style = [
color: '#ffffff'
}
]
},
{
name: '',
scaleDenominator: { max: 25000 },
symbolizers: [
{ kind: 'Icon', image: 'simple_point_2_symbol.svg' },
{
kind: 'Text',
label: '{{ref}}',
font: ['ptsansbold'],
size: 5.644432194046306,
color: '#ffffff'
}
]
},
{
name: '',
scaleDenominator: { max: 20000 },
symbolizers: [
{ kind: 'Icon', image: 'simple_point_3_symbol.svg' },
{
kind: 'Text',
label: '{{ref}}',
font: ['ptsansbold'],
size: 4.644432194046306,
color: '#ffffff'
}
]
}
]
}
];

export default pointSymbolStyle;
48 changes: 32 additions & 16 deletions src/MapfileStyleParser.ts
Expand Up @@ -45,8 +45,6 @@ export class MapfileStyleParser implements StyleParser {

symbolsPath = `${process.cwd()}/symbols.sym`;

iconsOnLabels: IconSymbolizer = { kind: 'Icon' };

constructor(opts?: ConstructorParams) {
Object.assign(this, opts);
}
Expand Down Expand Up @@ -476,15 +474,6 @@ export class MapfileStyleParser implements StyleParser {
textSymbolizer.padding = parseFloat(styleParameters.buffer);
}

// collect icon data if defined within the label tag
if (styleParameters.styles) {
styleParameters.styles.forEach((style: MapfileStyle )=> {
if (style.symbol) {
this.iconsOnLabels = this.getIconSymbolizerFromMapfileStyle(style);
}
});
}

if (styleParameters.position) {
const anchorpointMap = {
cc: 'center',
Expand Down Expand Up @@ -821,6 +810,15 @@ export class MapfileStyleParser implements StyleParser {
mapfileLayerLabelItem = mapfileClass.text ? mapfileClass.text : mapfileLayerLabelItem;
mapfileClass.labels.forEach((mapfileLabel) => {
mapfileLabel.text = mapfileLabel.text ? mapfileLabel.text : mapfileLayerLabelItem;

// Set Icons in front of the associated label
const labelIcons = this.getIconsFromMapfileLabel(mapfileLabel);
if (labelIcons) {
labelIcons.forEach(labelIcon => {
symbolizers.push(labelIcon);
});
}

const symbolizer = Object.assign(
this.getTextSymbolizerFromMapfileStyle(mapfileLabel),
this.getBaseSymbolizerFromMapfileStyle(mapfileLabel)
Expand All @@ -832,14 +830,32 @@ export class MapfileStyleParser implements StyleParser {
});
}

// check for available icons
if (Object.keys(this.iconsOnLabels).length > 1) {
symbolizers.unshift(this.iconsOnLabels as IconSymbolizer);
}

return symbolizers;
}

/**
* Collect icon data if defined within the label tag
*
* @param mapfileLabel
* @returns
*/
getIconsFromMapfileLabel(
mapfileLabel: MapfileLabel
): IconSymbolizer[] | void {
const labelStyles: IconSymbolizer[] = [];
mapfileLabel?.styles?.forEach((style: MapfileStyle) => {
if (style.symbol) {
labelStyles.push(this.getIconSymbolizerFromMapfileStyle(style));
}
});

if (labelStyles.length) {
return labelStyles;
} else {
return undefined;
}
}

/**
* Get the GeoStyler-Style Rule from an Mapfile Object.
*
Expand Down

0 comments on commit 8900ca0

Please sign in to comment.