0

I'm working with gis data and bevy with the following code

fn building_meshes(
    mut commands: Commands,
    asset_server: Res<AssetServer>,
    mut assets_meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<ColorMaterial>>,
    windows: Res<Windows>,
) {
    let feature_collection =
        read_geojson_feature_collection(read_geojson("maps/only_point.geojson".to_owned()));
    let from = "EPSG:4326";
    let to = "EPSG:3857";
    let proj = Proj::new_known_crs(&from, &to, None).unwrap();

    for feature in feature_collection {
        let geometry = feature.geometry.unwrap();
        let geom: geo_types::geometry::Geometry<f64> = geometry.try_into().unwrap();
        // convert geom to proj format
        let proj_geom: geo_types::Geometry<f64> = geom.clone().into();
        let result = projection_geometry(proj_geom, proj);

        let mesh_iter = build_bevy_meshes(&result, Color::RED, BuildBevyMeshesContext::new())
            .unwrap()
            .collect::<Vec<_>>();

        for prepared_mesh in mesh_iter {
            match prepared_mesh {
                geo_bevy::PreparedMesh::Point(points) => {
                    for geo::Point(coord) in points.iter() {
                        let color = Color::RED;
                        let bundle = SpriteBundle {
                            sprite: Sprite {
                                color,
                                ..Default::default()
                            },
                            texture: asset_server.load("circle.png"),
                            transform: bevy::prelude::Transform::from_translation(
                                bevy::prelude::Vec3::new(coord.x as f32, coord.y as f32, 0.),
                            ),
                            ..Default::default()
                        };

                        commands.spawn(bundle);
                    }
                }
                geo_bevy::PreparedMesh::Polygon { mesh, color } => {
                    let material = materials.add(color.into());

                    commands.spawn(MaterialMesh2dBundle {
                        material,
                        mesh: bevy::sprite::Mesh2dHandle(assets_meshes.add(mesh)),
                        visibility: bevy::render::view::Visibility { is_visible: true },
                        ..Default::default()
                    });
                }
                geo_bevy::PreparedMesh::LineString { mesh, color } => {
                    //just like Polygon
                }
            }
        }
    }
    commands.spawn(Camera2dBundle::default());
}

Where

projection_geometry

is a simple function that do the conversion with proj like that

match proj_geom {
         geo_types::Geometry::Point(point) => {
             let new_point = proj.convert(point).unwrap();
             geo_types::Geometry::Point(new_point)
         }
         _ => todo!(),
}

But the problem is that the new coordinates are larger than the size of the window so how can I fit them inside it and then scale the mesh size?

0 Answers0