Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
HARP-10452: Merge the style and the technique parameters.
Browse files Browse the repository at this point in the history
Before this change the member "attr" was used to set the technique
parameters and the style properties where stored in enclosing object.
This was inconsitent and confusing, for example `textMinZoomLevel`
was a member of "attr" but "minZoomLevel" was a member of style.

Signed-off-by: Roberto Raggi <roberto.raggi@here.com>
  • Loading branch information
robertoraggi committed May 15, 2020
1 parent 748b036 commit d8b3dfe
Show file tree
Hide file tree
Showing 12 changed files with 5,253 additions and 6,361 deletions.
28 changes: 17 additions & 11 deletions @here/harp-datasource-protocol/lib/StyleSetEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import {
Definitions,
isActualSelectorDefinition,
isJsonExprReference,
LineStyle,
Style,
StyleDeclaration,
StyleSelector,
Expand Down Expand Up @@ -815,17 +814,24 @@ export class StyleSetEvaluator {
}
};

processAttribute("_category", style.category);
processAttribute("_secondaryCategory", (style as LineStyle).secondaryCategory);
const replacement = new Map<string, string>([
["category", "_category"],
["secondaryCategory", "_secondaryCategory"]
]);

processAttribute("renderOrder", style.renderOrder);

// TODO: What the heck is that !?
processAttribute("label", style.labelProperty);

// line & solid-line secondaryRenderOrder should be generic attr
// TODO: maybe just warn and force move it to `attr` ?
processAttribute("secondaryRenderOrder", (style as LineStyle).secondaryRenderOrder);
for (const p in style) {
if (!style.hasOwnProperty(p)) {
continue;
}
if (p.startsWith("_")) {
continue;
}
if (["when", "technique", "layer", "attr", "description"].includes(p)) {
continue;
}
const pp = replacement.get(p) ?? p;
processAttribute(pp, (style as any)[p]);
}

