@@ -27,8 +27,6 @@ import {
27
27
createBoxShadow ,
28
28
getSpeedFactor ,
29
29
isCompletedOneCycle ,
30
- getContainerResponsiveWidth ,
31
- getContainerResponsiveHeight ,
32
30
getMovingDirection ,
33
31
applyStylesToContainer ,
34
32
initControls ,
@@ -39,6 +37,7 @@ import {
39
37
generateZoomInSteps ,
40
38
generateZoomOutSteps ,
41
39
isSrcPropsChanged ,
40
+ getImageAspectRatio ,
42
41
} from './utils' ;
43
42
44
43
class CI360Viewer {
@@ -648,12 +647,8 @@ import {
648
647
loop ( this . autoplayBehavior , this . spinY , reversed , loopTriggers ) ;
649
648
}
650
649
651
- updateContainerSize ( image ) {
652
- const parentEl = this . container . parentNode || { } ;
653
- const imageAspectRatio = image . width / image . height ;
654
- const isProvidedHeightLessThanWidth = this . containerHeight < this . containerWidth ;
655
- const containerWidth = getContainerResponsiveWidth ( parentEl , this . containerWidth ) ;
656
- const containerHeight = getContainerResponsiveHeight ( this . container , containerWidth , this . containerHeight ) ;
650
+ updateContainerAndCanvasSize ( image ) {
651
+ const imageAspectRatio = getImageAspectRatio ( image , this . ratio ) ;
657
652
658
653
if ( this . fullscreenView ) {
659
654
this . container . width = window . innerWidth * this . devicePixelRatio ;
@@ -665,26 +660,11 @@ import {
665
660
return ;
666
661
}
667
662
668
- if ( this . containerWidth && this . containerHeight ) {
669
- this . container . style . width = containerWidth + 'px' ;
670
- this . container . style . height = containerHeight / imageAspectRatio + 'px' ;
671
-
672
- return ;
673
- }
674
-
675
- if ( ! this . containerWidth && ! this . containerHeight ) {
676
- this . container . style . height = containerHeight / imageAspectRatio + 'px' ;
677
-
678
- return ;
679
- }
663
+ this . canvas . width = this . container . offsetWidth * this . devicePixelRatio ;
664
+ this . canvas . style . width = this . container . offsetWidth + 'px' ;
680
665
681
- if ( ( isProvidedHeightLessThanWidth || ! this . containerWidth ) && this . containerHeight ) {
682
- this . container . style . maxWidth = containerHeight * imageAspectRatio + 'px' ;
683
- this . container . style . height = containerHeight + 'px' ;
684
- } else {
685
- this . container . style . maxWidth = containerWidth + 'px' ;
686
- this . container . style . height = containerWidth / imageAspectRatio + 'px' ;
687
- }
666
+ this . canvas . height = ( this . container . offsetWidth / imageAspectRatio ) * this . devicePixelRatio ;
667
+ this . canvas . style . height = ( this . container . offsetWidth / imageAspectRatio ) + 'px' ;
688
668
}
689
669
690
670
onResizedImageLoad ( orientation , image , index ) {
@@ -715,7 +695,7 @@ import {
715
695
const responsive = this . ciParams . ciToken ;
716
696
const firstImage = this . imagesX [ 0 ] ;
717
697
718
- this . updateContainerSize ( firstImage ) ;
698
+ this . updateContainerAndCanvasSize ( firstImage ) ;
719
699
this . update ( ) ;
720
700
721
701
this . speedFactor = getSpeedFactor ( this . dragSpeed , this . amountX , this . container . offsetWidth ) ;
@@ -752,12 +732,6 @@ import {
752
732
const ctx = this . canvas . getContext ( "2d" ) ;
753
733
ctx . scale ( this . devicePixelRatio , this . devicePixelRatio ) ;
754
734
755
- this . canvas . width = this . container . offsetWidth * this . devicePixelRatio ;
756
- this . canvas . style . width = this . container . offsetWidth + 'px' ;
757
-
758
- this . canvas . height = this . container . offsetHeight * this . devicePixelRatio ;
759
- this . canvas . style . height = this . container . offsetHeight + 'px' ;
760
-
761
735
if ( this . fullscreenView ) {
762
736
const { width, height, offsetX, offsetY } =
763
737
contain ( this . canvas . width , this . canvas . height , image . width , image . height ) ;
@@ -1206,7 +1180,7 @@ import {
1206
1180
init ( container , update = false , reload = false ) {
1207
1181
let {
1208
1182
folder, apiVersion, filenameX, filenameY, imageListX, imageListY, indexZeroBase, amountX, amountY, draggable = true , swipeable = true , keys, keysReverse, bottomCircle, bottomCircleOffset, boxShadow,
1209
- autoplay, autoplayBehavior, playOnce, speed, autoplayReverse, disableDrag = true , fullscreen, magnifier, ciToken, ciFilters, ciTransformation, lazyload, lazySelector, spinReverse, dragSpeed, stopAtEdges, controlReverse, hide360Logo, logoSrc, containerWidth , containerHeight , pointerZoom
1183
+ autoplay, autoplayBehavior, playOnce, speed, autoplayReverse, disableDrag = true , fullscreen, magnifier, ciToken, ciFilters, ciTransformation, lazyload, lazySelector, spinReverse, dragSpeed, stopAtEdges, controlReverse, hide360Logo, logoSrc, pointerZoom , ratio
1210
1184
} = get360ViewProps ( container ) ;
1211
1185
1212
1186
const ciParams = { ciToken, ciFilters, ciTransformation } ;
@@ -1240,17 +1214,16 @@ import {
1240
1214
this . lazySelector = lazySelector ;
1241
1215
this . spinReverse = spinReverse ;
1242
1216
this . controlReverse = controlReverse ;
1243
- this . dragSpeed = Math . max ( magnifier , 50 ) ;
1217
+ this . dragSpeed = Math . max ( dragSpeed , 50 ) ;
1244
1218
this . autoplaySpeed = this . speed * 36 / this . amountX ;
1245
1219
this . stopAtEdges = stopAtEdges ;
1246
1220
this . hide360Logo = hide360Logo ;
1247
1221
this . logoSrc = logoSrc ;
1248
1222
this . ciParams = ciParams ;
1249
1223
this . apiVersion = apiVersion ;
1250
- this . containerWidth = containerWidth ;
1251
- this . containerHeight = containerHeight ;
1252
1224
this . pointerZoom = pointerZoom > 1 ? Math . min ( pointerZoom , 3 ) : 0 ;
1253
1225
this . keysReverse = keysReverse ;
1226
+ this . ratio = ratio && JSON . parse ( ratio ) ;
1254
1227
1255
1228
if ( reload ) {
1256
1229
new CI360Viewer ( this . container ) ;
@@ -1342,7 +1315,7 @@ import {
1342
1315
if ( this . lazyloadX || this . lazyloadY ) return initLazyload ( image , orientation ) ;
1343
1316
1344
1317
if ( isFirstImageLoaded ) {
1345
- this . updateContainerSize ( image ) ;
1318
+ this . updateContainerAndCanvasSize ( image ) ;
1346
1319
this . onFirstImageLoaded ( image ) ;
1347
1320
}
1348
1321
0 commit comments