package nl.tudelft.simulation.dsol.animation.D2; import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.awt.image.ImageObserver; import java.net.URL; import java.rmi.RemoteException; import javax.media.j3d.Bounds; import javax.naming.Context; import javax.naming.NamingException; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import nl.javel.gisbeans.io.esri.CoordinateTransform; import nl.javel.gisbeans.map.MapInterface; import nl.javel.gisbeans.map.mapfile.MapFileXMLParser; import nl.tudelft.simulation.dsol.animation.Locatable; import nl.tudelft.simulation.dsol.simulators.AnimatorInterface; import nl.tudelft.simulation.dsol.simulators.SimulatorInterface; import nl.tudelft.simulation.language.d3.BoundingBox; import nl.tudelft.simulation.language.d3.CartesianPoint; import nl.tudelft.simulation.language.d3.DirectedPoint; import nl.tudelft.simulation.naming.context.ContextUtil; /** * This renderable draws CAD/GIS objects. *
* (c) copyright 2002-2005 Delft University of Technology , the
* Netherlands.
* See for project information www.simulation.tudelft.nl
* License of use: Lesser General Public License (LGPL) , no
* warranty.
* @author Peter Jacobs
* @version $Revision: 1.1 $ $Date: 2010/08/10 11:37:20 $
* @since 1.5
*/
public class GisRenderable2D implements Renderable2DInterface, Locatable
{
/** the map to display */
protected MapInterface map = null;
/** the image cached image. */
protected BufferedImage image = null;
/** the cached extent. */
protected Rectangle2D extent = new Rectangle2D.Double();
/** the cached screenSize. */
protected Dimension screenSize = new Dimension();
/** the location of the image. */
protected DirectedPoint location = null;
/** the bounds of the image. */
protected Bounds bounds = null;
/** the logger. */
private static Logger logger = LogManager.getLogger(GisRenderable2D.class);
/**
* the context for (un)binding.
*/
protected Context context;
/**
* constructs a new GisRenderable2D.
* @param simulator the simulator.
* @param mapFile the mapfile to use.
*/
public GisRenderable2D(final SimulatorInterface, ?, ?> simulator, final URL mapFile)
{
this(simulator, mapFile, new CoordinateTransform.NoTransform());
}
/**
* constructs a new GisRenderable2D.
* @param simulator the simulator.
* @param mapFile the mapfile to use.
* @param coordinateTransform the transformation of (x, y) coordinates to (x', y') coordinates.
*/
public GisRenderable2D(final SimulatorInterface, ?, ?> simulator, final URL mapFile,
final CoordinateTransform coordinateTransform)
{
super();
if (!(simulator instanceof AnimatorInterface))
{
return;
}
try
{
this.map = MapFileXMLParser.parseMapFile(mapFile, coordinateTransform);
this.location =
new DirectedPoint(new CartesianPoint(this.extent.getCenterX(), this.extent.getCenterY(),
-Double.MAX_VALUE));
this.bounds = new BoundingBox(this.extent.getWidth(), this.extent.getHeight(), 0.0);
simulator.getReplication().getTreatment().getProperties()
.put("animationPanel.extent", this.map.getExtent());
this.bind2Context(simulator);
}
catch (Exception exception)
{
logger.warn("