[gnome-maps/wip/refactor: 4/4] MapView: move out route layer



commit e945073e2ebe0193f8225530d59c913c4d039915
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date:   Sun Aug 17 22:11:39 2014 +0200

    MapView: move out route layer
    
    Move out the general marker layer and its associated methods to its own
    class and call it placeLayer.
    
    PlaceLayer is meant to host single places from searches and similar.

 src/contextMenu.js              |    2 +-
 src/gnome-maps.js.gresource.xml |    1 +
 src/mainWindow.js               |    2 +-
 src/mapView.js                  |   25 +++++-----------
 src/placeLayer.js               |   58 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 69 insertions(+), 19 deletions(-)
---
diff --git a/src/contextMenu.js b/src/contextMenu.js
index f0f8397..23d5b78 100644
--- a/src/contextMenu.js
+++ b/src/contextMenu.js
@@ -66,7 +66,7 @@ const ContextMenu = new Lang.Class({
                                               accuracy: 0 });
 
         this._reverseGeocode(location, (function(place) {
-            this._mapView.showLocation(place);
+            this._mapView.placeLayer.showPlace(place);
         }).bind(this));
     },
 
diff --git a/src/gnome-maps.js.gresource.xml b/src/gnome-maps.js.gresource.xml
index cee9118..0ae9a62 100644
--- a/src/gnome-maps.js.gresource.xml
+++ b/src/gnome-maps.js.gresource.xml
@@ -17,6 +17,7 @@
     <file>notificationManager.js</file>
     <file>path.js</file>
     <file>placeEntry.js</file>
+    <file>placeLayer.js</file>
     <file>placeStore.js</file>
     <file>route.js</file>
     <file>routeLayer.js</file>
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 9f1448b..857d20e 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -96,7 +96,7 @@ const MainWindow = new Lang.Class({
                                                    });
         placeEntry.connect('notify::place', (function() {
             if (placeEntry.place) {
-                this.mapView.showNGotoLocation(placeEntry.place);
+                this.mapView.placeLayer.showAndGotoPlace(placeEntry.place);
                 Application.placeStore.addRecent(placeEntry.place);
             }
         }).bind(this));
diff --git a/src/mapView.js b/src/mapView.js
index 4495575..f167234 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -37,6 +37,7 @@ const Application = imports.application;
 const Utils = imports.utils;
 const Path = imports.path;
 const MapLocation = imports.mapLocation;
+const PlaceLayer = imports.placeLayer;
 const RouteLayer = imports.routeLayer;
 const UserLocation = imports.userLocation;
 const _ = imports.gettext.gettext;
@@ -91,10 +92,10 @@ const MapView = new Lang.Class({
                                                        mapView: this });
         this.view.add_layer(this._routeLayer);
 
-        let mode = Champlain.SelectionMode.SINGLE;
-        this._markerLayer = new Champlain.MarkerLayer({ selection_mode: mode });
-        this.view.add_layer(this._markerLayer);;
+        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.view.add_layer(this._userLocationLayer);
     },
@@ -103,6 +104,10 @@ const MapView = new Lang.Class({
         return this._routeLayer;
     },
 
+    get placeLayer() {
+        return this._placeLayer;
+    },
+
     setMapType: function(mapType) {
         if (this.view.map_source.id === mapType)
             return;
@@ -160,20 +165,6 @@ const MapView = new Lang.Class({
         this.emit('user-location-changed');
     },
 
-    showLocation: function(place) {
-        this._markerLayer.remove_all();
-        let mapLocation = new MapLocation.MapLocation(place, this);
-
-        mapLocation.show(this._markerLayer);
-
-        return mapLocation;
-    },
-
-    showNGotoLocation: function(place) {
-        let mapLocation = this.showLocation(place);
-        mapLocation.goTo(true);
-    },
-
     _onViewMoved: function() {
         this.emit('view-moved');
     }
diff --git a/src/placeLayer.js b/src/placeLayer.js
new file mode 100644
index 0000000..bebf44c
--- /dev/null
+++ b/src/placeLayer.js
@@ -0,0 +1,58 @@
+/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
+/* vim: set et ts=4 sw=4: */
+/*
+ * 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: Mattias Bengtsson <mattias jc bengtsson gmail com>
+ */
+
+const Champlain = imports.gi.Champlain;
+const Geocode = imports.gi.GeocodeGlib;
+const Lang = imports.lang;
+
+const MapLocation = imports.mapLocation;
+
+const PlaceLayer = new Lang.Class({
+    Name: 'PlaceLayer',
+    Extends: Champlain.MarkerLayer,
+
+    _init: function(props) {
+        props = props || {};
+
+        this._mapView = props.mapView;
+        delete props.mapView;
+
+        if(props.selection_mode === undefined)
+            props.selection_mode = Champlain.SelectionMode.SINGLE;
+
+        this.parent(props);
+    },
+
+    showPlace: function(place) {
+        this.remove_all();
+
+        let mapLocation = new MapLocation.MapLocation(place, this._mapView);
+        mapLocation.show(this);
+
+        return mapLocation;
+    },
+
+    showAndGotoPlace: function(place) {
+        let location = this.showPlace(place);
+        location.goTo(true);
+    }
+});


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