Skip to content

Commit

Permalink
Merge pull request #61 from geostyler/fix-types
Browse files Browse the repository at this point in the history
fix: typing
  • Loading branch information
ger-benjamin authored Nov 4, 2024
2 parents 18c4965 + 2c6a239 commit 8cd7222
Show file tree
Hide file tree
Showing 19 changed files with 651 additions and 465 deletions.
6 changes: 6 additions & 0 deletions .idea/jsLinters/eslint.xml

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

43 changes: 0 additions & 43 deletions src/badTypes.ts

This file was deleted.

8 changes: 8 additions & 0 deletions src/esri/types/labeling/CIMSymbolReference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@ import { CIMSymbol } from '../symbols/index.ts';
type CIMPrimitiveOverride = {};
type CIMScaleDependentSizeVariation = {};


export type Geometry = {
rings?: number[][][];
paths?: number[][][];
curveRings?: { a?: number[][]; c?: number[][] }[][];
};

/**
* Represents a symbol reference.
*
*/
export type CIMSymbolReference = {
geometry: Geometry;
/**
* Gets or sets the primitive overrides. Typically set by renderers at draw time.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/esri/types/layers/CIMFeatureLayer.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { CIMLayerAction } from '../CIMLayerAction.ts';
import { CIMLayerDefinition } from './CIMLayerDefinition.ts';
import { CIMRenderer } from '../renderers/CIMRenderer.ts';
import { CIMLabelClass } from '../labeling/CIMLabelClass.ts';
import { CIMSymbolReference } from '../labeling/CIMSymbolReference.ts';
import {CIMRenderer} from '../renderers';

type CIMDataConnection = {};
type CIMSymbolLayerMasking = {};
Expand Down
17 changes: 17 additions & 0 deletions src/esri/types/renderers/CIMBreaksRenderer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {CIMRenderer, Group } from './CIMRenderer.ts';
import {CIMSymbolReference} from '../labeling';

export type CIMBreaksRenderer = CIMRenderer & {
classBreakType: string;
defaultSymbol?: CIMSymbolReference;
field: string;
groups?: Group[];
showInAscendingOrder: boolean;
breaks: {
type: string;
fieldValues: string[];
label: string;
symbol: CIMSymbolReference;
upperBound: number;
}[];
};
42 changes: 34 additions & 8 deletions src/esri/types/renderers/CIMRenderer.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,38 @@
import { CIMObject } from '../CIMObject.ts';
import {CIMObject} from '../CIMObject.ts';
import {CIMSymbolReference} from '../labeling';

type Group = {};
type SymbolReference = {};

export type Class = {
alternateSymbols: CIMSymbolReference[];
label: string;
filter: string;
symbol: CIMSymbolReference;
minValue?: number;
maxValue?: number;
breakCount?: number;
breakValues?: number[];
breakLabels?: string[];
breakSymbols?: CIMSymbolReference[];
values: {
type: string;
fieldValues: string[];
}[];
};

export type Group = {
classes: Class[];
};

export type VisualVariable = CIMObject & {
rotationTypeZ: string;
visualVariableInfoZ: {
expression: string;
valueExpressionInfo: {
expression: string;
};
};
};

export type CIMRenderer = CIMObject & {
type: string;
fields?: string[];
groups?: Group[];
defaultSymbol?: SymbolReference;
classBreakType?: string;
visualVariables?: VisualVariable[];
};
7 changes: 7 additions & 0 deletions src/esri/types/renderers/CIMSimpleRenderer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {CIMRenderer} from './CIMRenderer.ts';
import {CIMSymbolReference} from '../labeling';

export type CIMSimpleRenderer = CIMRenderer & {
label: string;
symbol: CIMSymbolReference;
};
8 changes: 6 additions & 2 deletions src/esri/types/renderers/CIMUniqueValueRenderer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import {CIMRenderer, Group} from './CIMRenderer.ts';
import {CIMSymbolReference} from '../labeling';

export type CIMUniqueValueRenderer = {

export type CIMUniqueValueRenderer = CIMRenderer & {
defaultSymbol?: CIMSymbolReference;
fields?: string[];
groups?: Group[];
};
40 changes: 39 additions & 1 deletion src/esri/types/symbols/CIMSymbol.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
import { CIMObject } from '../CIMObject.ts';
import {CIMColor} from './CIMTextSymbol.ts';
import {CIMSymbolReference} from '../labeling';

export type CIMSymbol = CIMObject & {};
export type CIMColorType = CIMColor & CIMObject;

export type CIMMarkerPlacement = CIMObject & {
angleToLine: boolean;
extremityPlacement: string;
flipFirst: boolean;
placementTemplate: number[];
positionArray: number[];
};

export type CIMEffect = CIMObject & {
dashTemplate: number[];
offset: number;
};

export type SymbolLayer = CIMObject & {
capStyle: string;
characterIndex: number;
color: CIMColorType;
effects: CIMEffect[];
enable: boolean;
fontFamilyName: string;
joinStyle: string;
lineSymbol: CIMSymbol;
markerPlacement: CIMMarkerPlacement;
markerGraphics: CIMSymbolReference[];
rotateClockwise: boolean;
rotation: number;
separation: number;
size: number;
symbol: CIMSymbol;
};

export type CIMSymbol = CIMObject & {
enabled: boolean;
symbolLayers?: SymbolLayer[];
};
89 changes: 58 additions & 31 deletions src/expressions.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,38 @@
import { LabelExpressionEngine } from './esri/types/index.ts';
import {ComparisonOperator, Filter} from 'geostyler-style';
import {
CombinationFilter,
ComparisonOperator,
Filter,
Fproperty,
GeoStylerNumberFunction
} from 'geostyler-style';
import {WARNINGS} from './toGeostylerUtils.ts';

export const fieldToFProperty = (field: string, toLowerCase: boolean): Fproperty => {
return {
args: [toLowerCase ? field.toLowerCase() : field],
name: 'property',
};
};

export const andFilter = (filters: Filter[]): CombinationFilter => {
return ['&&', ...filters];
};

export const orFilter = (conditions: Filter[]): CombinationFilter => {
return ['||', ...conditions];
};

export const equalFilter = (name: string, val: string, toLowerCase: boolean): Filter => {
return getSimpleFilter('==', name, val, toLowerCase);
};

export const getSimpleFilter = (
operator: ComparisonOperator,
value1: string, value2: string,
toLowerCase=true): Filter => {
value1: string,
value2: string,
toLowerCase=true
): Filter => {
return [operator, stringToParameter(value1, toLowerCase), stringToParameter(value2, toLowerCase)];
};

Expand Down Expand Up @@ -35,66 +63,65 @@ export const convertExpression = (
return processPropertyName(expression);
};


export const convertWhereClause = (clause: string, toLowerCase: boolean): any => {
export const convertWhereClause = (clause: string, toLowerCase: boolean): Filter => {
clause = clause.replace('(', '').replace(')', '');
const expression = [];
if (clause.includes(' AND ')) {
expression.push('And');
let subexpressions = clause.split(' AND ').map(s => s.trim());
expression.push(...subexpressions.map(s => convertWhereClause(s, toLowerCase)));
return expression;
const subexpressions = clause.split(' AND ').map(s => s.trim());
return andFilter(subexpressions.map(s => convertWhereClause(s, toLowerCase)));
}
if (clause.includes('=')) {
let tokens = clause.split('=').map(t => t.trim());
const tokens = clause.split('=').map(t => t.trim());
return getSimpleFilter('==', tokens[0], tokens[1], toLowerCase);
}
if (clause.includes('<>')) {
let tokens = clause.split('<>').map(t => t.trim());
const tokens = clause.split('<>').map(t => t.trim());
return getSimpleFilter('!=', tokens[0], tokens[1], toLowerCase);
}
if (clause.includes('>')) {
let tokens = clause.split('>').map(t => t.trim());
const tokens = clause.split('>').map(t => t.trim());
return getSimpleFilter('>', tokens[0], tokens[1], toLowerCase);
}
if (clause.toLowerCase().includes(' in ')) {
clause = clause.replace(' IN ', ' in ');
let tokens = clause.split(' in ');
let attribute = tokens[0];
const tokens = clause.split(' in ');
const attribute = tokens[0];
let values: string[] = [];
if (tokens[1].startsWith('() ')) {
values = tokens[1].substring(3).split(',');
}
let subexpressions = [];
for (let v of values) {
subexpressions.push([
'PropertyIsEqualTo',
stringToParameter(attribute, toLowerCase), stringToParameter(v, toLowerCase)
]);
}
const subexpressions: Filter[] = [];
values.forEach(value => {
subexpressions.push(
getSimpleFilter(
'==',
`${stringToParameter(attribute, toLowerCase)}`,
`${stringToParameter(value, toLowerCase)}`
)
);
});
if (values.length === 1) {
return subexpressions[0];
}

let accum: any = ['Or', subexpressions[0], subexpressions[1]];
let accum: Filter = orFilter([subexpressions[0], subexpressions[1]]);
for (let subexpression of subexpressions.slice(2)) {
accum = ['Or', accum, subexpression];
accum = orFilter([accum, subexpression]);
}
return accum;
}
return clause;
WARNINGS.push(`Clause skipped because it is not supported as filter: ${clause}}`);
return ['==', 0, 0];
};

export const processRotationExpression = (
expression: string,
rotationType: string,
toLowerCase: boolean): [string, string[], number] | null => {
let field = expression.includes('$feature') ? convertArcadeExpression(expression) : processPropertyName(expression);
let propertyNameExpression = ['PropertyName', toLowerCase ? field.toLowerCase() : field];
toLowerCase: boolean): GeoStylerNumberFunction | null => {
const field = expression.includes('$feature') ? convertArcadeExpression(expression) : processPropertyName(expression);
const fProperty: Fproperty = fieldToFProperty(field, toLowerCase);
if (rotationType === 'Arithmetic') {
return ['Mul', propertyNameExpression, -1];
return { args: [fProperty, -1], name: 'mul' };
} else if (rotationType === 'Geographic') {
return ['Sub', propertyNameExpression, 90];
return { args: [fProperty, 90], name: 'sub' };
}
return null;
};
Expand Down
Loading

0 comments on commit 8cd7222

Please sign in to comment.