if (style.attr !== undefined) {
for (const attrName in style.attr) {
Expand Down
34 changes: 17 additions & 17 deletions @here/harp-datasource-protocol/lib/TechniqueParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,15 @@ export interface BaseTechniqueParams {
* If not specified in style file, [[StyleSetEvaluator]] will assign monotonically increasing
* values according to style position in file.
*/
renderOrder: number;
renderOrder?: DynamicProperty<number>;

/**
* The category of this technique.
*
* The category is used in conjunction with [[Theme.priorities]]
* to assign render orders to the objects created by this [[Style]].
*/
category?: string;
category?: DynamicProperty<string>;

/**
* Optional. If `true`, no IDs will be saved for the geometry this technique creates.
Expand Down Expand Up @@ -487,7 +487,7 @@ export interface MarkerTechniqueParams extends BaseTechniqueParams {
*
* See [[ExtendedTileInfo.getFeatureText]]
*/
text?: string;
text?: DynamicProperty<string>;

/**
* Field name of object containing the text to be rendered.
Expand Down Expand Up @@ -658,7 +658,7 @@ export interface MarkerTechniqueParams extends BaseTechniqueParams {
/**
* Name of [[ImageTexture]] definition to use.
*/
imageTexture?: string;
imageTexture?: DynamicProperty<string>;
/**
* Field name to extract imageTexture content from.
*/
Expand Down Expand Up @@ -778,7 +778,7 @@ export interface MarkerTechniqueParams extends BaseTechniqueParams {
* World space offset in meters applied to the icon. Valid only for icons which have the
* "offset_direction" property as an attribute of the data.
*/
worldOffset?: number;
worldOffset?: DynamicProperty<number>;
}

export interface LineTechniqueParams extends BaseTechniqueParams {
Expand Down Expand Up @@ -928,7 +928,7 @@ export interface BasicExtrudedLineTechniqueParams
* Style of both end caps. Possible values: `"None"`, `"Circle"`. A value of undefined maps to
* `"Circle"`.
*/
caps?: "None" | "Circle";
caps?: DynamicProperty<"None" | "Circle">;
}

/**
Expand All @@ -953,7 +953,7 @@ export interface StandardExtrudedLineTechniqueParams
* Style of both end caps. Possible values: `"None"`, `"Circle"`. A value of undefined maps to
* `"Circle"`.
*/
caps?: "None" | "Circle";
caps?: DynamicProperty<"None" | "Circle">;
}

/**
Expand Down Expand Up @@ -999,12 +999,12 @@ export interface SolidLineTechniqueParams extends BaseTechniqueParams, Polygonal
/**
* Clip the line outside the tile if `true`.
*/
clipping?: boolean;
clipping?: DynamicProperty<boolean>;
/**
* Describes line caps type (`"None"`, `"Round"`, `"Square"`, `"TriangleOut"`, `"TriangleIn"`).
* Default is `"Round"`.
*/
caps?: LineCaps;
caps?: DynamicProperty<LineCaps>;
/**
* Color of secondary line geometry in hexadecimal or CSS-style notation, for example:
* `"#e4e9ec"`, `"#fff"`, `"rgb(255, 0, 0)"`, or `"hsl(35, 11%, 88%)"`.
Expand All @@ -1018,17 +1018,17 @@ export interface SolidLineTechniqueParams extends BaseTechniqueParams, Polygonal
/**
* The render order of the secondary line geometry object created using this technique.
*/
secondaryRenderOrder?: number;
secondaryRenderOrder?: DynamicProperty<number>;
/**
* Describes secondary line caps type (`"None"`, `"Round"`, `"Square"`, `"TriangleOut"`,
* `"TriangleIn"`).
* Default is `"Round"`.
*/
secondaryCaps?: LineCaps;
secondaryCaps?: DynamicProperty<LineCaps>;
/**
* Describes the category of the secondary geometry object created using this technique.
*/
secondaryCategory?: string;
secondaryCategory?: DynamicProperty<string>;
/**
* Describes the starting drawing position for the line (in the range [0...1]).
* Default is `0.0`.
Expand All @@ -1043,7 +1043,7 @@ export interface SolidLineTechniqueParams extends BaseTechniqueParams, Polygonal
* Describes line dash type (`"Round"`, `"Square"`, `"Diamond"`).
* Default is `"Square"`.
*/
dashes?: LineDashes;
dashes?: DynamicProperty<LineDashes>;
/**
* Color of a line dashes in hexadecimal or CSS-style notation,
* for example: `"#e4e9ec"`, `"#fff"`, `"rgb(255, 0, 0)"`, or `"hsl(35, 11%, 88%)"`.
Expand All @@ -1061,7 +1061,7 @@ export interface SolidLineTechniqueParams extends BaseTechniqueParams, Polygonal
/**
* Size in world units how far to offset the line perpendicular to its direction.
*/
offset?: number;
offset?: DynamicProperty<number>;
}

/**
Expand Down Expand Up @@ -1138,14 +1138,14 @@ export interface ExtrudedPolygonTechniqueParams extends StandardTechniqueParams
*
* Usually, unique per feature, so defaults to `["get", "height"]`.
*/
height?: number;
height?: DynamicProperty<number>;

/**
* Height of "floor" of extruded polygon in world units of extruded polygon.
*
* Usually, unique per feature, so defaults to `["number", ["get", "min_height"], 0]`.
*/
floorHeight?: number;
floorHeight?: DynamicProperty<number>;

/**
* In some data sources, for example Tilezen, building extrusion information might be missing.
Expand Down Expand Up @@ -1260,7 +1260,7 @@ export interface TextTechniqueParams extends BaseTechniqueParams {
*
* See [[ExtendedTileInfo.getFeatureText]].
*/
text?: string;
text?: DynamicProperty<string>;

/**
* Field name of object containing the text to be rendered.
Expand Down
111 changes: 33 additions & 78 deletions @here/harp-datasource-protocol/lib/Theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
DynamicProperty,
ExtrudedPolygonTechniqueParams,
FillTechniqueParams,
LineTechniqueParams,
MarkerTechniqueParams,
PointTechniqueParams,
SegmentsTechniqueParams,
Expand Down Expand Up @@ -465,7 +466,7 @@ export type StyleSet = StyleDeclaration[];
* tile. [[Style]] is describing which features are shown on a map and in what way they are being
* shown.
*/
export interface BaseStyle {
export type BaseStyle<Technique, Params> = Partial<Params> & {
/**
* Human readable description.
*/
Expand All @@ -486,7 +487,7 @@ export interface BaseStyle {
* techniques are possible, includes `"line"`, `"fill"`, `"solid-line"`, `"extruded-line"`,
* `"extruded-polygon"`, `"text"`, `"none"`.
*/
technique?: string;
technique: Technique;

/**
* Specify `renderOrder` of value.
Expand Down Expand Up @@ -530,7 +531,9 @@ export interface BaseStyle {
* XYZ defines the property to display as text label of a feature in the styles.
*/
labelProperty?: string;
}

attr?: Partial<Params>;
};

/**
*
Expand Down Expand Up @@ -801,121 +804,73 @@ export type Attr<T> = { [P in keyof T]?: T[P] | JsonExpr };
*
* @see [[PointTechniqueParams]].
*/
export interface SquaresStyle extends BaseStyle {
technique: "squares";
attr?: Attr<PointTechniqueParams>;
}
export type SquaresStyle = BaseStyle<"squares", PointTechniqueParams>;

/**
* Render feature as set of circles rendered in screen space.
*
* @see [[PointTechniqueParams]].
*/
export interface CirclesStyle extends BaseStyle {
technique: "circles";
attr?: Attr<PointTechniqueParams>;
}
export type CirclesStyle = BaseStyle<"circles", PointTechniqueParams>;

/**
* Render feature as POIs (icons and text) rendered in screen space.
*
* @see [[MarkerTechniqueParams]].
*/
export interface PoiStyle extends BaseStyle {
technique: "labeled-icon";
attr?: Attr<MarkerTechniqueParams>;
}
export type PoiStyle = BaseStyle<"labeled-icon", MarkerTechniqueParams>;

/**
* Render feature as line markers, which is a recurring marker along a line (usually road).
*
* @see [[MarkerTechniqueParams]].
*/
export interface LineMarkerStyle extends BaseStyle {
technique: "line-marker";
attr?: Attr<MarkerTechniqueParams>;
}
export type LineMarkerStyle = BaseStyle<"line-marker", MarkerTechniqueParams>;

/**
* Render feature as line.
*/
export interface LineStyle extends BaseStyle {
technique: "line";
secondaryRenderOrder?: number;
secondaryCategory?: string;
attr?: Attr<MarkerTechniqueParams>;
}
export type LineStyle = BaseStyle<"line", LineTechniqueParams>;

/**
* Render feature as segments.
*/
export interface SegmentsStyle extends BaseStyle {
technique: "segments";
attr?: Attr<SegmentsTechniqueParams>;
}
export type SegmentsStyle = BaseStyle<"segments", SegmentsTechniqueParams>;

export interface SolidLineStyle extends BaseStyle {
technique: "solid-line" | "dashed-line";
secondaryRenderOrder?: number;
secondaryCategory?: string;
attr?: Attr<SolidLineTechniqueParams>;
}
export type SolidLineStyle = BaseStyle<"solid-line" | "dashed-line", SolidLineTechniqueParams>;

export interface LabelRejectionLineStyle extends BaseStyle {
technique: "label-rejection-line";
attr?: Attr<BaseTechniqueParams>;
}
export type LabelRejectionLineStyle = BaseStyle<"label-rejection-line", BaseTechniqueParams>;

export interface FillStyle extends BaseStyle {
technique: "fill";
attr?: Attr<FillTechniqueParams>;
}
export type FillStyle = BaseStyle<"fill", FillTechniqueParams>;

export interface StandardStyle extends BaseStyle {
technique: "standard";
attr?: Attr<StandardTechniqueParams>;
}
export type StandardStyle = BaseStyle<"standard", StandardTechniqueParams>;

export interface TerrainStyle extends BaseStyle {
technique: "terrain";
attr?: Attr<TerrainTechniqueParams>;
}
export type TerrainStyle = BaseStyle<"terrain", TerrainTechniqueParams>;

export interface BasicExtrudedLineStyle extends BaseStyle {
technique: "extruded-line";
shading?: "basic";
attr?: Attr<BasicExtrudedLineTechniqueParams>;
}
export type BasicExtrudedLineStyle = BaseStyle<"extruded-line", BasicExtrudedLineTechniqueParams>;

export interface StandardExtrudedLineStyle extends BaseStyle {
technique: "extruded-line";
shading: "standard";
attr?: Attr<StandardExtrudedLineTechniqueParams>;
}
export type StandardExtrudedLineStyle = BaseStyle<
"extruded-line",
StandardExtrudedLineTechniqueParams
>;

/**
* Style used to draw a geometry as an extruded polygon, for example extruded buildings.
*/
export interface ExtrudedPolygonStyle extends BaseStyle {
technique: "extruded-polygon";
attr?: Attr<ExtrudedPolygonTechniqueParams>;
}
export type ExtrudedPolygonStyle = BaseStyle<"extruded-polygon", ExtrudedPolygonTechniqueParams>;

export interface ShaderStyle extends BaseStyle {
technique: "shader";
attr?: Attr<ShaderTechniqueParams>;
}
export type ShaderStyle = BaseStyle<"shader", ShaderTechniqueParams>;

export interface TextTechniqueStyle extends BaseStyle {
technique: "text";
attr?: Attr<TextTechniqueParams>;
}
export type TextTechniqueStyle = BaseStyle<"text", TextTechniqueParams>;

export interface NoneStyle extends BaseStyle {
technique: "none";
attr?: {
[name: string]: any;
};
export interface NoneStyle
extends BaseStyle<
"none",
{
[name: string]: any;
}
> {
[name: string]: any;
}

/**
Expand Down
4 changes: 1 addition & 3 deletions @here/harp-map-theme/resources/berlin_derived.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
"extrudedBuildings": {
"technique": "fill",
"when": ["ref", "extrudedBuildingsCondition"],
"attr": {
"color": "#00f"
}
"color": "#00f"
},
"countryBorderLineWidth": [
"interpolate",
Expand Down
Loading

0 comments on commit d8b3dfe

Please sign in to comment.