android - map 上不需要的灰色区域

标签 android cordova leaflet

我正在尝试在 Android 中使用 PhoneGap 和 LeafLet。

我阅读了关于 LeafLet 的教程,我选择从 mobile example 开始

这个灰色区域是我的问题.. 为什么会出现这个灰色区域?
browser 上没有灰色区域.除了文件路径,我没有改变任何东西。

如何让 map 全屏显示?

更新说明:我在 10"平板横向模式下工作,现在我在 3.2"手机上尝试了这个例子,3.2"屏幕没有问题。10"屏幕有问题-横向模式

enter image description here

MainActivity.java

public class MainActivity extends DroidGap {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        appView= (CordovaWebView) findViewById(R.id.tutorialView);

        appView.loadUrl("file:///android_asset/www/main.html");

    }

}

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <org.apache.cordova.CordovaWebView
            android:id="@+id/tutorialView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />

</RelativeLayout>

ma​​in.html

<!DOCTYPE html>
<html>
<head>
    <title>Leaflet mobile example</title>

    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">

    <link rel="stylesheet" href="leaflet.css" />
    <!--[if lte IE 8]><link rel="stylesheet" href="leaflet.ie.css" /><![endif]-->

    <script src="leaflet.js"></script>

    <style>
        body {
            padding: 0;
            margin: 0;
        }
        html, body, #map {
            height: 100%;
        }
    </style>
</head>
<body>
    <div id="map"></div>

    <script>
        var map = L.map('map');

        L.tileLayer('http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png', {
            maxZoom: 18,
            attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://cloudmade.com">CloudMade</a>'
        }).addTo(map);

        function onLocationFound(e) {
            var radius = e.accuracy / 2;

            L.marker(e.latlng).addTo(map)
                .bindPopup("You are within " + radius + " meters from this point").openPopup();

            L.circle(e.latlng, radius).addTo(map);
        }

        function onLocationError(e) {
            alert(e.message);
        }

        map.on('locationfound', onLocationFound);
        map.on('locationerror', onLocationError);

        map.locate({setView: true, maxZoom: 16});
    </script>
</body>
</html>

最佳答案

Leaflet doesn't always correctly infer the dimensions of maps without explicit dimensions.作为 Leaflet 此类问题的一般解决方案,请尝试将其添加到您的 javascript 末尾:

setTimeout(map.invalidateSize.bind(map));

这将导致 Leaflet 重新计算 map 的尺寸​​,并有望修复您看到的灰色方 block 。

有时,可能还需要进一步延迟重新计算,例如 setTimeout(map.invalidateSize.bind(map),200);这可能会修复异常浏览器加载条件下的灰色图 block 。

关于android - map 上不需要的灰色区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19564366/

相关文章:

android - 如何让我的 Android 应用程序在后台运行?

Java Android,解码AES-256时出错

android - Facebook - 无法发布给未安装该应用程序的用户

Androidplot:改进轴布局(删除截止值)

android - 使用cordova将android图库中的图片分享到cordova应用程序

visual-studio - Ionic 2 的智能感知在 Visual Studio 2015 中不起作用

r - 使用 addWMSTiles 在 R leaflet 中加载 WMS 层

ios - 带有 Cordova 垂直滚动的 Framework7 在 iOS 上不起作用

r - 将 "rgb"图例添加到 R 传单热图

r - 从 R 中的传单包创建 html 时字符编码错误