Android上WebView的性能低下
我在一个Android应用程序中使用MopleJS以geojson格式渲染局部多边形(没有CRS信息),而没有maptiles。不幸的是,缩放和其他触摸动作非常缓慢。我的geojson文件包含3000个多边形。这个问题有什么解决办法吗?我唯一能找到的就是一个解决方法 这就是它的样子: 这是我的密码: 在onCreate中:Android上WebView的性能低下,android,webview,leaflet,gis,polygon,Android,Webview,Leaflet,Gis,Polygon,我在一个Android应用程序中使用MopleJS以geojson格式渲染局部多边形(没有CRS信息),而没有maptiles。不幸的是,缩放和其他触摸动作非常缓慢。我的geojson文件包含3000个多边形。这个问题有什么解决办法吗?我唯一能找到的就是一个解决方法 这就是它的样子: 这是我的密码: 在onCreate中: public void loadMap(){ scanFiles(); checkStoragePermissions();
public void loadMap(){
scanFiles();
checkStoragePermissions();
webview = (WebView) findViewById(R.id.myWebView);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// chromium, enable hardware acceleration
webview.setLayerType(View.LAYER_TYPE_HARDWARE, null);
} else {
// older android version, disable hardware acceleration
webview.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
WebSettings webSettings =
webview.getSettings();
webSettings.setAllowFileAccess(true);
webSettings.setAllowFileAccessFromFileURLs(true);
webSettings.setJavaScriptEnabled(true);
webview.setWebContentsDebuggingEnabled(BuildConfig.DEBUG);
webview.setWebChromeClient(
new WebChromeClient());
File leafletMap = new File(Environment.getExternalStorageDirectory(), "/LeafletMap/Map.html");
webview.loadUrl("file:///" + leafletMap.getAbsolutePath());
}
和我的HTML文件:
<!DOCTYPE html>
<html>
<head>
<title>Leaflet Map</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<link rel="stylesheet" href="file:///android_asset/leaflet/leaflet.css">
<script type="text/javascript" src="file:///android_asset/leaflet/leaflet.js"></script>
<style>
body {
padding: 0;
margin: 0;
}
html, body, #mapid {
height: 100%;
width: 100vw;
}
</style>
</head>
<body>
<div id="mapid"></div>
<script>
var mymap = L.map('mapid', {
crs: L.CRS.Simple
});
//Add local
var layer;
const xhr = new XMLHttpRequest();
xhr.open('GET', 'file:///android_asset/poly.json');
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.responseType = 'json';
xhr.onload = function () {
if (xhr.status !== 200) return
var blahlayer = L.geoJSON(xhr.response).getBounds();
mymap.fitBounds(blahlayer);
L.geoJSON(xhr.response).addTo(mymap);
};
xhr.send();
</script>
</body>
</html>
单张地图
身体{
填充:0;
保证金:0;
}
html,正文,#mapid{
身高:100%;
宽度:100vw;
}
var mymap=L.map('mapid'{
crs:L.crs.Simple
});
//添加本地
var层;
const xhr=new XMLHttpRequest();
xhr.open('GET','file:///android_asset/poly.json');
setRequestHeader('Content-Type','application/json');
xhr.responseType='json';
xhr.onload=函数(){
如果(xhr.status!==200)返回
var blahlayer=L.geoJSON(xhr.response).getBounds();
mymap.fitBounds(blahlayer);
L.geoJSON(xhr.response).addTo(mymap);
};
xhr.send();
如果尚未使用,请尝试使用VectorGrid.Slicer。这将有助于简化和延迟加载几何体。作为一个中间解决方案,您还可以尝试首先使用画布渲染器而不是svg,请看,使用画布渲染器会更平滑一些,但仍然有点不太好。我正在尝试切片器,但我的多边形没有显示。我是这样做的:L.vectorGrid.slicer(geoJ.addTo(mymap);如果还没有,请尝试矢量网格。切片器。这将有助于简化和延迟加载几何体。作为一个中间解决方案,您还可以尝试首先使用画布渲染器而不是svg,请看,使用画布渲染器会更平滑一些,但仍然有点不太好。我正在尝试切片器,但我的多边形没有显示。我是这样做的:L.vectorGrid.slicer(geoJ.addTo(mymap);