[gnome-maps] Add SearchResultMarker



commit 87b53837b57fa9e44b7dd0cfd756b427fceaab65
Author: Damián Nohales <damiannohales gmail com>
Date:   Tue Jun 24 14:58:21 2014 -0300

    Add SearchResultMarker
    
    The search result marker now is based on the MapMarker and
    MapBubble classes. This improves the UI and the information for
    searched places.
    
    Adding complete support for most Geocode place types is a
    pending task.
    
    This also removes MapLocation class.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=722871

 po/POTFILES.in                    |    2 +-
 src/contextMenu.js                |    2 +-
 src/gnome-maps.data.gresource.xml |    1 +
 src/gnome-maps.js.gresource.xml   |    3 +-
 src/mainWindow.js                 |    2 +-
 src/mapLocation.js                |  229 -------------------------------------
 src/mapView.js                    |   23 ++--
 src/search-result-bubble.ui       |   56 +++++++++
 src/searchResultBubble.js         |   99 ++++++++++++++++
 src/searchResultMarker.js         |   50 ++++++++
 10 files changed, 221 insertions(+), 246 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 6225ef3..457f9ff 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -8,9 +8,9 @@ src/application.js
 src/geoclue.js
 src/mainWindow.js
 [type: gettext/glade]src/main-window.ui
-src/mapLocation.js
 src/mapView.js
 src/routeService.js
+src/searchResultBubble.js
 src/sidebar.js
 [type: gettext/glade]src/sidebar.ui
 [type: gettext/glade]src/user-location-bubble.ui
diff --git a/src/contextMenu.js b/src/contextMenu.js
index f0f8397..2db05e9 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.showSearchResult(place);
         }).bind(this));
     },
 
diff --git a/src/gnome-maps.data.gresource.xml b/src/gnome-maps.data.gresource.xml
index 8bfd3f9..633b451 100644
--- a/src/gnome-maps.data.gresource.xml
+++ b/src/gnome-maps.data.gresource.xml
@@ -10,6 +10,7 @@
     <file preprocess="xml-stripblanks">context-menu.ui</file>
     <file preprocess="xml-stripblanks">layers-popover.ui</file>
     <file preprocess="xml-stripblanks">notification.ui</file>
+    <file preprocess="xml-stripblanks">search-result-bubble.ui</file>
     <file preprocess="xml-stripblanks">user-location-bubble.ui</file>
     <file alias="application.css">../data/gnome-maps.css</file>
     <file alias="zoom-in.png">../data/media/zoom-in.png</file>
diff --git a/src/gnome-maps.js.gresource.xml b/src/gnome-maps.js.gresource.xml
index fee0121..9343fee 100644
--- a/src/gnome-maps.js.gresource.xml
+++ b/src/gnome-maps.js.gresource.xml
@@ -12,7 +12,6 @@
     <file>main.js</file>
     <file>mainWindow.js</file>
     <file>mapBubble.js</file>
-    <file>mapLocation.js</file>
     <file>mapMarker.js</file>
     <file>mapView.js</file>
     <file>mapWalker.js</file>
@@ -25,6 +24,8 @@
     <file>routeQuery.js</file>
     <file>routeService.js</file>
     <file>searchPopup.js</file>
+    <file>searchResultBubble.js</file>
+    <file>searchResultMarker.js</file>
     <file>settings.js</file>
     <file>sidebar.js</file>
     <file>userLocationMarker.js</file>
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 4eb2774..ff2aa14 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -98,7 +98,7 @@ const MainWindow = new Lang.Class({
                                                    });
         placeEntry.connect('notify::place', (function() {
             if (placeEntry.place) {
-                this.mapView.showNGotoLocation(placeEntry.place);
+                this.mapView.showSearchResult(placeEntry.place);
                 Application.placeStore.addRecent(placeEntry.place);
             }
         }).bind(this));
diff --git a/src/mapView.js b/src/mapView.js
index bfcc072..c8d02eb 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -36,8 +36,8 @@ const Signals = imports.signals;
 const Application = imports.application;
 const Utils = imports.utils;
 const Path = imports.path;
-const MapLocation = imports.mapLocation;
 const MapWalker = imports.mapWalker;
+const SearchResultMarker = imports.searchResultMarker;
 const UserLocationMarker = imports.userLocationMarker;
 const _ = imports.gettext.gettext;
 
