-
Notifications
You must be signed in to change notification settings - Fork 1
/
osm-features-wdc.js
101 lines (86 loc) · 2.99 KB
/
osm-features-wdc.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
(function() {
var myConnector = tableau.makeConnector();
myConnector.getSchema = function(schemaCallback) {
var cols = [{
id: "id",
alias: "id",
dataType: tableau.dataTypeEnum.int
}, {
id: "name",
alias: "name",
dataType: tableau.dataTypeEnum.string
}, {
id: "url",
alias: "url",
dataType: tableau.dataTypeEnum.string
}, {
id: "lat",
alias: "latitude",
columnRole: "dimension",
dataType: tableau.dataTypeEnum.float
}, {
id: "lon",
alias: "longitude",
columnRole: "dimension",
dataType: tableau.dataTypeEnum.float
}];
var tableInfo = {
id: "osm_features",
alias: "OpenStreetMap Features",
columns: cols
};
schemaCallback([tableInfo]);
};
myConnector.getData = function(table, doneCallback) {
var user_selection = JSON.parse(tableau.connectionData),
feat_type = user_selection[0],
bounds = user_selection[1].replace(/['"]+/g, ""),
id = 0,
name = "",
url = "",
lat = 0,
lon = 0;
$.getJSON("http://overpass-api.de/api/interpreter?data=[out:json];node[%22amenity%22=%22" + feat_type + "%22](" + bounds + ");out;", function(resp) {
var feat = resp.elements,
tableData = [];
// Iterate over the JSON object
for (var i = 0, len = feat.length; i < len; i++) {
id = feat[i].id;
name = feat[i].tags.name || "";
url = feat[i].tags.website || "";
lat = feat[i].lat;
lon = feat[i].lon;
tableData.push({
"id": id,
"name": name,
"url": url,
"lat": lat,
"lon": lon
});
}
table.appendRows(tableData);
doneCallback();
});
};
// Register connector and submit
tableau.registerConnector(myConnector);
$(document).ready(function() {
$("#feature-menu li").on("click", function () {
$("#feature-button-text").text($(this).text());
});
$("#submitButton").click(function() {
if ($("#feature-button-text").text() === "Select a feature") {
alert("Select a feature from the dropdown menu.");
return;
} else if (typeof $("#map").attr("latlon") === "undefined") {
alert("Select an area on the map.");
return;
}
var connectDataObj = [$("#feature-button-text").text(), $("#map").attr("latlon")];
tableau.connectionName = "OSM Features";
tableau.connectionData = JSON.stringify(connectDataObj);
console.log($("#map").attr("latlon"));
tableau.submit();
});
});
})();