[gnome-maps/wip/routing2: 9/10] Split out geocode to its own service
- From: Mattias Bengtsson <mattiasb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/routing2: 9/10] Split out geocode to its own service
- Date: Mon, 16 Jun 2014 04:14:00 +0000 (UTC)
commit 249d064ec363443b162f8a327a940e43e14a0148
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date: Wed Jun 11 01:41:05 2014 +0200
Split out geocode to its own service
This is needed for when you want to perform a geocode query without
access to MapView.
https://bugzilla.gnome.org/show_bug.cgi?id=728695
src/application.js | 13 +++++++--
src/geocodeService.js | 57 +++++++++++++++++++++++++++++++++++++++
src/gnome-maps.js.gresource.xml | 1 +
src/mapView.js | 24 ----------------
src/placeEntry.js | 4 ++-
5 files changed, 71 insertions(+), 28 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index 01cb7a1..36526d2 100644
--- a/src/application.js
+++ b/src/application.js
@@ -35,6 +35,7 @@ const GLib = imports.gi.GLib;
const Main = imports.main;
const Format = imports.format;
const Geoclue = imports.geoclue;
+const GeocodeService = imports.geocodeService;
const MainWindow = imports.mainWindow;
const Notification = imports.notification;
const NotificationManager = imports.notificationManager;
@@ -51,6 +52,7 @@ let placeStore = null;
let notificationManager = null;
let routeService = null;
let geoclue = null;
+let geocodeService = null;
const Application = new Lang.Class({
Name: 'Application',
@@ -97,9 +99,7 @@ const Application = new Lang.Class({
Utils.loadStyleSheet(Gio.file_new_for_uri('resource:///org/gnome/maps/application.css'));
application = this;
- settings = new Settings.Settings('org.gnome.maps');
- routeService = new RouteService.GraphHopper();
- geoclue = new Geoclue.Geoclue();
+ this._initServices();
Utils.initActions(this, [{
properties: { name: 'quit' },
@@ -110,6 +110,13 @@ const Application = new Lang.Class({
this._initAppMenu();
},
+ _initServices: function() {
+ settings = new Settings.Settings('org.gnome.maps');
+ routeService = new RouteService.GraphHopper();
+ geoclue = new Geoclue.Geoclue();
+ geocodeService = new GeocodeService.GeocodeService();
+ },
+
_createWindow: function() {
if (this._mainWindow)
return;
diff --git a/src/geocodeService.js b/src/geocodeService.js
new file mode 100644
index 0000000..434afd6
--- /dev/null
+++ b/src/geocodeService.js
@@ -0,0 +1,57 @@
+/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
+/* vim: set et ts=4 sw=4: */
+/*
+ * Copyright (c) 2013, 2014 Red Hat, Inc., 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 Geocode = imports.gi.GeocodeGlib;
+const Lang = imports.lang;
+
+const Application = imports.application;
+
+const GeocodeService = new Lang.Class({
+ Name: 'GeocodeService',
+
+ _init: function() { },
+
+ search: function(string, bbox, callback) {
+ let answerCount = Application.settings.get('max-search-results');
+ let forward = Geocode.Forward.new_for_string(string);
+
+ if (bbox) {
+ forward.search_area = new Geocode.BoundingBox({
+ top: bbox.top,
+ left: bbox.left,
+ bottom: bbox.bottom,
+ right: bbox.right
+ });
+ }
+ forward.bounded = false;
+ forward.set_answer_count(answerCount);
+ forward.search_async(null, function(forward, res) {
+ try {
+ let places = forward.search_finish(res);
+ callback(places);
+ } catch (e) {
+ callback(null);
+ }
+ });
+ }
+});
diff --git a/src/gnome-maps.js.gresource.xml b/src/gnome-maps.js.gresource.xml
index 17d486d..ca842c7 100644
--- a/src/gnome-maps.js.gresource.xml
+++ b/src/gnome-maps.js.gresource.xml
@@ -6,6 +6,7 @@
<file>contextMenu.js</file>
<file>epaf.js</file>
<file>geoclue.js</file>
+ <file>geocodeService.js</file>
<file>http.js</file>
<file>layersPopover.js</file>
<file>main.js</file>
diff --git a/src/mapView.js b/src/mapView.js
index 5129a40..157799b 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -115,30 +115,6 @@ const MapView = new Lang.Class({
this.view.set_map_source(source);
},
- geocodeSearch: function(searchString, searchCompleteCallback) {
- let forward = Geocode.Forward.new_for_string(searchString);
- let places = [];
- let answerCount = Application.settings.get('max-search-results');
- let bbox = this.view.get_bounding_box();
-
- forward.search_area = new Geocode.BoundingBox({
- top: bbox.top,
- left: bbox.left,
- bottom: bbox.bottom,
- right: bbox.right
- });
- forward.bounded = false;
- forward.set_answer_count(answerCount);
- forward.search_async (null, (function(forward, res) {
- try {
- places = forward.search_finish(res);
- } catch (e) {
- places = null;
- }
- searchCompleteCallback(places);
- }).bind(this));
- },
-
ensureLocationsVisible: function(locations) {
let bbox = new Champlain.BoundingBox({ left: 180,
right: -180,
diff --git a/src/placeEntry.js b/src/placeEntry.js
index a2b1af9..6bf93d4 100644
--- a/src/placeEntry.js
+++ b/src/placeEntry.js
@@ -114,8 +114,10 @@ const PlaceEntry = new Lang.Class({
return;
}
+ let bbox = this._mapView.view.get_bounding_box();
+
this._popover.showSpinner();
- this._mapView.geocodeSearch(this.text, (function(places) {
+ Application.geocodeService.search(this.text, bbox, (function(places) {
if (!places) {
this.place = null;
this._popover.hide();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]