-
Notifications
You must be signed in to change notification settings - Fork 982
/
DefaultShapeMetaSetter.java
50 lines (42 loc) · 1.67 KB
/
DefaultShapeMetaSetter.java
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package org.osmdroid.shape;
import net.iryndin.jdbf.core.DbfRecord;
import org.osmdroid.util.BoundingBox;
import org.osmdroid.views.overlay.Marker;
import org.osmdroid.views.overlay.Polygon;
import org.osmdroid.views.overlay.Polyline;
import java.nio.charset.Charset;
import java.text.ParseException;
public class DefaultShapeMetaSetter implements ShapeMetaSetter {
private static String getSensibleTitle(String snippet) {
if (snippet.length() > 100) {
return snippet.substring(0, 96) + "...";
}
return snippet;
}
@Override
public void set(DbfRecord metadata, Marker marker) throws ParseException {
if (metadata != null) {
metadata.setStringCharset(Charset.defaultCharset());
marker.setSnippet(metadata.toMap().toString());
marker.setTitle(getSensibleTitle(marker.getSnippet()));
}
}
@Override
public void set(DbfRecord metadata, Polygon polygon) throws ParseException {
if (metadata != null) {
metadata.setStringCharset(Charset.defaultCharset());
polygon.setSnippet(metadata.toMap().toString());
polygon.setTitle(getSensibleTitle(polygon.getSnippet()));
}
final BoundingBox boundingBox = polygon.getBounds();
polygon.setSubDescription(boundingBox.toString());
}
@Override
public void set(DbfRecord metadata, Polyline polyline) throws ParseException {
if (metadata != null) {
metadata.setStringCharset(Charset.defaultCharset());
polyline.setSnippet(metadata.toMap().toString());
polyline.setTitle(getSensibleTitle(polyline.getSnippet()));
}
}
}