|
@@ -0,0 +1,98 @@
|
|
|
+## 控制器
|
|
|
+
|
|
|
+### 修改拖拽视角方向
|
|
|
+
|
|
|
+在移动端竖屏模式下,通过样式旋转横屏,但是物理方向并没有改变,需要重新代理 touch 事件
|
|
|
+
|
|
|
+```tsx
|
|
|
+import React, { useRef, useEffect, useState } from "react";
|
|
|
+import { Krpano, Scene, View, Control } from "@dage/krpano";
|
|
|
+
|
|
|
+const URL = "https://houseoss.4dkankan.com/project/leifeng-transfer";
|
|
|
+
|
|
|
+export default () => {
|
|
|
+ const startX = useRef(0);
|
|
|
+ const startY = useRef(0);
|
|
|
+
|
|
|
+ const handleTouchStart = (e: React.TouchEvent<HTMLDivElement>) => {
|
|
|
+ const touch = e.touches[0];
|
|
|
+ startX.current = touch.clientX;
|
|
|
+ startY.current = touch.clientY;
|
|
|
+ };
|
|
|
+ const handleTouchMove = (e: React.TouchEvent<HTMLDivElement>) => {
|
|
|
+ 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;
|
|
|
+ };
|
|
|
+
|
|
|
+ return (
|
|
|
+ <div className="demo">
|
|
|
+ <div onTouchStart={handleTouchStart} onTouchMove={handleTouchMove}>
|
|
|
+ <Krpano
|
|
|
+ className="krpano"
|
|
|
+ currentScene="center"
|
|
|
+ littlePlanetIntro={true}
|
|
|
+ passQueryParameters={true}
|
|
|
+ >
|
|
|
+ <Control usercontrol="off" />
|
|
|
+
|
|
|
+ <Scene
|
|
|
+ name="center"
|
|
|
+ previewUrl={URL + "/panos/center1.tiles/preview.jpg"}
|
|
|
+ imageTagAttributes={{
|
|
|
+ type: "cube",
|
|
|
+ tileSize: 512,
|
|
|
+ multires: true,
|
|
|
+ }}
|
|
|
+ images={[
|
|
|
+ {
|
|
|
+ tiledImageWidth: 2624,
|
|
|
+ tiledImageHeight: 2624,
|
|
|
+ url: URL + "/panos/center1.tiles/%s/l3/%v/l3_%s_%v_%h.jpg",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ tiledImageWidth: 1280,
|
|
|
+ tiledImageHeight: 1280,
|
|
|
+ url: URL + "/panos/center1.tiles/%s/l2/%v/l2_%s_%v_%h.jpg",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ tiledImageWidth: 640,
|
|
|
+ tiledImageHeight: 640,
|
|
|
+ url: URL + "/panos/center1.tiles/%s/l1/%v/l1_%s_%v_%h.jpg",
|
|
|
+ },
|
|
|
+ ]}
|
|
|
+ >
|
|
|
+ <View
|
|
|
+ hlookat={0}
|
|
|
+ vlookat={0}
|
|
|
+ fovType="DFOV"
|
|
|
+ fov={120}
|
|
|
+ fovMin={90}
|
|
|
+ fovMax={140}
|
|
|
+ />
|
|
|
+ </Scene>
|
|
|
+ </Krpano>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+};
|
|
|
+```
|
|
|
+
|
|
|
+### API
|
|
|
+
|
|
|
+<API hideTitle exports='["Control"]' src='@dage/krpano/index.d.ts'></API>
|