圆形图层Mabox-计算聚集点(Java)

我用Java编写了一个Android应用程序。我想在地图上显示COVID数据,但是有问题。我使用Mapbox框架在地图上显示数据。我有geoJSON文件geojson file,其中一行表示每个国家或地区的案件数量。 现在,我的小观点没有正确地聚类。缩小后的紫色(5)和深蓝色(4)应该给出9个数字的红点。现在我得到了没有数字的蓝点(我知道我只计算了一些点,这就是蓝色的原因)。我不知道如何解决。我不了解Mapbox的文档。我只知道我需要一些表情。

Actual effect 1

Actual effect 2

public class CovidMapFragment extends Fragment implements CovidMapContract.View {


private MapView mapView;
private MapboxMap mapboxMap;
private Mainactivity activity;
private CovidMapPresenter presenter;



@Override
public void onAttach(Context context) {
    super.onAttach(context);
    activity = (Mainactivity) context;
}
@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) {
    Mapbox.getInstance(activity,getString(R.string.mapbox_access_token));
    View view = inflater.inflate(R.layout.fragment_map,container,false);
    return view;
}

@Override
public void onViewCreated(View view,Bundle savedInstanceState) {
    super.onViewCreated(view,savedInstanceState);

    mapView = activity.findViewById(R.id.mapView);

    mapView.onCreate(savedInstanceState);
    mapView.getMapAsync(new OnmapReadyCallback() {
        @Override
        public void onmapReady(@NonNull MapboxMap map) {

            mapboxMap = map;

            map.setStyle(Style.LIGHT,new Style.OnStyleLoaded() {
                @Override
                public void onStyleLoaded(@NonNull Style style) {


                    style.setTransition(new TransitionOptions(0,false));

                    mapboxMap.animateCamera(CameraUpdateFactory.newLatLngzoom(new LatLng(
                            51.919438,19.145136),3));

                    addClusteredGeoJsonSource(style);
                    style.addImage(
                            "cross-icon-id",Objects.requireNonNull(BitmapUtils.getBitmapFromDrawable(getResources().getDrawable(R.drawable.ic_circle))),true
                    );

                    Toast.makeText(activity,R.string.app_name,Toast.LENGTH_SHORT).show();
                }
            });
        }
    });


}
private void addClusteredGeoJsonSource(@NonNull Style loadedMapStyle) {


    try {
        loadedMapStyle.addSource(

                new GeoJsonSource("earthquakes",new URI("asset://earthquakes.geojson"),new GeoJsonOptions()
                                .withCluster(true)
                                .withClusterMaxzoom(14)
                                .withClusterRadius(50)
                )
        );
    } catch (URISyntaxException uriSyntaxException) {
        Timber.e("Check the URL %s",uriSyntaxException.getMessage());
    }


    SymbolLayer unclustered = new SymbolLayer("unclustered-points","earthquakes");

    unclustered.setProperties(
            iconImage("cross-icon-id"),iconSize(
                    division(
                            get("cases"),literal(4.0f)
                    )
            ),iconColor(
                    interpolate(exponential(1),get("cases"),stop(2.0,rgb(0,255,0)),stop(4,255)),stop(7.0,rgb(255,0))
                    )
            )
    );
    unclustered.setfilter(has("cases"));
    loadedMapStyle.addLayer(unclustered);


    int[][] layers = new int[][] {
            new int[] {7,ContextCompat.getcolor(activity.getapplicationContext(),R.color.red)},new int[] {4,R.color.green)},new int[] {0,R.color.blue)}
    };

    for (int i = 0; i < layers.length; i++) {

        CircleLayer circles = new CircleLayer("cluster-" + i,"earthquakes");
        circles.setProperties(
                circleColor(layers[i][1]),circleRadius(18f)
        );

        Expression pointCount = toNumber(get("point_count"));


        circles.setfilter(
                i == 0
                        ? all(has("point_count"),gte(pointCount,literal(layers[i][0]))
                ) : all(has("point_count"),literal(layers[i][0])),lt(pointCount,literal(layers[i - 1][0]))
                )
        );
        loadedMapStyle.addLayer(circles);
    }


    SymbolLayer count = new SymbolLayer("count","earthquakes");
    count.setProperties(
            //textField(Expression.toString(get("point_count"))),textField(Expression.toString(get("cases"))),textSize(12f),textColor(Color.WHITE),textIgnorePlacement(true),textAllowOverlap(true)
    );
    loadedMapStyle.addLayer(count);
}

@Override
public void onStart() {
    super.onStart();
    mapView.onStart();
}

@Override
public void onResume() {
    super.onResume();
    mapView.onResume();
}

@Override
public void onPause() {
    super.onPause();
    mapView.onPause();
}

@Override
public void onStop() {
    super.onStop();
    mapView.onStop();
}

@Override
public void onLowMemory() {
    super.onLowMemory();
    mapView.onLowMemory();
}

@Override
public void onDestroy() {
    super.onDestroy();
    mapView.onDestroy();
}

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    mapView.onSaveInstanceState(outState);
}


@Override
public void showMessage(String message) {
    System.out.println("Fragment");
}

}

ylzg_2000 回答:圆形图层Mabox-计算聚集点(Java)

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2348273.html

大家都在问