Skip to content

Commit

Permalink
feat: Dynamic add hotspots
Browse files Browse the repository at this point in the history
  • Loading branch information
Amr Wagdy committed Sep 25, 2023
1 parent 853cc4f commit 39469ed
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ Types of changes:
- ...

-------------
## 3.2.0 - 2023-09-25
### Added
- Possibility to add hotspots dynamically

## 3.1.1 - 2023-04-19
### Fixed
- Remove CVE vulnerabilities
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "js-cloudimage-360-view",
"version": "3.1.1",
"version": "3.2.0",
"main": "dist/index.js",
"description": "",
"author": "scaleflex",
Expand Down
12 changes: 9 additions & 3 deletions src/ci360.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ class CI360Viewer {
window.clearTimeout(this.loopTimeoutId);
}

updateView(forceUpdate, viewers) {
updateView(forceUpdate, viewers, hotspotConfigs) {
let container = this.container;

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

this.stop();
this.init(container, true);
this.init(container, true, hotspotConfigs);
}

destroy() {
Expand Down Expand Up @@ -1273,7 +1273,7 @@ class CI360Viewer {
document.addEventListener('keydown', this.keyDownGeneral.bind(this));
}

init(container, update = false) {
init(container, update = false, hotspotsConfigs = null) {
let {
folder, apiVersion, filenameX, filenameY, imageListX, imageListY, indexZeroBase, amountX, amountY, draggable = true, swipeable = true, keys, keysReverse, bottomCircle, bottomCircleOffset, boxShadow,
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
Expand Down Expand Up @@ -1351,6 +1351,12 @@ class CI360Viewer {
this.boxShadowEl = createBoxShadow(this.boxShadow, this.innerBox);
}


if (hotspotsConfigs && !this.fullscreenView) {
this.hotspotsConfigs = generateHotspotsConfigs(hotspotsConfigs);
createHotspots(container, this.hotspotsConfigs);
}

return this.onAllImagesLoaded();
}

Expand Down
22 changes: 16 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,17 @@ function add(id) {
}
}

function update(id = null, forceUpdate = false) {
function update(id = null, forceUpdate = false, hotspotConfigs = null) {
if (id) {
const view = window.CI360._viewers.filter(viewer => viewer.id === id)[0];
view.updateView(forceUpdate, window.CI360._viewers);

if (hotspotConfigs) {
const view360Array = document.querySelectorAll('.cloudimage-360');
const container = Array.from(view360Array).find((view) => view.id === id);
container.setAttribute('data-hotspots', true);
}

view.updateView(forceUpdate, window.CI360._viewers, hotspotConfigs);
} else {
window.CI360._viewers
.forEach(viewer => { viewer.updateView(forceUpdate, window.CI360._viewers); });
Expand All @@ -80,11 +87,14 @@ function isNoViewers() {

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

if (container) {
window.CI360._viewers.push(new CI360Viewer(container, false, config))
if (notInitializedContainer) {
container.setAttribute('data-hotspots', true)

return window.CI360._viewers.push(new CI360Viewer(container, false, config))
} else {
update(instanceId, false, config)
}
}

Expand Down

0 comments on commit 39469ed

Please sign in to comment.