update
This commit is contained in:
parent
9a929b3493
commit
ada325c230
@ -3,15 +3,11 @@ use crate::render::WindowCoord;
|
|||||||
use super::{proj::ProjectionS, Range};
|
use super::{proj::ProjectionS, Range};
|
||||||
use geo_types::{coord, Coord as GCoord, LineString};
|
use geo_types::{coord, Coord as GCoord, LineString};
|
||||||
use proj::{Proj, ProjError};
|
use proj::{Proj, ProjError};
|
||||||
use std::ops;
|
|
||||||
|
|
||||||
pub struct Mapper {
|
pub struct Mapper {
|
||||||
proj: Proj,
|
proj: Proj,
|
||||||
pub range: (Range, Range),
|
pub range: (Range, Range),
|
||||||
bounds: (f64, f64, f64, f64),
|
bounds: (f64, f64, f64, f64),
|
||||||
scale: f32,
|
|
||||||
translate: (f32, f32),
|
|
||||||
focus_point: Option<(f64, f64)>,
|
|
||||||
}
|
}
|
||||||
impl From<Proj> for Mapper {
|
impl From<Proj> for Mapper {
|
||||||
fn from(proj: Proj) -> Self {
|
fn from(proj: Proj) -> Self {
|
||||||
@ -21,9 +17,6 @@ impl From<Proj> for Mapper {
|
|||||||
proj: proj,
|
proj: proj,
|
||||||
range: (default_range.0.into(), default_range.1.into()),
|
range: (default_range.0.into(), default_range.1.into()),
|
||||||
bounds,
|
bounds,
|
||||||
scale: 1.0,
|
|
||||||
translate: (0.0, 0.0),
|
|
||||||
focus_point: None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -50,42 +43,17 @@ impl Mapper {
|
|||||||
proj: proj,
|
proj: proj,
|
||||||
range,
|
range,
|
||||||
bounds,
|
bounds,
|
||||||
scale,
|
|
||||||
translate,
|
|
||||||
focus_point: None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fore_map(&self, coord: WindowCoord) -> Result<(f64, f64), ProjError> {
|
pub fn fore_map(&self, coord: WindowCoord) -> Result<(f64, f64), ProjError> {
|
||||||
let (t1, t2) = if let Some(_) = self.focus_point {
|
|
||||||
let (a, b) = self.translate;
|
|
||||||
(a * (self.scale - 1.0), b * (self.scale - 1.0))
|
|
||||||
} else {
|
|
||||||
self.translate
|
|
||||||
};
|
|
||||||
let (x, y) = coord;
|
let (x, y) = coord;
|
||||||
let c = (x as f64 + t1 as f64) / self.scale as f64 * (self.bounds.1 - self.bounds.0)
|
let c = (x as f64) * (self.bounds.1 - self.bounds.0) + self.bounds.0;
|
||||||
+ self.bounds.0;
|
let d = (y as f64) * (self.bounds.3 - self.bounds.2) + self.bounds.2;
|
||||||
let d = (y as f64 + t2 as f64) / self.scale as f64 * (self.bounds.3 - self.bounds.2)
|
|
||||||
+ self.bounds.2;
|
|
||||||
let (lon, lat) = self.proj.project((c, d), true)?;
|
let (lon, lat) = self.proj.project((c, d), true)?;
|
||||||
Ok((lon.to_degrees(), lat.to_degrees()))
|
Ok((lon.to_degrees(), lat.to_degrees()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_scale(&mut self, scale: f32) {
|
|
||||||
self.scale = scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_translate(&mut self, translate: (f32, f32)) {
|
|
||||||
self.translate = translate;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_focus_point(&mut self, point: (f64, f64)) {
|
|
||||||
self.focus_point = Some(point);
|
|
||||||
let (rx, ry) = self.map(point).unwrap();
|
|
||||||
self.translate = (rx as f32, ry as f32);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn point_in_bound(&self, point: (f64, f64)) -> bool {
|
pub fn point_in_bound(&self, point: (f64, f64)) -> bool {
|
||||||
let (x, y) = point;
|
let (x, y) = point;
|
||||||
let (lon_range, lat_range) = self.range;
|
let (lon_range, lat_range) = self.range;
|
||||||
@ -104,17 +72,8 @@ impl Mapper {
|
|||||||
.proj
|
.proj
|
||||||
.convert((point.0.to_radians(), point.1.to_radians()))?;
|
.convert((point.0.to_radians(), point.1.to_radians()))?;
|
||||||
|
|
||||||
let (t1, t2) = if let Some(_) = self.focus_point {
|
let x = (p1 - self.bounds.0) / (self.bounds.1 - self.bounds.0);
|
||||||
let (a, b) = self.translate;
|
let y = (p2 - self.bounds.2) / (self.bounds.3 - self.bounds.2);
|
||||||
(a * (self.scale - 1.0), b * (self.scale - 1.0))
|
|
||||||
} else {
|
|
||||||
self.translate
|
|
||||||
};
|
|
||||||
|
|
||||||
let x = (p1 - self.bounds.0) / (self.bounds.1 - self.bounds.0) * self.scale as f64
|
|
||||||
- t1 as f64 * self.scale as f64;
|
|
||||||
let y = (p2 - self.bounds.2) / (self.bounds.3 - self.bounds.2) * self.scale as f64
|
|
||||||
- t2 as f64 * self.scale as f64;
|
|
||||||
|
|
||||||
Ok((x, y))
|
Ok((x, y))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,13 +30,22 @@ impl Monitor {
|
|||||||
scale_detecture.connect_scroll(clone!(
|
scale_detecture.connect_scroll(clone!(
|
||||||
@weak this as s, @weak render as r => @default-panic,move |_context, _x, y| {
|
@weak this as s, @weak render as r => @default-panic,move |_context, _x, y| {
|
||||||
let renderer = s.imp().renderer.borrow();
|
let renderer = s.imp().renderer.borrow();
|
||||||
|
let p = r.imp().config.borrow().pointer_lon_lat;
|
||||||
|
let (px,py) = r.imp().mapper.borrow().map(p).unwrap();
|
||||||
|
|
||||||
|
let mut scale = 1.0;
|
||||||
|
|
||||||
renderer.change_cfg(|cfg| {
|
renderer.change_cfg(|cfg| {
|
||||||
let current_scale = cfg.scale;
|
let current_scale = cfg.scale;
|
||||||
let scale = (current_scale - y as f32 / 10.0).max(1.0).min(5.0);
|
let s = (current_scale - y as f32 / 10.0).max(1.0).min(5.0);
|
||||||
cfg.scale = scale;
|
cfg.scale = s;
|
||||||
r.imp().mapper.borrow_mut().set_scale(scale);
|
scale = s;
|
||||||
});
|
});
|
||||||
r.calc_translate();
|
r.set_translate((
|
||||||
|
px as f32 * (scale - 1.0),
|
||||||
|
py as f32 * (scale - 1.0)
|
||||||
|
));
|
||||||
|
r.queue_render();
|
||||||
Inhibit(false)
|
Inhibit(false)
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
@ -48,6 +57,7 @@ impl Monitor {
|
|||||||
r.change_cfg(|cfg|{
|
r.change_cfg(|cfg|{
|
||||||
cfg.updated_translate = ( - ox as f32, -oy as f32);
|
cfg.updated_translate = ( - ox as f32, -oy as f32);
|
||||||
} );
|
} );
|
||||||
|
r.queue_render();
|
||||||
}));
|
}));
|
||||||
drag_detecture.connect_drag_end(clone!(
|
drag_detecture.connect_drag_end(clone!(
|
||||||
@weak render as r => move |this,_,_|{
|
@weak render as r => move |this,_,_|{
|
||||||
|
|||||||
@ -79,8 +79,8 @@ impl BackgroundWidget {
|
|||||||
.points()
|
.points()
|
||||||
.map(|p| {
|
.map(|p| {
|
||||||
(
|
(
|
||||||
p.x() as f32 * canvas_width - translate.0,
|
p.x() as f32 * canvas_width * scale - translate.0,
|
||||||
(1.0 - p.y() as f32) * canvas_height - translate.1,
|
(1.0 - p.y() as f32) * canvas_height * scale - translate.1,
|
||||||
)
|
)
|
||||||
.into()
|
.into()
|
||||||
})
|
})
|
||||||
@ -135,8 +135,8 @@ impl BackgroundWidget {
|
|||||||
.points()
|
.points()
|
||||||
.map(|p| {
|
.map(|p| {
|
||||||
(
|
(
|
||||||
p.x() as f32 * canvas_width - translate.0,
|
p.x() as f32 * canvas_width * scale - translate.0,
|
||||||
(1.0 - p.y()) as f32 * canvas_height - translate.1,
|
(1.0 - p.y()) as f32 * canvas_height * scale - translate.1,
|
||||||
)
|
)
|
||||||
.into()
|
.into()
|
||||||
})
|
})
|
||||||
@ -236,8 +236,8 @@ impl BackgroundWidget {
|
|||||||
) -> (f32, f32) {
|
) -> (f32, f32) {
|
||||||
let (x, y) = mapper.map(point).unwrap();
|
let (x, y) = mapper.map(point).unwrap();
|
||||||
(
|
(
|
||||||
x as f32 * canvas_width - translate.0,
|
x as f32 * canvas_width * scale - translate.0,
|
||||||
(1.0 - y as f32) * canvas_height - translate.1,
|
(1.0 - y as f32) * canvas_height * scale - translate.1,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -63,10 +63,10 @@ impl ObjectImpl for Render {
|
|||||||
let area = self.obj();
|
let area = self.obj();
|
||||||
area.set_has_stencil_buffer(true);
|
area.set_has_stencil_buffer(true);
|
||||||
|
|
||||||
area.add_tick_callback(|area, _| {
|
// area.add_tick_callback(|area, _| {
|
||||||
area.queue_render();
|
// area.queue_render();
|
||||||
glib::Continue(true)
|
// glib::Continue(true)
|
||||||
});
|
// });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -69,33 +69,26 @@ impl Render {
|
|||||||
let cw = canvas.width();
|
let cw = canvas.width();
|
||||||
let ch = canvas.height();
|
let ch = canvas.height();
|
||||||
let (tx, ty) = self.imp().translate();
|
let (tx, ty) = self.imp().translate();
|
||||||
println!("tx,ty: {:?}", (tx, ty));
|
let scale = self.imp().config.borrow().scale;
|
||||||
println!("x :{} , y: {}, x + tx :{}", x, y, x + tx);
|
|
||||||
let (lon, lat) = self
|
let (lon, lat) = self
|
||||||
.imp()
|
.imp()
|
||||||
.mapper
|
.mapper
|
||||||
.borrow()
|
.borrow()
|
||||||
.fore_map((
|
.fore_map((
|
||||||
(x * dpi as f32+ tx) / cw,
|
(x * dpi as f32 + tx) / cw / scale,
|
||||||
(1.0 - (y * dpi as f32+ ty) / ch ),
|
(1.0 - (y * dpi as f32 + ty) / ch / scale),
|
||||||
))
|
))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
println!("lon,lat : {:?}", (lon, lat));
|
|
||||||
let mut cfg = self.imp().config.borrow_mut();
|
let mut cfg = self.imp().config.borrow_mut();
|
||||||
cfg.pointer_lon_lat = (lon, lat);
|
cfg.pointer_lon_lat = (lon, lat);
|
||||||
cfg.pointer_location = (x, y);
|
cfg.pointer_location = (x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn calc_translate(&self) {
|
pub fn set_translate(&self, trans: (f32, f32)) {
|
||||||
let ll = self.imp().config.borrow().pointer_lon_lat;
|
if let Some(c) = self.imp().canvas.borrow().as_ref() {
|
||||||
let scale = self.imp().config.borrow().scale;
|
self.imp().config.borrow_mut().translate = (c.width() * trans.0, c.height() * trans.1);
|
||||||
let (rx, ry) = self.imp().mapper.borrow().map((ll.0, ll.1)).unwrap();
|
}
|
||||||
|
|
||||||
self.imp()
|
|
||||||
.mapper
|
|
||||||
.borrow_mut()
|
|
||||||
.set_translate((rx as f32 * (scale - 1.0), ry as f32 * (scale - 1.0)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_mapper(&self, mapper: Mapper) {
|
pub fn set_mapper(&self, mapper: Mapper) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user