@@ -94,8 +94,8 @@ const MapView = new Lang.Class({
         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._searchResultLayer = new Champlain.MarkerLayer({ selection_mode: mode });
+        this.view.add_layer(this._searchResultLayer);
 
         this._userLocationLayer = new Champlain.MarkerLayer({ selection_mode: mode });
         this.view.add_layer(this._userLocationLayer);
@@ -152,18 +152,15 @@ const MapView = new Lang.Class({
         this.emit('user-location-changed');
     },
 
-    showLocation: function(place) {
-        this._markerLayer.remove_all();
-        let mapLocation = new MapLocation.MapLocation(place, this);
+    showSearchResult: function(place) {
+        this._searchResultLayer.remove_all();
+        let searchResultMarker = new SearchResultMarker.SearchResultMarker({ place: place,
+                                                                             mapView: this });
 
-        mapLocation.show(this._markerLayer);
+        this._searchResultLayer.add_marker(searchResultMarker);
+        searchResultMarker.goToAndSelect(true);
 
-        return mapLocation;
-    },
-
-    showNGotoLocation: function(place) {
-        let mapLocation = this.showLocation(place);
-        mapLocation.goTo(true);
+        return searchResultMarker;
     },
 
     showRoute: function(route) {
diff --git a/src/search-result-bubble.ui b/src/search-result-bubble.ui
new file mode 100644
index 0000000..b1aaa00
--- /dev/null
+++ b/src/search-result-bubble.ui
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.18.1 -->
+<interface>
+  <requires lib="gtk+" version="3.12"/>
+  <object class="GtkGrid" id="grid">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="margin_start">10</property>
+    <property name="margin_end">15</property>
+    <property name="margin_top">10</property>
+    <property name="margin_bottom">15</property>
+    <child>
+      <object class="GtkImage" id="image">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="valign">start</property>
+        <property name="margin_top">5</property>
+        <property name="pixel_size">0</property>
+        <property name="icon_size">0</property>
+      </object>
+      <packing>
+        <property name="left_attach">0</property>
+        <property name="top_attach">0</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkBox" id="box-right">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="margin_start">15</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">3</property>
+        <child>
+          <object class="GtkLabel" id="label-title">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="halign">start</property>
+            <property name="vexpand">True</property>
+            <style>
+              <class name="bubble-title"/>
+            </style>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+      </object>
+      <packing>
+        <property name="left_attach">1</property>
+        <property name="top_attach">0</property>
+      </packing>
+    </child>
+  </object>
+</interface>
diff --git a/src/searchResultBubble.js b/src/searchResultBubble.js
new file mode 100644
index 0000000..fb40535
--- /dev/null
+++ b/src/searchResultBubble.js
@@ -0,0 +1,99 @@
+/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
+/* vim: set et ts=4 sw=4: */
+/*
+ * Copyright (c) 2014 Damián Nohales
+ *
+ * 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: Damián Nohales <damiannohales gmail com>
+ */
+
+const Geocode = imports.gi.GeocodeGlib;
+const Gtk = imports.gi.Gtk;
+
+const Lang = imports.lang;
+
+const MapBubble = imports.mapBubble;
+const Utils = imports.utils;
+const _ = imports.gettext.gettext;
+
+const SearchResultBubble = new Lang.Class({
+    Name: "SearchResultBubble",
+    Extends: MapBubble.MapBubble,
+
+    _init: function(params) {
+        this.parent(params);
+
+        let ui = Utils.getUIObject('search-result-bubble', [ 'grid',
+                                                             'box-right',
+                                                             'image',
+                                                             'label-title' ]);
+        let place = this.place;
+
+        Utils.load_icon(this.place.icon, 48, function(pixbuf) {
+            ui.image.pixbuf = pixbuf;
+        });
+
+        let title = null;
+        let content = [];
+
+        if (this._isBrokenPlace(place)) {
+            // Fallback for places coming from PlaceStore
+            title = place.name;
+        } else {
+            switch (place.place_type) {
+            case Geocode.PlaceType.COUNTRY:
+                title = place.country;
+                if (place.country_code)
+                    content.push(_("Country code: %s").format(place.country_code));
+                break;
+
+            case Geocode.PlaceType.TOWN:
+                title = place.town;
+                if (place.postal_code)
+                    content.push(_("Postal code: %s").format(place.postal_code));
+                if (place.state)
+                    content.push(place.state + ', ' + place.country);
+                else
+                    content.push(place.country);
+                break;
+
+            //TODO: add specific UIs for the rest of the place types
+            default:
+                title = place.name;
+                break;
+            }
+        }
+
+        ui.labelTitle.label = title;
+
+        content.forEach(function(c) {
+            let label = new Gtk.Label({ label: c,
+                                        visible: true,
+                                        halign: Gtk.Align.START });
+            ui.boxRight.pack_start(label, false, true, 0);
+        });
+
+        this.add(ui.grid);
+    },
+
+    _isBrokenPlace: function(place) {
+        // Broken places are GeocodePlace objects coming from PlaceStore,
+        // which doesn't save most of the place properties.
+        // See: https://bugzilla.gnome.org/show_bug.cgi?id=726625
+        return !place.country && !place.state && !place.county && !place.town &&
+               !place.street && !place.street_address;
+    }
+});
diff --git a/src/searchResultMarker.js b/src/searchResultMarker.js
new file mode 100644
index 0000000..fc45b10
--- /dev/null
+++ b/src/searchResultMarker.js
@@ -0,0 +1,50 @@
+/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
+/* vim: set et ts=4 sw=4: */
+/*
+ * Copyright (c) 2014 Damián Nohales
+ *
+ * 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: Damián Nohales <damiannohales gmail com>
+ */
+
+const Lang = imports.lang;
+
+const MapMarker = imports.mapMarker;
+const Path = imports.path;
+const SearchResultBubble = imports.searchResultBubble;
+const Utils = imports.utils;
+
+const SearchResultMarker = new Lang.Class({
+    Name: 'SearchResultMarker',
+    Extends: MapMarker.MapMarker,
+
+    _init: function(params) {
+        this.parent(params);
+
+        let iconActor = Utils.CreateActorFromImageFile(Path.ICONS_DIR + "/pin.svg");
+        this.add_actor(iconActor);
+    },
+
+    get anchor() {
+        return { x: Math.floor(this.width / 2),
+                 y: this.height - 3 };
+    },
+
+    _createBubble: function() {
+        return new SearchResultBubble.SearchResultBubble({ place: this.place,
+                                                           mapView: this._mapView });
+    }
+});


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