从设备的本地存储中呈现图纸

时间:2022-01-18 08:56:48

I am trying to build an android app using leaflet which can work offline with tiles stored locally on the device's sd card. Is this possible and is there a recommended way to reference the local drive in the url? I have tried all combinations but it fails to load the tiles. I do have a similar app built using OSMdroid that works just fine retrieving the locally stored tiles. I am just trying to get the same working using leaflet.

我正在尝试使用传单构建一个Android应用程序,它可以使用本地存储在设备的SD卡上的磁贴离线工作。这是否可行,是否有推荐的方法来引用网址中的本地驱动器?我尝试了所有组合,但无法加载瓷砖。我确实有一个类似的应用程序使用OSMdroid构建,可以很好地检索本地存储的瓷砖。我只是想尝试使用传单进行相同的工作。

Any suggestions or is this just not possible? Thanks!

有什么建议或者这是不可能的吗?谢谢!

My app activity's onCreate:

我的应用活动是onCreate:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mWebView= (WebView)findViewById(R.id.mapview);
        mWebView.setWebChromeClient(new WebChromeClient());
        mWebView.loadUrl("file:///android_asset/map.html");
    }

I have the map.html in assets folder along with leaflet.js. Below is a snippet of my map.html:(I think the issue is with the url - /sdcard/osmdroid/...)

我在assets文件夹中有map.html和leaflet.js。下面是我的map.html的片段:(我认为问题在于url - / sdcard / osmdroid / ...)

<script>

    var map = L.map('map');

    L.tileLayer('/sdcard/osmdroid/', {
        attribution: 'Map data from MOBAC',
        maxZoom: 18
    }).addTo(map);
    map.locate({setView: true, maxZoom: 16});
    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);
    }

</script>

1 个解决方案

#1


2  

Here is an example especially putMapsOnSd save it on sd https://github.com/tomkincaid/PathExample/blob/master/src/com/example/pathexample/MainActivity.java

这是一个例子,特别是putMapsOnSd将它保存在sd https://github.com/tomkincaid/PathExample/blob/master/src/com/example/pathexample/MainActivity.java

and he read this file at onCreate

他在onCreate上读到了这个文件

#1


2  

Here is an example especially putMapsOnSd save it on sd https://github.com/tomkincaid/PathExample/blob/master/src/com/example/pathexample/MainActivity.java

这是一个例子,特别是putMapsOnSd将它保存在sd https://github.com/tomkincaid/PathExample/blob/master/src/com/example/pathexample/MainActivity.java

and he read this file at onCreate

他在onCreate上读到了这个文件