-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.js
66 lines (52 loc) · 1.85 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* @fileoverview The demo application for goog.ui.AutoComplete.Nominatim.
*
* @author [email protected] (Petr Pridal)
*
* Copyright 2011 Klokan Technologies Gmbh (www.klokantech.com)
*/
goog.provide('nominatim.main');
goog.require('goog.array');
goog.require('goog.debug.Console');
goog.require('goog.debug.DivConsole');
goog.require('goog.debug.ErrorHandler');
goog.require('goog.debug.LogManager');
goog.require('goog.debug.Logger');
goog.require('goog.dom');
goog.require('goog.events.EventType');
goog.require('goog.ui.AutoComplete.Nominatim');
/**
* Demo application for goog.ui.AutoComplete.Nominatim. Main function.
*/
nominatim.main = function() {
// Initialize logger
var logger = goog.debug.Logger.getLogger('nominatim');
var logconsole = new goog.debug.DivConsole(goog.dom.getElement('log'));
// var logconsole = new goog.debug.Console();
logconsole.setCapturing(true);
var input = /** @type {!Element} */
(goog.dom.getElement('txtInput'));
var ac = new goog.ui.AutoComplete.Nominatim(input);
// the action which should be done on the selected item
var run_action = function(item) {
logger.info('DISPLAY: ' + item['lat'] + ',' + item['lon'] + ' -- ' +
item['boundingbox'].toString());
// console.log(item);
}
ac.addEventListener(goog.ui.AutoComplete.EventType.UPDATE, function(e) {
logger.info('SELECT: ' + e.row['display_name']);
run_action(e.row);
});
goog.events.listen(goog.dom.getElement('form1'),
goog.events.EventType.SUBMIT, function(e) {
e.preventDefault();
logger.info('DIRECT: ' + input.value);
ac.search(input.value, 1, function(token, result) {
if (result.length > 0) {
logger.info(result[0]['display_name']);
run_action(result[0]);
}
});
});
};
goog.exportSymbol('main', nominatim.main);