mapserver: zoom
This commit is contained in:
parent
3d476999b9
commit
f5aa0349ee
|
@ -13,7 +13,6 @@ enum Error {
|
|||
Image(image::ImageError),
|
||||
Io(std::io::Error),
|
||||
Minetestmapper,
|
||||
Todo,
|
||||
}
|
||||
|
||||
#[async_std::main]
|
||||
|
@ -111,7 +110,13 @@ fn generate_tile(
|
|||
} else {
|
||||
if generate {
|
||||
let (sender, receiver) = crossbeam_channel::bounded(0);
|
||||
tasks_guard.insert((z, x, y), sender);
|
||||
let lock_coord = if z > config.zoom_default {
|
||||
// Generate 4 tiles at once
|
||||
(z, x & !1, y & !1)
|
||||
} else {
|
||||
(z, x, y)
|
||||
};
|
||||
tasks_guard.insert(lock_coord, sender);
|
||||
drop(tasks_guard);
|
||||
|
||||
let res: Result<(), Error> = try {
|
||||
|
@ -189,11 +194,116 @@ fn generate_tile(
|
|||
Error::Image(e)
|
||||
})?;
|
||||
}
|
||||
std::cmp::Ordering::Greater => Err(Error::Todo)?,
|
||||
std::cmp::Ordering::Greater => {
|
||||
let ntile_path =
|
||||
get_dep_tile(z - 1, x / 2, y / 2, tasks.clone(), config.clone())?;
|
||||
let ntile = image::open(ntile_path).map_err(Error::Image)?;
|
||||
let ntile = image::imageops::resize(
|
||||
&ntile,
|
||||
config.tile_size as u32 * 2,
|
||||
config.tile_size as u32 * 2,
|
||||
image::imageops::Nearest,
|
||||
);
|
||||
|
||||
image::imageops::crop_imm(
|
||||
&ntile,
|
||||
0,
|
||||
0,
|
||||
config.tile_size as u32,
|
||||
config.tile_size as u32,
|
||||
)
|
||||
.to_image()
|
||||
.save(format!(
|
||||
"{}{}/{}/{}.png",
|
||||
config.output_path, z, lock_coord.1, lock_coord.2
|
||||
))
|
||||
.map_err(|e| {
|
||||
error!(
|
||||
"Generating tile ({},{},{}): {}",
|
||||
z, lock_coord.1, lock_coord.2, e
|
||||
);
|
||||
Error::Image(e)
|
||||
})?;
|
||||
image::imageops::crop_imm(
|
||||
&ntile,
|
||||
0,
|
||||
config.tile_size as u32,
|
||||
config.tile_size as u32,
|
||||
config.tile_size as u32,
|
||||
)
|
||||
.to_image()
|
||||
.save(format!(
|
||||
"{}{}/{}/{}.png",
|
||||
config.output_path,
|
||||
z,
|
||||
lock_coord.1,
|
||||
lock_coord.2 + 1
|
||||
))
|
||||
.map_err(|e| {
|
||||
error!(
|
||||
"Generating tile ({},{},{}): {}",
|
||||
z,
|
||||
lock_coord.1,
|
||||
lock_coord.2 + 1,
|
||||
e
|
||||
);
|
||||
Error::Image(e)
|
||||
})?;
|
||||
image::imageops::crop_imm(
|
||||
&ntile,
|
||||
config.tile_size as u32,
|
||||
0,
|
||||
config.tile_size as u32,
|
||||
config.tile_size as u32,
|
||||
)
|
||||
.to_image()
|
||||
.save(format!(
|
||||
"{}{}/{}/{}.png",
|
||||
config.output_path,
|
||||
z,
|
||||
lock_coord.1 + 1,
|
||||
lock_coord.2
|
||||
))
|
||||
.map_err(|e| {
|
||||
error!(
|
||||
"Generating tile ({},{},{}): {}",
|
||||
z,
|
||||
lock_coord.1 + 1,
|
||||
lock_coord.2,
|
||||
e
|
||||
);
|
||||
Error::Image(e)
|
||||
})?;
|
||||
image::imageops::crop_imm(
|
||||
&ntile,
|
||||
config.tile_size as u32,
|
||||
config.tile_size as u32,
|
||||
config.tile_size as u32,
|
||||
config.tile_size as u32,
|
||||
)
|
||||
.to_image()
|
||||
.save(format!(
|
||||
"{}{}/{}/{}.png",
|
||||
config.output_path,
|
||||
z,
|
||||
lock_coord.1 + 1,
|
||||
lock_coord.2 + 1
|
||||
))
|
||||
.map_err(|e| {
|
||||
error!(
|
||||
"Generating tile ({},{},{}): {}",
|
||||
z,
|
||||
lock_coord.1 + 1,
|
||||
lock_coord.2 + 1,
|
||||
e
|
||||
);
|
||||
Error::Image(e)
|
||||
})?;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
tasks.write().remove(&(z, x, y));
|
||||
tasks.write().remove(&lock_coord);
|
||||
receiver.recv().ok();
|
||||
res?;
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue