[gnome-maps/wip/mlundblad/additional-place-icons: 1/3] WIP: Add utility module for place icons
- From: Marcus Lundblad <mlundblad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/mlundblad/additional-place-icons: 1/3] WIP: Add utility module for place icons
- Date: Sat, 17 Apr 2021 21:35:18 +0000 (UTC)
commit 898568df74cf96b3bcc0e898143c6d6f1321e740
Author: Marcus Lundblad <ml update uu se>
Date: Tue Apr 13 23:13:50 2021 +0200
WIP: Add utility module for place icons
Add function for mapping place icon names
to places based on types.
src/org.gnome.Maps.src.gresource.xml | 1 +
src/placeIcons.js | 117 +++++++++++++++++++++++++++++++++++
tests/meson.build | 3 +-
tests/placeIconsTest.js | 68 ++++++++++++++++++++
4 files changed, 188 insertions(+), 1 deletion(-)
---
diff --git a/src/org.gnome.Maps.src.gresource.xml b/src/org.gnome.Maps.src.gresource.xml
index cec373ea..3c5bc128 100644
--- a/src/org.gnome.Maps.src.gresource.xml
+++ b/src/org.gnome.Maps.src.gresource.xml
@@ -62,6 +62,7 @@
<file>placeDialog.js</file>
<file>placeEntry.js</file>
<file>placeFormatter.js</file>
+ <file>placeIcons.js</file>
<file>placeListRow.js</file>
<file>placeMarker.js</file>
<file>placePopover.js</file>
diff --git a/src/placeIcons.js b/src/placeIcons.js
new file mode 100644
index 00000000..13e433be
--- /dev/null
+++ b/src/placeIcons.js
@@ -0,0 +1,117 @@
+/* -*- 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>
+ */
+
+/**
+ * Mapping OSM key/values to place icons.
+ * Keys in top map correspond to osmKey from Place.
+ * Keys in nested maps correspond to osmValue from Place,
+ * _ matches catch-all case for that osmKey.
+ */
+const TYPE_ICON_MAP = {
+ aeroway: {
+ aerodrome: 'route-transit-airplane-symbolic'
+ },
+ amenity: {
+ bar: 'bar-symbolic',
+ bus_station: 'route-transit-bus-symbolic',
+ cafe: 'cafe-symbolic',
+ charging_station: 'electric-car-symbolic',
+ cinema: 'video-camera-symbolic',
+ clinic: 'hospital-sign-symbolic',
+ doctors: 'hospital-sign-symbolic',
+ fast_food: 'restaurant-symbolic',
+ ferry_terminal: 'route-transit-ferry-symbolic',
+ fuel: 'fuel-symbolic',
+ hospital: 'hospital-symbolic',
+ kindergarten: 'school-symbolic',
+ night_club: 'bar-symbolic',
+ parking: 'parking-sign-symbolic',
+ post_office: 'post-box-symbolic',
+ pub: 'pub-symbolic',
+ restaurant: 'restaurant-symbolic',
+ school: 'school-symbolic',
+ university: 'school-symbolic'
+ },
+ building: {
+ yes: 'building-symbolic',
+ railway_station: 'route-transit-train'
+ },
+ highway: {
+ bus_stop: 'route-transit-bus-symbolic',
+ cycleway: 'route-bike-symbolic',
+ footway: 'route-pedestrian-symbolic',
+ pedestrian: 'route-pedestrian-symbolic',
+ platform: 'route-transit-bus-symbolic',
+ steps: 'route-pedestrian-symbolic',
+ path: 'route-pedestrian-symbolic',
+ _: 'route-car-symbolic'
+ },
+ leisure: {
+ nature_reserve: 'tree-symbolic',
+ park: 'tree-symbolic'
+ },
+ natural: {
+ peak: 'mountain-symbolic'
+ },
+ office: {
+ _: 'building-symbolic'
+ },
+ place: {
+ city: 'city-symbolic',
+ city_block: 'building-symbolic',
+ hamlet: 'town-symbolic',
+ isolated_dwelling:'building-symbolic',
+ square: 'route-pedestrian-symbolic',
+ suburb: 'town-symbolic',
+ town: 'town-symbolic',
+ village: 'town-symbolic'
+ },
+ railway: {
+ halt: 'route-transit-train-symbolic',
+ station: 'route-transit-train-symbolic',
+ stop: 'route-transit-train-symbolic',
+ tram_stop: 'route-transit-tram-symbolic'
+ },
+ shop: {
+ _: 'shopping-cart-symbolic'
+ },
+ tourism: {
+ alpine_hut: 'bed-symbolic',
+ attraction: 'photo-camera-symbolic',
+ artwork: 'photo-camera-symbolic',
+ gallery: 'museum-symbolic',
+ guest_house: 'bed-symbolic',
+ hostel: 'bed-symbolic',
+ hotel: 'bed-symbolic',
+ motel: 'bed-symbolic',
+ museum: 'museum-symbolic',
+ zoo: 'penguin-symbolic'
+ }
+};
+
+/**
+ * Get place icon name suitable for a Place.
+ */
+function getIconForPlace(place) {
+ return TYPE_ICON_MAP?.[place.osmKey]?.[place.osmValue] ??
+ TYPE_ICON_MAP?.[place.osmKey]?.['_'] ?? 'map-marker-symbolic';
+}
+
diff --git a/tests/meson.build b/tests/meson.build
index 2ba07ab0..09728da2 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -1,5 +1,6 @@
tests = ['addressTest', 'boundingBoxTest', 'colorTest', 'osmNamesTest',
- 'timeTest', 'translationsTest', 'utilsTest', 'urlsTest']
+ 'placeIconsTest', 'timeTest', 'translationsTest', 'utilsTest',
+ 'urlsTest']
foreach test : tests
script_conf = configuration_data()
diff --git a/tests/placeIconsTest.js b/tests/placeIconsTest.js
new file mode 100644
index 00000000..e7a4f3b0
--- /dev/null
+++ b/tests/placeIconsTest.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 JsUnit = imports.jsUnit;
+
+const PlaceIcons = imports.placeIcons;
+
+/* use a minimal mock of Place, since Place throught dependencies requires
+ * the GResources to be setup, so it can't easily be used from tests
+ */
+class MockedPlace {
+ constructor(params) {
+ this._osmKey = params.osmKey;
+ this._osmValue = params.osmValue;
+ }
+
+ get osmKey() {
+ return this._osmKey;
+ }
+
+ get osmValue() {
+ return this._osmValue;
+ }
+}
+
+function main() {
+ testKnownTypes();
+ testDefaultIcon();
+}
+
+// test some known place type → icon mappings
+function testKnownTypes() {
+ let p1 = new MockedPlace({ osmKey: 'amenity', osmValue: 'restaurant' });
+ let p2 = new MockedPlace({ osmKey: 'place', osmValue: 'city' });
+ let p3 = new MockedPlace({ osmKey: 'amenity', osmValue: 'pub' });
+
+ JsUnit.assertEquals('restaurant-symbolic', PlaceIcons.getIconForPlace(p1));
+ JsUnit.assertEquals('city-symbolic', PlaceIcons.getIconForPlace(p2));
+ JsUnit.assertEquals('pub-symbolic', PlaceIcons.getIconForPlace(p3));
+}
+
+// test that some unknown type gets the default map marker icon
+function testDefaultIcon() {
+ let p1 = new MockedPlace({ osmKey: 'amenity', osmValue: 'unknown' });
+ let p2 = new MockedPlace({ osmKey: 'other', osmValue: 'unknown' });
+ let p3 = new MockedPlace({});
+
+ JsUnit.assertEquals('map-marker-symbolic', PlaceIcons.getIconForPlace(p1));
+ JsUnit.assertEquals('map-marker-symbolic', PlaceIcons.getIconForPlace(p2));
+ JsUnit.assertEquals('map-marker-symbolic', PlaceIcons.getIconForPlace(p3));
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]