Skip to content

Commit

Permalink
Fix #787 markers: add gotoMarkerSpeed option
Browse files Browse the repository at this point in the history
  • Loading branch information
mistic100 committed Nov 27, 2022
1 parent f763c22 commit 109b53e
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 9 deletions.
8 changes: 7 additions & 1 deletion docs/plugins/plugin-markers.md
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,12 @@ lang: {

_Note: this option is not part of the plugin but is merged with the main [`lang`](../guide/config.md#lang) object._

#### `gotoMarkerSpeed` <Badge text="4.8.1"/>
- type: `string|number`
- default `'8rpm'`

Default animation speed for `gotoMarker` method.

#### `clickEventOnMarker`
- type: `boolean`
- default: `false`
Expand Down Expand Up @@ -529,7 +535,7 @@ Returns the last marker clicked by the user.
Moves the view to face a specific marker.

```js
markersPlugin.gotoMarker('marker-1', 1500)
markersPlugin.gotoMarker('marker-1', '4rpm')
.then(() => /* animation complete */);
```

Expand Down
8 changes: 4 additions & 4 deletions example/plugin-markers.html
Original file line number Diff line number Diff line change
Expand Up @@ -426,11 +426,11 @@ <h2>Lorem ipsum</h2>
});

// add markers all hover the sphere
for (let i = 0; i < Math.PI * 2; i += Math.PI / 4) {
for (let j = -Math.PI / 2 + Math.PI / 4; j < Math.PI / 2; j += Math.PI / 4) {
for (let i = 0, k = 1; i < Math.PI * 2; i += Math.PI / 4) {
for (let j = -Math.PI / 2 + Math.PI / 4; j < Math.PI / 2; j += Math.PI / 4, k++) {
a.push({
id : '#' + a.length,
tooltip : '#' + a.length,
id : '#' + k,
tooltip : '#' + k,
latitude : j,
longitude: i,
image : 'assets/pin-red.png',
Expand Down
12 changes: 10 additions & 2 deletions src/Viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ import { Notification } from './components/Notification';
import { Overlay } from './components/Overlay';
import { Panel } from './components/Panel';
import { CONFIG_PARSERS, DEFAULTS, DEPRECATED_OPTIONS, getConfig, READONLY_OPTIONS } from './data/config';
import { CHANGE_EVENTS, DEFAULT_TRANSITION, EVENTS, IDS, SPHERE_RADIUS, VIEWER_DATA } from './data/constants';
import {
ANIMATION_MIN_DURATION,
CHANGE_EVENTS,
DEFAULT_TRANSITION,
EVENTS,
IDS,
SPHERE_RADIUS,
VIEWER_DATA
} from './data/constants';
import { SYSTEM } from './data/system';
import errorIcon from './icons/error.svg';
import { AbstractPlugin } from './plugins/AbstractPlugin';
Expand Down Expand Up @@ -877,7 +885,7 @@ export class Viewer extends EventEmitter {

this.prop.animationPromise = new Animation({
properties: animProperties,
duration : duration,
duration : Math.max(ANIMATION_MIN_DURATION, duration),
easing : 'inOutSine',
onTick : (properties) => {
if (positionProvided) {
Expand Down
8 changes: 8 additions & 0 deletions src/data/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
*/
export const DEFAULT_TRANSITION = 1500;

/**
* @summary Minimum duration of the animations created with {@link Viewer#animate}
* @memberOf PSV.constants
* @type {number}
* @constant
*/
export const ANIMATION_MIN_DURATION = 500;

/**
* @summary Number of pixels bellow which a mouse move will be considered as a click
* @memberOf PSV.constants
Expand Down
6 changes: 4 additions & 2 deletions src/plugins/markers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import './style.scss';
/**
* @typedef {Object} PSV.plugins.MarkersPlugin.Options
* @property {boolean} [clickEventOnMarker=false] If a `click` event is triggered on the viewer additionally to the `select-marker` event.
* @property {string | number} [gotoMarkerSpeed=8rpm] Default animation speed for `gotoMarker` method
* @property {PSV.plugins.MarkersPlugin.Properties[]} [markers]
*/

Expand Down Expand Up @@ -82,6 +83,7 @@ export class MarkersPlugin extends AbstractPlugin {
*/
this.config = {
clickEventOnMarker: false,
gotoMarkerSpeed: '8rpm',
...options,
};

Expand Down Expand Up @@ -438,7 +440,7 @@ export class MarkersPlugin extends AbstractPlugin {
* @fires PSV.plugins.MarkersPlugin.goto-marker-done
* @return {PSV.utils.Animation} A promise that will be resolved when the animation finishes
*/
gotoMarker(markerId, speed) {
gotoMarker(markerId, speed = this.config.gotoMarkerSpeed) {
const marker = this.getMarker(markerId);

return this.psv.animate({
Expand Down Expand Up @@ -560,7 +562,7 @@ export class MarkersPlugin extends AbstractPlugin {

this.trigger(EVENTS.SELECT_MARKER_LIST, marker);

this.gotoMarker(marker, 1000);
this.gotoMarker(marker);
this.hideMarkersList();
}
},
Expand Down
1 change: 1 addition & 0 deletions types/plugins/markers/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export type SelectMarkerData = {

export type MarkersPluginOptions = {
clickEventOnMarker?: boolean;
gotoMarkerSpeed?: string | number;
markers?: MarkerProperties[];
};

Expand Down

0 comments on commit 109b53e

Please sign in to comment.