[gnome-maps/wip/mlundblad/osm-add-location: 1/4] osmEdit: WIP: Add a module for handling POI type mapping to OSM tagging



commit 8296b07d7164378a9897f6787c767d55f6daef94
Author: Marcus Lundblad <ml update uu se>
Date:   Wed Dec 30 00:24:00 2015 +0100

    osmEdit: WIP: Add a module for handling POI type mapping to OSM tagging

 src/org.gnome.Maps.src.gresource.xml |    3 +
 src/osmTypeLookup.js                 |   73 ++++++++++++++++++++++++++++++++++
 2 files changed, 76 insertions(+), 0 deletions(-)
---
diff --git a/src/org.gnome.Maps.src.gresource.xml b/src/org.gnome.Maps.src.gresource.xml
index 36f4c07..676ea96 100644
--- a/src/org.gnome.Maps.src.gresource.xml
+++ b/src/org.gnome.Maps.src.gresource.xml
@@ -34,6 +34,9 @@
     <file>osmConnection.js</file>
     <file>osmEdit.js</file>
     <file>osmEditDialog.js</file>
+    <file>osmTypeSearchEntry.js</file>
+    <file>osmTypeLookup.js</file>
+    <file>osmTypeSearchPopover.js</file>
     <file>osmUtils.js</file>
     <file>overpass.js</file>
     <file>place.js</file>
diff --git a/src/osmTypeLookup.js b/src/osmTypeLookup.js
new file mode 100644
index 0000000..b2ff2a9
--- /dev/null
+++ b/src/osmTypeLookup.js
@@ -0,0 +1,73 @@
+/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
+/* vim: set et ts=4 sw=4: */
+/*
+ * Copyright (c) 2015 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>
+ */
+
+/* Lists the OSM tags we base our notion of location types on */
+const OSM_TYPE_TAGS = ['amenity', 'leasure', 'office', 'place', 'shop' ];
+
+const OSM_TYPE_MAP = [
+    /* amenities */
+    {key: 'amenity', value: 'pub', title: _("Pub")},
+    {key: 'amenity', value: 'bar', title: _("Bar")},
+    {key: 'amenity', value: 'atm', title: _("ATM")},
+    {key: 'amenity', value: 'restaurant', title: _("Restaurant")},
+    {key: 'amenity', value: 'school', title: _("School")},
+    {key: 'amenity', value: 'kindergarden', title: _("Kindergarden")},
+    {key: 'amenity', value: 'pharmacy', title: _("Pharmacy")},
+
+    /* shops */
+    {key: 'shop', value: 'supermarket', title: _("Supermarket")}
+];
+
+/* Sort function comparing two type values accoring to the locale-specific
+   comparison of the type title */
+function _sortType(t1, t2) {
+    return t1.title.toLocaleLowerCase().localeCompare(t2.title.toLocaleLowerCase());
+}
+
+function findMatches(prefix, maxMatches) {
+    let numMatches = 0;
+    let prefixLength = prefix.length;
+    let normalized = prefix.toLocaleLowerCase();
+    let matches = [];
+
+    for (let i = 0; i < OSM_TYPE_MAP.length && numMatches < maxMatches; i++) {
+        let item = OSM_TYPE_MAP[i];
+
+        if (item.title.substring(0, prefixLength).toLocaleLowerCase() === normalized) {
+            numMatches++;
+            matches.push(item);
+        }
+    }
+
+    return matches.sort(_sortType);
+}
+
+/* return the title of a type with a given key/value if it is known by us */
+function lookupType(key, value) {
+    for (let i = 0; i < OSM_TYPE_MAP.length; i++) {
+        let row = OSM_TYPE_MAP[i];
+
+        if (row.value === value && row.key === key)
+            return row.title;
+    }
+
+    return null;
+}


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