[gnome-maps/wip/mlundblad/night-mode: 2/4] mapView: Use dark tiles when night mode is active



commit 3fdadd0fd677c56388e7c97204895ec305f0856f
Author: Marcus Lundblad <ml update uu se>
Date:   Fri Jun 5 00:28:10 2020 +0200

    mapView: Use dark tiles when night mode is active
    
    Use the dark tile set, if available from the service
    file when night mode is activated.

 src/mapView.js | 29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)
---
diff --git a/src/mapView.js b/src/mapView.js
index fcf4481d..1e81f169 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -42,6 +42,7 @@ const MapWalker = imports.mapWalker;
 const Place = imports.place;
 const PlaceMarker = imports.placeMarker;
 const RouteQuery = imports.routeQuery;
+const Service = imports.service;
 const ShapeLayer = imports.shapeLayer;
 const StoredRoute = imports.storedRoute;
 const TransitArrivalMarker = imports.transitArrivalMarker;
@@ -198,10 +199,25 @@ var MapView = GObject.registerClass({
             }
         });
 
+        // if dark tiles is available, setup handler to switch style
+        if (Service.getService().tiles.streetDark) {
+            Application.settings.connect('changed::night-mode',
+                                         this._onNightModeChanged.bind(this));
+        }
+
         this._initScale(view);
         return view;
     }
 
+    _onNightModeChanged() {
+        if (this._mapType === MapType.STREET) {
+            if (Application.settings.get('night-mode'))
+                this.view.map_source = MapSource.createStreetDarkSource();
+            else
+                this.view.map_source = MapSource.createStreetSource();
+        }
+    }
+
     /* create and store a route layer, pass true to get a dashed line */
     _createRouteLayer(dashed, lineColor, width) {
         let red = Color.parseColor(lineColor, 0);
@@ -323,11 +339,16 @@ var MapView = GObject.registerClass({
         this._mapType = mapType;
 
         if (mapType !== MapType.LOCAL) {
-            if (mapType === MapType.AERIAL)
+            if (mapType === MapType.AERIAL) {
                 this.view.map_source = MapSource.createAerialSource();
-            else
-                this.view.map_source = MapSource.createStreetSource();
-
+            } else {
+                if (Service.getService().tiles.streetDark &&
+                    Application.settings.get('night-mode')) {
+                    this.view.map_source = MapSource.createStreetDarkSource();
+                } else {
+                    this.view.map_source = MapSource.createStreetSource();
+                }
+            }
             if (!this._attribution) {
                 this._attribution = new MapSource.AttributionLogo(this.view);
                 this.view.add_child(this._attribution);


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