1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.leaflet.business;
35
36 import fr.paris.lutece.util.xml.XmlUtil;
37
38
39
40
41
42
43
44
45
46
47
48 import com.fasterxml.jackson.annotation.JsonAutoDetect;
49 import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
50 import com.fasterxml.jackson.annotation.JsonProperty;
51 import com.fasterxml.jackson.core.JsonParseException;
52 import com.fasterxml.jackson.databind.JsonMappingException;
53 import com.fasterxml.jackson.databind.ObjectMapper;
54 import com.fasterxml.jackson.databind.DeserializationFeature;
55
56 import java.io.IOException;
57
58 import java.util.HashMap;
59 import java.util.List;
60 import java.util.Map;
61
62
63
64
65
66 @JsonAutoDetect( creatorVisibility = Visibility.NONE, fieldVisibility = Visibility.NONE, getterVisibility = Visibility.NONE, isGetterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE )
67 public class GeolocItemPolygon
68 {
69 public static final String PATH_TYPE = "type";
70 public static final String PATH_GEOMETRY = "geometry";
71 public static final String PATH_GEOMETRY_TYPE = "type";
72 public static final String PATH_GEOMETRY_COORDINATES = "coordinates";
73 public static final String PATH_PROPERTIES = "properties";
74 public static final String PATH_PROPERTIES_ICON = "icon";
75 public static final String PATH_PROPERTIES_LAYER = "layer";
76 public static final String XML_ROOT = "geoloc";
77 public static final String XML_LON = "lon";
78 public static final String XML_LAT = "lat";
79 public static final String XML_ICON = "icon";
80 public static final String XML_LAYER = "layer";
81 public static final String VALUE_TYPE = "Feature";
82 public static final String VALUE_GEOMETRY_TYPE_POLYGON = "Polygon";
83 public static final String VALUE_GEOMETRY_TYPE_POLYLINE = "Polyline";
84 private static final ObjectMapper _objectMapper;
85
86 static
87 {
88 _objectMapper = new ObjectMapper( );
89
90 _objectMapper.configure( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false );
91 }
92
93 private List<Double> _lonlat;
94 private List<List<Double>> _polygonLonLoat;
95 private String _icon;
96 private String _layer;
97 private String _typegeometry;
98 private String _typePolygon;
99
100
101
102
103
104
105
106
107
108 @JsonProperty( PATH_GEOMETRY )
109 public void setGeometry( Map<String, Object> geometry )
110 {
111
112
113 _polygonLonLoat = ( List<List<Double>> ) geometry.get( PATH_GEOMETRY_COORDINATES );
114 }
115
116
117
118
119
120
121 @JsonProperty( PATH_PROPERTIES )
122 public void setProperties( Map<String, Object> properties )
123 {
124 _icon = (String) properties.get( PATH_PROPERTIES_ICON );
125 _layer = (String) properties.get( PATH_PROPERTIES_LAYER );
126 }
127
128
129
130
131
132
133 @JsonProperty( PATH_TYPE )
134 public String getType( )
135 {
136 return VALUE_TYPE;
137 }
138
139
140
141
142
143
144 @JsonProperty( PATH_PROPERTIES )
145 public Map<String, Object> getProperties( )
146 {
147 HashMap<String, Object> properties = new HashMap<String, Object>( );
148
149 if ( _icon != null )
150 {
151 properties.put( PATH_PROPERTIES_ICON, _icon );
152 }
153
154 if ( _layer != null )
155 {
156 properties.put( PATH_PROPERTIES_LAYER, _layer );
157 }
158
159 return properties;
160 }
161
162
163
164
165
166
167 @JsonProperty( PATH_GEOMETRY )
168 public Map<String, Object> getGeometry( )
169 {
170 HashMap<String, Object> geometry = new HashMap<String, Object>( );
171
172 geometry.put( PATH_GEOMETRY_TYPE, _typegeometry );
173
174 geometry.put( PATH_GEOMETRY_COORDINATES, _polygonLonLoat );
175
176 return geometry;
177 }
178
179
180
181
182
183
184 public List<Double> getLonLat( )
185 {
186 return _lonlat;
187 }
188
189
190
191
192
193
194 public double getLon( )
195 {
196 return _lonlat.get( 0 );
197 }
198
199
200
201
202
203
204 public double getLat( )
205 {
206 return _lonlat.get( 1 );
207 }
208
209
210
211
212
213
214 public String getIcon( )
215 {
216 return _icon;
217 }
218
219
220
221
222
223
224 public String getLayer( )
225 {
226 return _layer;
227 }
228
229
230
231
232
233
234 public void setIcon( String icon )
235 {
236 _icon = icon;
237 }
238
239
240
241
242
243
244 public String toJSON( )
245 {
246 try
247 {
248 return _objectMapper.writeValueAsString( this );
249 }
250 catch ( IOException e )
251 {
252
253 throw new RuntimeException( e );
254 }
255 }
256
257
258
259
260
261
262 public String toXML( )
263 {
264 StringBuffer stringBuffer = new StringBuffer( );
265 XmlUtil.beginElement( stringBuffer, XML_ROOT );
266 XmlUtil.addElement( stringBuffer, XML_LON, _lonlat.get( 0 ).toString( ) );
267 XmlUtil.addElement( stringBuffer, XML_LAT, _lonlat.get( 1 ).toString( ) );
268
269 if ( _icon != null )
270 {
271 XmlUtil.addElement( stringBuffer, XML_ICON, _icon );
272 }
273
274 if ( _layer != null )
275 {
276 XmlUtil.addElement( stringBuffer, XML_LAYER, _layer );
277 }
278
279 XmlUtil.endElement( stringBuffer, XML_ROOT );
280
281 return stringBuffer.toString( );
282 }
283
284
285
286
287
288
289 public static GeolocItemPolygon fromJSON( String strJson )
290 throws JsonParseException, JsonMappingException, IOException
291 {
292 return _objectMapper.readValue( strJson, GeolocItemPolygon.class );
293 }
294
295 public String getTypegeometry() {
296 return _typegeometry;
297 }
298
299 public void setTypegeometry(String _typegeometry) {
300 this._typegeometry = _typegeometry;
301 }
302 }