bevy_slippy_tiles

Crates.iobevy_slippy_tiles
lib.rsbevy_slippy_tiles
version
sourcesrc
created_at2023-01-23 19:17:34.483439
updated_at2024-12-06 21:28:51.950242
descriptionProvides slippy tile fetching functionality in the Bevy game engine
homepage
repositoryhttps://github.com/edouardpoitras/bevy_slippy_tiles
max_upload_size
id766097
Cargo.toml error:TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Edouard Poitras (edouardpoitras)

documentation

README

Bevy Slippy Tiles

Bevy Slippy Tiles Latest version Documentation MIT Apache

A helper bevy plugin to handle downloading and displaying OpenStreetMap-compliant slippy tiles.

[DownloadSlippyTilesEvent] can be fired to request one or more slippy tile downloads.

[SlippyTileDownloadedEvent] is fired when a requested slippy tile has been retrieved successfully. The file path is stored in the event and can be used with the asset loader.

Features

  • Automatic tile rendering with configurable reference point
  • Control over tile Z-layer for proper rendering order
  • Optional transform offset for precise positioning
  • Toggle automatic rendering for manual control
  • Configurable download settings (concurrency, retries, rate limits)

Example

Here's a snippet showing how to download and display map tiles at a specific location. This app will load a slippy tile and its surrounding 24 tiles at the specified latitude and longitude.

Run with: cargo run --example simple

use bevy::prelude::*;
use bevy_slippy_tiles::*;

const LATITUDE: f64 = 45.4111;
const LONGITUDE: f64 = -75.6980;

fn main() {
    App::new()
        // Configure settings with defaults
        .insert_resource(SlippyTilesSettings {
            reference_latitude: LATITUDE,
            reference_longitude: LONGITUDE,
            ..Default::default()
        })
        .add_plugins(DefaultPlugins)
        .add_plugins(SlippyTilesPlugin)
        .add_systems(Startup, request_slippy_tiles)
        .run();
}

fn request_slippy_tiles(mut commands: Commands, mut download_slippy_tile_events: EventWriter<DownloadSlippyTilesEvent>) {
    commands.spawn(Camera2dBundle::default());
    let slippy_tile_event = DownloadSlippyTilesEvent {
        tile_size: TileSize::Normal,    // Size of tiles - Normal = 256px, Large = 512px
        zoom_level: ZoomLevel::L18,     // Map zoom level (L0 = entire world, L19 = closest)
        coordinates: Coordinates::from_latitude_longitude(LATITUDE, LONGITUDE),
        radius: Radius(2),              // Request surrounding tiles (2 = 25 tiles total)
        use_cache: true,                // Use cached tiles if available
    };
    download_slippy_tile_events.send(slippy_tile_event);
}

Configuration

SlippyTilesSettings

The plugin uses reasonable defaults but can be configured:

  • endpoint: The tile server endpoint
  • tiles_directory: The tile cache directory (where tiles will end up after being downloaded)
  • max_concurrent_downloads: Maximum number of concurrent tile downloads
  • max_retries: Maximum number of times a tile download will be retried upon failure
  • rate_limit_requests: Maximum number of tile download requests within the rate limit window
  • rate_limit_window: The duration of the rate limit window
  • reference_latitude/reference_longitude: The geographic point that should appear at Transform(0,0,0) (or at transform_offset if specified)
  • transform_offset: Optional Transform to offset where the reference point appears
  • z_layer: Z coordinate for rendered tiles, useful for layering with other sprites
  • auto_render: Toggle automatic tile rendering (disable for manual control)
SlippyTilesSettings {
    endpoint: "https://tile.openstreetmap.org".into(), // Tile server endpoint
    tiles_directory: "tiles/".into(), // Cache directory
    max_concurrent_downloads: 4, // Concurrent downloads
    max_retries: 3, // Download retry attempts
    rate_limit_requests: 10, // Rate limit requests
    rate_limit_window: Duration::from_secs(1), // Rate limit window
    reference_latitude: 45.4111, // Reference latitude
    reference_longitude: -75.6980, // Reference longitude
    transform_offset: Some( // Optional offset from 0,0 (default: None)
        Transform::from_xyz(100.0, 100.0, 0.0)
    ),
    z_layer: 1.0, // Z coordinate for tiles (default: 0.0)
    auto_render: true, // Enable automatic rendering (default: true)
}

Bevy Compatibility

bevy bevy_slippy_tiles
0.15 0.8
0.14 0.7
0.13 0.5
0.12 0.4
0.11 0.3
0.10 0.2
0.9 0.1.3
Commit count: 52

cargo fmt