Adding labels to GeoRSSViewer Sample

I was recently working on the sample posted on EDN website showing how to plot the Recent Earthquake GeoRSS feed from USGS. Before I go any further here is the link to the sample : Custom Task – GeoRSS

I wanted to modify the sample to not only plot the earthquake points on the map using Graphics layer but also show me the information associated with the point such as magnitude and location. Here are the steps involved :

  • Add a new command to the existing custom task (GeorssTask.java) to plot both points and show labels
  • Add a new TaskDescriptor entry for the command in the TaskInfo class (GeorssTaskInfo.java)

This new method will take the current extent of the map and plot all the Georss points within the extent using both a symbol and a label.

Lets look at the code :

Add this code to the “GeorssTask.java” class from the sample

public void addGeorssSourceWithLabel(TaskEvent event) {
try {

getGeorssCoords(getGeorssURL());

WebExtent currExt = event.getWebContext().getWebMap().getCurrentExtent();
WebGraphics webGraphics = event.getWebContext().getWebGraphics();
Map rssInfo = null;

if (hash.size() > 0) {
Enumeration locations = hash.keys();
while (locations.hasMoreElements()) {

String loc = locations.nextElement().toString();

String[] strLoc = loc.split(":");
if (strLoc.length >= 2) {

WebPoint webPoint = new WebPoint(Double.parseDouble(strLoc[0]),Double.parseDouble(strLoc[1]));
if (webPoint != null && currExt.contains(webPoint)) {
WebGeometry webGeometry = (WebGeometry) webPoint;

rssInfo = (Map)hash.get(loc);

WebTrueTypeMarkerSymbol ttms = new WebTrueTypeMarkerSymbol();
ttms.addTextValue(rssInfo.get("title").toString());
ttms.setFontColor("0,0,0");
ttms.setFontSize(12);
ttms.setFontStyle(WebTrueTypeMarkerSymbol.BOLD);
ttms.setTextPosition(WebTrueTypeMarkerSymbol.RIGHT);

WebSimpleMarkerSymbol sms = new WebSimpleMarkerSymbol();
sms.setColor("255,255,0");
sms.setMarkerType(WebSimpleMarkerSymbol.CIRCLE);
sms.setTransparency(0.5);
sms.setWidth(20);

//Add point
GraphicElement pointGE = new GraphicElement();
pointGE.setGeometry(webGeometry);
pointGE.setSymbol(sms);

//Add the Label
GraphicElement textGE = new GraphicElement();
textGE.setGeometry(webGeometry);
textGE.setSymbol(ttms);

//Add graphic elements to WebGraphics
webGraphics.addGraphics(pointGE);
webGraphics.addGraphics(textGE);
}
}
}
event.getWebContext().refresh();
}
} catch (Exception e) {
e.printStackTrace();
}
}

Add this code to the “GeorssTaskInfo.java”class


//we are adding the command as an image

taskActions[2] = new TaskActionDescriptor(GeorssTask.class,"addGeorssSourceWithLabel", "Add GeoRSS with Labels");
taskActions[2].setToolTip("Click to Add GeoRSS locations with labels");
taskActions[2].setDefaultImage("images/tasks/editing/enterxy.gif");
taskActions[2].setSelectedImage("images/tasks/editing/enterxyD.gif");
taskActions[2].setHoverImage("images/tasks/editing/enterxyU.gif");
taskActions[2].setDisabledImage("images/tasks/editing/enterxyX.gif");
taskActions[2].setRendererType(TaskToolDescriptor.IMAGE_RENDERER_TYPE);

Screenshot showing the new tool and output :

Advertisements

One Response to “Adding labels to GeoRSSViewer Sample”

  1. before and after breast actives Says:

    I’m impressed, I must say. Rarely do I come across a blog that’s both equally educative and entertaining, and without a doubt,
    you’ve hit the nail on the head. The problem is something which not enough folks are speaking intelligently about. I’m very
    happy that I stumbled across this during my search
    for something relating to this.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: