[gnome-maps/wip/refactor: 5/5] MapView: move out user location layer
- From: Mattias Bengtsson <mattiasb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/refactor: 5/5] MapView: move out user location layer
- Date: Mon, 18 Aug 2014 01:32:33 +0000 (UTC)
commit 5098d797909d51acf16dd88dcb0eb54922dc08c6
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date: Mon Aug 18 03:29:07 2014 +0200
MapView: move out user location layer
Move out the user location layer and its associated methods to its own
class.
src/gnome-maps.js.gresource.xml | 1 +
src/mainWindow.js | 10 ++---
src/mapView.js | 49 ++++------------------
src/userLocationLayer.js | 87 +++++++++++++++++++++++++++++++++++++++
4 files changed, 101 insertions(+), 46 deletions(-)
---
diff --git a/src/gnome-maps.js.gresource.xml b/src/gnome-maps.js.gresource.xml
index 0ae9a62..b32910f 100644
--- a/src/gnome-maps.js.gresource.xml
+++ b/src/gnome-maps.js.gresource.xml
@@ -27,6 +27,7 @@
<file>settings.js</file>
<file>sidebar.js</file>
<file>userLocation.js</file>
+ <file>userLocationLayer.js</file>
<file>utils.js</file>
<file>zoomControl.js</file>
</gresource>
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 857d20e..e4771b8 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -64,7 +64,7 @@ const MainWindow = new Lang.Class({
this.mapView = new MapView.MapView();
overlay.add(this.mapView);
- this.mapView.gotoUserLocation(false);
+ this.mapView.userLocationLayer.gotoUserLocation(false);
this._sidebar = new Sidebar.Sidebar(this.mapView);
overlay.add_overlay(this._sidebar);
@@ -252,14 +252,12 @@ const MainWindow = new Lang.Class({
_onGotoUserLocationActivate: function() {
if (Application.geoclue.userSetLocation) {
- Utils.once(Application.geoclue,
- 'location-changed',
- (function() {
- this.mapView.gotoUserLocation(true);
+ Utils.once(Application.geoclue, 'location-changed', (function() {
+ this.mapView.userLocationLayer.gotoUserLocation(true);
}).bind(this));
Application.geoclue.findLocation();
} else
- this.mapView.gotoUserLocation(true);
+ this.mapView.userLocationLayer.gotoUserLocation(true);
},
_onMapTypeMenuActivate: function(action) {
diff --git a/src/mapView.js b/src/mapView.js
index f167234..1a8f8b2 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -40,6 +40,7 @@ const MapLocation = imports.mapLocation;
const PlaceLayer = imports.placeLayer;
const RouteLayer = imports.routeLayer;
const UserLocation = imports.userLocation;
+const UserLocationLayer = imports.userLocationLayer;
const _ = imports.gettext.gettext;
const MapType = {
@@ -61,10 +62,6 @@ const MapView = new Lang.Class({
this._factory = Champlain.MapSourceFactory.dup_default();
this.setMapType(MapType.STREET);
-
- this._updateUserLocation();
- Application.geoclue.connect("location-changed",
- this._updateUserLocation.bind(this));
},
_initView: function() {
@@ -95,8 +92,10 @@ const MapView = new Lang.Class({
this._placeLayer = new PlaceLayer.PlaceLayer({ mapView: this });
this.view.add_layer(this._placeLayer);
- let mode = Champlain.SelectionMode.SINGLE;
- this._userLocationLayer = new Champlain.MarkerLayer({ selection_mode: mode });
+ this._userLocationLayer =
+ new UserLocationLayer.UserLocationLayer({ mapView: this,
+ model: Application.geoclue
+ });
this.view.add_layer(this._userLocationLayer);
},
@@ -108,6 +107,10 @@ const MapView = new Lang.Class({
return this._placeLayer;
},
+ get userLocationLayer() {
+ return this._userLocationLayer;
+ },
+
setMapType: function(mapType) {
if (this.view.map_source.id === mapType)
return;
@@ -131,40 +134,6 @@ const MapView = new Lang.Class({
this.view.ensure_visible(bbox, true);
},
- gotoUserLocation: function(animate) {
- this.emit('going-to-user-location');
- this._userLocation.once("gone-to", (function() {
- this.emit('gone-to-user-location');
- }).bind(this));
- this._userLocation.goTo(animate);
- },
-
- userLocationVisible: function() {
- let box = this.view.get_bounding_box();
-
- return box.covers(this._userLocation.latitude, this._userLocation.longitude);
- },
-
- _updateUserLocation: function() {
- if (!Application.geoclue)
- return;
-
- let location = Application.geoclue.location;
-
- if (!location)
- return;
-
- let place = Geocode.Place.new_with_location(location.description,
- Geocode.PlaceType.UNKNOWN,
- location);
-
- let selected = this._userLocation && this._userLocation.getSelected();
- this._userLocation = new UserLocation.UserLocation(place, this);
- this._userLocation.show(this._userLocationLayer);
- this._userLocation.setSelected(selected);
- this.emit('user-location-changed');
- },
-
_onViewMoved: function() {
this.emit('view-moved');
}
diff --git a/src/userLocationLayer.js b/src/userLocationLayer.js
new file mode 100644
index 0000000..ac0b56e
--- /dev/null
+++ b/src/userLocationLayer.js
@@ -0,0 +1,87 @@
+/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
+/* vim: set et ts=4 sw=4: */
+/*
+ * Copyright (c) 2011, 2012, 2013 Red Hat, Inc.
+ * Copyright (c) 2014 Mattias Bengtsson
+ *
+ * GNOME Maps is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * GNOME Maps is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with GNOME Maps; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
+ * Mattias Bengtsson <mattias jc bengtsson gmail com>
+ */
+
+const Champlain = imports.gi.Champlain;
+const Geocode = imports.gi.GeocodeGlib;
+const Lang = imports.lang;
+
+const UserLocation = imports.userLocation;
+
+const UserLocationLayer = new Lang.Class({
+ Name: 'UserLocationLayer',
+ Extends: Champlain.MarkerLayer,
+
+ _init: function(props) {
+ props = props || {};
+
+ let model = props.model;
+ delete props.model;
+
+ this._mapView = props.mapView;
+ delete props.mapView;
+
+ if (props.selection_mode === undefined)
+ props.selection_mode = Champlain.SelectionMode.SINGLE;
+
+ this.parent(props);
+
+ if (model)
+ this.setModel(model);
+ },
+
+ setModel: function(model) {
+ this._model = model;
+
+ this._model.connect("location-changed",
+ this._refresh.bind(this));
+ this._refresh();
+ },
+
+ userLocationVisible: function() {
+ let box = this._mapView.view.get_bounding_box();
+
+ return box.covers(this._userLocation.latitude,
+ this._userLocation.longitude);
+ },
+
+ gotoUserLocation: function(animate) {
+ this._userLocation.goTo(animate);
+ },
+
+ _refresh: function() {
+ if (!this._model || !this._model.location)
+ return;
+
+ let location = this._model.location;
+ let place = Geocode.Place.new_with_location(location.description,
+ Geocode.PlaceType.UNKNOWN,
+ location);
+
+ let selected = this._userLocation && this._userLocation.getSelected();
+ this._userLocation = new UserLocation.UserLocation(place,
+ this._mapView);
+ this._userLocation.show(this);
+ this._userLocation.setSelected(selected);
+ }
+});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]