xzw 2 days ago
parent
commit
2a817116eb
2 changed files with 49 additions and 2 deletions
  1. 2 2
      src/Potree.js
  2. 47 0
      src/custom/utils/Common.js

+ 2 - 2
src/Potree.js

@@ -630,9 +630,9 @@ export function load4dkkPanos(sceneCode, model, defaultRotation, done, tileRes){
         
         //path = `${prefix}/swkk/${sceneCode}/wwwroot/scene_view_data/${sceneCode}/images/vision.txt`
         if(Potree.settings.urls.templates.vision){
-            path = prefix + Potree.Common.replaceAll(Potree.settings.urls.templates.vision, '{sceneCode}',  sceneCode)  
+            path = Potree.Common.joinUrl(prefix, Potree.Common.replaceAll(Potree.settings.urls.templates.vision, '{sceneCode}',  sceneCode)) 
         }else{
-            path = `${prefix}/scene_view_data/${sceneCode}/images/vision.txt`
+            path = Potree.Common.joinUrl(prefix, `/scene_view_data/${sceneCode}/images/vision.txt`)
         }  
     }
     model.sceneCode = sceneCode

+ 47 - 0
src/custom/utils/Common.js

@@ -253,6 +253,24 @@ var Common = {
         }
     }, 
       
+    
+    cleanUrl(url){//斜杠处理   协议aaa://保留双斜杠,其余单斜杠
+        //分离协议和路径部分
+        const protocolMatch = url.match(/^(\w+:)\/{2,}/);
+
+        if (protocolMatch) {
+            const protocol = protocolMatch[1];
+            const path = url.slice(protocolMatch[0].length);
+            return protocol + '//' + path.replace(/\/+/g, '/');
+        } else {
+            return url.replace(/\/+/g, '/');
+        }
+    },
+    
+    joinUrl(){//拼接地址。总是出现前后多个/造成双斜杠或者缺斜杠的问题,处理一下
+        return this.cleanUrl(Array.from(arguments).join('/'))
+    },
+    
     dealURL(url=''){ 
         let urlNew = this.replaceAll(url, "+", "%2B"); //this.replaceAll(url, "\\+", "%2B");// 浏览器似乎不支持访问带+的地址
     
@@ -604,6 +622,35 @@ var Common = {
  
     },
     
+    
+    mobileAutoPlay(media, playFun){//移动端。不这么写video不会播放 . (2022.11.29: 可为何加了Hot.updateHots之后又会自动播了?https有关?
+        
+        
+        if(this.autoPlayList.includes(media))return
+        this.autoPlayList.push(media)
+        viewer.addEventListener       
+        let events = ['global_touchstart','global_mousedown']    
+        
+        let fun = ()=>{
+            let index = this.autoPlayList.indexOf(media)
+            if(index>-1){
+                
+                console.log( 'try autoplay '+ media.src)
+                playFun()
+                this.autoPlayList.splice(index,1)
+                events.forEach((eventName)=>{ 
+                    viewer.removeEventListener(eventName,fun)
+                })
+            }
+        }
+    
+        events.forEach((eventName)=>{ 
+            viewer.addEventListener(eventName,fun)
+        })
+ 
+        
+    },
+    
     /* changeShaderToWebgl2(vs, fs, matType, otherReplaces=[]){//部分shader要根据webgl版本作更改
         if(!Potree.settings.isWebgl2)return {vs, fs}
         let turnTo300 = matType != 'ShaderMaterial' && (vs.includes('gl_FragDepthEXT') || fs.includes('gl_FragDepthEXT') )