[gnome-maps/wip/mlundblad/place-zoom-levels: 1/2] Add module for place zoom levels




commit 875340750be3534bfcf370a307aeff8231da0110
Author: Marcus Lundblad <ml update uu se>
Date:   Mon Nov 29 22:47:27 2021 +0100

    Add module for place zoom levels
    
    Add utility module to define default
    zoom levels for place types.

 src/org.gnome.Maps.src.gresource.xml.in |  1 +
 src/placeZoom.js                        | 62 +++++++++++++++++++++++++++++++++
 tests/meson.build                       |  4 +--
 tests/placeZoomTest.js                  | 46 ++++++++++++++++++++++++
 4 files changed, 111 insertions(+), 2 deletions(-)
---
diff --git a/src/org.gnome.Maps.src.gresource.xml.in b/src/org.gnome.Maps.src.gresource.xml.in
index 2338a132..da8266e7 100644
--- a/src/org.gnome.Maps.src.gresource.xml.in
+++ b/src/org.gnome.Maps.src.gresource.xml.in
@@ -68,6 +68,7 @@
     <file>placeStore.js</file>
     <file>placeView.js</file>
     <file>placeViewImage.js</file>
+    <file>placeZoom.js</file>
     <file>printLayout.js</file>
     <file>printOperation.js</file>
     <file>route.js</file>
diff --git a/src/placeZoom.js b/src/placeZoom.js
new file mode 100644
index 00000000..5cf38a35
--- /dev/null
+++ b/src/placeZoom.js
@@ -0,0 +1,62 @@
+/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
+/* vim: set et ts=4 sw=4: */
+/*
+ * Copyright (c) 2021 Marcus Lundblad
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Marcus Lundblad <ml update uu se>
+ */
+
+const TYPE_ZOOM_MAP = {
+    amenity: {
+        _:           17
+    },
+    highway: {
+        bus_stop:    17
+    },
+    place: {
+        continent:    4,
+        ocean:        4,
+        sea:          5,
+        country:      6,
+        state:        7,
+        region:       8,
+        province:     8,
+        county:       8,
+        municipality: 8,
+        island:       9,
+        city:        10,
+        town:        12,
+        borough:     12,
+        village:     15,
+        suburb:      15,
+        hamlet:      15,
+        _:           17
+
+    },
+    railway: {
+        halt:        16,
+        station:     14,
+        tram_stop:   16
+    },
+    shop: {
+        _:           17
+    }
+}
+
+function getZoomLevelForPlace(place) {
+    return TYPE_ZOOM_MAP?.[place.osmKey]?.[place.osmValue] ??
+           TYPE_ZOOM_MAP?.[place.osmKey]?.['_'];
+}
diff --git a/tests/meson.build b/tests/meson.build
index 4d3abab6..c42c8137 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -1,6 +1,6 @@
 tests = ['addressTest', 'boundingBoxTest', 'colorTest', 'osmNamesTest',
-         'placeIconsTest', 'timeTest', 'translationsTest', 'utilsTest',
-         'urisTest', 'wikipediaTest']
+         'placeIconsTest', 'placeZoomTest', 'timeTest', 'translationsTest',
+         'utilsTest', 'urisTest', 'wikipediaTest']
 
 foreach test : tests
   script_conf = configuration_data()
diff --git a/tests/placeZoomTest.js b/tests/placeZoomTest.js
new file mode 100644
index 00000000..b99a16e8
--- /dev/null
+++ b/tests/placeZoomTest.js
@@ -0,0 +1,46 @@
+/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
+/* vim: set et ts=4 sw=4: */
+/*
+ * Copyright (c) 2021 Marcus Lundblad
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Marcus Lundblad <ml update uu se>
+ */
+const JsUnit = imports.jsUnit;
+
+const PlaceZoom = imports.placeZoom;
+
+function main() {
+    placeZoomTest();
+}
+
+function placeZoomTest() {
+    // specific place types
+    JsUnit.assertEquals(17,
+                        PlaceZoom.getZoomLevelForPlace({ osmKey:   'shop',
+                                                         osmValue: 'supermarket' }));
+    JsUnit.assertEquals(4,
+                        PlaceZoom.getZoomLevelForPlace({ osmKey:   'place',
+                                                         osmValue: 'continent' }));
+
+    // fallback for for OSM key
+    JsUnit.assertEquals(17,
+                        PlaceZoom.getZoomLevelForPlace({ osmKey:   'place',
+                                                         osmValue: 'other' }));
+
+    // undefined for not defined type
+    JsUnit.assertUndefined(PlaceZoom.getZoomLevelForPlace({ osmKey:   'type',
+                                                            osmValue: 'other' }));
+}


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