Ver código fonte

Add OrthograficView::zoom_at

which only includes a dummy implementation.
Johannes Hofmann 7 anos atrás
pai
commit
f95d4268c8
2 arquivos alterados com 39 adições e 10 exclusões
  1. 15
    8
      src/map_view_gl.rs
  2. 24
    2
      src/orthografic_view.rs

+ 15
- 8
src/map_view_gl.rs Ver arquivo

@@ -266,15 +266,22 @@ impl MapViewGl {
266 266
     }
267 267
 
268 268
     pub fn zoom_at(&mut self, pos: ScreenCoord, zoom_delta: f64) {
269
-        //TODO implement for OrthograficView
270
-        if self.map_view.zoom + zoom_delta < MIN_ZOOM_LEVEL {
271
-            MercatorView::set_zoom_at(&mut self.map_view, pos, MIN_ZOOM_LEVEL);
272
-        } else if self.map_view.zoom + zoom_delta > MAX_ZOOM_LEVEL {
273
-            MercatorView::set_zoom_at(&mut self.map_view, pos, MAX_ZOOM_LEVEL);
274
-        } else {
275
-            MercatorView::zoom_at(&mut self.map_view, pos, zoom_delta);
269
+        match self.projection {
270
+            Projection::Mercator => {
271
+                if self.map_view.zoom + zoom_delta < MIN_ZOOM_LEVEL {
272
+                    MercatorView::set_zoom_at(&mut self.map_view, pos, MIN_ZOOM_LEVEL);
273
+                } else if self.map_view.zoom + zoom_delta > MAX_ZOOM_LEVEL {
274
+                    MercatorView::set_zoom_at(&mut self.map_view, pos, MAX_ZOOM_LEVEL);
275
+                } else {
276
+                    MercatorView::zoom_at(&mut self.map_view, pos, zoom_delta);
277
+                }
278
+                self.map_view.center.normalize_xy();
279
+            },
280
+            Projection::Orthografic => {
281
+                //TODO ensure new zoom level in between min/max zoom level
282
+                OrthograficView::zoom_at(&mut self.map_view, pos, zoom_delta);
283
+            },
276 284
         }
277
-        self.map_view.center.normalize_xy();
278 285
     }
279 286
 
280 287
     pub fn change_tile_zoom_offset(&mut self, delta_offset: f64) {

+ 24
- 2
src/orthografic_view.rs Ver arquivo

@@ -287,7 +287,7 @@ impl OrthograficView {
287 287
     }
288 288
 
289 289
     // Returns the coordinates of the location that is nearest to the given `ScreenCoord`.
290
-    pub fn screen_coord_to_latlonrad(map_view: &MapView, screen_coord: ScreenCoord) -> LatLonRad {
290
+    pub fn screen_coord_to_sphere_point(map_view: &MapView, screen_coord: ScreenCoord) -> Point3<f64> {
291 291
         // Point on unit sphere
292 292
         let sphere_point = {
293 293
             let recip_radius = 2.0 * Self::diameter_physical_pixels(map_view).recip();
@@ -314,11 +314,33 @@ impl OrthograficView {
314 314
 
315 315
         // Rotate
316 316
         let inv_trans = Self::inv_rotation_matrix(map_view);
317
-        let p = inv_trans.transform_point(sphere_point);
317
+        inv_trans.transform_point(sphere_point)
318
+    }
319
+
320
+    // Returns the coordinates of the location that is nearest to the given `ScreenCoord`.
321
+    pub fn screen_coord_to_latlonrad(map_view: &MapView, screen_coord: ScreenCoord) -> LatLonRad {
322
+        let p = Self::screen_coord_to_sphere_point(map_view, screen_coord);
318 323
 
319 324
         // Transform to latitude, longitude
320 325
         LatLonRad::new(p.y.asin(), p.z.atan2(p.x))
321 326
     }
327
+
328
+    /// Change zoom value by `zoom_delta` and zoom to a position given in screen coordinates.
329
+    pub fn zoom_at(map_view: &mut MapView, pos: ScreenCoord, zoom_delta: f64) {
330
+        //TODO Do something sophisticated: Increase zoom and rotate slightly so that the given
331
+        // ScreenCoord points to the same geographical location.
332
+        /*
333
+        let latlon = Self::screen_coord_to_latlonrad(map_view, pos);
334
+
335
+        let delta_x = pos.x - map_view.width * 0.5;
336
+        let delta_y = pos.y - map_view.height * 0.5;
337
+
338
+        map_view.center = latlon.into();
339
+        */
340
+
341
+        map_view.zoom += zoom_delta;
342
+    }
343
+
322 344
 }
323 345
 
324 346
 #[cfg(test)]