diff options
author | Marcus Lundblad <ml@update.uu.se> | 2021-11-29 22:47:27 +0100 |
---|---|---|
committer | Marcus Lundblad <ml@update.uu.se> | 2022-01-06 22:22:33 +0100 |
commit | 9d3fab7f7bc3d2da5a39dcfb55d5ef9d5be6d76e (patch) | |
tree | 4b624c35e377ba1c7b19dfc482e69a753bbb67eb | |
parent | f3943a2d915dd199c1c915abf92cbb3fecaf7b08 (diff) | |
download | gnome-maps-9d3fab7f7bc3d2da5a39dcfb55d5ef9d5be6d76e.tar.gz |
Add module for place zoom levels
Add utility module to define default
zoom levels for place types.
-rw-r--r-- | src/org.gnome.Maps.src.gresource.xml.in | 1 | ||||
-rw-r--r-- | src/placeZoom.js | 68 | ||||
-rw-r--r-- | tests/meson.build | 4 | ||||
-rw-r--r-- | tests/placeZoomTest.js | 46 |
4 files changed, 117 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..389d720e --- /dev/null +++ b/src/placeZoom.js @@ -0,0 +1,68 @@ +/* -*- 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, + islet: 16, + _: 17 + + }, + railway: { + halt: 16, + station: 14, + tram_stop: 16 + }, + shop: { + _: 17 + } +} + +/** + * Get default zoom level for a given place, if one is defined + * otherwise return undefined, in which case the maximum zoom level + * (as defined by the map source) could be used. + */ +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' })); +} |