package nl.tudelft.simulation.examples.dsol.animation.gis; import java.io.IOException; import java.io.Serializable; import java.net.URL; import java.rmi.RemoteException; import javax.naming.NamingException; import org.djutils.draw.bounds.Bounds2d; import org.djutils.io.URLResource; import nl.tudelft.simulation.dsol.SimRuntimeException; import nl.tudelft.simulation.dsol.animation.D2.RenderableScale; import nl.tudelft.simulation.dsol.animation.gis.GisRenderable2D; import nl.tudelft.simulation.dsol.animation.gis.esri.EsriFileCsvParser; import nl.tudelft.simulation.dsol.animation.gis.esri.EsriRenderable2D; import nl.tudelft.simulation.dsol.experiment.ReplicationInterface; import nl.tudelft.simulation.dsol.experiment.SingleReplication; import nl.tudelft.simulation.dsol.model.AbstractDSOLModel; import nl.tudelft.simulation.dsol.simulators.DEVSRealTimeAnimator; import nl.tudelft.simulation.dsol.simulators.DEVSSimulatorInterface; import nl.tudelft.simulation.dsol.swing.gui.DSOLPanel; import nl.tudelft.simulation.dsol.swing.gui.animation.DSOLAnimationApplication; import nl.tudelft.simulation.dsol.swing.gui.animation.DSOLAnimationGisTab; import nl.tudelft.simulation.dsol.swing.gui.control.RealTimeControlPanel; import nl.tudelft.simulation.language.DSOLException; /** * GIS demo to show a map using ESRI shape files. *

* Copyright (c) 2002-2022 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See * for project information https://simulation.tudelft.nl. The DSOL * project is distributed under a three-clause BSD-style license, which can be found at * * https://simulation.tudelft.nl/dsol/3.0/license.html. *

* @author Alexander Verbraeck */ public class EsriCsvSwingApplication extends DSOLAnimationApplication { /** * @param title String; the title * @param panel DSOLPanel; the panel * @param animationTab DSOLAnimationGisTab; the (custom) animation tab * @throws DSOLException when simulator is not an animator * @throws IllegalArgumentException for illegal bounds * @throws RemoteException on network error */ public EsriCsvSwingApplication(final String title, final DSOLPanel panel, final DSOLAnimationGisTab animationTab) throws RemoteException, IllegalArgumentException, DSOLException { super(panel, title, animationTab); panel.enableSimulationControlButtons(); } /** */ private static final long serialVersionUID = 1L; /** * @param args String[]; arguments, expected to be empty * @throws SimRuntimeException on error * @throws RemoteException on error * @throws NamingException on error * @throws DSOLException when simulator is not an animator */ public static void main(final String[] args) throws SimRuntimeException, RemoteException, NamingException, DSOLException { DEVSRealTimeAnimator.TimeDouble simulator = new DEVSRealTimeAnimator.TimeDouble("EsriSwingApplication", 0.001); EmptyModel model = new EmptyModel(simulator); ReplicationInterface.TimeDouble replication = new SingleReplication.TimeDouble("rep1", 0.0, 0.0, 1000000.0); simulator.initialize(model, replication); DSOLPanel panel = new DSOLPanel(new RealTimeControlPanel.TimeDouble(model, simulator)); Bounds2d mapBounds = new Bounds2d(4.355, 4.386, 51.995, 52.005); DSOLAnimationGisTab animationTab = new DSOLAnimationGisTab(mapBounds, simulator); animationTab.getAnimationPanel().setRenderableScale( new RenderableScale(Math.cos(Math.toRadians(mapBounds.midPoint().getY())), 1.0 / 111319.24)); animationTab.addAllToggleGISButtonText("MAP LAYERS", model.getGisMap(), "hide or show this GIS layer"); new EsriCsvSwingApplication("EsriSwingApplication", panel, animationTab); } /** The empty model -- this demo is just to show a map on the screen. */ static class EmptyModel extends AbstractDSOLModel.TimeDouble { /** The default serial version UID for serializable classes. */ private static final long serialVersionUID = 1L; /** the GIS map. */ private GisRenderable2D gisMap; /** * constructs a new EmptyModel. * @param simulator DEVSSimulatorInterface.TimeDouble; the simulator */ EmptyModel(final DEVSSimulatorInterface.TimeDouble simulator) { super(simulator); } /** {@inheritDoc} */ @Override public void constructModel() throws SimRuntimeException { URL csvUrl = URLResource.getResource("/resources/esri/tudelft.csv"); System.out.println("ESRI-map file: " + csvUrl.toString()); try { this.gisMap = new EsriRenderable2D( getSimulator().getReplication(), EsriFileCsvParser.parseMapFile(csvUrl, "TU Delft")); } catch (IOException e) { throw new SimRuntimeException(e); } } /** {@inheritDoc} */ @Override public Serializable getSourceId() { return "EmptyModel"; } /** * @return gisMap */ public GisRenderable2D getGisMap() { return this.gisMap; } } }