Android Mapbox:创建具有20000个功能的新GeoJsonSource需要很长时间
当我在android项目中尝试在mapbox地图上显示大约20000个项目时,创建GeoJsonSource需要很长时间,并且会将设备冻结8到10秒。启用或禁用群集都需要这么长的时间。我们在iOS项目中也遇到了类似的问题 对于这个项目,我们需要集群,所以据我所知,我们现在需要使用源代码来显示项目 有没有办法让这更快,或者我应该使用另一种方法来显示集群项目 我的源代码:Android Mapbox:创建具有20000个功能的新GeoJsonSource需要很长时间,android,ios,mapbox,Android,Ios,Mapbox,当我在android项目中尝试在mapbox地图上显示大约20000个项目时,创建GeoJsonSource需要很长时间,并且会将设备冻结8到10秒。启用或禁用群集都需要这么长的时间。我们在iOS项目中也遇到了类似的问题 对于这个项目,我们需要集群,所以据我所知,我们现在需要使用源代码来显示项目 有没有办法让这更快,或者我应该使用另一种方法来显示集群项目 我的源代码: new AsyncTask<Object, Object, FeatureCollection>() { @Ove
new AsyncTask<Object, Object, FeatureCollection>() {
@Override
protected FeatureCollection doInBackground(Object... params) {
List<Feature> featureArrayList = new ArrayList<>();
// currentMapPoiList contains 20000 location items:
for (Poi p : currentMapPoiList) {
JsonObject properties = new JsonObject();
properties.addProperty("poitype", p.type);
properties.addProperty("poiId", p.id);
featureArrayList.add(Feature.fromGeometry(Point.fromCoordinates(Position.fromCoordinates(p.lon, p.lat)), properties, Integer.toString(p.id)));
}
FeatureCollection featureCollection = FeatureCollection.fromFeatures(featureArrayList);
return featureCollection;
}
@Override
protected void onPostExecute(FeatureCollection featureCollection) {
super.onPostExecute(featureCollection);
// Start timeconsuming code:
poiSource = new GeoJsonSource(
"sourcePoiItems",
featureCollection,
new GeoJsonOptions()
.withCluster(true)
.withClusterMaxZoom(8)
.withClusterRadius(50));
// End timeconsuming code
mapboxMap.addSource(poiSource);
...
newasynctask(){
@凌驾
受保护的功能集合doInBackground(对象…参数){
List featureArrayList=新建ArrayList();
//CurrentMapPoList包含20000个位置项:
用于(Poi p:currentMapPoiList){
JsonObject属性=新的JsonObject();
属性。添加属性(“poitype”,p.type);
属性。添加属性(“POID”,p.id);
featureArrayList.add(Feature.fromGeometry(Point.fromCoordinates(Position.fromCoordinates(p.lon,p.lat)),properties,Integer.toString(p.id));
}
FeatureCollection FeatureCollection=FeatureCollection.fromFeatures(featureArrayList);
返回特征集合;
}
@凌驾
PostExecute上受保护的无效(FeatureCollection FeatureCollection){
super.onPostExecute(featureCollection);
//启动耗时代码:
poisesource=新的GeoJsonSource(
“源项目”,
特色收藏,
新地理选项()
.withCluster(真)
.使用ClusterMaxZoom(8)
.具有簇半径(50));
//结束耗时代码
mapboxMap.addSource(PoiseSource);
...
谢谢你的指点
onPostExecute
是主线程,因此将耗时部分移到doInBackground
我不是mapbox专家,但我希望这能有所帮助。谢谢你的评论。1.GeoJsonSource的创建必须在主线程中完成。2.计算是在创建GeoJsonSource时完成的,因此所有这些工作都是由mapbox框架完成的。我们的解决方案可能是只为一个国家加载集群项目或删除集群现在大家都在一起。