1 package nl.tudelft.simulation.dsol.animation.gis.map;
2
3 import java.awt.Color;
4 import java.awt.geom.Point2D;
5 import java.awt.geom.Rectangle2D;
6 import java.util.ArrayList;
7 import java.util.List;
8
9 import org.djutils.draw.bounds.Bounds2d;
10 import org.djutils.logger.CategoryLogger;
11
12 import nl.tudelft.simulation.dsol.animation.gis.FeatureInterface;
13 import nl.tudelft.simulation.dsol.animation.gis.GisObject;
14 import nl.tudelft.simulation.dsol.animation.gis.SerializablePath;
15 import nl.tudelft.simulation.language.d2.Shape;
16
17
18
19
20
21
22
23
24
25
26
27
28 public class Feature implements FeatureInterface
29 {
30
31 private static final long serialVersionUID = 20210201L;
32
33
34 private String key = "*";
35
36
37
38
39
40 private String value = "*";
41
42
43
44
45
46 private List<GisObject> shapes = new ArrayList<>();
47
48
49 private Color fillColor = null;
50
51
52 private Color outlineColor = Color.BLACK;
53
54
55 private boolean initialized = false;
56
57
58 @Override
59 public final String getKey()
60 {
61 return this.key;
62 }
63
64
65 @Override
66 public final void setKey(final String key)
67 {
68 this.key = key;
69 }
70
71
72 @Override
73 public final String getValue()
74 {
75 return this.value;
76 }
77
78
79
80
81
82
83
84
85
86 @Override
87 public boolean isInitialized()
88 {
89 return this.initialized;
90 }
91
92
93 @Override
94 public void setInitialized(final boolean initialized)
95 {
96 this.initialized = initialized;
97 }
98
99
100 @Override
101 public int getNumShapes()
102 {
103 return this.shapes.size();
104 }
105
106
107 @Override
108 public GisObject getShape(final int index) throws IndexOutOfBoundsException
109 {
110 return this.shapes.get(index);
111 }
112
113
114 @Override
115 public List<GisObject> getShapes()
116 {
117 return this.shapes;
118 }
119
120
121 @Override
122 public List<GisObject> getShapes(final Bounds2d rectangle)
123 {
124 List<GisObject> result = new ArrayList<>();
125 Rectangle2D rectangle2D = rectangle.toRectangle2D();
126 for (GisObject shape : this.shapes)
127 {
128 if (shape.getShape() instanceof SerializablePath)
129 {
130 if (Shape.overlaps(rectangle2D, ((SerializablePath) shape.getShape()).getBounds2D()))
131 {
132 result.add(shape);
133 }
134 }
135 else if (shape.getShape() instanceof Point2D)
136 {
137 if (rectangle2D.contains((Point2D) shape.getShape()))
138 {
139 result.add(shape);
140 }
141 }
142 else
143 {
144 CategoryLogger.always().error("unknown shape in cached content " + shape);
145 }
146 }
147 return result;
148 }
149
150
151
152
153
154
155
156
157
158 @Override
159 public final void setValue(final String value)
160 {
161 this.value = value;
162 }
163
164
165 @Override
166 public Color getFillColor()
167 {
168 return this.fillColor;
169 }
170
171
172 @Override
173 public void setFillColor(final Color fillColor)
174 {
175 this.fillColor = fillColor;
176 }
177
178
179 @Override
180 public Color getOutlineColor()
181 {
182 return this.outlineColor;
183 }
184
185
186 @Override
187 public void setOutlineColor(final Color outlineColor)
188 {
189 this.outlineColor = outlineColor;
190 }
191
192 }