Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 8 Bing地图信息框中的超链接会破坏Windows 8应用程序导航状态_Windows 8_Bing Maps_Winjs_Infobox - Fatal编程技术网

Windows 8 Bing地图信息框中的超链接会破坏Windows 8应用程序导航状态

Windows 8 Bing地图信息框中的超链接会破坏Windows 8应用程序导航状态,windows-8,bing-maps,winjs,infobox,Windows 8,Bing Maps,Winjs,Infobox,我在WinJS Windows 8应用程序的页面上有Bing地图 地图上有几个图钉,每个图钉都有自己的信息框。单击pin时,它会正确显示信息框及其内容。该内容包含一个链接到Windows 8应用程序中其他页面的超链接。应用程序可正确导航到此页面,但“后退”按钮停止工作,应用程序栏也无法访问。(导航到页面通常可以正常工作) 我认为页面导航方式和导航器记录状态的方式出了问题。我是新来的,所以这可能只是一个愚蠢的问题 以下是页面的.js文件中的代码: // For an introductio

我在WinJS Windows 8应用程序的页面上有Bing地图

地图上有几个图钉,每个图钉都有自己的信息框。单击pin时,它会正确显示信息框及其内容。该内容包含一个链接到Windows 8应用程序中其他页面的超链接。应用程序可正确导航到此页面,但“后退”按钮停止工作,应用程序栏也无法访问。(导航到页面通常可以正常工作)

我认为页面导航方式和导航器记录状态的方式出了问题。我是新来的,所以这可能只是一个愚蠢的问题

以下是页面的.js文件中的代码:

    // For an introduction to the Page Control template, see the following documentation:
// http://go.microsoft.com/fwlink/?LinkId=232511
(function () {
    "use strict";

    WinJS.UI.Pages.define("/pages/testBing/testBing.html", {
        // This function is called whenever a user navigates to this page. It
        // populates the page elements with the app's data.
        ready: function (element, options) {
            // TODO: Initialize the page here.
            Microsoft.Maps.loadModule('Microsoft.Maps.Map', { callback: initMap });
        }
    });


})();

var pinInfobox = null;

function initMap() {
    try {
        var mapOptions =
        {
            credentials: "credentials",
            center: new Microsoft.Maps.Location(-33.961176, 22.420985),
            mapTypeId: Microsoft.Maps.MapTypeId.road,
            zoom: 5
        };
        var mapDiv = document.querySelector("#mapdiv");
        map = new Microsoft.Maps.Map(mapDiv, mapOptions);
        centerPosition();
    }
    catch (e) {
        var md = new Windows.UI.Popups.MessageDialog(e.message);
        md.showAsync();
    }
}

function addPushPin(location) {
    map.entities.clear();
    var pushpin = new Microsoft.Maps.Pushpin(location, null);

    pinInfobox = new Microsoft.Maps.Infobox(new Microsoft.Maps.Location(0, 0), { title: 'My Pushpin', visible: true, description: "<a href='/pages/player/player.html'>Profile</a>" });
    Microsoft.Maps.Events.addHandler(pushpin, 'click', displayInfobox);
    Microsoft.Maps.Events.addHandler(map, 'viewchange', hideInfobox);

    map.entities.push(pushpin);
    map.entities.push(pinInfobox);
}


function hideInfobox(e) {
    pinInfobox.setOptions({ visible: false });
}

function centerPosition() {
    var geolocator = new Windows.Devices.Geolocation.Geolocator();
    geolocator.getGeopositionAsync().then(function (loc) {
        var mapCenter = map.getCenter();
        mapCenter.latitude = loc.coordinate.latitude;
        mapCenter.longitude = loc.coordinate.longitude;
        map.setView({ center: mapCenter, zoom: 15 });
        addPushPin(mapCenter);


    });
}

