Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/223.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
圆形图层映射框-在geojson(Java)中传递点数_Java_Android_Mapbox_Points - Fatal编程技术网

圆形图层映射框-在geojson(Java)中传递点数

圆形图层映射框-在geojson(Java)中传递点数,java,android,mapbox,points,Java,Android,Mapbox,Points,我有这个问题,因为我制作了这样的地图,上面有点,比如说,但在我的例子中,我想在地图上用每个国家的人口数来表示这样的点。geojson文件应在每个坐标上多加一个属性“number”。可能吗?我在Android上用Java编写代码 编辑: 现在我的小点没有正确聚集。缩小后的紫色(5)和深蓝色(4)应给出带有9号的红色点。现在我得到了没有数字的蓝点(我知道我只计算点数,这就是为什么蓝色) 公共类CovidMapFragment扩展片段实现CovidMapContract.View{ 私有地图视图;

我有这个问题,因为我制作了这样的地图,上面有点,比如说,但在我的例子中,我想在地图上用每个国家的人口数来表示这样的点。geojson文件应在每个坐标上多加一个属性“number”。可能吗?我在Android上用Java编写代码

编辑: 现在我的小点没有正确聚集。缩小后的紫色(5)和深蓝色(4)应给出带有9号的红色点。现在我得到了没有数字的蓝点(我知道我只计算点数,这就是为什么蓝色)

公共类CovidMapFragment扩展片段实现CovidMapContract.View{
私有地图视图;
私有MapboxMap MapboxMap;
私人活动;
私人CovidMapPresenter;
@凌驾
公共void-onAttach(上下文){
super.onAttach(上下文);
活动=(MainActivity)上下文;
}
@凌驾
创建视图上的公共视图(布局、充气机、视图组容器、,
Bundle savedInstanceState){
getInstance(活动,getString(R.string.Mapbox\u访问\u令牌));
视图=充气机。充气(R.layout.fragment\u图,容器,假);
返回视图;
}
@凌驾
已创建视图上的公共void(视图,捆绑保存状态){
super.onViewCreated(视图,savedInstanceState);
mapView=activity.findViewById(R.id.mapView);
onCreate(savedInstanceState);
getMapAsync(新的OnMapReadyCallback(){
@凌驾
mapready上的公共无效(@NonNull MapboxMap-map){
mapboxMap=map;
map.setStyle(Style.LIGHT,new Style.OnStyleLoaded(){
@凌驾
已加载的公共void onstyled(@NonNull Style){
setTransition(新的TransitionOptions(0,0,false));
mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(新LatLng(
51.919438, 19.145136), 3));
addClusteredGeoJsonSource(样式);
style.addImage(
“交叉图标id”,
Objects.requirennull(BitmapUtils.getBitmapFromDrawable(getResources().getDrawable(R.drawable.ic_circle)),
真的
);
Toast.makeText(活动,R.string.app_名称,
吐司。长度(短)。show();
}
});
}
});
}
私有void addClusteredGeoJsonSource(@NonNull Style loadedMapStyle){
试一试{
loadedMapStyle.addSource(
新GeoJsonSource(“地震”,
新URI(“asset://earthquakes.geojson"),
新地理选项()
.withCluster(真)
.使用ClusterMaxZoom(14)
.带群集半径(50)
)
);
}捕获(URISyntaxException URISyntaxException){
e(“检查URL%s”,uriSyntaxException.getMessage());
}
SymbolLayer unclustered=新SymbolLayer(“未聚集点”、“地震”);
unclustered.setProperties(
图标图像(“交叉图标id”),
意识到(
分部(
获取(“案例”),文字(4.0f)
)
),
iconColor(
插值(指数(1),获取(“案例”),
停止(2.0,rgb(0,255,0)),
停止(4,rgb(0,0,255)),
停止(7.0,rgb(255,0,0))
)
)
);
未聚集。setFilter(有(“案例”);
loadedMapStyle.addLayer(未聚集);
int[][]层=新int[][]{
新的int[]{7,ContextCompat.getColor(activity.getApplicationContext(),R.color.red)},
新的int[]{4,ContextCompat.getColor(activity.getApplicationContext(),R.color.green)},
新int[]{0,ContextCompat.getColor(activity.getApplicationContext(),R.color.blue)}
};
对于(int i=0;ipublic 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, 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, rgb(0, 0, 255)),
                                stop(7.0, rgb(255, 0, 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, ContextCompat.getColor(activity.getApplicationContext(), R.color.green)},
                new int[] {0, ContextCompat.getColor(activity.getApplicationContext(), 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"),

                            gte(pointCount, 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");
    }


}