Javafx,WorldWind,jGeoPlanet and Twitter
I will start with talking about all the APIs that i have used to build this application doesn't do much,it displays tweets user location if found from a given hashtag.("#NationalPrayerBreakfast")
worldwind API its simply an open source virtual globe written in java.
jGeoPlanet a java library for the Yahoo! GeoPlanet API .Needs an application Id .
twitter4j a java library for the Twitter API.Needs an access Token.
controlsFX a javafx library with high quality controls.
The Globe
WorldWindowGLJPanel wwd = new WorldWindowGLJPanel();
wwd.setPreferredSize(new java.awt.Dimension(1000, 700));
BasicModel basicModel=new BasicModel();
wwd.setModel(basicModel);
SwingNode swingNode=new SwingNode();
swingNode.setContent(wwd);
ViewControlsLayer viewControlsLayer=new ViewControlsLayer();
viewControlsLayer.setLocationCenter(new Vec4(150,70));
ViewControlsSelectListener vcl=new ViewControlsSelectListener(wwd,viewControlsLayer);
wwd.addSelectListener(viewControlsLayer);
wwd.getModel().getLayers().add(viewControlsLayer);
root.getChildren().add(swingNode);
The Tweets
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey("****************************")
.setOAuthConsumerSecret("***********************")
.setOAuthAccessToken("***************************")
.setOAuthAccessTokenSecret("*******************");
TwitterFactory tw=new TwitterFactory(cb.build());
Twitter t=tw.getInstance();
Query q=new Query("NationalPrayerBreakfast");
q.setCount(100);
QueryResult qr = t.search(q);
for(Status s:qr.getTweets()){
location=s.getUser().getLocation();
imageUrl=s.getUser().getBiggerProfileImageURL();
name=s.getUser().getName();
status=s.getText();
}
The Markers
AnnotationLayer annotationLayer=new AnnotationLayer();
String [] tweets="location,imageUrl,Name,status";
String location=item[0];
java.awt.Image image=ImageIO.read(new URL(item[1]));
AnnotationAttributes attr=new AnnotationAttributes();
attr.setBorderWidth(3);
attr.setBorderColor(Color.white);
attr.setImageSource(image);
attr.setFrameShape(AVKey.SHAPE_ELLIPSE);
attr.setImageRepeat(Annotation.IMAGE_REPEAT_NONE);
attr.setImageOffset(new Point(15,15));
attr.setSize(new Dimension(110,110));
GlobeAnnotation globeAnnotation = new GlobeAnnotation("",Position.fromDegrees(lat, lon));
globeAnnotation.setValue("name", item[2]);
globeAnnotation.setValue("status", item[3]);
globeAnnotation.setValue("http", item[1]);
globeAnnotation.setAttributes(attr);
annotationLayer.addAnnotation(globeAnnotation);
Getting LonLat
GeoPlanet g = new GeoPlanet(appID);
Place earth=g.getPlace(item[0]);
double lat=earth.getCentroid().getLatitude();
double lon=earth.getCentroid().getLongitude();
Globe Interaction
wwd.addSelectListener((SelectEvent se) -> {
Object o=se.getTopObject();
if(o !=null){
if(o instanceof GlobeAnnotation){
if(se.getEventAction().equals(SelectEvent.LEFT_CLICK)){
Platform.runLater(() -> {
GlobeAnnotation gl=(GlobeAnnotation)o;
Notifications.create()
.owner(swingNode)
.position(Pos.CENTER)
.title(gl.getStringValue("name"))
.text(gl.getStringValue("status"))
.graphic(new ImageView(gl.getStringValue("http")))
.darkStyle()
.show();
});
}
}
}
});
Results
worldwind API its simply an open source virtual globe written in java.
jGeoPlanet a java library for the Yahoo! GeoPlanet API .Needs an application Id .
twitter4j a java library for the Twitter API.Needs an access Token.
controlsFX a javafx library with high quality controls.
WorldWindowGLJPanel wwd = new WorldWindowGLJPanel();
wwd.setPreferredSize(new java.awt.Dimension(1000, 700));
BasicModel basicModel=new BasicModel();
wwd.setModel(basicModel);
SwingNode swingNode=new SwingNode();
swingNode.setContent(wwd);
ViewControlsLayer viewControlsLayer=new ViewControlsLayer();
viewControlsLayer.setLocationCenter(new Vec4(150,70));
ViewControlsSelectListener vcl=new ViewControlsSelectListener(wwd,viewControlsLayer);
wwd.addSelectListener(viewControlsLayer);
wwd.getModel().getLayers().add(viewControlsLayer);
root.getChildren().add(swingNode);
The Tweets
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey("****************************")
.setOAuthConsumerSecret("***********************")
.setOAuthAccessToken("***************************")
.setOAuthAccessTokenSecret("*******************");
TwitterFactory tw=new TwitterFactory(cb.build());
Twitter t=tw.getInstance();
Query q=new Query("NationalPrayerBreakfast");
q.setCount(100);
QueryResult qr = t.search(q);
for(Status s:qr.getTweets()){
location=s.getUser().getLocation();
imageUrl=s.getUser().getBiggerProfileImageURL();
name=s.getUser().getName();
status=s.getText();
}
The Markers
AnnotationLayer annotationLayer=new AnnotationLayer();
String [] tweets="location,imageUrl,Name,status";
String location=item[0];
java.awt.Image image=ImageIO.read(new URL(item[1]));
AnnotationAttributes attr=new AnnotationAttributes();
attr.setBorderWidth(3);
attr.setBorderColor(Color.white);
attr.setImageSource(image);
attr.setFrameShape(AVKey.SHAPE_ELLIPSE);
attr.setImageRepeat(Annotation.IMAGE_REPEAT_NONE);
attr.setImageOffset(new Point(15,15));
attr.setSize(new Dimension(110,110));
GlobeAnnotation globeAnnotation = new GlobeAnnotation("",Position.fromDegrees(lat, lon));
globeAnnotation.setValue("name", item[2]);
globeAnnotation.setValue("status", item[3]);
globeAnnotation.setValue("http", item[1]);
globeAnnotation.setAttributes(attr);
annotationLayer.addAnnotation(globeAnnotation);
Getting LonLat
GeoPlanet g = new GeoPlanet(appID);
Place earth=g.getPlace(item[0]);
double lat=earth.getCentroid().getLatitude();
double lon=earth.getCentroid().getLongitude();
Globe Interaction
wwd.addSelectListener((SelectEvent se) -> {
Object o=se.getTopObject();
if(o !=null){
if(o instanceof GlobeAnnotation){
if(se.getEventAction().equals(SelectEvent.LEFT_CLICK)){
Platform.runLater(() -> {
GlobeAnnotation gl=(GlobeAnnotation)o;
Notifications.create()
.owner(swingNode)
.position(Pos.CENTER)
.title(gl.getStringValue("name"))
.text(gl.getStringValue("status"))
.graphic(new ImageView(gl.getStringValue("http")))
.darkStyle()
.show();
});
}
}
}
});
Results
Zoom |
onClick2 |
onClick1 |
Comments
Post a Comment