summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Danielsson <jonas@threetimestwo.org>2015-08-12 15:26:06 +0200
committerJonas Danielsson <jonas@threetimestwo.org>2015-09-11 17:34:50 +0200
commit0ba1f101dbca64f0d95b2612ac562973654a5329 (patch)
tree5d12ac59ddf5257ebc61e15f97bd6bc5f05f5515
parent30a9721f208b84721941b2880cd31912a4256a6d (diff)
downloadgnome-maps-0ba1f101dbca64f0d95b2612ac562973654a5329.tar.gz
Add --local switch to open local tile directory
If one have access to a directory structure such as: my_tiles//zoom-level/x/y.extension Then one can point maps to it as: $ gnome-maps --offline /path/to/my_tiles And view them, online or offline.
-rw-r--r--src/application.js14
-rw-r--r--src/mainWindow.js12
-rw-r--r--src/mapView.js34
3 files changed, 53 insertions, 7 deletions
diff --git a/src/application.js b/src/application.js
index 1903336b..e92e6e84 100644
--- a/src/application.js
+++ b/src/application.js
@@ -78,6 +78,20 @@ const Application = new Lang.Class({
this.parent({ application_id: 'org.gnome.Maps' });
this._connected = false;
+
+ this.add_main_option('local',
+ 0,
+ GLib.OptionFlags.NONE,
+ GLib.OptionArg.FILENAME,
+ _("A path to a local tiles directory structure"),
+ null);
+
+ this.connect('handle-local-options', (function(app, options) {
+ if (options.contains('local')) {
+ let variant = options.lookup_value('local', null);
+ this.local_tile_path = variant.deep_unpack();
+ }
+ }).bind(this));
},
_checkNetwork: function() {
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 02ff04c1..3ad690b0 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -70,7 +70,11 @@ const MainWindow = new Lang.Class({
this._configureId = 0;
- this._mapView = new MapView.MapView();
+ this._mapView = new MapView.MapView({
+ mapType: this.application.local_tile_path ?
+ MapView.MapType.LOCAL : MapView.MapType.STREET
+ });
+
this._overlay.add(this._mapView);
this._mapView.gotoUserLocation(false);
@@ -179,6 +183,7 @@ const MainWindow = new Lang.Class({
this.connect('delete-event', this._quit.bind(this));
this.connect('configure-event',
this._onConfigureEvent.bind(this));
+
this.connect('window-state-event',
this._onWindowStateEvent.bind(this));
this._mapView.view.connect('button-press-event', (function() {
@@ -190,7 +195,7 @@ const MainWindow = new Lang.Class({
}).bind(this));
this.application.connect('notify::connected', (function() {
- if (this.application.connected)
+ if (this.application.connected || this.application.local_tile_path)
this._mainStack.visible_child = this._overlay;
else
this._mainStack.visible_child = this._noNetworkView;
@@ -199,7 +204,8 @@ const MainWindow = new Lang.Class({
_updateLocationSensitivity: function() {
let sensitive = (Application.geoclue.state !== Geoclue.State.INITIAL &&
- this.application.connected);
+ (this.application.connected ||
+ this.application.local_tile_path));
this._gotoUserLocationButton.sensitive = sensitive;
},
diff --git a/src/mapView.js b/src/mapView.js
index c4f46756..c37023ea 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -30,6 +30,7 @@ const Application = imports.application;
const ContactPlace = imports.contactPlace;
const Geoclue = imports.geoclue;
const Location = imports.location;
+const Maps = imports.gi.GnomeMaps;
const MapWalker = imports.mapWalker;
const Place = imports.place;
const PlaceMarker = imports.placeMarker;
@@ -39,6 +40,7 @@ const UserLocationMarker = imports.userLocationMarker;
const Utils = imports.utils;
const MapType = {
+ LOCAL: 'MapsLocalSource',
STREET: Champlain.MAP_SOURCE_OSM_MAPQUEST,
AERIAL: Champlain.MAP_SOURCE_OSM_AERIAL_MAP,
CYCLING: Champlain.MAP_SOURCE_OSM_CYCLE_MAP,
@@ -71,14 +73,17 @@ const MapView = new Lang.Class({
this.notify('routeVisible');
},
- _init: function() {
+ _init: function(params) {
this.parent();
+ let mapType = params.mapType || MapType.STREET;
+ delete params.mapType;
+
this.view = this._initView();
this._initLayers();
this._factory = Champlain.MapSourceFactory.dup_default();
- this.setMapType(MapType.STREET);
+ this.setMapType(mapType);
this._updateUserLocation();
Application.geoclue.connect('location-changed',
@@ -150,8 +155,29 @@ const MapView = new Lang.Class({
if (this.view.map_source.id === mapType)
return;
- let source = this._factory.create_cached_source(mapType);
- this.view.map_source = source;
+ if (mapType !== MapType.LOCAL) {
+ let source = this._factory.create_cached_source(mapType);
+ this.view.map_source = source;
+ } else {
+ let renderer = new Champlain.ImageRenderer();
+ let source = new Maps.FileTileSource({
+ path: Application.application.local_tile_path.toString(),
+ renderer: renderer
+ });
+ try {
+ source.prepare();
+
+ this.view.map_source = source;
+ this.view.world = source.world;
+ let [lat, lon] = this.view.world.get_center();
+ this.view.center_on(lat, lon);
+ } catch(e) {
+ this.setMapType(MapType.STREET);
+ Application.application.local_tile_path = false;
+ Application.application.notify('connected');
+ Application.notificationManager.showMessage(e.message);
+ }
+ }
},
gotoUserLocation: function(animate) {