*
* @param props LinkProperties containing map parameters.
*/
public void updateMap(LinkProperties props) {
Proj projection = (Proj) getProjection();
float latitude = PropUtils.floatFromProperties(props,
LPC_CENTER_LAT,
projection.getCenter().getLatitude());
float longitude = PropUtils.floatFromProperties(props,
LPC_CENTER_LONG,
projection.getCenter().getLongitude());
float scale = PropUtils.floatFromProperties(props,
LPC_SCALE,
projection.getScale());
int width = PropUtils.intFromProperties(props,
LPC_WIDTH,
projection.getWidth());
int height = PropUtils.intFromProperties(props,
LPC_HEIGHT,
projection.getHeight());
String projType = props.getProperty(LPC_PROJECTION);
float latmin = PropUtils.floatFromProperties(props, LPC_LATMIN, -1000.f);
float latmax = PropUtils.floatFromProperties(props, LPC_LATMAX, -1000.f);
float lonmin = PropUtils.floatFromProperties(props, LPC_LONMIN, -1000.f);
float lonmax = PropUtils.floatFromProperties(props, LPC_LONMAX, -1000.f);
if (latmin >= -90.f && latmax <= 90.f && lonmin >= -180.f
&& lonmax <= 180.f && latmin <= latmax && lonmin <= lonmax) {
// Calculate center point
float dist = 0.5f * GreatCircle.spherical_distance(ProjMath.degToRad(latmax),
ProjMath.degToRad(lonmin),
ProjMath.degToRad(latmin),
ProjMath.degToRad(lonmax));
float azimuth = GreatCircle.spherical_azimuth(ProjMath.degToRad(latmax),
ProjMath.degToRad(lonmin),
ProjMath.degToRad(latmin),
ProjMath.degToRad(lonmax));
LatLonPoint center = GreatCircle.spherical_between(ProjMath.degToRad(latmax),
ProjMath.degToRad(lonmin),
dist,
azimuth);
latitude = center.getLatitude();
longitude = center.getLongitude();
}
MapHandler mapHandler = (MapHandler) getBeanContext();
if (mapHandler == null) {
Debug.message("link", "Warning...mapHandler = null");
} else {
MapBean mapBean = (MapBean) mapHandler.get("com.bbn.openmap.MapBean");
if (mapBean == null) {
Debug.message("link", "Warning...mapBean = null");
} else {
if (projType != null) {
Class projClass = ProjectionFactory.getProjClassForName(projType);
if (projClass == null) {
projClass = Mercator.class;
}
projection = (Proj) ProjectionFactory.makeProjection(projClass,
latitude,
longitude,
scale,
width,
height);
} else {
projection = (Proj) mapBean.getProjection();
projection.setCenter(latitude, longitude);
projection.setScale(scale);
projection.setWidth(width);
projection.setHeight(height);
}
if (latmin >= -90.f && latmax <= 90.f && lonmin >= -180.f
&& lonmax <= 180.f && latmin <= latmax
&& lonmin <= lonmax) {
LatLonPoint upperLeft = new LatLonPoint(latmax, lonmin);
LatLonPoint lowerRight = new LatLonPoint(latmin, lonmax);
scale = ProjMath.getScale(upperLeft, lowerRight, projection);
projection.setScale(scale);
LatLonPoint ul = projection.getUpperLeft();
LatLonPoint lr = projection.getLowerRight();
float factor1 = (latmax - latmin)
/ (ul.getLatitude() - lr.getLatitude());
float factor2 = (lonmax - lonmin)
/ (lr.getLongitude() - ul.getLongitude());
if (factor2 > factor1)
factor1 = factor2;
if (factor1 > 1.0) {
scale *= factor1;
projection.setScale(scale);
}
}
mapBean.setProjection(projection);
}