Geographic overlays
crisol-geo is a small, dependency-light crate for maps: Web Mercator and equirectangular projections, GeoJSON point/line/polygon layers, and slippy-map tile math. crisol exposes it as crisol::geo behind the geo feature; crisol-plot turns a layer into ordinary series.
[dependencies]
crisol = { version = "1.15", features = ["geo"] }Project a layer
use crisol::components::plot::{Plot, geo};
use crisol::geo::{GeoJson, Projection, TileGrid};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let layer = GeoJson::parse(
r#"{
"type": "FeatureCollection",
"features": [
{"type": "Feature", "properties": {"name": "station"},
"geometry": {"type": "Point", "coordinates": [-3.7038, 40.4168]}},
{"type": "Feature", "properties": {"name": "route"},
"geometry": {"type": "LineString", "coordinates": [[-3.70, 40.41], [-3.69, 40.42]]}}
]
}"#,
)?;
let projected = layer.project(Projection::WebMercator);
assert_eq!(projected.len(), 2);
let plot = geo::add_to(
Plot::new("map").x_label("lon").y_label("lat"),
&layer,
&geo::GeoLayer::default(),
);
let _ = plot;
let grid = TileGrid::new(4);
let tile = grid.tile_for(-3.7038, 40.4168);
assert_eq!(tile.zoom, 4);
let bounds = grid.bounds(tile);
assert!(bounds[0] <= -3.7038 && -3.7038 <= bounds[2]);
assert_eq!(
grid.url("https://tiles.example/{z}/{x}/{y}.png", tile),
format!("https://tiles.example/4/{}/{}.png", tile.x, tile.y)
);
println!("geo layer and tile ok");
Ok(())
}GeoJson::parse accepts a geometry, a Feature, or a FeatureCollection; a geometry type outside the six supported ones returns GeoError::Unsupported. project returns a (name, paths) pair per feature. A point becomes one scatter series; lines and rings become line series.
Tiles
use crisol::geo::TileGrid;
let grid = TileGrid::new(8);
let tile = grid.tile_for(2.3522, 48.8566);
let url = grid.url("https://tiles.example/{z}/{x}/{y}.png", tile);
assert!(url.contains("/8/"));TileGrid::new clamps the zoom to 0–22. tile_for clamps latitude to the Web Mercator limit; bounds returns [west, south, east, north] in degrees. TileRequest in components::plot::geo stores the URL template next to the projection, and GeoLayer pairs both for an application that keeps one map.
Plot notes
- The projected layer is in meters for Web Mercator and degrees for equirectangular; set the axis labels to match.
- Geo series use the left y axis (
GEO_AXIS); a second axis is still available for data. - A large layer is ordinary plot data: decimation, export, legend toggles, and selection all work unchanged.
- The crate does not download tiles. The application fetches the URL and registers the image with its own texture cache.