首页 文章

ARView中看不到标记和雷达由于AR.ImageResource未加载本 Map 像

提问于
浏览
1

在我的PhoneGap应用程序中,我使用的是Wikitude Cordova插件(5.1.1),所有Wikitude功能都运行良好 . 现在我将我的插件更新到5.3.0版本的最新版本,但我们在IOS设备中面临一些Wikitude插件功能的问题 . 问题是 :

When I load the Wikitude ARView in the app, All markers and radar are shown properly, but When I destroy all objects from the ARView using AR.context.destroyAll(); and after that when I again try to draw radar and makers on ARView, these objects are not visible on ARView. My app has the feature in which I need to clear all the marker from the ARView and redraw the markers with some filters.

现在我找到了破坏后标记和雷达不可见的原因 .

The reason is "AR.ImageResource" is not loaded properly for marker and radar after destroying. 当我为AR.ImageResource添加onLoaded和onError回调时 . 我们第一次加载AR World时,会收到"onLoadded"回调的呼叫 . 但是当我在销毁后加载ImageResouce时,我收到了"onError"回调的调用,错误显示它找到错误路径的图像 .

我将loadARchitectWorld的AR体验URL用作:var arExperienceUrl =“www / main_home_ar_view_screen.html”;

用于雷达图像资源的图像路径:www> img> wikitude_img> radar_bg.png

加载AR.ImageResource的代码:

AR.radar.background = new AR.ImageResource("img/wikitude_img/radar_bg.png", {
onLoaded : function successFn(loadedURL) {
           /* Respond to successful world loading if you need to */
            alert("onLoaded");                   
    },
onError : function errorFn(error) 
{
            alert("onError " + error + " & " +  error.message);
    }});

当我加载AR World时,上面的代码工作正常 . 但是在从ARView中销毁对象后,AR.ImageResource在此路径中找到图像“/www/main_home_ar_view_screen.html/img/wikitude_img/radar_bg.png”,由于在错误的路径上找到图像,因此未加载图像(请参阅附图) .

enter image description here

我也找到了这些东西:

  • 相同的代码在Android平台上正常运行 .

  • 如果我使用带有AR.ImageResource的图像URL(远程图像),那么iOS上的一切都很好 . 这意味着所有标记和雷达在ARView上销毁后都能正常显示但是当我使用AR.ImageResource的本 Map 像路径时破坏后不显示标记和雷达(当我使用本 Map 像路径加载AR World时,标记和雷达正确显示) .

Please suggest me how to solve the AR.ImageResouce problem with local image Path.

1 回答

  • 0

    要解决此问题,只需将以下代码段粘贴到主Architect .js文件的顶部即可

    AR.__resourceUrl = function(url) 
    {
       if (/^([a-z\d.-]+:)?\/\//i.test(url)) 
       {
          // URL contains protocol and can be considered absolute
          return url;
       }
       // get protocol
       var protocol = document.baseURI.substring(0,
       document.baseURI.indexOf('/') + 2);
       var uri = document.baseURI.substring(document.baseURI.indexOf('/') +    2);
        // remove fragment identifier
        if ( uri.indexOf('#') > 0 && uri.length > uri.indexOf('#') +1 ) {
            uri = uri.substring(0, uri.lastIndexOf('#'));
            // in case there was a '/' after the fragment identifier, we need to add it back again
            if ( uri[uri.length - 1] !== '/' ) {
                uri += '/';
            }
        }
        // remove trailing file (edge case, this is just a domain e.g.
        // www.google.com)
        uri = uri.substring(0, uri.lastIndexOf('/') + 1);
        var baseUrl = protocol + uri;
        if (baseUrl[baseUrl.length - 1] !== '/')
        baseUrl += '/';
        if (url[0] === '/') {
        // url references root
        baseUrl = baseUrl.substring(0, baseUrl.indexOf('/', baseUrl
     .indexOf('//') + 2));
        }
        var resourceURL = baseUrl + url;
        return resourceURL;
    };
    

    当我从Wikitude开发者论坛获得此解决方案时

相关问题