1 package nl.tudelft.simulation.examples.dsol.animation.gis;
2
3 import java.io.IOException;
4 import java.net.URL;
5 import java.rmi.RemoteException;
6
7 import javax.naming.NamingException;
8
9 import org.djutils.draw.bounds.Bounds2d;
10 import org.djutils.io.URLResource;
11
12 import nl.tudelft.simulation.dsol.SimRuntimeException;
13 import nl.tudelft.simulation.dsol.animation.d2.RenderableScale;
14 import nl.tudelft.simulation.dsol.animation.gis.GisRenderable2d;
15 import nl.tudelft.simulation.dsol.animation.gis.esri.EsriFileXmlParser;
16 import nl.tudelft.simulation.dsol.animation.gis.esri.EsriRenderable2d;
17 import nl.tudelft.simulation.dsol.experiment.Replication;
18 import nl.tudelft.simulation.dsol.experiment.SingleReplication;
19 import nl.tudelft.simulation.dsol.model.AbstractDsolModel;
20 import nl.tudelft.simulation.dsol.simulators.DevsRealTimeAnimator;
21 import nl.tudelft.simulation.dsol.simulators.DevsSimulatorInterface;
22 import nl.tudelft.simulation.dsol.swing.gui.DsolPanel;
23 import nl.tudelft.simulation.dsol.swing.gui.animation.DsolAnimationApplication;
24 import nl.tudelft.simulation.dsol.swing.gui.animation.DsolAnimationGisTab;
25 import nl.tudelft.simulation.dsol.swing.gui.control.RealTimeControlPanel;
26 import nl.tudelft.simulation.language.DsolException;
27
28
29
30
31
32
33
34
35
36
37
38
39 public class EsriXmlSwingApplication extends DsolAnimationApplication
40 {
41
42
43
44
45
46
47
48
49 public EsriXmlSwingApplication(final String title, final DsolPanel panel, final DsolAnimationGisTab animationTab)
50 throws RemoteException, IllegalArgumentException, DsolException
51 {
52 super(panel, title, animationTab);
53 panel.enableSimulationControlButtons();
54 }
55
56
57 private static final long serialVersionUID = 1L;
58
59
60
61
62
63
64
65
66 public static void main(final String[] args) throws SimRuntimeException, RemoteException, NamingException, DsolException
67 {
68 DevsRealTimeAnimator.TimeDouble simulator = new DevsRealTimeAnimator.TimeDouble("EsriSwingApplication", 0.001);
69 EmptyModel model = new EmptyModel(simulator);
70 Replication<Double> replication = new SingleReplication<Double>("rep1", 0.0, 0.0, 1000000.0);
71 simulator.initialize(model, replication);
72
73 DsolPanel panel = new DsolPanel(new RealTimeControlPanel.TimeDouble(model, simulator));
74 Bounds2d mapBounds = new Bounds2d(4.355, 4.386, 51.995, 52.005);
75 DsolAnimationGisTab animationTab = new DsolAnimationGisTab(mapBounds, simulator);
76 animationTab.getAnimationPanel().setRenderableScale(
77 new RenderableScale(Math.cos(Math.toRadians(mapBounds.midPoint().getY())), 1.0 / 111319.24));
78 animationTab.addAllToggleGISButtonText("MAP LAYERS", model.getGisMap(), "hide or show this GIS layer");
79 new EsriXmlSwingApplication("EsriSwingApplication", panel, animationTab);
80 }
81
82
83 static class EmptyModel extends AbstractDsolModel<Double, DevsSimulatorInterface<Double>>
84 {
85
86 private static final long serialVersionUID = 1L;
87
88
89 private GisRenderable2d gisMap;
90
91
92
93
94
95 EmptyModel(final DevsSimulatorInterface<Double> simulator)
96 {
97 super(simulator);
98 }
99
100
101 @Override
102 public void constructModel() throws SimRuntimeException
103 {
104 URL gisURL = URLResource.getResource("/resources/esri/tudelft.xml");
105 System.out.println("ESRI-map file: " + gisURL.toString());
106 try
107 {
108 this.gisMap = new EsriRenderable2d(getSimulator().getReplication(), EsriFileXmlParser.parseMapFile(gisURL));
109 }
110 catch (IOException e)
111 {
112 throw new SimRuntimeException(e);
113 }
114 }
115
116
117
118
119 public GisRenderable2d getGisMap()
120 {
121 return this.gisMap;
122 }
123 }
124 }