[gnome-maps] userLocation: Don't show accuracy circle bigger than view



commit 33953b8e0bfe4e1c17abf12de3b01ea8ad4d0812
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Sun Apr 14 21:13:09 2013 +0300

    userLocation: Don't show accuracy circle bigger than view
    
    If zoom level is high that accuracy circle doesn't fit in the view,
    don't show it at all. The accuracy info on the location itself should be
    sufficient in this case.
    
    This way we avoid creating too big textures w/o ugly hacks.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=697736

 src/userLocation.js | 52 ++++++++++++++++++++++++----------------------------
 1 file changed, 24 insertions(+), 28 deletions(-)
---
diff --git a/src/userLocation.js b/src/userLocation.js
index 87377fa..ff0468d 100644
--- a/src/userLocation.js
+++ b/src/userLocation.js
@@ -99,41 +99,37 @@ const UserLocation = new Lang.Class({
         this._accuracyMarker.set_reactive(false);
 
         this._updateAccuracyMarker();
-        this._locationMarker.connect("notify::selected", Lang.bind(this, this._updateAccuracyMarker));
-
-        let allocSize = Lang.bind(this,
-            function(zoom) {
-                let source = this._view.get_map_source();
-                let metersPerPixel = source.get_meters_per_pixel(zoom,
-                                                                 this.latitude,
-                                                                 this.longitude);
-                let size = this.accuracy * 2 / metersPerPixel;
-                let viewWidth = this._view.get_width();
-                let viewHeight = this._view.get_height();
-                // Ensure we don't endup creating way too big texture/canvas,
-                // otherwise we easily end up with bus error
-                if ((viewWidth > 0 && viewHeight > 0) &&
-                    (size > viewWidth && size > viewHeight))
-                    // Pythagorean theorem to get diagonal length of the view
-                    size = Math.sqrt(Math.pow(viewWidth, 2) + Math.pow(viewHeight, 2));
-
-                this._accuracyMarker.set_size(size);
-            });
-        let zoom = Utils.getZoomLevelForAccuracy(this.accuracy);
-        allocSize(zoom);
+        if (this._selectedId > 0)
+            this._locationMarker.disconnect(this._selectedId);
+        this._selectedId = this._locationMarker.connect("notify::selected",
+                                                        Lang.bind(this, this._updateAccuracyMarker));
+
         layer.add_marker(this._accuracyMarker);
         layer.add_marker(this._locationMarker);
 
         if (this._zoomLevelId > 0)
             this._view.disconnect(this._zoomLevelId);
-        this._zoomLevelId = this._view.connect("notify::zoom-level", Lang.bind(this,
-            function() {
-                let zoom = this._view.get_zoom_level();
-                allocSize(zoom);
-            }));
+        this._zoomLevelId = this._view.connect("notify::zoom-level", Lang.bind(this, 
this._updateAccuracyMarker));
     },
 
     _updateAccuracyMarker: function() {
-        this._accuracyMarker.visible = this._locationMarker.get_selected();
+        if (!this._locationMarker.get_selected()) {
+            this._accuracyMarker.hide();
+            return;
+        }
+
+        let zoom = this._view.get_zoom_level();
+        let source = this._view.get_map_source();
+        let metersPerPixel = source.get_meters_per_pixel(zoom, this.latitude, this.longitude);
+        let size = this.accuracy * 2 / metersPerPixel;
+        let viewWidth = this._view.get_width();
+        let viewHeight = this._view.get_height();
+        if ((viewWidth > 0 && viewHeight > 0) &&
+            (size > viewWidth && size > viewHeight))
+            this._accuracyMarker.hide();
+        else {
+            this._accuracyMarker.set_size(size);
+            this._accuracyMarker.show();
+        }
     },
 });


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]