[gnome-maps/wip/mlundblad/osm-add-location: 2/5] osmEdit: WIP: Add a module for handling POI type mapping to OSM tagging
- From: Marcus Lundblad <mlundblad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/mlundblad/osm-add-location: 2/5] osmEdit: WIP: Add a module for handling POI type mapping to OSM tagging
- Date: Mon, 4 Jan 2016 21:24:22 +0000 (UTC)
commit d5e4cbdd55e006b623dd3d72b96f381e93bb891a
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 | 50 ++++++++++++++++++++++++++++++++++
2 files changed, 53 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..2f99966
--- /dev/null
+++ b/src/osmTypeLookup.js
@@ -0,0 +1,50 @@
+/* -*- 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 = [
+ {key: 'amenity', value: 'pub', title: _("Pub")},
+ {key: 'amenity', value: 'bar', title: _("Bar")},
+ {key: 'amenity', value: 'atm', title: _("ATM")}
+];
+
+/* Sort function comparing two type values accoring to the locale-specific
+ comparison of the type title */
+function _sortType(t1, t2) {
+ return t1.title.toLocaleLowerCase().compareLocale(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]