|
@@ -1,68 +1,76 @@
|
|
-import { FC, forwardRef, useEffect, useImperativeHandle, useMemo, useRef } from "react";
|
|
|
|
-import { useSelector } from "react-redux";
|
|
|
|
-
|
|
|
|
-export interface KrpanoMiddlewareProps {
|
|
|
|
- children: React.ReactNode;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-export interface KrpanoMiddlewareMethods {
|
|
|
|
- ready: () => void;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-export const KrpanoMiddleware = forwardRef<KrpanoMiddlewareMethods, KrpanoMiddlewareProps>(({ children }, ref) => {
|
|
|
|
- const isHH = useSelector((state: any) => state.A0Layout.isHH)
|
|
|
|
- const fakeEvent = useMemo(() => !isHH && /Mobi|Android|iPhone/i.test(navigator.userAgent), [isHH])
|
|
|
|
- const startX = useRef(0);
|
|
|
|
- const startY = useRef(0);
|
|
|
|
-
|
|
|
|
- const handleTouchStart = (e: React.TouchEvent<HTMLDivElement>) => {
|
|
|
|
- if (!fakeEvent) return
|
|
|
|
- const touch = e.touches[0]
|
|
|
|
- startX.current = touch.clientX
|
|
|
|
- startY.current = touch.clientY
|
|
|
|
- }
|
|
|
|
- const handleTouchMove = (e: React.TouchEvent<HTMLDivElement>) => {
|
|
|
|
- if (!fakeEvent) return
|
|
|
|
- const touch = e.touches[0]
|
|
|
|
- const deltaX = touch.clientX - startX.current
|
|
|
|
- const deltaY = touch.clientY - startY.current
|
|
|
|
-
|
|
|
|
- const krpano = window.ReactKrpanoActionProxy
|
|
|
|
- if (krpano) {
|
|
|
|
- const currentHlookat = krpano.get("view.hlookat")
|
|
|
|
- const currentVlookat = krpano.get("view.vlookat")
|
|
|
|
-
|
|
|
|
- const newHlookat = currentHlookat - deltaY * 0.1
|
|
|
|
- const newVlookat = currentVlookat + deltaX * 0.1
|
|
|
|
-
|
|
|
|
- krpano.set("view.hlookat", newHlookat)
|
|
|
|
- krpano.set("view.vlookat", newVlookat)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- startX.current = touch.clientX
|
|
|
|
- startY.current = touch.clientY
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- useImperativeHandle(ref, () => ({
|
|
|
|
- ready: () => {
|
|
|
|
- if (fakeEvent) {
|
|
|
|
- window.ReactKrpanoActionProxy?.krpanoRenderer?.call("set(control.usercontrol, 'off');")
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }))
|
|
|
|
-
|
|
|
|
- useEffect(() => {
|
|
|
|
- if (window.ReactKrpanoActionProxy?.krpanoRenderer) {
|
|
|
|
- window.ReactKrpanoActionProxy?.krpanoRenderer?.call(`set(control.usercontrol, '${fakeEvent ? 'off' : 'all'}');`)
|
|
|
|
- }
|
|
|
|
- }, [fakeEvent])
|
|
|
|
-
|
|
|
|
- return (
|
|
|
|
- <div style={{width: '100%', height: '100%'}}
|
|
|
|
- onTouchStart={handleTouchStart}
|
|
|
|
- onTouchMove={handleTouchMove}
|
|
|
|
- >
|
|
|
|
- {children}
|
|
|
|
- </div>
|
|
|
|
- )
|
|
|
|
-})
|
|
|
|
|
|
+import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef } from 'react'
|
|
|
|
+import { useSelector } from 'react-redux'
|
|
|
|
+
|
|
|
|
+export interface KrpanoMiddlewareProps {
|
|
|
|
+ children: React.ReactNode
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+export interface KrpanoMiddlewareMethods {
|
|
|
|
+ ready: () => void
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+export const KrpanoMiddleware = forwardRef<KrpanoMiddlewareMethods, KrpanoMiddlewareProps>(
|
|
|
|
+ ({ children }, ref) => {
|
|
|
|
+ const isHH = useSelector((state: any) => state.A0Layout.isHH)
|
|
|
|
+ const fakeEvent = useMemo(
|
|
|
|
+ () => !isHH && /Mobi|Android|iPhone/i.test(navigator.userAgent),
|
|
|
|
+ [isHH]
|
|
|
|
+ )
|
|
|
|
+ const startX = useRef(0)
|
|
|
|
+ const startY = useRef(0)
|
|
|
|
+
|
|
|
|
+ const handleTouchStart = (e: React.TouchEvent<HTMLDivElement>) => {
|
|
|
|
+ if (!fakeEvent) return
|
|
|
|
+ const touch = e.touches[0]
|
|
|
|
+ startX.current = touch.clientX
|
|
|
|
+ startY.current = touch.clientY
|
|
|
|
+ }
|
|
|
|
+ const handleTouchMove = (e: React.TouchEvent<HTMLDivElement>) => {
|
|
|
|
+ if (!fakeEvent) return
|
|
|
|
+ const touch = e.touches[0]
|
|
|
|
+ const deltaX = touch.clientX - startX.current
|
|
|
|
+ const deltaY = touch.clientY - startY.current
|
|
|
|
+
|
|
|
|
+ const krpano = window.ReactKrpanoActionProxy
|
|
|
|
+ if (krpano) {
|
|
|
|
+ const currentHlookat = krpano.get('view.hlookat')
|
|
|
|
+ const currentVlookat = krpano.get('view.vlookat')
|
|
|
|
+
|
|
|
|
+ const newHlookat = currentHlookat - deltaY * 0.1
|
|
|
|
+ const newVlookat = currentVlookat + deltaX * 0.1
|
|
|
|
+
|
|
|
|
+ krpano.set('view.hlookat', newHlookat)
|
|
|
|
+ krpano.set('view.vlookat', newVlookat)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ startX.current = touch.clientX
|
|
|
|
+ startY.current = touch.clientY
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ useImperativeHandle(ref, () => ({
|
|
|
|
+ ready: () => {
|
|
|
|
+ if (fakeEvent) {
|
|
|
|
+ window.ReactKrpanoActionProxy?.krpanoRenderer?.call("set(control.usercontrol, 'off');")
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }))
|
|
|
|
+
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ if (window.ReactKrpanoActionProxy?.krpanoRenderer) {
|
|
|
|
+ window.ReactKrpanoActionProxy?.krpanoRenderer?.call(
|
|
|
|
+ `set(control.usercontrol, '${fakeEvent ? 'off' : 'all'}');`
|
|
|
|
+ )
|
|
|
|
+ }
|
|
|
|
+ }, [fakeEvent])
|
|
|
|
+
|
|
|
|
+ return (
|
|
|
|
+ <div
|
|
|
|
+ style={{ width: '100%', height: '100%' }}
|
|
|
|
+ onTouchStart={handleTouchStart}
|
|
|
|
+ onTouchMove={handleTouchMove}
|
|
|
|
+ >
|
|
|
|
+ {children}
|
|
|
|
+ </div>
|
|
|
|
+ )
|
|
|
|
+ }
|
|
|
|
+)
|