[gnome-maps/wip/mark-user-location: 1/2] mapView: Display accuracy circle for user location



commit 056b00eca6321fc8a821842fbee3e263b760ce81
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Mon Apr 8 20:05:14 2013 +0300

    mapView: Display accuracy circle for user location
    
    Overlay a translucent circle to indicate accuracy of user's location on
    the map.

 src/mapView.js |   38 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)
---
diff --git a/src/mapView.js b/src/mapView.js
index f9e9315..4687ff1 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -60,6 +60,10 @@ const MapView = new Lang.Class({
         this._markerLayer.set_selection_mode(Champlain.SelectionMode.SINGLE);
         this._view.add_layer(this._markerLayer);
 
+        this._userLocationLayer = new Champlain.MarkerLayer();
+        this._userLocationLayer.set_selection_mode(Champlain.SelectionMode.NONE);
+        this._view.add_layer(this._userLocationLayer);
+
         this._factory = Champlain.MapSourceFactory.dup_default();
         this.setMapType(MapType.STREET);
 
@@ -124,6 +128,38 @@ const MapView = new Lang.Class({
         this._view.go_to(location.latitude, location.longitude);
     },
 
+    _showUserLocation: function (location) {
+        if (location.accuracy <= 0)
+            return;
+
+        this._userLocationLayer.remove_all();
+        let point = new Champlain.Point();
+        point.set_color(new Clutter.Color({ red: 0,
+                                            blue: 255,
+                                            green: 0,
+                                            alpha: 50 }));
+        point.set_location(location.latitude, location.longitude);
+        point.set_reactive(false);
+
+        let allocSize = Lang.bind(this,
+            function(zoom) {
+                let source = this._view.get_map_source();
+                let metersPerPixel = source.get_meters_per_pixel(zoom, location.latitude, 
location.longitude);
+                point.set_size(location.accuracy / metersPerPixel);
+            });
+        let zoom = Utils.getZoomLevelForAccuracy(location.accuracy);
+        allocSize(zoom);
+        this._userLocationLayer.add_marker(point);
+
+        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);
+            }));
+    },
+
     _gotoUserLocation: function () {
         let lastLocation = Application.settings.get_value('last-location');
         if (lastLocation.n_children() >= 3) {
@@ -138,6 +174,7 @@ const MapView = new Lang.Class({
             location.set_description(lastLocationDescription);
 
             this._gotoLocation(location, false);
+            this._showUserLocation(location);
         }
 
         let ipclient = new Geocode.Ipclient();
@@ -149,6 +186,7 @@ const MapView = new Lang.Class({
                     let location = ipclient.search_finish(res);
 
                     this._gotoLocation(location, true);
+                    this._showUserLocation(location);
 
                     let variant = GLib.Variant.new('ad', [location.latitude, location.longitude, 
location.accuracy]);
                     Application.settings.set_value('last-location', variant);


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