Skip to content

Commit

Permalink
Merge pull request #489 from geostyler/basic-check
Browse files Browse the repository at this point in the history
Add some basic type checks
  • Loading branch information
KaiVolland authored Nov 29, 2024
2 parents debc79d + 25eb984 commit 7cfdcce
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-react-hooks": "^4.2.0",
"extensionless": "^1.9.9",
"geostyler-style": "9.2.0",
"geostyler-style": "^9.2.0",
"jsdom": "^24.1.0",
"ol": "^9.1.0",
"rimraf": "^3.0.2",
Expand Down
13 changes: 13 additions & 0 deletions src/LegendRenderer/LegendRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import OlGeomPolygon from 'ol/geom/Polygon';
import OlGeomLineString from 'ol/geom/LineString';
import OlStyle from 'ol/style/Style';
import Renderer from 'ol/render/canvas/Immediate';
import {
isRule,
isSymbolizer
} from 'geostyler-style';
import { create as createTransform } from 'ol/transform';
import {
Style,
Expand Down Expand Up @@ -126,6 +130,10 @@ export class LegendRenderer {
* @param {Symbolizer} symbolizer the symbolizer object
*/
getGeometryForSymbolizer(symbolizer: Symbolizer): OlGeometry {
if (!isSymbolizer(symbolizer)) {
throw new Error('Invalid symbolizer');
}

const kind = symbolizer.kind;
switch (kind) {
case 'Mark':
Expand Down Expand Up @@ -154,6 +162,10 @@ export class LegendRenderer {
* @param {Object} rule the geostyler rule
*/
getRuleIcon(rule: Rule): Promise<string> {
if (!isRule(rule)) {
return Promise.reject('Invalid rule');
}

const canvas = document.createElement('canvas');
canvas.setAttribute('width', `${iconSize[0]}`);
canvas.setAttribute('height', `${iconSize[1]}`);
Expand All @@ -163,6 +175,7 @@ export class LegendRenderer {
const transform = createTransform();
const renderer = new Renderer(context as CanvasRenderingContext2D, pixelRatio, extent, transform, 0);
const geoms: OlGeometry[] = [];

rule.symbolizers.forEach(symbolizer => geoms.push(this.getGeometryForSymbolizer(symbolizer)));

const styleParser = new OlStyleParser();
Expand Down

0 comments on commit 7cfdcce

Please sign in to comment.