-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.html
executable file
·133 lines (117 loc) · 3.75 KB
/
index.html
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<html>
<head>
<meta charset=utf-8 />
<title>related table</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.2.4/bootstrap-table.min.css">
<script src="https://code.jquery.com/jquery-1.11.0.min.js"></script>
<!-- cool bootstrap plugin for working with tables
//http://wenzhixin.net.cn/p/bootstrap-table/docs/index.html
-->
<script src="//rawgit.com/wenzhixin/bootstrap-table/master/dist/bootstrap-table.min.js"></script>
<!-- Load Leaflet from CDN-->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet.css" />
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet.js"></script>
<!-- Load Esri Leaflet from CDN -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/esri-leaflet.js"></script>
<!-- Esri Leaflet Related -->
<script src="https://cdn.jsdelivr.net/leaflet.esri.related/2.0.0/esri-leaflet-related.js"></script>
<style>
body {margin:0;padding:0;}
#map {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
}
#info-pane {
position: absolute;
top: 10px;
right: 10px;
z-index: 1000;
padding: 1em;
background: white;
}
.fixed-table-container {
position: absolute;
top: 10px;
left: 50px;
z-index: 1000;
padding: 1em;
background: white;
}
.fixed-table-body {
max-height: 600px;
max-width: 400px;
}
#hidden {
display:none;
}
</style>
</head>
<body>
<div id='my-table' class="hidden leaflet-bar table-condensed">
</div>
<div id="map"></div>
<div id="info-pane" class="leaflet-bar">
<label>
click on a bikeshare location <br>to see crowdsourced counts!
</label>
</div>
<script>
var map = L.map('map').setView([34.05873, -117.20317 ], 14);
L.esri.basemapLayer('Topographic').addTo(map);
var fl = L.esri.featureLayer({
url: 'https://services.arcgis.com/uCXeTVveQzP4IIcx/ArcGIS/rest/services/stationActivity/FeatureServer/0'
}).addTo(map);
// fire a query when users click on a feature
fl.on("click", queryRelated);
function queryRelated(evt) {
L.esri.Related.query(fl).objectIds([evt.layer.feature.id]).relationshipId("0").run(function(error, response, raw) {
//pull the attributes out of the geoJson response
if (response.features.length > 0) {
var results = [];
for (i=0; i < response.features.length; i++){
results.push(response.features[i].properties);
}
$('#my-table').removeClass('hidden');
//you can only call refresh() when loading from a url
$('#my-table').bootstrapTable('destroy');
$('#my-table').bootstrapTable({
data: results,
cache: false,
striped: true,
clickToSelect: true,
columns: [{
field: 'TIMESTAMP',
title: 'date',
sortable: true,
formatter: dateFormatter
}, {
field: 'AVAILABLEBIKES',
title: '# of bikes',
sortable: true
}, {
field: 'COMMENTS',
title: 'comments',
sortable: true
}]
});
}
});
}
function dateFormatter(value, row) {
//reformat to make the dates human readable
var d = new Date(value);
when = d.getMonth() + '/' + d.getDay() + '/' + d.getFullYear();
return when;
}
map.on("click", function(){
//hide the table when the map is clicked
$('#my-table').bootstrapTable('destroy');
});
</script>
</body>
</html>