-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelasticsearch.html
More file actions
202 lines (186 loc) · 7.33 KB
/
Copy pathelasticsearch.html
File metadata and controls
202 lines (186 loc) · 7.33 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<!DOCTYPE html>
<html lang="en">
<head>
<!-- source : http://mapcentia.github.io/examples/elasticsearch.html -->
<!-- https://github.com/mapcentia/mapcentia.github.io/blob/master/examples/elasticsearch.html -->
<meta charset="utf-8">
<link href="css/leaflet.css" type="text/css" rel="stylesheet">
<link href="css/font-awesome-4.0.1.min.css" type="text/css" rel="stylesheet">
<link href="css/leaflet.awesome-markers.css" type="text/css" rel="stylesheet">
<link href="css/bootstrap-3.0.3.min.css" rel="stylesheet">
<title>Spatial type-a-head with Elasticsearch</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<style>
body {
margin: 0px;
padding: 0px;
font: normal 15px/20px Arial, sans-serif;
background: #fff;
}
#pane {
position: fixed;
top: 0px;
bottom: 0px;
right: 0px;
width: 100%;
}
#map {
position: absolute;
width: 100%;
transition: opacity 250ms;
-moz-transition: opacity 250ms;
-webkit-transition: opacity 250ms;
height: 100%;
}
i {
font-size: 80%;
}
.alert {
position: relative;
top: 5px;
left: 5px;
width: 300px;
}
#search {
position: relative;
width: 300px;
left: 5px;
}
#tweetContainer {
position: relative;
width: 300px;
left: 5px;
}
section {
margin-top: 5px;
}
.highlighted {
color: #0044cc;
}
</style>
</head>
<body>
<div id="pane">
<div id="map"></div>
</div>
<article>
<div class="alert alert-info">Demo showing how to make a spatial type-a-head with Elasticsearch. Only features
within the map viewport are loaded. After typing a search try to pan/zoom the map, and the search will
refresh.
</div>
<div id="search"><input class="form-control" id="search-input" name="search-input" type="text"
placeholder="Search in geolocated tweets"/></div>
<div class="list-group" id="tweetContainer"></div>
</article>
</body>
<script src='js/underscore-min.js'></script>
<script src="js/raphael-min.js"></script>
<script src='js/leaflet.js'></script>
<script src="js/leaflet.awesome-markers.js"></script>
<script src="js/rlayer.js"></script>
<script src='http://us1.mapcentia.com/api/v1/baselayerjs'></script>
<script src='http://us1.mapcentia.com/api/v3/js/geocloud.js'></script>
<script>
(function () {
var map, input, highlighter, search, elastic, markerMap = {};
$("input[name=search-input]").keyup(function () {
if (!this.value) {
$('#tweetContainer').empty();
}
});
$("input[name=search-input]").on('input', _.debounce(function (e) {
search(e.target.value)
}, 300));
search = function (value) {
elastic.reset();
if (value) {
elastic.q = '{ "query": { "filtered": { "query": { "query_string": { "default_field": "text", "query": "' + value + '", "default_operator": "AND" } }, "filter": { "geo_bounding_box": { "geometry.coordinates": { "top_left": { "lat": {maxY}, "lon": {minX} }, "bottom_right": { "lat": {minY}, "lon": {maxX} } } } } } } }';
elastic.load();
$('#tweetContainer').empty();
elastic.onLoad = function () {
for (var i = 0; i < this.geoJSON.features.length; i++) {
var tweet = this.geoJSON.features[i];
$('#tweetContainer').append(
'<section><a href="javascript:void(0)" class="list-group-item" data-tweetid=\"' +
tweet.properties.gid +
'">' +
'<h4 class="list-group-item-heading">' +
tweet.properties.user_name +
'</h4>' +
'<p class="list-group-item-text">' +
highlighter(value, tweet.properties.text) +
'</p>' +
'</a></section>'
)
}
$('a.list-group-item').on("click", function (e) {
var tweetId = $(this).data('tweetid');
var marker = markerMap[tweetId];
marker.openPopup(marker.getLatLng());
var x = marker.feature.geometry.coordinates[1];
var y = marker.feature.geometry.coordinates[0];
var p = new R.Pulse(
[x, y],
30,
{'stroke': 'none', 'fill': 'none'},
{'stroke': '#30a3ec', 'stroke-width': 3});
map.map.addLayer(p);
setTimeout(function () {
map.map.removeLayer(p);
}, 1000);
});
}
}
};
highlighter = function (value, item) {
_($.trim(value).split(' ')).each(
function (s) {
var regex = new RegExp('(' + s + ')', 'gi');
item = item.replace(regex, "<b class=\"highlighted\">$1</b>");
}
);
return item;
}
// Create a new map object in element with id 'map-div'
map = new geocloud.map({el: "map"});
zoomControl = L.control.zoom({
position: 'bottomright'
});
map.map.addControl(zoomControl);
map.bingApiKey = "Avt2oTtuFcQ2rzuy41B5DGydLYOxpgZaxuHkc4Ktgu6sG_6y-Ja6ncptoxbelYdx";
map.addBaseLayer(geocloud.HERENORMALNIGHTGREY);
map.setBaseLayer(geocloud.HERENORMALNIGHTGREY);
map.map.fitBounds([
[40.74504607583721, -73.93369674682617],
[40.70315539593834, -74.05549049377441]
]);
map.on("moveend", function () {
search($("input[name=search-input]").val());
})
// Create a GeoJSON store
elastic = new geocloud.elasticStore({
db: "mydb",
index: "ny",
size: 20,
onEachFeature: function (feature, layer) {
layer.bindPopup(feature.properties['text']);
},
pointToLayer: function (feature, latlng) {
var marker = L.marker(latlng,
{
zIndexOffset: 10000,
icon: L.AwesomeMarkers.icon(
{
icon: 'twitter',
markerColor: 'blue',
prefix: 'fa'
}
)});
markerMap[feature.properties.gid] = marker;
return marker;
}
});
map.addGeoJsonStore(elastic);
})();
</script>
</html>