forked from cocoahero/android-geojson
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMultiLineString.java
112 lines (87 loc) · 3.24 KB
/
MultiLineString.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package com.cocoahero.android.geojson;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.os.Parcel;
import android.os.Parcelable;
public class MultiLineString extends Geometry {
// ------------------------------------------------------------------------
// Instance Variables
// ------------------------------------------------------------------------
private final List<LineString> mLineStrings = new ArrayList<LineString>();
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
public MultiLineString() {
// Default Constructor
}
public MultiLineString(JSONObject json) {
super(json);
this.setLineStrings(json.optJSONArray(JSON_COORDINATES));
}
public MultiLineString(JSONArray lineStrings) {
this.setLineStrings(lineStrings);
}
// ------------------------------------------------------------------------
// Parcelable Interface
// ------------------------------------------------------------------------
public static final Parcelable.Creator<MultiLineString> CREATOR = new Creator<MultiLineString>() {
@Override
public MultiLineString createFromParcel(Parcel in) {
return (MultiLineString) readParcel(in);
}
@Override
public MultiLineString[] newArray(int size) {
return new MultiLineString[size];
}
};
// ------------------------------------------------------------------------
// Public Methods
// ------------------------------------------------------------------------
public void addLineString(LineString lineString) {
this.mLineStrings.add(lineString);
}
public void removeLineString(LineString lineString) {
this.mLineStrings.remove(lineString);
}
public List<LineString> getLineStrings() {
return this.mLineStrings;
}
public void setLineStrings(JSONArray lineStrings) {
this.mLineStrings.clear();
if (lineStrings != null) {
for (int i = 0; i < lineStrings.length(); i++) {
JSONArray lineJSON = lineStrings.optJSONArray(i);
if (lineJSON != null) {
this.mLineStrings.add(new LineString(lineJSON));
}
}
}
}
public void setLineStrings(List<LineString> lineStrings) {
this.mLineStrings.clear();
if (lineStrings != null) {
this.mLineStrings.addAll(lineStrings);
}
}
@Override
public String getType() {
return GeoJSON.TYPE_MULTI_LINE_STRING;
}
@Override
public JSONObject toJSON() throws JSONException {
JSONObject json = super.toJSON();
JSONArray strings = new JSONArray();
for (LineString line : this.mLineStrings) {
JSONArray lineJSON = new JSONArray();
for (Position position : line.getPositions()) {
lineJSON.put(position.toJSON());
}
strings.put(lineJSON);
}
json.put(JSON_COORDINATES, strings);
return json;
}
}