-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedirom-image-viewer.js
More file actions
115 lines (88 loc) · 3.87 KB
/
edirom-image-viewer.js
File metadata and controls
115 lines (88 loc) · 3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
class EdiromOpenseadragon extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' });
console.log("Constructor called");
// Load OpenSeadragon library
}
static get observedAttributes() {
return ['preserveviewport', 'clicktozoom', 'visibilityratio', 'minzoomlevel', 'maxzoomlevel', 'shownavigationcontrol', 'sequencemode', 'shownavigator', 'showzoomcontrol', 'showhomecontrol', 'showfullpagecontrol', 'showsequencecontrol', 'tilesources'];
}
attributeChangedCallback(property, oldValue, newValue) {
// handle property change
this.set(property, newValue);
}
set(property, newPropertyValue) {
// set internal and html properties
this[property] = newPropertyValue;
// custom event for property update
const event = new CustomEvent('communicate-' + property + '-update', {
detail: { [property]: newPropertyValue },
bubbles: true
});
this.dispatchEvent(event);
// further handling of property change
this.handlePropertyChange(property, newPropertyValue);
}
connectedCallback() {
console.log("Connected to DOM");
const osdScript = document.createElement('script');
osdScript.src = "https://cdnjs.cloudflare.com/ajax/libs/openseadragon/4.1.1/openseadragon.min.js";
osdScript.defer = true;
this.shadowRoot.appendChild(osdScript);
// Create a div for the OpenSeadragon viewer
this.viewerDiv = document.createElement('div');
this.viewerDiv.id = 'viewer';
this.viewerDiv.style.width = '100%';
this.viewerDiv.style.height = '100%';
this.shadowRoot.appendChild(this.viewerDiv);
// Callback when the script is loaded
osdScript.onload = () => {
if (window.OpenSeadragon) {
this.set('tilesources', this.getAttribute('tilesources'));
}
};
}
handlePropertyChange(property, newPropertyValue) {
switch(property) {
// handle tileSources property change
case 'tilesources':
this.displayOpenSeadragon();
break;
case 'showfullpagecontrol':
this.openSeaDragon.showFullPageControl = newPropertyValue === 'true';
break;
// handle default
default:
console.log("Invalid property: '"+property+"'");
}
}
displayOpenSeadragon() {
if (window.OpenSeadragon) {
if(this.openSeaDragon) {
this.openSeaDragon.destroy();
}
this.openSeaDragon = OpenSeadragon({
element: this.shadowRoot.getElementById('viewer'),
preserveViewport: this.preserveviewport,
visibilityRatio: this.visibilityratio,
minZoomLevel: this.minzoomlevel,
defaultZoomLevel: this.defaultzoomLevel,
maxZoomLevel: this.maxzoomlevel,
showNavigationControl: this.shownavigationcontrol === 'true',
tileSources: JSON.parse(this.tilesources),
showNavigator: this.shownavigator === 'true',
showZoomControl: this.showzoomcontrol === 'true',
showHomeControl: this.showhomecontrol === 'true',
showFullPageControl: this.showfullpagecontrol === 'true',
showSequenceControl: this.showsequencecontrol === 'true',
gestureSettingsMouse: {
clickToZoom: this.clicktozoom === 'true',
}
});
} else {
console.error('OpenSeadragon library is not loaded.');
}
}
}
customElements.define('edirom-openseadragon', EdiromOpenseadragon);