Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/OlStyleParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,7 @@ export class OlStyleParser implements StyleParser {
* @return {object} The OpenLayers Style object or a StyleFunction
*/
getOlSymbolizerFromSymbolizer(symbolizer: Symbolizer): any {
let addGeomFunction = true;
let olSymbolizer: any;
switch (symbolizer.kind) {
case 'Mark':
Expand All @@ -696,9 +697,11 @@ export class OlStyleParser implements StyleParser {
olSymbolizer = this.getOlTextSymbolizerFromTextSymbolizer(symbolizer);
break;
case 'Line':
addGeomFunction = false;
olSymbolizer = this.getOlLineSymbolizerFromLineSymbolizer(symbolizer);
break;
case 'Fill':
addGeomFunction = false;
olSymbolizer = this.getOlPolygonSymbolizerFromFillSymbolizer(symbolizer);
break;
default:
Expand All @@ -722,6 +725,25 @@ export class OlStyleParser implements StyleParser {
});
break;
}

// We can only add the geometry function if the style allows for it
if (typeof olSymbolizer.setGeometry !== 'function') {
addGeomFunction = false;
}

// Allow for polygon geometries to be styled as a point
// TODO: should we cater for MultiPolygons (getInteriorPoints())?
if (addGeomFunction) {
const geomFunction = function (feature: any) {
const geom = feature.getGeometry();
const geomHasInteriorPoint = typeof geom.getInteriorPoint === 'function';

return geomHasInteriorPoint ? geom.getInteriorPoint() : geom;
};

olSymbolizer.setGeometry(geomFunction);
}

return olSymbolizer;
}

Expand Down