📄 elevationtask.java
字号:
package com.esri.solutions.jitk.web.tasks.elevation;
import com.esri.adf.web.data.GraphicElement;
import com.esri.adf.web.data.WebContext;
import com.esri.adf.web.data.WebContextInitialize;
import com.esri.adf.web.data.WebGraphics;
import com.esri.adf.web.data.geometry.WebPoint;
import com.esri.adf.web.data.geometry.WebSpatialReference;
import com.esri.adf.web.data.symbol.WebSimpleMarkerSymbol;
import com.esri.adf.web.data.tasks.SimpleTaskInfo;
import com.esri.adf.web.data.tasks.TaskInfo;
import com.esri.adf.web.data.tasks.TaskInfoBean;
import com.esri.adf.web.faces.event.MapEvent;
import com.esri.adf.web.faces.event.TaskEvent;
import com.esri.solutions.jitk.services.common.ServicesException;
import com.esri.solutions.jitk.services.elevation.Elevation;
import com.esri.solutions.jitk.services.elevation.ElevationCalculator;
import com.esri.solutions.jitk.web.tasks.RenderAwareTaskDescription;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;
/**
* Task to calculate elevation. This task allows the user
* to select a point on the map or type the X,Y coordinates
* within text boxes. The elevation is calculated and displayed
* to the user in meters and feet.
*
* <p>
* This task defers to an Elevation Calculator web service to
* perform the calculation of the elevation. The proxy to the
* web service can be set via {@link #setElevationCalculator(ElevationCalculator)}.
* </p>
*/
public class ElevationTask implements WebContextInitialize, TaskInfoBean {
/**
* Serialization ID
*/
private static final long serialVersionUID = -2797016910657944943L;
/**
* Logger to use to log messages from this class.
*/
private static final Logger LOG = LogManager.getLogger(ElevationTask.class);
/**
* Stores the elevation in feet.
*/
private String m_elevationFeet;
/**
* Stores the elevation in meters.
*/
private String m_elevationMeters;
/**
* Reference to the Task Info object.
*/
private ElevationTaskInfo m_taskInfo;
/**
* Reference to the Web Service proxy object.
*/
private ElevationCalculator m_elevCalc;
/**
* X-coordinate on the map.
*/
private String m_x;
/**
* Y-coordinate on the map.
*/
private String m_y;
/**
* Indicates if a marker should be shown for
* the location.
*/
private boolean m_showMarker;
/**
* Indicates if the location has been picked.
*/
private boolean m_locationPicked;
/**
* Spatial Reference ID.
*/
private int m_srsId;
/**
* List of Graphics that were drawn as markers.
*/
private final List<GraphicElement> m_graphics;
/**
* Indicates if the task's main function (calculate elevation)
* has been executed.
*/
private boolean m_executed;
/**
* Indicates if an error has occurred.
*/
private boolean m_errorOccurred;
/**
* Stores error message.
*/
private String m_error;
private String footerNote = null;
private String legendLocation = null;
private String legendElevation = null;
/**
* Constructs a new <code>ElevationTask</code> object. This
* constructor initializes the Task Info object. After this
* call, {@link #getTaskInfo()} will return a non-null
* value.
*/
public ElevationTask() {
m_taskInfo = new ElevationTaskInfo(this);
m_graphics = new ArrayList<GraphicElement>();
}
/**
* Get footer note
*/
public String getFooterNote() {
return this.footerNote;
}
/**
* Set footer note
*/
public void setFooterNote(String footerNote) {
this.footerNote = footerNote;
}
/**
* Get location legend
*/
public String getLegendLocation() {
return this.legendLocation;
}
/**
* Set location legend
*/
public void setLegendLocation(String legendLocation) {
this.legendLocation = legendLocation;
}
/**
* Get elevation legend
*/
public String getLegendElevation() {
return this.legendElevation;
}
/**
* Set elevation legend
*/
public void setLegendElevation(String legendElevation) {
this.legendElevation = legendElevation;
}
/**
* Action to store X,Y coordinates where the user clicked
* on the map. If the user indicated that a marker should be
* drawn, then this method will draw it. This method will get
* a reference to a {@link MapEvent} object from the ADF
* Task Framework.
*
* @param event Map event, will contain the click point
* on the map.
*/
public void pickLocation(MapEvent event) {
LOG.debug("Entered method");
WebPoint screenPt = null;
WebPoint mapPt = null;
WebContext webContext = event.getWebContext();
screenPt = (WebPoint) event.getWebGeometry();
mapPt = (WebPoint) screenPt.toMapGeometry(event.getWebContext()
.getWebMap());
if (LOG.isDebugEnabled()) {
LOG.debug("Map Coordinates [" + mapPt.getX() + "," + mapPt.getY() +
"]");
}
setX(String.valueOf(mapPt.getX()));
setY(String.valueOf(mapPt.getY()));
m_srsId = WebSpatialReference.getWebSpatialReferenceId(event.getWebContext()
.getSpatialReferenceDefinitionString());
if (LOG.isDebugEnabled()) {
LOG.debug("SRS ID: " + m_srsId);
}
if (getShowMarker()) {
LOG.debug("Showing marker");
showMarker(webContext);
}
m_locationPicked = true;
m_taskInfo.locationPickedState();
reRender();
LOG.debug("Exiting method");
}
/**
* Helper method to flag this task to be rerendered in the browser.
*/
private void reRender() {
if (m_taskInfo.getTaskDescriptor() instanceof RenderAwareTaskDescription) {
((RenderAwareTaskDescription) m_taskInfo.getTaskDescriptor()).setShouldRender(true);
}
}
/**
* Helper method to draw the marker symbol on the map where the
* user chose to calculate elevation.
*
* @param mapPt Map point (in map coordinates)
* @param webContext Needed for reference to {@link WebGraphics}.
*/
private void showMarker(WebContext webContext) {
WebPoint mapPt2 = new WebPoint();
mapPt2.setX(Double.valueOf(getX()));
mapPt2.setY(Double.valueOf(getY()));
WebSpatialReference sr = WebSpatialReference.getWebSpatialReference(webContext.getSpatialReferenceDefinitionString());
mapPt2.setSpatialReference(sr);
GraphicElement graphic = new GraphicElement();
graphic.setGeometry(mapPt2);
WebSimpleMarkerSymbol symbol = new WebSimpleMarkerSymbol();
symbol.setColor("255,0,0");
symbol.setWidth(6);
symbol.setMarkerType(WebSimpleMarkerSymbol.CIRCLE);
graphic.setSymbol(symbol);
webContext.getWebGraphics().addGraphics(graphic);
m_graphics.add(graphic);
webContext.refresh();
}
/**
* Calculates the elevation at the location chosen by the
* user. The location could have chosen by clicking on the
* map or entering X,Y coordinates into text boxes. If
* the user indicated that a marker should be drawn at the
* location chosen, then this method will draw the marker.
*
* <p>
* This method will call upon the Elevation Calculator web
* service through the proxy object to calculate the elevation.
* </p>
*
* <p>
* This method will populate the results so that the UI will
* reflect the elevation. If an error occurs, this method
* will put the UI in a state where the error will be displayed.
* </p>
*
* @param event Task Event passed by ADF Task Framework.
*/
public void calculateElevation(TaskEvent event) {
LOG.debug("Entering method");
setErrorOccurred(false);
if (getShowMarker()) {
LOG.debug("Showing Marker");
showMarker(event.getWebContext());
}
com.esri.solutions.jitk.services.elevation.Point elevPoint = new com.esri.solutions.jitk.services.elevation.Point();
elevPoint.setX(Double.valueOf(getX()));
elevPoint.setY(Double.valueOf(getY()));
elevPoint.setSrsId(m_srsId);
try {
LOG.debug("Invoking ElevationCalculator web service...");
Elevation result = m_elevCalc.calculateElevation(elevPoint);
LOG.debug("Successful invocation.");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -