Commit e1016431 authored by Dave McCormick's avatar Dave McCormick
Browse files

added filter

parent d4d8440f
......@@ -57,7 +57,7 @@ public class TwitterStreamActor extends UntypedActor {
// Build a json object to send over the wire to the client.
ObjectNode n = Json.newObject();
//n.put("msg", "@" + status.getUser().getScreenName() + "said " + status.getText() + " - " + loc);
n.put("msg", status.getText());
n.put("lat", loc.getLatitude());
n.put("lng", loc.getLongitude());
TweetHub.getInstance().send(n);
......@@ -70,7 +70,7 @@ public class TwitterStreamActor extends UntypedActor {
@Override
public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
System.out.println("Got track limitation notice:" + numberOfLimitedStatuses);
return;
}
@Override
......
......@@ -26,7 +26,7 @@ public class TweetWebSocketActor extends UntypedActor {
private final ActorRef out;
/** The topic string we have subscribed to */
private final String topic;
private String topic;
/** A listener that we will register with our TweetHub */
private final TweetListener listener;
......@@ -38,13 +38,19 @@ public class TweetWebSocketActor extends UntypedActor {
this.topic = topic;
this.out = out;
System.out.println("HERE IS YOUR TOPIC" + topic);
/*
Our TweetListener, written as a Java 8 Lambda.
Whenever we receive a tweet, if it matches our topic, convert it to a JSON string, and send it to the client.
*/
this.listener = (tweetJson) -> {
if (!tweetJson.findValue("msg").toString().matches(String.format("(?i).*%s.*", this.topic)) ){
return;
}
String message = tweetJson.toString();
out.tell(message, self());
};
......@@ -56,9 +62,11 @@ public class TweetWebSocketActor extends UntypedActor {
* This is called whenever the browser sends a message to the serverover the websocket
*/
public void onReceive(Object message) throws Exception {
// The client isn't going to send us messages down the websocket in this example, so this doesn't matter
if (message instanceof String) {
out.tell("I received your message: " + message, self());
String newTopic = message.toString();
if (message.toString().isEmpty()){ newTopic = ".*"; System.out.println("Received empty");}
this.topic = newTopic;
System.out.println("Set topic to" + this.topic);
}
}
......
......@@ -32,10 +32,16 @@
<style>
.angular-google-map-container { height: 700px; }
button, input {color: black; }
</style>
@if(u != null) {
<div ng-app="myApp" ng-controller="Example">
<label>Search for tweets relating to:
<input type="text" name="input" ng-model="filter.text" required ng-trim="false">
</label>
<button ng-click="filterTopic()">Search!</button>
<ui-gmap-google-map center='map.center' zoom='map.zoom' options="map.options">
<ui-gmap-layer namespace="visualization" type="HeatmapLayer" show="map.showHeat" onCreated="map.heatLayerCallback"></ui-gmap-layer>
</ui-gmap-google-map>
......
......@@ -14,7 +14,7 @@ angular.module("myApp", ['uiGmapgoogle-maps'])
latitude: 37.782551,
longitude: -122.445368
},
zoom: 1,
zoom: 2,
options : {
styles: [{"featureType":"all","elementType":"labels.text.fill","stylers":[{"saturation":36},{"color":"#000000"},{"lightness":40}]},{"featureType":"all","elementType":"labels.text.stroke","stylers":[{"visibility":"on"},{"color":"#343031"},{"lightness":"-44"}]},{"featureType":"all","elementType":"labels.icon","stylers":[{"visibility":"off"}]},{"featureType":"administrative","elementType":"geometry.fill","stylers":[{"color":"#000000"},{"lightness":20}]},{"featureType":"administrative","elementType":"geometry.stroke","stylers":[{"color":"#000000"},{"lightness":17},{"weight":1.2}]},{"featureType":"administrative","elementType":"labels","stylers":[{"visibility":"off"}]},{"featureType":"administrative.country","elementType":"all","stylers":[{"visibility":"simplified"}]},{"featureType":"administrative.country","elementType":"geometry","stylers":[{"visibility":"simplified"}]},{"featureType":"administrative.country","elementType":"labels.text","stylers":[{"visibility":"simplified"}]},{"featureType":"administrative.province","elementType":"all","stylers":[{"visibility":"off"}]},{"featureType":"administrative.locality","elementType":"all","stylers":[{"visibility":"simplified"},{"saturation":"-100"},{"lightness":"30"}]},{"featureType":"administrative.neighborhood","elementType":"all","stylers":[{"visibility":"off"}]},{"featureType":"administrative.land_parcel","elementType":"all","stylers":[{"visibility":"off"}]},{"featureType":"landscape","elementType":"all","stylers":[{"visibility":"simplified"},{"gamma":"0.00"},{"lightness":"74"}]},{"featureType":"landscape","elementType":"geometry","stylers":[{"color":"#544e50"},{"lightness":"-45"}]},{"featureType":"landscape.man_made","elementType":"all","stylers":[{"lightness":"3"}]},{"featureType":"poi","elementType":"all","stylers":[{"visibility":"off"}]},{"featureType":"poi","elementType":"geometry","stylers":[{"color":"#000000"},{"lightness":21}]},{"featureType":"road","elementType":"geometry","stylers":[{"visibility":"simplified"}]},{"featureType":"road.highway","elementType":"geometry.fill","stylers":[{"color":"#99664f"},{"lightness":"-16"}]},{"featureType":"road.highway","elementType":"geometry.stroke","stylers":[{"color":"#000000"},{"lightness":29},{"weight":0.2}]},{"featureType":"road.arterial","elementType":"geometry","stylers":[{"color":"#000000"},{"lightness":18}]},{"featureType":"road.local","elementType":"geometry","stylers":[{"color":"#000000"},{"lightness":16}]},{"featureType":"transit","elementType":"geometry","stylers":[{"color":"#000000"},{"lightness":19}]},{"featureType":"water","elementType":"geometry","stylers":[{"color":"#413c3e"},{"lightness":"-66"}]}]
......@@ -51,7 +51,7 @@ angular.module("myApp", ['uiGmapgoogle-maps'])
showHeat: true
};
var ws = new WebSocket("ws://127.0.0.1:9000/websocket?topic=Algernons");
var ws = new WebSocket("ws://127.0.0.1:9000/websocket?topic=Day");
// binding model for the UI
$scope.messages = [];
......@@ -65,4 +65,14 @@ angular.module("myApp", ['uiGmapgoogle-maps'])
$scope.heatLayer.setData($scope.pointArray);
};
$scope.filter = {
text: ''
};
$scope.filterTopic = function() {
$scope.tweetRingBuffer.empty();
$scope.pointArray = new google.maps.MVCArray($scope.tweetRingBuffer.toArray());
$scope.heatLayer.setData($scope.pointArray);
ws.send($scope.filter.text);
};
});
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment