Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
b4l committed Jun 5, 2020
1 parent 46d2431 commit e9f9a53
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 30 deletions.
70 changes: 41 additions & 29 deletions src/MapfileStyleParser.ts
Expand Up @@ -629,16 +629,49 @@ export class MapfileStyleParser implements StyleParser {
}

/**
* Get the GeoStyler-Style RasterSymbolizer from an Mapfile STYLE.
* Get the GeoStyler-Style ColorMap from an Mapfile LAYER.
*
* @param {object} mapfileLayer The Mapfile Style Parameters
* @param {MapfileLayer} mapfileLayer The Mapfile Layer object
* @return {ColorMap} The GeoStyler-Style ColorMap
*/
getColorMapFromMapfileLayer(mapfileLayer: MapfileLayer): ColorMap | undefined {
// color map based on the style attributes colorrange and datarange of the first class if defined
const mapfileClass = mapfileLayer.classes[0];

if (mapfileLayer.classes.length === 1 && mapfileClass.styles) {
const mapfileStyle = mapfileClass.styles[0];

if (mapfileStyle.colorrange && mapfileStyle.datarange) {
const colors = rgbRangeToHexArray(mapfileStyle.colorrange);
const values = mapfileStyle.datarange.split(' ').map((element) => parseFloat(element));
return {
type: 'ramp',
colorMapEntries: [
{ color: colors[0], quantity: values[0] },
{ color: colors[1], quantity: values[1] },
],
} as ColorMap;
}
} else {
console.warn('Raster classification not implemented!');
}
return;
}

/**
* Get the GeoStyler-Style RasterSymbolizer from an Mapfile LAYER.
*
* @param {MapfileLayer} mapfileLayer The Mapfile Layer object
* @return {RasterSymbolizer} The GeoStyler-Style RasterSymbolizer
*/
getRasterSymbolizersFromMapfileLayer(mapfileLayer: MapfileLayer): RasterSymbolizer {
const rasterSymbolizer = { kind: 'Raster' } as RasterSymbolizer;

if (mapfileLayer.composite && mapfileLayer.composite.opacity) {
rasterSymbolizer.opacity = mapfileLayer.composite.opacity / 100;
const opacity = mapfileLayer.composite?.opacity
? mapfileLayer.composite?.opacity
: mapfileLayer.classes[0]?.styles[0]?.opacity;
if (opacity) {
rasterSymbolizer.opacity = opacity / 100;
}

if (mapfileLayer.processings) {
Expand All @@ -648,7 +681,6 @@ export class MapfileStyleParser implements StyleParser {
processings[parts[0].toLowerCase()] = parts[1].toLowerCase();
});

// TODO: is this mapping ok?
switch (processings.resample) {
case 'average':
case 'bilinear':
Expand All @@ -675,31 +707,11 @@ export class MapfileStyleParser implements StyleParser {
}
}

if (mapfileLayer.classes) {
const mapfileClass = mapfileLayer.classes[0];

if (mapfileLayer.classes.length === 1 && mapfileClass.styles) {
const mapfileStyle = mapfileClass.styles[0];

if (mapfileStyle.opacity) {
rasterSymbolizer.opacity = mapfileStyle.opacity / 100;
}

if (mapfileStyle.colorrange && mapfileStyle.datarange) {
const colors = rgbRangeToHexArray(mapfileStyle.colorrange);
const values = mapfileStyle.datarange.split(' ').map((element) => parseFloat(element));
rasterSymbolizer.colorMap = {
type: 'ramp',
colorMapEntries: [
{ color: colors[0], quantity: values[0] },
{ color: colors[1], quantity: values[1] },
],
} as ColorMap;
}
} else {
console.warn('Raster classification not implemented!');
}
const colorMap = this.getColorMapFromMapfileLayer(mapfileLayer);
if (colorMap) {
rasterSymbolizer.colorMap = colorMap;
}

return rasterSymbolizer;
}

Expand Down
2 changes: 1 addition & 1 deletion src/mapfile2js/parseMapfile.ts
Expand Up @@ -54,7 +54,7 @@ function parseContent(content: string): object {
const lineObjects: Array<LineObject> = [];
// stack to keep track of blocks
const blocks: Array<any> = [result];
let pseudoBlockKey: any = undefined;
let pseudoBlockKey: any;
// split content into trimmed lines like Van Damme
const lines = content.split(/\s*(?:\r\n?|\n)\s*/g);
// iterate over lines
Expand Down

0 comments on commit e9f9a53

Please sign in to comment.