Skip to content

Commit 39469ed

Browse files
author
Amr Wagdy
committed
feat: Dynamic add hotspots
1 parent 853cc4f commit 39469ed

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ Types of changes:
2525
- ...
2626

2727
-------------
28+
## 3.2.0 - 2023-09-25
29+
### Added
30+
- Possibility to add hotspots dynamically
31+
2832
## 3.1.1 - 2023-04-19
2933
### Fixed
3034
- Remove CVE vulnerabilities

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "js-cloudimage-360-view",
3-
"version": "3.1.1",
3+
"version": "3.2.0",
44
"main": "dist/index.js",
55
"description": "",
66
"author": "scaleflex",

src/ci360.service.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ class CI360Viewer {
10331033
window.clearTimeout(this.loopTimeoutId);
10341034
}
10351035

1036-
updateView(forceUpdate, viewers) {
1036+
updateView(forceUpdate, viewers, hotspotConfigs) {
10371037
let container = this.container;
10381038

10391039
const imageProps = get360ViewProps(container);
@@ -1060,7 +1060,7 @@ class CI360Viewer {
10601060
container.setAttribute('draggable', 'false');
10611061

10621062
this.stop();
1063-
this.init(container, true);
1063+
this.init(container, true, hotspotConfigs);
10641064
}
10651065

10661066
destroy() {
@@ -1273,7 +1273,7 @@ class CI360Viewer {
12731273
document.addEventListener('keydown', this.keyDownGeneral.bind(this));
12741274
}
12751275

1276-
init(container, update = false) {
1276+
init(container, update = false, hotspotsConfigs = null) {
12771277
let {
12781278
folder, apiVersion, filenameX, filenameY, imageListX, imageListY, indexZeroBase, amountX, amountY, draggable = true, swipeable = true, keys, keysReverse, bottomCircle, bottomCircleOffset, boxShadow,
12791279
autoplay, autoplayBehavior, playOnce, speed, autoplayReverse, disableDrag = true, fullscreen, magnifier, ciToken, ciFilters, ciTransformation, lazyload, lazySelector, spinReverse, dragSpeed, stopAtEdges, controlReverse, hide360Logo, logoSrc, pointerZoom, ratio, imageInfo = 'black', requestResponsiveImages
@@ -1351,6 +1351,12 @@ class CI360Viewer {
13511351
this.boxShadowEl = createBoxShadow(this.boxShadow, this.innerBox);
13521352
}
13531353

1354+
1355+
if (hotspotsConfigs && !this.fullscreenView) {
1356+
this.hotspotsConfigs = generateHotspotsConfigs(hotspotsConfigs);
1357+
createHotspots(container, this.hotspotsConfigs);
1358+
}
1359+
13541360
return this.onAllImagesLoaded();
13551361
}
13561362

src/index.js

+16-6
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,17 @@ function add(id) {
6464
}
6565
}
6666

67-
function update(id = null, forceUpdate = false) {
67+
function update(id = null, forceUpdate = false, hotspotConfigs = null) {
6868
if (id) {
6969
const view = window.CI360._viewers.filter(viewer => viewer.id === id)[0];
70-
view.updateView(forceUpdate, window.CI360._viewers);
70+
71+
if (hotspotConfigs) {
72+
const view360Array = document.querySelectorAll('.cloudimage-360');
73+
const container = Array.from(view360Array).find((view) => view.id === id);
74+
container.setAttribute('data-hotspots', true);
75+
}
76+
77+
view.updateView(forceUpdate, window.CI360._viewers, hotspotConfigs);
7178
} else {
7279
window.CI360._viewers
7380
.forEach(viewer => { viewer.updateView(forceUpdate, window.CI360._viewers); });
@@ -80,11 +87,14 @@ function isNoViewers() {
8087

8188
function addHotspots(instanceId, config) {
8289
const view360Array = document.querySelectorAll('.cloudimage-360:not(.initialized)');
83-
const container = Array.from(view360Array)
84-
.find(view => view.id === instanceId);
90+
const notInitializedContainer = Array.from(view360Array).find(view => view.id === instanceId);
8591

86-
if (container) {
87-
window.CI360._viewers.push(new CI360Viewer(container, false, config))
92+
if (notInitializedContainer) {
93+
container.setAttribute('data-hotspots', true)
94+
95+
return window.CI360._viewers.push(new CI360Viewer(container, false, config))
96+
} else {
97+
update(instanceId, false, config)
8898
}
8999
}
90100

0 commit comments

Comments
 (0)