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



commit d8ee7355b17184714d98c56c403eada0f38c3852
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                 |   58 ++++++++++++++++++++++++++++++++++
 2 files changed, 61 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..dbdc330
--- /dev/null
+++ b/src/osmTypeLookup.js
@@ -0,0 +1,58 @@
+/* -*- 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>
+ */
+
+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);
+}


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