如果不双击 PhoneGap/jQuery Mobile 应用程序,OpenLayers 将无法加载

发布于 2024-12-27 17:30:36 字数 1981 浏览 0 评论 0原文

我在尝试将带有 Open Street Map 图层的基本 OL 地图集成到多页 jQuery Mobile HTML 界面中时遇到问题 - 它可以找到地图“div”,并​​正确加载几乎所有内容,但必须单击该控件在加载地图图块之前。以下是映射代码:

var map, layer;
function init(){
    map = new OpenLayers.Map( 'map');
    layer = new OpenLayers.Layer.OSM( "Simple OSM Map");
    map.addLayer(layer);
    map.setCenter(
        new OpenLayers.LonLat(-71.147, 42.472).transform(
            new OpenLayers.Projection("EPSG:4326"),
            map.getProjectionObject()
            ), 12
        );
}

使用“ondeviceready”事件调用此函数,该事件在 PhoneGap 准备好接受命令时触发。这是包含地图的页面:

<!-- page showing map of route being recorded. -->
<div id="route" data-role="page">
    <div data-id="recRoute" data-role="header" data-position="fixed">
    </div>
    <div data-role="content">
        <div id="map"></div>
    </div>
    <div data-id="recRouteFoot" data-role="footer" data-position="fixed">
    </div>
</div>

当页面加载到 DOM 中时,有什么方法可以重新绘制地图/图层吗?我希望用户不必单击地图控件即可实际查看地图。

更新:“route”页面的“pageinit”处理程序:

/** Executes when gps page loads. **/
$('#route').live('pageinit', function(event){
        $('.del').detach().trigger('create');
        /** Executes when addTag button clicked. **/
        $('#createTag').click(createTag);
        /** Executes when getPic button clicked. **/
        $('#getPic').click(function() {
                getPic();
        });
        /** Executes when pauseResume button clicked. **/
        $('.pauseResume').click(function() {
                pauseCounter();
        });
        /** Executes when stop button clicked. **/
        $('.stop').click(function() {
                stopCounter();
        });
        // remove stupid button.
        $('#del').detach().trigger('create');
        // load map.
        init();
        $('#map').trigger('create');
        $('#route').addClass('ui-page-active').trigger('create');
});

I'm having trouble trying to integrate a basic OL map with an Open Street Map layer into a multi-page jQuery Mobile HTML interface - it can find the map 'div', and loads almost everything properly, but the control has to be clicked before the map tiles load. Here's the map code:

var map, layer;
function init(){
    map = new OpenLayers.Map( 'map');
    layer = new OpenLayers.Layer.OSM( "Simple OSM Map");
    map.addLayer(layer);
    map.setCenter(
        new OpenLayers.LonLat(-71.147, 42.472).transform(
            new OpenLayers.Projection("EPSG:4326"),
            map.getProjectionObject()
            ), 12
        );
}

This function is called using the 'ondeviceready' event that fires when PhoneGap is ready to accept commands. This is the page that contains the map:

<!-- page showing map of route being recorded. -->
<div id="route" data-role="page">
    <div data-id="recRoute" data-role="header" data-position="fixed">
    </div>
    <div data-role="content">
        <div id="map"></div>
    </div>
    <div data-id="recRouteFoot" data-role="footer" data-position="fixed">
    </div>
</div>

Is there some way I could get the map/layer to be redrawn when the page is loaded into the DOM? I would rather a user not have to click the map controls to actually see the map.

UPDATE: the 'pageinit' handler for the 'route' page:

/** Executes when gps page loads. **/
$('#route').live('pageinit', function(event){
        $('.del').detach().trigger('create');
        /** Executes when addTag button clicked. **/
        $('#createTag').click(createTag);
        /** Executes when getPic button clicked. **/
        $('#getPic').click(function() {
                getPic();
        });
        /** Executes when pauseResume button clicked. **/
        $('.pauseResume').click(function() {
                pauseCounter();
        });
        /** Executes when stop button clicked. **/
        $('.stop').click(function() {
                stopCounter();
        });
        // remove stupid button.
        $('#del').detach().trigger('create');
        // load map.
        init();
        $('#map').trigger('create');
        $('#route').addClass('ui-page-active').trigger('create');
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半葬歌 2025-01-03 17:30:36

您应该仅在初始化“#route”页面时创建地图,因此当它具有尺寸时。

查看 http:// 中的 pageinit 事件jquerymobile.com/demos/1.0/docs/api/events.html

You should create the map only when the «#route» page is initialised, so when it has dimension.

Take a look at the pageinit event in http://jquerymobile.com/demos/1.0/docs/api/events.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文