/* ********************************************************************** * * ROLANDS & ASSOCIATES Corporation * 500 Sloat Avenue * Monterey, CA 93940 * (831) 373-2025 * * Copyright (C) 2002, 2003 ROLANDS & ASSOCIATES Corporation. All rights reserved. * Openmap is a trademark of BBN Technologies, A Verizon Company * * * ********************************************************************** * * $Source: /home/jtlsdev/src/wej/java_client/com/rolands/jtlsweb/map/layer/ScaleDisplayLayer.java,v $ * $Revision: 1.2 $ * $Date: 2003/02/18 16:11:33 $ * $Author: ward $ * * ********************************************************************** */ package com.rolands.jtlsweb.map.layer; /** * Layer objects are components which can be added to the MapBean to * make a map. *

* Layers implement the ProjectionListener interface to listen for * ProjectionEvents. When the projection changes, they may need to * refetch, regenerate their graphics, and then repaint themselves * into the new view. */ public class ScaleDisplayLayer extends com.bbn.openmap.Layer { com.bbn.openmap.omGraphics.OMGraphicList graphics = new com.bbn.openmap.omGraphics.OMGraphicList(); public ScaleDisplayLayer() { super(); } /** * Sets the properties for the Layer. This allows * Layers to get a richer set of parameters than the * setArgs method. * @param prefix the token to prefix the property names * @param props the Properties object */ public void setProperties(String prefix, java.util.Properties props) { super.setProperties(prefix, props); } /** * Invoked when the projection has changed or this Layer has been * added to the MapBean. * @param e ProjectionEvent */ com.bbn.openmap.proj.Projection projection; public void projectionChanged(com.bbn.openmap.event.ProjectionEvent e) { projection = e.getProjection(); createGraphics(); repaint(); } public void createGraphics() { int w = projection.getWidth(); int h = projection.getHeight(); int left_x = w-10-150; int right_x = w-10; int lower_y = h-10; int upper_y = h-10-10; graphics.clear(); com.bbn.openmap.omGraphics.OMLine line = new com.bbn.openmap.omGraphics.OMLine(left_x, lower_y, right_x, lower_y); graphics.add(line); line = new com.bbn.openmap.omGraphics.OMLine(left_x, lower_y, left_x, upper_y); graphics.add(line); line = new com.bbn.openmap.omGraphics.OMLine(right_x, lower_y, right_x, upper_y); graphics.add(line); com.bbn.openmap.LatLonPoint loc1 = projection.inverse(left_x, lower_y); com.bbn.openmap.LatLonPoint loc2 = projection.inverse(right_x, lower_y); float dist = com.bbn.openmap.proj.GreatCircle.spherical_distance(com.bbn.openmap.proj.ProjMath.degToRad(loc1.getLatitude()), com.bbn.openmap.proj.ProjMath.degToRad(loc1.getLongitude()), com.bbn.openmap.proj.ProjMath.degToRad(loc2.getLatitude()), com.bbn.openmap.proj.ProjMath.degToRad(loc2.getLongitude())); dist = com.rolands.util.Convert.radiansToKm(dist); String outtext = ""+dist+"Km"; if (dist >100) { outtext = ""+(int)dist+"Km"; } else if (dist > 1) { outtext = ""+(int)((dist*10f)/10f)+"Km"; } else { outtext = ""+(int)(dist*1000f)+"m"; } com.bbn.openmap.omGraphics.OMText text = new com.bbn.openmap.omGraphics.OMText((left_x+right_x)/2, lower_y-3, ""+outtext, com.bbn.openmap.omGraphics.OMText.JUSTIFY_CENTER); graphics.add(text); graphics.generate(projection); } /** * Paints the layer. * @param g the Graphics context for painting */ public void paint(java.awt.Graphics g) { graphics.render(g); } }