Skip to content

Commit

Permalink
Close #1235 markers: add "rotation" option
Browse files Browse the repository at this point in the history
  • Loading branch information
mistic100 committed Feb 13, 2024
1 parent a5da3a0 commit f382d5f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
8 changes: 8 additions & 0 deletions docs/plugins/markers.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,14 @@ Size of the marker in pixels.

_(This option is ignored for polygons and polylines)._

#### `rotation`

- type: `string | number`

Rotation applied to the marker, in degrees or radians.

_(This option is ignored for polygons and polylines)._

#### `orientation` (only for `imageLayer`, `videoLayer`)

- type: `'front' | 'horizontal' | 'vertical-left' | 'vertical-right'`
Expand Down
4 changes: 4 additions & 0 deletions packages/markers-plugin/src/markers/AbstractStandardMarker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ export abstract class AbstractStandardMarker extends AbstractDomMarker {
...this.config.hoverScale,
};
}

if (!utils.isNil(this.config.rotation)) {
element.style.rotate = MathUtils.radToDeg(this.config.rotation) + 'deg';
}
}

/**
Expand Down
3 changes: 3 additions & 0 deletions packages/markers-plugin/src/markers/Marker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ export abstract class Marker {
if (utils.isNil(this.config.opacity)) {
this.config.opacity = 1;
}
if (!utils.isNil(this.config.rotation)) {
this.config.rotation = utils.parseAngle(this.config.rotation);
}

this.state.anchor = utils.parsePoint(this.config.anchor);
}
Expand Down
1 change: 1 addition & 0 deletions packages/markers-plugin/src/markers/Marker3D.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export class Marker3D extends Marker {
this.state.size = this.config.size;

mesh.position.set(0.5 - this.state.anchor.x, this.state.anchor.y - 0.5, 0);
mesh.rotation.set(0, 0, -this.config.rotation ?? 0);
this.viewer.dataHelper.sphericalCoordsToVector3(this.state.position, group.position);

group.lookAt(0, group.position.y, 0);
Expand Down
7 changes: 6 additions & 1 deletion packages/markers-plugin/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ export type MarkerConfig = {
* Size of the marker (required for `image`, recommended for `html`, ignored for others)
*/
size?: Size;
/**
* Rotation applied to the marker (ignored for `polygon` and `polyline`)
*/
rotation?: string | number;
/**
* Applies a perspective on the image to make it look like placed on the floor or on a wall (only for `imageLayer`)
*/
Expand Down Expand Up @@ -185,7 +189,8 @@ export type MarkerConfig = {
data?: any;
};

export type ParsedMarkerConfig = Omit<MarkerConfig, 'scale' | 'tooltip' | 'hoverScale'> & {
export type ParsedMarkerConfig = Omit<MarkerConfig, 'rotation' | 'scale' | 'tooltip' | 'hoverScale'> & {
rotation?: number;
scale?:
| { zoom?: [number, number]; yaw?: [number, number] }
| ((zoomLevel: number, position: Position) => number);
Expand Down

0 comments on commit f382d5f

Please sign in to comment.