function displayInfobox(e) {
    pinInfobox.setOptions({ title: e.target.Title, innerHTML: e.target.Description, visible: true, offset: new Microsoft.Maps.Point(0, 25) });
    pinInfobox.setLocation(e.target.getLocation());
}
//有关页面控件模板的介绍,请参阅以下文档:
// http://go.microsoft.com/fwlink/?LinkId=232511
(功能(){
“严格使用”;
define(“/Pages/testBing/testBing.html”{
//每当用户导航到此页面时,都会调用此函数。它
//用应用程序的数据填充页面元素。
就绪:功能(元素、选项){
//TODO:在此处初始化页面。
loadModule('Microsoft.Maps.Map',{callback:initMap});
}
});
})();
var pinInfobox=null;
函数initMap(){
试一试{
var映射选项=
{
凭据:“凭据”,
中心:新的Microsoft.Maps.Location(-33.961176,22.420985),
mapTypeId:Microsoft.Maps.mapTypeId.road,
缩放:5
};
var mapDiv=document.querySelector(#mapDiv”);
map=新的Microsoft.Maps.map(mapDiv,mapOptions);
中心位置();
}
捕获(e){
var md=newwindows.UI.Popups.MessageDialog(e.message);
md.showsync();
}
}
功能添加图钉(位置){
map.entities.clear();
var pushpin=new Microsoft.Maps.pushpin(位置,null);
pinInfobox=new Microsoft.Maps.Infobox(new Microsoft.Maps.Location(0,0),{title:'My Pushpin',可见:true,description:”“});
Microsoft.Maps.Events.addHandler(图钉,'click',displayInfobox);
Microsoft.Maps.Events.addHandler(映射'viewchange',HideInfo框);
地图。实体。推(图钉);
map.entities.push(pinInfobox);
}
函数隐藏信息框(e){
setOptions({visible:false});
}
函数中心位置(){
var geologitor=new Windows.Devices.geologition.geologitor();
geolocator.getGeopositionAsync().then(函数(loc){
var mapCenter=map.getCenter();
mapCenter.latitude=loc.coordinate.latitude;
mapCenter.longitude=loc.coordinate.longitude;
setView({center:mapCenter,zoom:15});
添加图钉(地图中心);
});
}
功能显示信息框(e){
setOptions({title:e.target.title,innerHTML:e.target.Description,visible:true,offset:new Microsoft.Maps.Point(0,25)});
setLocation(例如target.getLocation());
}
HTML只包含以下内容

    <!-- WinJS references -->
    <link href="//Microsoft.WinJS.1.0/css/ui-dark.css" rel="stylesheet" />
    <script src="//Microsoft.WinJS.1.0/js/base.js"></script>
    <script src="//Microsoft.WinJS.1.0/js/ui.js"></script>

    <!--Bing Mapps Reference -->
     <script type="text/javascript" src="ms-appx:///Bing.Maps.JavaScript//js/veapicore.js"></script>

    <link href="testBing.css" rel="stylesheet" />
    <script src="testBing.js"></script>
</head>
<body>
    <div class="testBing fragment">
        <header aria-label="Header content" role="banner">
            <button class="win-backbutton" aria-label="Back" disabled type="button"></button>
            <h1 class="titlearea win-type-ellipsis">
                <span class="pagetitle">Welcome to testBing</span>
            </h1>
        </header>
        <section aria-label="Main content" role="main">
            <div id="mapdiv"></div>
        </section>
    </div>
</body>
</html>

欢迎来到testBing

多米尼克·霍普顿(Dominic Hopton)的评论是正确的:foo.html将作为整个页面加载,而不是作为应用程序导航过程的一部分加载。如果链接应该用于应用程序导航(而不是在外部web浏览器中打开),则可以将此代码添加到页面的就绪功能中,以将链接单击转换为导航事件

WinJS.Utilities.query("a").listen("click", function (e) {
    e.preventDefault();
    nav.navigate(e.target.href);
});
如果您有一些应该导航的链接和一些应该在浏览器中打开的链接,则可以修改查询。例如,如果可以将CSS类添加到应在web浏览器中打开的链接,则可以将查询更改为:

WinJS.Utilities.query("a:not(.defaultClick)")
您还可以修改查询以检查链接的href属性,以检查“http”,如下所示:

我还没有测试最后一个示例,但如果它像我怀疑的那样工作,它将有一个以“http”(因此包括“https”)开头的链接正常运行,而所有具有相对URL或包URL的链接都将转换为导航事件


我不建议您盲目地这样做,但根据您的应用程序,这个简单的快捷方式可能会改变行为以符合您的期望。

这是一个完整的实际浏览器导航吗?你所有的代码都被卸载了吗?如果在加载调试器的情况下执行此操作,您将看到JavaScript控制台输出项,指示导航。它不在浏览器中。它是一个Windows8商店应用程序,最终也将在WindowsPhone上使用。(不确定我是否误解了您的问题)我已设法将一个方法附加到信息框的单击事件。Microsoft.Maps.Events.addHandler(pinInfobox,'click',testMethod);使用WinJS.Navigation.navigate('/pages/player/player.html')然后允许我导航到另一个页面,这不会中断导航。但是,我想在infobox上添加多个链接,因此此解决方案不适用于该场景。WWA与浏览器具有相同的API界面。如果您有,那么当您在默认情况下单击它时,它会将整个页面移动到包中的/foo.html并删除您的脚本。为什么不直接监听父div上的click事件,处理冒泡事件,并在事件上调用e.preventDefault(),这样就不会出现默认导航(我刚才讨论过)。感谢Dominic的建议,但是现在我们被告知使用C#和xaml。我仍然想尝试一下,但我会在有时间的时候做。
WinJS.Utilities.query("a:not([href^=http])")