Codebase list libkmlframework-java / d7d3430
Updated to KML 2.2 Classes not updated has got a "todo" in package eivind@boehn.org 15 years ago
140 changed file(s) with 6457 addition(s) and 3717 deletion(s). Raw diff Collapse all Expand all
11 <classpath>
22 <classpathentry kind="src" path="src"/>
33 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
4 <classpathentry kind="lib" path="lib/commons-logging.jar"/>
54 <classpathentry kind="lib" path="lib/javax.servlet.jar"/>
65 <classpathentry kind="lib" path="lib/urlrewrite-2.6.0.jar"/>
7 <classpathentry kind="lib" path="lib/xom-1.0.jar"/>
8 <classpathentry kind="lib" path="lib/xpp3_min-1.1.3.4.O.jar"/>
9 <classpathentry kind="lib" path="lib/xpp3_xpath-1.1.3.4.O.jar"/>
10 <classpathentry kind="lib" path="lib/xpp3-1.1.3.4.O.jar"/>
116 <classpathentry kind="lib" path="lib/ant-googlecode-0.0.1.jar"/>
127 <classpathentry kind="output" path="bin"/>
138 </classpath>
0 package org.boehn.kmlframework;
1
2 public abstract class AbstractView extends KmlObject {
3
4 private Double longitude;
5 private Double latitude;
6 private Double altitude;
7 private Double heading;
8 private Double tilt;
9 private AltitudeModeEnum altitudeMode;
10
11 public Double getLongitude() {
12 return longitude;
13 }
14
15 public void setLongitude(Double longitude) {
16 this.longitude = longitude;
17 }
18
19 public Double getLatitude() {
20 return latitude;
21 }
22
23 public void setLatitude(Double latitude) {
24 this.latitude = latitude;
25 }
26
27 public Double getAltitude() {
28 return altitude;
29 }
30
31 public void setAltitude(Double altitude) {
32 this.altitude = altitude;
33 }
34
35 public Double getHeading() {
36 return heading;
37 }
38
39 public void setHeading(Double heading) {
40 this.heading = heading;
41 }
42
43 public Double getTilt() {
44 return tilt;
45 }
46
47 public void setTilt(Double tilt) {
48 this.tilt = tilt;
49 }
50
51 public AltitudeModeEnum getAltitudeMode() {
52 return altitudeMode;
53 }
54
55 public void setAltitudeMode(AltitudeModeEnum altitudeMode) {
56 this.altitudeMode = altitudeMode;
57 }
58
59 public void writeInner(KmlDocument kmlDocument) throws KmlException {
60 if (longitude != null) {
61 kmlDocument.println("<longitude>" + longitude + "</longitude>");
62 }
63 if (latitude != null) {
64 kmlDocument.println("<latitude>" + latitude + "</latitude>");
65 }
66 if (altitude != null) {
67 kmlDocument.println("<altitude>" + altitude + "</altitude>");
68 }
69 if (heading != null) {
70 kmlDocument.println("<heading>" + heading + "</heading>");
71 }
72 if (tilt != null) {
73 kmlDocument.println("<tilt>" + tilt + "</tilt>");
74 }
75 if (altitudeMode != null) {
76 kmlDocument.println("<altitudeMode>" + altitudeMode + "</altitudeMode>");
77 }
78 }
79 }
0 package org.boehn.kmlframework;
1
2 public class Alias extends KmlObject {
3
4 private String targetHref;
5 private String sourceHref;
6
7 public String getTargetHref() {
8 return targetHref;
9 }
10
11 public void setTargetHref(String targetHref) {
12 this.targetHref = targetHref;
13 }
14
15 public String getSourceHref() {
16 return sourceHref;
17 }
18
19 public void setSourceHref(String sourceHref) {
20 this.sourceHref = sourceHref;
21 }
22
23 public void write(KmlDocument kmlDocument) throws KmlException {
24 kmlDocument.println("<Alias" + getIdAndTargetIdFormatted() + ">", 1);
25 if (targetHref != null) {
26 kmlDocument.println("<targetHref>" + targetHref + "</targetHref>");
27 }
28 if (sourceHref != null) {
29 kmlDocument.println("<sourceHref>" + sourceHref + "</sourceHref>");
30 }
31 kmlDocument.println(-1, "</Alias>");
32 }
33 }
0 package org.boehn.kmlframework;
1
2 public enum AltitudeModeEnum {
3 relativeToGround, absolute, clampToGround
4 }
+0
-5
src/org/boehn/kmlframework/AltitudeModes.java less more
0 package org.boehn.kmlframework;
1
2 public enum AltitudeModes {
3 relativeToGround, absolute, clampToGround
4 }
0 package org.boehn.kmlframework;
1
2 public class BallonStyle extends KmlObject {
3
4 private String bgColor;
5 private String textColor;
6 private String text;
7 private DisplayModeEnum displayMode;
8
9 public String getBgColor() {
10 return bgColor;
11 }
12
13 public void setBgColor(String bgColor) {
14 this.bgColor = bgColor;
15 }
16
17 public String getTextColor() {
18 return textColor;
19 }
20
21 public void setTextColor(String textColor) {
22 this.textColor = textColor;
23 }
24
25 public String getText() {
26 return text;
27 }
28
29 public void setText(String text) {
30 this.text = text;
31 }
32
33 public DisplayModeEnum getDisplayMode() {
34 return displayMode;
35 }
36
37 public void setDisplayMode(DisplayModeEnum displayMode) {
38 this.displayMode = displayMode;
39 }
40
41 public void write(KmlDocument kmlDocument) throws KmlException {
42 kmlDocument.println("<BallonStyle" + getIdAndTargetIdFormatted() + ">", 1);
43 if (bgColor != null) {
44 kmlDocument.println("<bgColor>" + bgColor + "</bgColor>");
45 }
46 if (textColor != null) {
47 kmlDocument.println("<textColor>" + textColor + "</textColor>");
48 }
49 if (text != null) {
50 kmlDocument.println("<text>" + text + "</text>");
51 }
52 if (displayMode != null) {
53 kmlDocument.println("<displayMode>" + (displayMode == DisplayModeEnum._default ? "default" : displayMode) + "</displayMode>");
54 }
55 kmlDocument.println(-1, "</BallonStyle>");
56 }
57 }
+0
-57
src/org/boehn/kmlframework/BoundingBox.java less more
0 package org.boehn.kmlframework;
1
2 import org.boehn.kmlframework.coordinates.EarthCoordinate;
3
4 public class BoundingBox {
5
6 private Double north;
7 private Double east;
8 private Double south;
9 private Double west;
10
11 public BoundingBox() {}
12
13 public BoundingBox(Double north, Double east, Double south, Double west) {
14 this.north = north;
15 this.east = east;
16 this.south = south;
17 this.west = west;
18 }
19
20 public boolean isInsideBoundingBox(EarthCoordinate earthCoordinate) {
21 return earthCoordinate.getLatitude() < north && earthCoordinate.getLatitude() > south && earthCoordinate.getLongitude() > west && earthCoordinate.getLongitude() < east;
22 }
23
24 public Double getEast() {
25 return east;
26 }
27
28 public void setEast(Double east) {
29 this.east = east;
30 }
31
32 public Double getNorth() {
33 return north;
34 }
35
36 public void setNorth(Double north) {
37 this.north = north;
38 }
39
40 public Double getSouth() {
41 return south;
42 }
43
44 public void setSouth(Double south) {
45 this.south = south;
46 }
47
48 public Double getWest() {
49 return west;
50 }
51
52 public void setWest(Double west) {
53 this.west = west;
54 }
55
56 }
+0
-107
src/org/boehn/kmlframework/Button.java less more
0 package org.boehn.kmlframework;
1
2 import java.io.UnsupportedEncodingException;
3 import java.net.URLEncoder;
4 import java.util.HashMap;
5 import java.util.Map;
6
7 import javax.servlet.http.HttpServletRequest;
8
9 import org.boehn.kmlframework.servlet.HttpServletModel;
10
11
12 public class Button {
13
14 private String url;
15 private String text;
16 private Map<String, String> parameters;
17
18 public Button() {
19 }
20
21 public Button(String text, String url) {
22 this.text = text;
23 this.url = url;
24 }
25
26 public Button(String text, String url, String parameterName, String parameterValue) {
27 this(text, url);
28 addParameter(parameterName, parameterValue);
29 }
30
31 public Button(String text, String url, Map<String, String> parameters) {
32 this(text, url);
33 this.parameters = parameters;
34 }
35
36 public void addParameter(String parameterName, String parameterValue) {
37 if (parameters == null) {
38 parameters = new HashMap<String, String>();
39 }
40 parameters.put(parameterName, parameterValue);
41 }
42
43 public String getText() {
44 return text;
45 }
46
47 public void setText(String text) {
48 this.text = text;
49 }
50
51 public Map<String, String> getParameters() {
52 return parameters;
53 }
54
55 public void setParameters(Map<String, String> parameters) {
56 this.parameters = parameters;
57 }
58
59 public String toHtml(Model model) {
60 try {
61 StringBuffer html = new StringBuffer();
62 StringBuffer urlToUse;
63 if (url.startsWith("http://")) {
64 urlToUse = new StringBuffer(url);
65 } else {
66 // The url is not absolute. We need info from the HttpServletModel
67 if (model instanceof HttpServletModel) {
68 HttpServletModel httpServleModel = (HttpServletModel) model;
69 urlToUse = new StringBuffer(encodeURL(httpServleModel.getBaseUrl() + url, httpServleModel.getRequest()));
70 } else {
71 throw new IllegalArgumentException("Button has an url that is not absolute (does not starts with 'http://'). Then the model must be an instance of the HttpServletModel class.");
72 }
73 }
74 if (parameters != null) {
75 urlToUse.append("?");
76 for (Object key: parameters.keySet()) {
77 urlToUse.append("&" + URLEncoder.encode(key.toString(), "UTF-8") + "=" + URLEncoder.encode(parameters.get(key).toString(), "UTF-8"));
78 }
79 }
80 html.append("<a href=\"" + urlToUse.toString() + "\">" + text + "</a>");
81 return html.toString();
82 } catch (UnsupportedEncodingException e) {
83 throw new RuntimeException(e);
84 }
85 }
86
87 public String encodeURL(String url, HttpServletRequest request) {
88 // TODO This method should not be necessarily. There is a method for doing this in the HttpServletResponse.
89 // At the moment that method is not doing the encoding. No idea why. It used to work...
90 int indexQuestionMark = url.indexOf("?");
91 if (indexQuestionMark < 0) {
92 return url + ";jsessionid=" + request.getSession().getId();
93 } else {
94 return url.substring(0, indexQuestionMark) + ";jsessionid=" + request.getSession().getId() + url.substring(indexQuestionMark);
95 }
96 }
97
98 public String getUrl() {
99 return url;
100 }
101
102 public void setUrl(String url) {
103 this.url = url;
104 }
105
106 }
0 package org.boehn.kmlframework;
1
2 public class Camera extends AbstractView {
3
4 private Double roll;
5
6 public Double getRoll() {
7 return roll;
8 }
9
10 public void setRoll(Double roll) {
11 this.roll = roll;
12 }
13
14 public void write(KmlDocument kmlDocument) throws KmlException {
15 kmlDocument.println("<Camera" + getIdAndTargetIdFormatted() + ">", 1);
16 super.writeInner(kmlDocument);
17 if (roll != null) {
18 kmlDocument.println("<roll>" + roll + "</roll>");
19 }
20 kmlDocument.println(-1, "</Camera>");
21 }
22 }
0 package org.boehn.kmlframework;
1
2 public enum ColorModeEnum {
3 normal, random
4 }
0 package org.boehn.kmlframework;
1
2 public abstract class ColorStyle extends KmlObject {
3
4 private String color; // TOOD change to Java class?
5 private ColorModeEnum colorMode;
6
7 public String getColor() {
8 return color;
9 }
10
11 public void setColor(String color) {
12 this.color = color;
13 }
14
15 public ColorModeEnum getColorMode() {
16 return colorMode;
17 }
18
19 public void setColorMode(ColorModeEnum colorMode) {
20 this.colorMode = colorMode;
21 }
22
23 public void writeInner(KmlDocument kmlDocument) throws KmlException {
24 if (color != null) {
25 kmlDocument.println("<color>" + color + "</color>");
26 }
27 if (colorMode != null) {
28 kmlDocument.println("<colorMode>" + colorMode + "</colorMode>");
29 }
30 }
31 }
0 package org.boehn.kmlframework;
1
2 import java.util.ArrayList;
3 import java.util.List;
4
5 public abstract class Container extends Feature {
6 List<Feature> features;
7
8 public Container() {
9 features = new ArrayList<Feature>();
10 }
11
12 public List<Feature> getFeatures() {
13 return features;
14 }
15
16 public void setFeatures(List<Feature> features) {
17 this.features = features;
18 }
19
20 public void add(Feature feature) {
21 if (features == null) {
22 features = new ArrayList<Feature>();
23 }
24 features.add(feature);
25 }
26
27 public void writeInner(KmlDocument kmlDocument) throws KmlException {
28 if (features != null) {
29 for (Feature feature: features) {
30 feature.write(kmlDocument);
31 }
32 }
33 }
34 }
0 package org.boehn.kmlframework;
1
2 public class Data extends KmlObject {
3
4 private String name;
5 private String displayName;
6 private String value;
7
8 public Data() {}
9
10 public Data(String name, String displayName, String value) {
11 this.name = name;
12 this.displayName = displayName;
13 this.value = value;
14 }
15
16 public String getName() {
17 return name;
18 }
19
20 public void setName(String name) {
21 this.name = name;
22 }
23
24 public String getDisplayName() {
25 return displayName;
26 }
27
28 public void setDisplayName(String displayName) {
29 this.displayName = displayName;
30 }
31
32 public String getValue() {
33 return value;
34 }
35
36 public void setValue(String value) {
37 this.value = value;
38 }
39
40 public void write(KmlDocument kmlDocument) throws KmlException {
41 kmlDocument.println("<Data name=\"" + name +"\">", 1);
42 if (displayName != null) {
43 kmlDocument.println("<displayName>" + displayName + "</displayName>");
44 }
45 if (value != null) {
46 kmlDocument.println("<value>" + value + "</value>");
47 }
48 kmlDocument.println(-1, "</Data>");
49 }
50
51 }
0 package org.boehn.kmlframework;
1
2 public enum DisplayModeEnum {
3 _default, hide
4 }
0 package org.boehn.kmlframework;
1
2 import java.util.List;
3
4 public class ExtendedData extends KmlObject {
5
6 private List<Data> dataElements;
7 private String schemaUrl;
8 private List<SimpleData> simpleDataElements;
9 private String nameSpace;
10 private String customContent;
11
12 public List<Data> getDataElements() {
13 return dataElements;
14 }
15
16 public void setDataElements(List<Data> dataElements) {
17 this.dataElements = dataElements;
18 }
19
20 public String getSchemaUrl() {
21 return schemaUrl;
22 }
23
24 public void setSchemaUrl(String schemaUrl) {
25 this.schemaUrl = schemaUrl;
26 }
27
28 public List<SimpleData> getSimpleDataElements() {
29 return simpleDataElements;
30 }
31
32 public void setSimpleDataElements(List<SimpleData> simpleDataElements) {
33 this.simpleDataElements = simpleDataElements;
34 }
35
36 public String getNameSpace() {
37 return nameSpace;
38 }
39
40 public void setNameSpace(String nameSpace) {
41 this.nameSpace = nameSpace;
42 }
43
44 public String getCustomContent() {
45 return customContent;
46 }
47
48 public void setCustomContent(String customContent) {
49 this.customContent = customContent;
50 }
51
52 public void write(KmlDocument kmlDocument) throws KmlException {
53 kmlDocument.println("<ExtendedData" + getIdAndTargetIdFormatted() + (nameSpace != null ? " mlns:prefix=\"" + nameSpace + "\"" : "") + ">", 1);
54 if (dataElements != null) {
55 for (Data data : dataElements) {
56 data.write(kmlDocument);
57 }
58 }
59 if (schemaUrl != null || simpleDataElements != null) {
60 kmlDocument.println("<SchemaData" + (schemaUrl != null ? " schemaUrl=\"" + schemaUrl + "\"" : "") + ">", 1);
61 if (simpleDataElements != null) {
62 for (SimpleData simpleData : simpleDataElements) {
63 simpleData.write(kmlDocument);
64 }
65 }
66 kmlDocument.println("</SchemaData>");
67 }
68 if (customContent != null) {
69 kmlDocument.println(customContent);
70 }
71 kmlDocument.println(-1, "</ExtendedData>");
72 }
73 }
0 package org.boehn.kmlframework;
1
2 import org.boehn.kmlframework.atom.AtomAuthor;
3 import org.boehn.kmlframework.atom.AtomLink;
4
5 public abstract class Feature extends KmlObject {
6
7 private String name;
8 private Boolean visability;
9 private Boolean open;
10 private AtomAuthor atomAuthor;
11 private AtomLink atomLink;
12 private String address;
13 private String xalAddressDeatails;
14 private String phoneNumber;
15 private String snippet;
16 private Integer snippetMaxLines;
17 private String description;
18 private AbstractView cameraOrLookAt;
19 private TimePrimitive timeStampOrtimeSpan;
20 private String styleUrl;
21 private StyleSelector styleOrStyleMap;
22 private Region region;
23 private ExtendedData extendedData;
24
25 public String getName() {
26 return name;
27 }
28
29 public void setName(String name) {
30 this.name = name;
31 }
32
33 public Boolean isVisability() {
34 return visability;
35 }
36
37 public void setVisability(Boolean visability) {
38 this.visability = visability;
39 }
40
41 public boolean isOpen() {
42 return open;
43 }
44
45 public void setOpen(boolean open) {
46 this.open = open;
47 }
48
49 public AtomAuthor getAtomAuthor() {
50 return atomAuthor;
51 }
52
53 public void setAtomAuthor(AtomAuthor atomAuthor) {
54 this.atomAuthor = atomAuthor;
55 }
56
57 public AtomLink getAtomLink() {
58 return atomLink;
59 }
60
61 public void setAtomLink(AtomLink link) {
62 this.atomLink = link;
63 }
64
65 public String getAddress() {
66 return address;
67 }
68
69 public void setAddress(String address) {
70 this.address = address;
71 }
72
73 public String getXalAddressDeatails() {
74 return xalAddressDeatails;
75 }
76
77 public void setXalAddressDeatails(String xalAddressDeatails) {
78 this.xalAddressDeatails = xalAddressDeatails;
79 }
80
81 public String getPhoneNumber() {
82 return phoneNumber;
83 }
84
85 public void setPhoneNumber(String phoneNumber) {
86 this.phoneNumber = phoneNumber;
87 }
88
89 public String getSnippet() {
90 return snippet;
91 }
92
93 public void setSnippet(String snippet) {
94 this.snippet = snippet;
95 }
96
97 public Integer getSnippetMaxLines() {
98 return snippetMaxLines;
99 }
100
101 public void setSnippetMaxLines(Integer snippetMaxLines) {
102 this.snippetMaxLines = snippetMaxLines;
103 }
104
105 public String getDescription() {
106 return description;
107 }
108
109 public void setDescription(String description) {
110 this.description = description;
111 }
112
113 public AbstractView getCameraOrLookAt() {
114 return cameraOrLookAt;
115 }
116
117 public void setCameraOrLookAt(AbstractView cameraOrLookAt) {
118 this.cameraOrLookAt = cameraOrLookAt;
119 }
120
121 public String getStyleUrl() {
122 return styleUrl;
123 }
124
125 public void setStyleUrl(String styleUrl) {
126 this.styleUrl = styleUrl;
127 }
128
129 public StyleSelector getStyleOrStyleMap() {
130 return styleOrStyleMap;
131 }
132
133 public void setStyleOrStyleMap(StyleSelector styleOrStyleMap) {
134 this.styleOrStyleMap = styleOrStyleMap;
135 }
136
137 public TimePrimitive getTimeStampOrtimeSpan() {
138 return timeStampOrtimeSpan;
139 }
140
141 public void setTimeStampOrtimeSpan(TimePrimitive timeStampOrtimeSpan) {
142 this.timeStampOrtimeSpan = timeStampOrtimeSpan;
143 }
144
145 public Region getRegion() {
146 return region;
147 }
148
149 public void setRegion(Region region) {
150 this.region = region;
151 }
152
153 public ExtendedData getExtendedData() {
154 return extendedData;
155 }
156
157 public void setExtendedData(ExtendedData extendedData) {
158 this.extendedData = extendedData;
159 }
160
161 public void writeInner(KmlDocument kmlDocument) throws KmlException {
162 if (name != null) {
163 kmlDocument.println("<name>" + name + "</name>");
164 }
165 if (visability != null) {
166 kmlDocument.println("<visability>" + booleanToInt(visability) + "</visability>");
167 }
168 if (open != null) {
169 kmlDocument.println("<open>" + booleanToInt(open) + "</open>");
170 }
171 if (atomAuthor != null) {
172 atomAuthor.write(kmlDocument);
173 }
174 if (atomLink != null) {
175 atomLink.write(kmlDocument);
176 }
177 if (address != null) {
178 kmlDocument.println("<address>" + address + "</address>");
179 }
180 if (xalAddressDeatails != null) {
181 kmlDocument.println("<xal:AddressDetails>" + xalAddressDeatails + "</xal:AddressDetails>");
182 }
183 if (phoneNumber != null) {
184 kmlDocument.println("<phoneNumber>" + phoneNumber + "</phoneNumber>");
185 }
186 if (snippet != null) {
187 kmlDocument.println("<snippet maxLines=\"" + (snippetMaxLines != null ? snippetMaxLines : "2" ) + "\">" + snippet + "</snippet>");
188 }
189 if (description != null) {
190 kmlDocument.println("<description>" + description + "</description>");
191 }
192 if (cameraOrLookAt != null) {
193 cameraOrLookAt.write(kmlDocument);
194 }
195 if (timeStampOrtimeSpan != null) {
196 timeStampOrtimeSpan.write(kmlDocument);
197 }
198 if (styleUrl!= null) {
199 kmlDocument.println("<styleUrl>" + styleUrl + "</styleUrl>");
200 }
201 if (styleOrStyleMap != null) {
202 styleOrStyleMap.write(kmlDocument);
203 }
204 if (region != null) {
205 region.write(kmlDocument);
206 }
207 if (extendedData != null) {
208 extendedData.write(kmlDocument);
209 }
210 }
211 }
00 package org.boehn.kmlframework;
11
2 import java.io.IOException;
3 import java.io.Writer;
4 import java.util.ArrayList;
5 import java.util.Collection;
2 public class Folder extends Container {
63
7 import org.w3c.dom.Document;
8 import org.w3c.dom.Element;
9 import org.xmlpull.v1.XmlSerializer;
10
11 public class Folder implements ModelElement {
12
13 private Collection<ModelElement> modelElements;
14 private ViewPosition viewPosition;
15 private String name;
16 private String description;
17 private Boolean visibility;
18
19 public Folder() {}
20
21 public Folder(String name) {
22 this.name = name;
23 }
24
25 public ViewPosition getViewPosition() {
26 return viewPosition;
27 }
28
29 public void setViewPosition(ViewPosition viewPosition) {
30 this.viewPosition = viewPosition;
31 }
32
33 public Collection<ModelElement> getModelElements() {
34 return modelElements;
35 }
36
37 public void setModelElements(Collection<ModelElement> modelElements) {
38 this.modelElements = modelElements;
39 }
40
41 public void add(ModelElement element) {
42 if (modelElements == null) {
43 modelElements = new ArrayList<ModelElement>();
44 }
45 modelElements.add(element);
46 }
47
48 public void add(Collection<ModelElement> modelElements) {
49 if (this.modelElements == null) {
50 this.modelElements = modelElements;
51 } else {
52 this.modelElements.addAll(modelElements);
53 }
54 }
55
56 public String getDescription() {
57 return description;
58 }
59
60 public void setDescription(String description) {
61 this.description = description;
62 }
63
64 public String getName() {
65 return name;
66 }
67
68 public void setName(String name) {
69 this.name = name;
70 }
71
72 public Boolean getVisibility() {
73 return visibility;
74 }
75
76 public void setVisibility(Boolean visibility) {
77 this.visibility = visibility;
78 }
79
80 public void addKml(Element parentElement, Model model, Document xmlDocument) throws ModelException {
81 Element folderElement = xmlDocument.createElement("Folder");
82
83 if (name != null) {
84 Element nameElement = xmlDocument.createElement("name");
85 nameElement.appendChild(xmlDocument.createTextNode(name));
86 folderElement.appendChild(nameElement);
87 }
88
89 if (description != null) {
90 Element descriptionElement = xmlDocument.createElement("description");
91 descriptionElement.appendChild(xmlDocument.createCDATASection(description));
92 folderElement.appendChild(descriptionElement);
93 }
94
95 if (viewPosition != null) {
96 viewPosition.addKml(folderElement, model, xmlDocument);
97 }
98
99 if (modelElements != null) {
100 for (ModelElement modelElement : modelElements) {
101 // If the object is a MapObject it is only being added if:
102 // - ENABLE_ONLY_SHOW_OBJECTS_VISIBLE_TO_OBSERVER is false or the object is inside the view to the observer
103 // - observer == null or distance to observer is withoin the visibleFrom/To values to the object
104 boolean showCurrentModelElement;
105 if (!(modelElement instanceof MapObject) || model.getObserver() == null) {
106 showCurrentModelElement = true;
107 } else {
108 MapObject mapObject = (MapObject) modelElement;
109 if (mapObject.getLocation() != null) {
110 if (!model.ENABLE_ONLY_SHOW_OBJECTS_VISIBLE_TO_OBSERVER || model.getObserver().isVisibleToObserver(mapObject.getLocation())) {
111 double distanceToObserver = model.getObserver().distanceTo(mapObject.getLocation());
112 MapObjectClass mapObjectClass = mapObject.getMapObjectClass();
113 if (mapObjectClass == null) {
114 showCurrentModelElement = true;
115 } else {
116 if (!model.ENABLE_DETAILS_DEPENDS_ON_DISTANCE_TO_OBSERVER || ((mapObjectClass.getVisibleFrom() == null || mapObjectClass.getVisibleFrom() < distanceToObserver) && (mapObjectClass.getVisibleTo() == null || mapObjectClass.getVisibleTo() > distanceToObserver))) {
117 showCurrentModelElement = true;
118 } else {
119 showCurrentModelElement = false;
120 }
121 }
122 } else {
123 showCurrentModelElement = false;
124 }
125 } else {
126 showCurrentModelElement = true;
127 }
128 }
129 if (showCurrentModelElement) {
130 modelElement.addKml(folderElement, model, xmlDocument);
131 }
132 }
133 }
134
135 if (visibility != null) {
136 Element visibilityElement = xmlDocument.createElement("visibility");
137 visibilityElement.appendChild(xmlDocument.createTextNode((visibility) ? "1" : "0"));
138 folderElement.appendChild(visibilityElement);
139 }
140
141 parentElement.appendChild(folderElement);
4 public void write(KmlDocument kmlDocument) throws KmlException {
5 kmlDocument.println("<Folder" + getIdAndTargetIdFormatted() + ">", 1);
6 writeInner(kmlDocument);
7 kmlDocument.println(-1, "</Folder>");
1428 }
1439
144 public void addKmlXPP(Model model, XmlSerializer serializer) throws IllegalArgumentException, IllegalStateException, IOException {
145 // TODO This is a temp version of this method for testing the speed only
146 serializer.startTag(null, "Folder");
147 if (modelElements != null) {
148 for (ModelElement modelElement : modelElements) {
149 if (modelElement instanceof MapObject) {
150 ((MapObject) modelElement).addKmlXPP(model, serializer);
151 }
152 }
153 }
154 serializer.endTag(null, "Folder");
155 }
156
157 public void addKmlDirect(Model model, Writer writer) throws IOException {
158 // TODO This is a temp version of this method for testing the speed only
159 writer.write("<Folder>");
160
161 if (modelElements != null) {
162 for (ModelElement modelElement : modelElements) {
163 if (modelElement instanceof MapObject) {
164 ((MapObject) modelElement).addKmlDirect(model, writer);
165 }
166 }
167 }
168 writer.write("</Folder>");
169 }
17010 }
0 package org.boehn.kmlframework;
1
2 public abstract class Geometry extends KmlObject {
3
4 }
+0
-75
src/org/boehn/kmlframework/GraphicalModel.java less more
0 package org.boehn.kmlframework;
1
2 import java.util.ArrayList;
3 import java.util.Collection;
4
5 import org.boehn.kmlframework.coordinates.CartesianCoordinate;
6 import org.boehn.kmlframework.coordinates.Coordinate;
7 import org.boehn.kmlframework.coordinates.EarthCoordinate;
8 import org.w3c.dom.Document;
9 import org.w3c.dom.Element;
10
11 public class GraphicalModel implements GraphicalModelElement {
12
13 private Collection<GraphicalModelElement> elements;
14 private Integer visibleFrom;
15 private Integer visibleTo;
16
17 public GraphicalModel() {}
18
19 public Collection<GraphicalModelElement> getElements() {
20 return elements;
21 }
22
23 public void setElements(Collection<GraphicalModelElement> elements) {
24 this.elements = elements;
25 }
26
27 public void addGraphicalModelElement(GraphicalModelElement graphicalModelElement) {
28 if (elements == null) {
29 elements = new ArrayList<GraphicalModelElement>();
30 }
31 elements.add(graphicalModelElement);
32 }
33
34 public Integer getVisibleFrom() {
35 return visibleFrom;
36 }
37
38 public void setVisibleFrom(Integer visibleFrom) {
39 this.visibleFrom = visibleFrom;
40 }
41
42 public Integer getVisibleTo() {
43 return visibleTo;
44 }
45
46 public void setVisibleTo(Integer visibleTo) {
47 this.visibleTo = visibleTo;
48 }
49
50 public Collection<Coordinate> getCoordinates() {
51 Collection<Coordinate> coordinates = new ArrayList<Coordinate>();
52 for (GraphicalModelElement element : elements) {
53 coordinates.addAll(element.getCoordinates());
54 }
55 return coordinates;
56 }
57
58 public void addKml(Element parentElement, Model model, Document xmlDocument, EarthCoordinate location, Double rotation, CartesianCoordinate localReferenceCoordinate, CartesianCoordinate scale) throws ModelException {
59 if (elements != null) {
60 for (GraphicalModelElement element : elements) {
61 element.addKml(parentElement, model, xmlDocument, location, rotation, localReferenceCoordinate, scale);
62 }
63 }
64 }
65
66 public String toString() {
67 StringBuffer text = new StringBuffer("GraphicalModel:\n");
68 text.append(" visibleFrom: " + visibleFrom + "\n");
69 text.append(" visibleTo: " + visibleTo + "\n");
70 text.append(" elements: " + elements);
71 return text.toString();
72 }
73
74 }
+0
-16
src/org/boehn/kmlframework/GraphicalModelElement.java less more
0 package org.boehn.kmlframework;
1
2 import java.util.Collection;
3
4 import org.boehn.kmlframework.coordinates.CartesianCoordinate;
5 import org.boehn.kmlframework.coordinates.Coordinate;
6 import org.boehn.kmlframework.coordinates.EarthCoordinate;
7 import org.w3c.dom.Document;
8 import org.w3c.dom.Element;
9
10 public interface GraphicalModelElement {
11
12 public Collection<Coordinate> getCoordinates();
13 public void addKml(Element parentElement, Model model, Document xmlDocument, EarthCoordinate earthCoordinate, Double rotation, CartesianCoordinate localReferenceCoordinate, CartesianCoordinate scale) throws ModelException;
14
15 }
0 package org.boehn.kmlframework;
1
2 public enum GridOriginEnum {
3 lowerLeft, upperLeft
4 }
0 package org.boehn.kmlframework;
1
2 public class GroundOverlay extends Overlay {
3
4 private Double altitude;
5 private AltitudeModeEnum altitudeMode;
6 private Double north;
7 private Double south;
8 private Double east;
9 private Double west;
10 private Double rotation;
11
12 public Double getAltitude() {
13 return altitude;
14 }
15
16 public void setAltitude(Double altitude) {
17 this.altitude = altitude;
18 }
19
20 public AltitudeModeEnum getAltitudeMode() {
21 return altitudeMode;
22 }
23
24 public void setAltitudeMode(AltitudeModeEnum altitudeMode) {
25 this.altitudeMode = altitudeMode;
26 }
27
28 public Double getNorth() {
29 return north;
30 }
31
32 public void setNorth(Double north) {
33 this.north = north;
34 }
35
36 public Double getSouth() {
37 return south;
38 }
39
40 public void setSouth(Double south) {
41 this.south = south;
42 }
43
44 public Double getEast() {
45 return east;
46 }
47
48 public void setEast(Double east) {
49 this.east = east;
50 }
51
52 public Double getWest() {
53 return west;
54 }
55
56 public void setWest(Double west) {
57 this.west = west;
58 }
59
60 public Double getRotation() {
61 return rotation;
62 }
63
64 public void setRotation(Double rotation) {
65 this.rotation = rotation;
66 }
67
68 public void write(KmlDocument kmlDocument) throws KmlException {
69 kmlDocument.println("<GroundOverlay" + getIdAndTargetIdFormatted() + ">", 1);
70 super.writeInner(kmlDocument);
71 if (altitude != null) {
72 kmlDocument.println("<altitude>" + altitude + "</altitude>");
73 }
74 if (altitudeMode != null) {
75 kmlDocument.println("<altitudeMode>" + altitudeMode + "</altitudeMode>");
76 }
77 if (north != null || south != null || east != null || west != null || rotation != null) {
78 kmlDocument.println("<LatLonBox>", 1);
79 if (north != null) {
80 kmlDocument.println("<north>" + north + "</north>");
81 }
82 if (south != null) {
83 kmlDocument.println("<south>" + south + "</south>");
84 }
85 if (east != null) {
86 kmlDocument.println("<east>" + east + "</east>");
87 }
88 if (west != null) {
89 kmlDocument.println("<west>" + west + "</west>");
90 }
91 if (rotation != null) {
92 kmlDocument.println("<rotation>" + rotation + "</rotation>");
93 }
94 kmlDocument.println(-1, "</LatLonBox>");
95 }
96 kmlDocument.println(-1, "</GroundOverlay>");
97 }
98 }
0 package org.boehn.kmlframework;
1
2 public class Icon extends Link {
3
4 public void write(KmlDocument kmlDocument) throws KmlException {
5 kmlDocument.println("<Icon" + getIdAndTargetIdFormatted() + ">", 1);
6 writeInner(kmlDocument);
7 kmlDocument.println(-1, "</Icon>");
8 }
9 }
0 package org.boehn.kmlframework;
1
2 public class IconStyle extends ColorStyle {
3
4 private Double scale;
5 private Double heading;
6 private String iconHref;
7 private Double hotSpotX;
8 private Double hotSpotY;
9 private UnitEnum hotSpotXunits;
10 private UnitEnum hotSpotYunits;
11
12 public Double getScale() {
13 return scale;
14 }
15
16 public void setScale(Double scale) {
17 this.scale = scale;
18 }
19
20 public Double getHeading() {
21 return heading;
22 }
23
24 public void setHeading(Double heading) {
25 this.heading = heading;
26 }
27
28 public String getIconHref() {
29 return iconHref;
30 }
31
32 public void setIconHref(String iconHref) {
33 this.iconHref = iconHref;
34 }
35
36 public Double getHotSpotX() {
37 return hotSpotX;
38 }
39
40 public void setHotSpotX(Double hotSpotX) {
41 this.hotSpotX = hotSpotX;
42 }
43
44 public Double getHotSpotY() {
45 return hotSpotY;
46 }
47
48 public void setHotSpotY(Double hotSpotY) {
49 this.hotSpotY = hotSpotY;
50 }
51
52 public UnitEnum getHotSpotXunits() {
53 return hotSpotXunits;
54 }
55
56 public void setHotSpotXunits(UnitEnum hotSpotXunits) {
57 this.hotSpotXunits = hotSpotXunits;
58 }
59
60 public UnitEnum getHotSpotYunits() {
61 return hotSpotYunits;
62 }
63
64 public void setHotSpotYunits(UnitEnum hotSpotYunits) {
65 this.hotSpotYunits = hotSpotYunits;
66 }
67
68 public void write(KmlDocument kmlDocument) throws KmlException {
69 kmlDocument.println("<IconStyle" + getIdAndTargetIdFormatted() + ">", 1);
70 super.writeInner(kmlDocument);
71 if (scale != null) {
72 kmlDocument.println("<scale>" + scale + "</scale>");
73 }
74 if (heading != null) {
75 kmlDocument.println("<heading>" + heading + "</heading>");
76 }
77 if (iconHref != null) {
78 kmlDocument.println("<Icon>", 1);
79 kmlDocument.println("<href>" + iconHref + "</href>");
80 kmlDocument.println(-1, "</Icon>");
81 }
82 if (hotSpotX != null || hotSpotY != null || hotSpotXunits != null || hotSpotYunits != null) {
83 kmlDocument.println("<hotSpot" + (hotSpotX != null ? " x=\"" + hotSpotX + "\"" : "") + (hotSpotY != null ? " y=\"" + hotSpotY + "\"" : "") + (hotSpotXunits != null ? " xunits=\"" + hotSpotXunits + "\"" : "") + (hotSpotYunits != null ? " yunits=\"" + hotSpotYunits + "\"" : "") + "/>");
84 }
85 kmlDocument.println(-1, "</IconStyle>");
86 }
87 }
0 package org.boehn.kmlframework;
1
2 import java.io.BufferedWriter;
3 import java.io.FileWriter;
4 import java.io.IOException;
5 import java.io.PrintWriter;
6 import java.util.Hashtable;
7
8 import org.boehn.kmlframework.todo.servlet.Observer;
9 import org.boehn.kmlframework.todo.style.Style;
10
11 public class KmlDocument extends Container {
12
13 private Observer observer;
14 private Hashtable<String,Style> styles; // TODO to remove?
15 // TODO Schema
16
17 private PrintWriter printWriter;
18 private int indentLevel = 0;
19
20 public int CURRENT_TIME_OFFSET = 0; // in seconds
21 public int TAIL_HISTORY_TIME_LIMIT = 3600; // in seconds
22 public boolean ENABLE_TAILS = true;
23 public boolean ENABLE_3D_OBJECTS = true;
24 public int DISTANCE_LIMIT_TAIL = 15000; // in meters
25 public int DISTANCE_LIMIT_3D_OBJECTS = 15000; // in meters
26 public boolean ENABLE_DETAILS_DEPENDS_ON_DISTANCE_TO_OBSERVER = true;
27 public boolean ENABLE_ONLY_SHOW_OBJECTS_VISIBLE_TO_OBSERVER = true;
28 public String ENCODING = "UTF-8";
29 public boolean XML_INDENT = false;
30
31 public KmlDocument() {
32
33 }
34
35 public Observer getObserver() {
36 return observer;
37 }
38
39 public void setObserver(Observer observer) {
40 this.observer = observer;
41 }
42
43 public Hashtable<String, Style> getStyles() {
44 return styles;
45 }
46
47 public void setStyles(Hashtable<String, Style> styles) {
48 this.styles = styles;
49 }
50
51 public void addStyle(Style style) {
52 if (styles == null) {
53 styles = new Hashtable<String, Style>();
54 }
55 // We give a name to the style if it is missing that
56 if (style.getId() == null) {
57 int i = styles.size();
58 while (styles.containsKey("style" + i)) {
59 i++;
60 }
61 style.setId("style" + i);
62 }
63 styles.put(style.getId(), style);
64 }
65
66 public Style getStyle(String id) {
67 return styles.get(id);
68 }
69
70 public void print(String string) {
71 print(string, 0);
72 }
73
74 public void println(String string) {
75 println(string, 0);
76 }
77
78 public void print(String string, int indentChangeAfter) {
79 printIndents();
80 indentLevel += indentChangeAfter;
81 printWriter.print(string);
82 }
83
84 public void println(String string, int indentChangeAfter) {
85 printIndents();
86 indentLevel += indentChangeAfter;
87 printWriter.println(string);
88 }
89
90 public void print(int indentChangeBefore, String string) {
91 indentLevel += indentChangeBefore;
92 printIndents();
93 printWriter.print(string);
94 }
95
96 public void println(int indentChangeBefore, String string) {
97 indentLevel += indentChangeBefore;
98 printIndents();
99 printWriter.println(string);
100 }
101
102 private void printIndents() {
103 if (XML_INDENT) {
104 for (int i = 0; i < indentLevel; i++) {
105 printWriter.print("\t");
106 }
107 }
108 }
109
110 public void decreaseIndentLevel() {
111 indentLevel--;
112 }
113
114 public void increaseIndentLevel() {
115 indentLevel++;
116 }
117
118 public void write(KmlDocument kmlDocument) throws KmlException {
119 println("<Document" + getIdAndTargetIdFormatted() + ">", 1);
120 writeInner(kmlDocument);
121 //TODO add support for styles in KmlDocument
122 //if (styles != null) {
123 // for (Style style: styles.values()) {
124 // style.addKml(documentElement, this, xmlDocument);
125 // }
126 //}
127
128 if (features != null) {
129 for (Feature feature: features)
130 feature.write(this);
131 }
132
133 println(-1, "</Document>");
134 }
135
136 public void createKml(String fileName) throws KmlException, IOException {
137 createKml(new PrintWriter(new BufferedWriter(new FileWriter(fileName))));
138 }
139
140 public void createKml(PrintWriter printWriter) throws KmlException, IOException {
141 this.printWriter = printWriter;
142 println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
143 println("<kml xmlns=\"http://earth.google.com/kml/2.2\">", 1);
144 write(this);
145 println(-1, "</kml>");
146 this.printWriter.close();
147 }
148
149 }
0 package org.boehn.kmlframework;
1
2 public class KmlException extends Exception {
3
4 private static final long serialVersionUID = 1L;
5
6 public KmlException() {
7 super();
8 }
9
10 public KmlException(String arg0) {
11 super(arg0);
12 }
13
14 public KmlException(String arg0, Throwable arg1) {
15 super(arg0, arg1);
16 }
17
18 public KmlException(Throwable arg0) {
19 super(arg0);
20 }
21
22 }
0 package org.boehn.kmlframework;
1
2 public abstract class KmlObject {
3
4 private String id;
5 private String targetId;
6
7 public String getId() {
8 return id;
9 }
10 public void setId(String id) {
11 this.id = id;
12 }
13 public String getTargetId() {
14 return targetId;
15 }
16 public void setTargetId(String targetId) {
17 this.targetId = targetId;
18 }
19
20 public abstract void write(KmlDocument kmlDocument) throws KmlException;
21
22 protected String getIdAndTargetIdFormatted() {
23 String result = "";
24 if (id!= null) {
25 result += " id=\"" + id + "\"";
26 }
27 if (targetId!= null) {
28 result += " targetId=\"" + targetId + "\"";
29 }
30 return result;
31 }
32
33 public static int booleanToInt(boolean booleanValue) {
34 return (booleanValue? 1 : 0);
35 }
36
37 }
0 package org.boehn.kmlframework;
1
2 public class LabelStyle extends ColorStyle {
3
4 private Double scale;
5
6 public Double getScale() {
7 return scale;
8 }
9
10 public void setScale(Double scale) {
11 this.scale = scale;
12 }
13
14 public void write(KmlDocument kmlDocument) throws KmlException {
15 kmlDocument.println("<LabelStyle" + getIdAndTargetIdFormatted() + ">", 1);
16 super.writeInner(kmlDocument);
17 if (scale != null) {
18 kmlDocument.println("<scale>" + scale + "</scale>");
19 }
20 kmlDocument.println(-1, "</LabelStyle>");
21 }
22 }
0 package org.boehn.kmlframework;
1
2 import java.util.List;
3
4 public class LineString extends Geometry {
5
6 private Boolean extrude;
7 private Boolean tessellate;
8 private AltitudeModeEnum altitudeMode;
9 private List<Point> coordinates;
10
11 public Boolean getExtrude() {
12 return extrude;
13 }
14
15 public void setExtrude(Boolean extrude) {
16 this.extrude = extrude;
17 }
18
19 public Boolean getTessellate() {
20 return tessellate;
21 }
22
23 public void setTessellate(Boolean tessellate) {
24 this.tessellate = tessellate;
25 }
26
27 public AltitudeModeEnum getAltitudeMode() {
28 return altitudeMode;
29 }
30
31 public void setAltitudeMode(AltitudeModeEnum altitudeMode) {
32 this.altitudeMode = altitudeMode;
33 }
34
35 public List<Point> getCoordinates() {
36 return coordinates;
37 }
38
39 public void setCoordinates(List<Point> coordinates) {
40 this.coordinates = coordinates;
41 }
42
43 public void write(KmlDocument kmlDocument) throws KmlException {
44 // We validate the data
45 if (coordinates == null || coordinates.size() < 2) {
46 throw new KmlException("LineString must contain at least 2 points");
47 }
48
49 kmlDocument.println("<LineString" + getIdAndTargetIdFormatted() + ">", 1);
50 if (extrude != null) {
51 kmlDocument.println("<extrude>" + booleanToInt(extrude) + "</extrude>");
52 }
53 if (tessellate!= null) {
54 kmlDocument.println("<tessellate>" + booleanToInt(tessellate) + "</tessellate>");
55 }
56 if (altitudeMode!= null) {
57 kmlDocument.println("<altitudeMode>" + altitudeMode + "</altitudeMode>");
58 }
59 if (coordinates != null) {
60 kmlDocument.print("<coordinates>");
61 boolean firstLoop = true;
62 for (Point point : coordinates) {
63 if (firstLoop) {
64 firstLoop = false;
65 } else {
66 kmlDocument.print(" ");
67 }
68 kmlDocument.print(point.getLongitudeLatitudeAltitudeString());
69 }
70 kmlDocument.println("</coordinates>");
71 }
72 kmlDocument.println(-1, "</LineString>");
73
74 }
75
76 }
0 package org.boehn.kmlframework;
1
2 public class LineStyle extends ColorStyle {
3
4 private Double width;
5
6 public Double getWidth() {
7 return width;
8 }
9
10 public void setWidth(Double width) {
11 this.width = width;
12 }
13
14 public void write(KmlDocument kmlDocument) throws KmlException {
15 kmlDocument.println("<LineStyle" + getIdAndTargetIdFormatted() + ">", 1);
16 super.writeInner(kmlDocument);
17 if (width != null) {
18 kmlDocument.println("<width>" + width + "</width>");
19 }
20 kmlDocument.println(-1, "</LineStyle>");
21 }
22 }
0 package org.boehn.kmlframework;
1
2 import java.util.List;
3
4 public class LinearRing extends Geometry {
5
6 private Boolean extrude;
7 private Boolean tessellate;
8 private AltitudeModeEnum altitudeMode;
9 private List<Point> coordinates;
10
11 public Boolean getExtrude() {
12 return extrude;
13 }
14
15 public void setExtrude(Boolean extrude) {
16 this.extrude = extrude;
17 }
18
19 public Boolean getTessellate() {
20 return tessellate;
21 }
22
23 public void setTessellate(Boolean tessellate) {
24 this.tessellate = tessellate;
25 }
26
27 public AltitudeModeEnum getAltitudeMode() {
28 return altitudeMode;
29 }
30
31 public void setAltitudeMode(AltitudeModeEnum altitudeMode) {
32 this.altitudeMode = altitudeMode;
33 }
34
35 public List<Point> getCoordinates() {
36 return coordinates;
37 }
38
39 public void setCoordinates(List<Point> coordinates) {
40 this.coordinates = coordinates;
41 }
42
43 public void write(KmlDocument kmlDocument) throws KmlException {
44 // We validate the data
45 if (coordinates == null || coordinates.size() < 3) {
46 throw new KmlException("LineString must contain at least 3 points");
47 }
48
49 kmlDocument.println("<LinearRing" + getIdAndTargetIdFormatted() + ">", 1);
50 if (extrude != null) {
51 kmlDocument.println("<extrude>" + booleanToInt(extrude) + "</extrude>");
52 }
53 if (tessellate!= null) {
54 kmlDocument.println("<tessellate>" + booleanToInt(tessellate) + "</tessellate>");
55 }
56 if (altitudeMode!= null) {
57 kmlDocument.println("<altitudeMode>" + altitudeMode + "</altitudeMode>");
58 }
59 kmlDocument.print("<coordinates>");
60 boolean firstLoop = true;
61 for (Point point : coordinates) {
62 if (firstLoop) {
63 firstLoop = false;
64 } else {
65 kmlDocument.print(" ");
66 }
67 kmlDocument.print(point.getLongitudeLatitudeAltitudeString());
68 }
69 // We add the first coordinate to the end, as KML require the first coordinate to be equal to the last
70 kmlDocument.print(" " + coordinates.get(0).getLongitudeLatitudeAltitudeString());
71
72 kmlDocument.println("</coordinates>");
73
74 kmlDocument.println(-1, "</LinearRing>");
75 }
76
77 }
0 package org.boehn.kmlframework;
1
2 public class Link extends KmlObject {
3
4 private String href;
5 private RefreshModeEnum refreshMode;
6 private Double refreshInterval;
7 private ViewRefreshModeEnum viewRefreshMode;
8 private Double viewRefreshTime;
9 private Double viewBoundScale;
10 private ViewFormat viewFormat;
11 private String httpQuery;
12
13 public String getHref() {
14 return href;
15 }
16
17 public void setHref(String href) {
18 this.href = href;
19 }
20
21 public RefreshModeEnum getRefreshMode() {
22 return refreshMode;
23 }
24
25 public void setRefreshMode(RefreshModeEnum refreshMode) {
26 this.refreshMode = refreshMode;
27 }
28
29 public Double getRefreshInterval() {
30 return refreshInterval;
31 }
32
33 public void setRefreshInterval(Double refreshInterval) {
34 this.refreshInterval = refreshInterval;
35 }
36
37 public ViewRefreshModeEnum getViewRefreshMode() {
38 return viewRefreshMode;
39 }
40
41 public void setViewRefreshMode(ViewRefreshModeEnum viewRefreshMode) {
42 this.viewRefreshMode = viewRefreshMode;
43 }
44
45 public Double getViewRefreshTime() {
46 return viewRefreshTime;
47 }
48
49 public void setViewRefreshTime(Double viewRefreshTime) {
50 this.viewRefreshTime = viewRefreshTime;
51 }
52
53 public Double getViewBoundScale() {
54 return viewBoundScale;
55 }
56
57 public void setViewBoundScale(Double viewBoundScale) {
58 this.viewBoundScale = viewBoundScale;
59 }
60
61 public ViewFormat getViewFormat() {
62 return viewFormat;
63 }
64
65 public void setViewFormat(ViewFormat viewFormat) {
66 this.viewFormat = viewFormat;
67 }
68
69 public String getHttpQuery() {
70 return httpQuery;
71 }
72
73 public void setHttpQuery(String httpQuery) {
74 this.httpQuery = httpQuery;
75 }
76
77 public void write(KmlDocument kmlDocument) throws KmlException {
78 kmlDocument.println("<Link" + getIdAndTargetIdFormatted() + ">", 1);
79 writeInner(kmlDocument);
80 kmlDocument.println(-1, "</Link>");
81 }
82
83 protected void writeInner(KmlDocument kmlDocument) throws KmlException {
84 if (href != null) {
85 kmlDocument.println("<href>" + href + "</href>");
86 }
87 if (refreshMode != null) {
88 kmlDocument.println("<refreshMode>" + refreshMode + "</refreshMode>");
89 }
90 if (refreshInterval != null) {
91 kmlDocument.println("<refreshInterval>" + refreshInterval + "</refreshInterval>");
92 }
93 if (refreshInterval != null) {
94 kmlDocument.println("<refreshInterval>" + refreshInterval + "</refreshInterval>");
95 }
96 if (viewRefreshMode != null) {
97 kmlDocument.println("<viewRefreshMode>" + viewRefreshMode + "</viewRefreshMode>");
98 }
99 if (viewRefreshTime != null) {
100 kmlDocument.println("<viewRefreshTime>" + viewRefreshTime + "</viewRefreshTime>");
101 }
102 if (viewBoundScale != null) {
103 kmlDocument.println("<viewBoundScale>" + viewBoundScale + "</viewBoundScale>");
104 }
105 if (viewFormat != null) {
106 viewFormat.write(kmlDocument);
107 }
108 if (httpQuery != null) {
109 kmlDocument.println("<httpQuery>" + httpQuery + "</httpQuery>");
110 }
111 }
112 }
0 package org.boehn.kmlframework;
1
2 public enum ListItemTypeEnum {
3 check, checkOffOnly, checkHideChildren, radioFolder
4 }
0 package org.boehn.kmlframework;
1
2 public class ListStyle extends KmlObject {
3
4 private ListItemTypeEnum listItemType;
5 private String bgColor;
6 private String itemIconState; // TODO understand the valid states (unclear in KLM Reference)
7 private String href;
8
9 public ListItemTypeEnum getListItemType() {
10 return listItemType;
11 }
12
13 public void setListItemType(ListItemTypeEnum listItemType) {
14 this.listItemType = listItemType;
15 }
16
17 public String getBgColor() {
18 return bgColor;
19 }
20
21 public void setBgColor(String bgColor) {
22 this.bgColor = bgColor;
23 }
24
25 public String getItemIconState() {
26 return itemIconState;
27 }
28
29 public void setItemIconState(String itemIconState) {
30 this.itemIconState = itemIconState;
31 }
32
33 public String getHref() {
34 return href;
35 }
36
37 public void setHref(String href) {
38 this.href = href;
39 }
40
41 public void write(KmlDocument kmlDocument) throws KmlException {
42 kmlDocument.println("<ListStyle" + getIdAndTargetIdFormatted() + ">", 1);
43 if (listItemType != null) {
44 kmlDocument.println("<listItemType>" + listItemType + "</listItemType>");
45 }
46 if (bgColor != null) {
47 kmlDocument.println("<bgColor>" + bgColor + "</bgColor>");
48 }
49 if (itemIconState != null || href != null) {
50 kmlDocument.println("<ItemIcon>", 1);
51 if (itemIconState != null) {
52 kmlDocument.println("<state>" + itemIconState + "</state>");
53 }
54 if (href != null) {
55 kmlDocument.println("<href>" + href + "</href>");
56 }
57 kmlDocument.println(-1, "</ItemIcon>");
58 }
59 kmlDocument.println(-1, "</ListStyle>");
60 }
61 }
0 package org.boehn.kmlframework;
1
2 public class LookAt extends AbstractView {
3
4 private Double range;
5
6 public Double getRange() {
7 return range;
8 }
9
10 public void setRange(Double range) {
11 this.range = range;
12 }
13
14 public void write(KmlDocument kmlDocument) throws KmlException {
15 kmlDocument.println("<LookAt" + getIdAndTargetIdFormatted() + ">", 1);
16 super.writeInner(kmlDocument);
17 if (range != null) {
18 kmlDocument.println("<range>" + range + "</range>");
19 }
20 kmlDocument.println(-1, "</LookAt>");
21 }
22 }
+0
-269
src/org/boehn/kmlframework/MapObject.java less more
0 package org.boehn.kmlframework;
1
2 import java.io.IOException;
3 import java.io.Writer;
4 import java.util.ArrayList;
5 import java.util.List;
6
7 import org.boehn.kmlframework.coordinates.CartesianCoordinate;
8 import org.boehn.kmlframework.coordinates.EarthCoordinate;
9 import org.boehn.kmlframework.coordinates.TimeAndPlace;
10 import org.w3c.dom.Document;
11 import org.w3c.dom.Element;
12 import org.xmlpull.v1.XmlSerializer;
13
14 public class MapObject implements ModelElement {
15
16 private String name;
17 private String description;
18 private EarthCoordinate location;
19 private MapObjectClass mapObjectClass;
20 private List<Button> buttons;
21 private List<TimeAndPlace> movements;
22 private String snippet;
23 private Boolean visibility;
24
25 private Double rotation;
26 private CartesianCoordinate localReferenceCoordinate;
27 private CartesianCoordinate scale;
28
29 public MapObject() {}
30
31 public MapObject(String name) {
32 this.name = name;
33 }
34
35 public MapObject(MapObjectClass mapObjectClass) {
36 this.mapObjectClass = mapObjectClass;
37 }
38
39 public MapObject(String name, MapObjectClass mapObjectClass) {
40 this.name = name;
41 this.mapObjectClass = mapObjectClass;
42 }
43
44 public MapObjectClass getMapObjectClass() {
45 return mapObjectClass;
46 }
47
48 public void setMapObjectClass(MapObjectClass mapObjectClass) {
49 this.mapObjectClass = mapObjectClass;
50 }
51
52 public CartesianCoordinate getLocalReferenceCoordinate() {
53 return localReferenceCoordinate;
54 }
55
56 public void setLocalReferenceCoordinate(
57 CartesianCoordinate localReferenceCoordinate) {
58 this.localReferenceCoordinate = localReferenceCoordinate;
59 }
60
61 public Double getRotation() {
62 return rotation;
63 }
64
65 public void setRotation(Double rotation) {
66 this.rotation = rotation;
67 }
68
69 public CartesianCoordinate getScale() {
70 return scale;
71 }
72
73 public void setScale(CartesianCoordinate scale) {
74 this.scale = scale;
75 }
76
77 public Boolean getVisibility() {
78 return visibility;
79 }
80
81 public void setVisibility(Boolean visibility) {
82 this.visibility = visibility;
83 }
84
85 public void setButtons(List<Button> buttons) {
86 this.buttons = buttons;
87 }
88
89 public void addButton(Button button) {
90 if (buttons == null) {
91 buttons = new ArrayList<Button>();
92 }
93 buttons.add(button);
94 }
95
96 public void addButtons(List<Button> buttons) {
97 if (this.buttons == null) {
98 this.buttons = buttons;
99 } else {
100 this.buttons.addAll(buttons);
101 }
102 }
103
104 public String getDescription() {
105 return description;
106 }
107
108 public void setDescription(String description) {
109 this.description = description;
110 }
111
112 public String getDescriptionTextWithButtons(Model model) {
113 StringBuffer result = new StringBuffer();
114 if (buttons != null) {
115 for (Button button : buttons) {
116 result.append(button.toHtml(model) + "<br />");
117 }
118 }
119 if (description != null) {
120 result.append(description);
121 }
122
123 return (result.length() == 0) ? null : result.toString();
124 }
125
126 public EarthCoordinate getLocation() {
127 return location;
128 }
129
130 public void setLocation(EarthCoordinate earthCoordinate) {
131 this.location = earthCoordinate;
132 }
133
134 public String getName() {
135 return name;
136 }
137
138 public void setName(String name) {
139 this.name = name;
140 }
141
142 public String getSnippet() {
143 return snippet;
144 }
145
146 public void setSnippet(String snippet) {
147 this.snippet = snippet;
148 }
149
150 public void addKml(Element parentElement, Model model, Document xmlDocument) throws ModelException {
151
152 Element placemarkElement = xmlDocument.createElement("Placemark");
153
154 if (name != null) {
155 Element nameElement = xmlDocument.createElement("name");
156 nameElement.appendChild(xmlDocument.createTextNode(name));
157 placemarkElement.appendChild(nameElement);
158 }
159
160 if (snippet != null) {
161 Element snippetElement = xmlDocument.createElement("Snippet");
162 snippetElement.appendChild(xmlDocument.createTextNode(snippet));
163 placemarkElement.appendChild(snippetElement);
164 }
165
166 String descriptionText = getDescriptionTextWithButtons(model);
167 if (descriptionText != null) {
168 Element descriptionElement = xmlDocument.createElement("description");
169 descriptionElement.appendChild(xmlDocument.createCDATASection(descriptionText));
170 placemarkElement.appendChild(descriptionElement);
171 }
172
173 if (mapObjectClass != null) {
174
175 mapObjectClass.addKml(this, parentElement, model, xmlDocument, location, rotation, localReferenceCoordinate, scale, name);
176
177 if (mapObjectClass.getStyleUrl() != null || mapObjectClass.getStyle() != null) {
178 Element styleUrlElement = xmlDocument.createElement("styleUrl");
179 styleUrlElement.appendChild(xmlDocument.createTextNode((mapObjectClass.getStyleUrl() != null ? mapObjectClass.getStyleUrl() : "#" + mapObjectClass.getStyle().getId())));
180 placemarkElement.appendChild(styleUrlElement);
181 }
182 }
183
184 if (location != null) {
185 location.addKml(placemarkElement, model, xmlDocument);
186 }
187
188 if (visibility != null) {
189 Element visibilityElement = xmlDocument.createElement("visibility");
190 visibilityElement.appendChild(xmlDocument.createTextNode((visibility) ? "1" : "0"));
191 placemarkElement.appendChild(visibilityElement);
192 }
193
194 parentElement.appendChild(placemarkElement);
195 }
196
197 public void addKmlXPP(Model model, XmlSerializer serializer) throws IllegalArgumentException, IllegalStateException, IOException {
198 // TODO this is a temp method for speed testing
199 serializer.startTag(null, "Placemark");
200
201 if (name != null) {
202 serializer.startTag(null, "name");
203 serializer.text(name);
204 serializer.endTag(null, "name");
205 }
206
207 String descriptionText = getDescriptionTextWithButtons(model);
208 if (descriptionText != null) {
209 serializer.startTag(null, "description");
210 serializer.cdsect(descriptionText);
211 serializer.endTag(null, "description");
212 }
213
214 if (location != null) {
215 location.addKmlXPP(model, serializer);
216 }
217 serializer.endTag(null, "Placemark");
218 }
219
220 public void addKmlDirect(Model model, Writer writer) throws IOException {
221 // TODO this is a temp method for speed testing
222 writer.write("<Placemark>");
223
224 if (name != null) {
225 writer.write("<name>" + name + "</name>");
226 }
227
228 String descriptionText = getDescriptionTextWithButtons(model);
229 if (descriptionText != null) {
230 writer.write("<description>" + descriptionText + "</description>");
231 }
232
233 if (location != null) {
234 location.addKmlDirect(model, writer);
235 }
236 writer.write("</Placemark>");
237 }
238
239 public List<TimeAndPlace> getMovements() {
240 return movements;
241 }
242
243 public void setMovements(List<TimeAndPlace> movements) {
244 this.movements = movements;
245 }
246
247 public void addMovement(TimeAndPlace movement) {
248 if (this.movements == null) {
249 this.movements = new ArrayList<TimeAndPlace>();
250 }
251 this.movements.add(movement);
252 }
253
254 public String toString() {
255 StringBuffer text = new StringBuffer("MapObject:\n");
256 text.append(" name: '" + name + "'\n");
257 text.append(" description: '" + description + "'\n");
258 text.append(" rotation: " + rotation + "\n");
259 text.append(" scale: " + scale + "\n");
260 text.append(" localReferenceCoordinate: " + localReferenceCoordinate + "\n");
261 text.append(" location: " + location + "\n");
262 text.append(" buttons: " + buttons + "\n");
263 text.append(" movements: " + movements + "\n");
264 text.append(" mapObjectClass: " + mapObjectClass + "\n");
265 return text.toString();
266 }
267
268 }
+0
-216
src/org/boehn/kmlframework/MapObjectClass.java less more
0 package org.boehn.kmlframework;
1
2 import java.util.ArrayList;
3 import java.util.Calendar;
4 import java.util.Date;
5 import java.util.GregorianCalendar;
6 import java.util.List;
7
8 import org.boehn.kmlframework.coordinates.CartesianCoordinate;
9 import org.boehn.kmlframework.coordinates.EarthCoordinate;
10 import org.boehn.kmlframework.coordinates.TimeAndPlace;
11 import org.boehn.kmlframework.style.Style;
12 import org.w3c.dom.Document;
13 import org.w3c.dom.Element;
14
15 public class MapObjectClass {
16
17 private String className;
18 private List<GraphicalModel> models;
19 private boolean showTail = true;
20 private boolean showModels = true;
21 private Integer visibleFrom;
22 private Integer visibleTo;
23 private Integer tailHistoryLimit;
24 private Integer tailVisibleFrom;
25 private Integer tailVisibleTo;
26 private String styleUrl;
27 private Style style;
28
29 public MapObjectClass(String className) {
30 this.className = className;
31 }
32
33 public String getClassName() {
34 return className;
35 }
36
37 public void setClassName(String className) {
38 this.className = className;
39 }
40
41 public List<GraphicalModel> getModels() {
42 return models;
43 }
44
45 public void setModels(List<GraphicalModel> models) {
46 this.models = models;
47 }
48
49 public void addModel(GraphicalModel model) {
50 if (models == null) {
51 models = new ArrayList<GraphicalModel>();
52 }
53 models.add(model);
54 }
55
56 public void addModels(List<GraphicalModel> models) {
57 if (this.models == null) {
58 this.models = models;
59 } else {
60 this.models.addAll(models);
61 }
62 }
63
64 public Integer getVisibleFrom() {
65 return visibleFrom;
66 }
67
68 public void setVisibleFrom(Integer visibleFrom) {
69 this.visibleFrom = visibleFrom;
70 }
71
72 public Integer getVisibleTo() {
73 return visibleTo;
74 }
75
76 public void setVisibleTo(Integer visibleTo) {
77 this.visibleTo = visibleTo;
78 }
79
80 public String getStyleUrl() {
81 return styleUrl;
82 }
83
84 public void setStyleUrl(String styleUrl) {
85 this.styleUrl = styleUrl;
86 // styleUrl and style cannot be set at the same time
87 this.style = null;
88 }
89
90 public Style getStyle() {
91 return style;
92 }
93
94 public void setStyle(Style style) {
95 this.style = style;
96 // styleUrl and style cannot be set at the same time
97 this.styleUrl = null;
98 }
99
100 public boolean getShowModels() {
101 return showModels;
102 }
103
104 public void setShowModels(boolean showModel) {
105 this.showModels = showModel;
106 }
107
108 public boolean getShowTail() {
109 return showTail;
110 }
111
112 public void setShowTail(boolean showTail) {
113 this.showTail = showTail;
114 }
115
116 public Integer getTailVisibleFrom() {
117 return tailVisibleFrom;
118 }
119
120 public void setTailVisibleFrom(Integer tailVisibleFrom) {
121 this.tailVisibleFrom = tailVisibleFrom;
122 }
123
124 public Integer getTailVisibleTo() {
125 return tailVisibleTo;
126 }
127
128 public void setTailVisibleTo(Integer tailVisibleTo) {
129 this.tailVisibleTo = tailVisibleTo;
130 }
131
132 public Integer getTailHistoryLimit() {
133 return tailHistoryLimit;
134 }
135
136 public void setTailHistoryLimit(Integer tailHistoryLimit) {
137 this.tailHistoryLimit = tailHistoryLimit;
138 }
139
140 public void addKml(MapObject mapObject, Element parentElement, Model model, Document xmlDocument, EarthCoordinate location, Double rotation, CartesianCoordinate localReferenceCoordinate, CartesianCoordinate scale, String name) throws ModelException {
141 if (models != null || (mapObject.getMovements() != null && showTail)) {
142
143 boolean objectHasGraphicalElementToDraw = false;
144
145 Element multiGeometryElement = xmlDocument.createElement("MultiGeometry");
146 // If we are going to draw a tail after this MapObject, we have to add another model containing the tail. We cannot add this
147 // model to models, because then it will be added to all MapObject using this MapObject class. Thus we have to make a new list
148 List<GraphicalModel> graphicalModelsTemp;
149 if (mapObject.getMovements() == null || !showTail) {
150 graphicalModelsTemp = models;
151 } else {
152 graphicalModelsTemp = new ArrayList<GraphicalModel>(models);
153 GraphicalModel graphicalModel = new GraphicalModel();
154 Path path = new Path();
155 path.addCoordinate(location);
156
157 // We stop drawing the tail if passing the timeHistoryLimit
158 Date timeHistoryLimitAbsolute;
159 if (tailHistoryLimit != null) {
160 GregorianCalendar calendar = new GregorianCalendar();
161 calendar.add(Calendar.SECOND, -tailHistoryLimit);
162 timeHistoryLimitAbsolute = calendar.getTime();
163 } else {
164 timeHistoryLimitAbsolute = null;
165 }
166
167 for (TimeAndPlace timeAndPlace : mapObject.getMovements()) {
168 if (timeHistoryLimitAbsolute != null && timeHistoryLimitAbsolute.after(timeAndPlace.getTime())) {
169 // We stop drawing the tail because the tail history has passed the timeHistoryLimit
170 break;
171 }
172 path.addCoordinate(timeAndPlace.getPlace());
173 }
174 graphicalModel.addGraphicalModelElement(path);
175 graphicalModel.setVisibleFrom(tailVisibleFrom);
176 graphicalModel.setVisibleTo(tailVisibleTo);
177 graphicalModelsTemp.add(graphicalModel);
178 }
179 Double distanceToObserver = (model.getObserver() != null && mapObject.getLocation() != null) ? model.getObserver().distanceTo(mapObject.getLocation()) : null;
180 for (GraphicalModel graphicalModel : graphicalModelsTemp) {
181 if (!model.ENABLE_DETAILS_DEPENDS_ON_DISTANCE_TO_OBSERVER || (distanceToObserver == null || (graphicalModel.getVisibleTo() == null || graphicalModel.getVisibleTo() > distanceToObserver) && (graphicalModel.getVisibleFrom() == null || graphicalModel.getVisibleFrom() < distanceToObserver))) {
182 graphicalModel.addKml(multiGeometryElement, model, xmlDocument, location, rotation, localReferenceCoordinate, scale);
183 objectHasGraphicalElementToDraw = true;
184 }
185 }
186
187 if (objectHasGraphicalElementToDraw) {
188 Element placemarkElement = xmlDocument.createElement("Placemark");
189 Element nameElement = xmlDocument.createElement("name");
190 nameElement.appendChild(xmlDocument.createTextNode((name != null) ? name + " model" : "model"));
191 placemarkElement.appendChild(nameElement);
192 if (styleUrl != null || style != null) {
193 Element styleUrlElement = xmlDocument.createElement("styleUrl");
194 styleUrlElement.appendChild(xmlDocument.createTextNode((styleUrl != null ? styleUrl : "#" + style.getId())));
195 placemarkElement.appendChild(styleUrlElement);
196 }
197 placemarkElement.appendChild(multiGeometryElement);
198 parentElement.appendChild(placemarkElement);
199 }
200 }
201 }
202
203 public String toString() {
204 StringBuffer text = new StringBuffer("MapObjectClass:\n");
205 text.append(" className: '" + className + "'\n");
206 text.append(" styleUrl: '" + styleUrl + "'\n");
207 text.append(" models: " + models + "\n");
208 text.append(" showModels: " + showModels + "\n");
209 text.append(" showTail: " + showTail + "\n");
210 text.append(" tailVisibleFrom: " + tailVisibleFrom + "\n");
211 text.append(" tailVisibleTo: " + tailVisibleTo + "\n");
212 text.append(" timeHistoryLimit: " + tailHistoryLimit + "\n");
213 return text.toString();
214 }
215 }
0 package org.boehn.kmlframework;
1
2 import java.util.List;
3
4 public class Model extends Geometry {
5
6 private AltitudeModeEnum altitudeMode;
7 private Double longitude;
8 private Double latitude;
9 private Integer altitude;
10 private Double heading;
11 private Double tilt;
12 private Double roll;
13 private Double scaleX;
14 private Double scaleY;
15 private Double scaleZ;
16 private Link link;
17 private List<Alias> resourceMap;
18
19 public AltitudeModeEnum getAltitudeMode() {
20 return altitudeMode;
21 }
22
23 public void setAltitudeMode(AltitudeModeEnum altitudeMode) {
24 this.altitudeMode = altitudeMode;
25 }
26
27 public Double getLongitude() {
28 return longitude;
29 }
30
31 public void setLongitude(Double longitude) {
32 this.longitude = longitude;
33 }
34
35 public Double getLatitude() {
36 return latitude;
37 }
38
39 public void setLatitude(Double latitude) {
40 this.latitude = latitude;
41 }
42
43 public Integer getAltitude() {
44 return altitude;
45 }
46
47 public void setAltitude(Integer altitude) {
48 this.altitude = altitude;
49 }
50
51 public Double getHeading() {
52 return heading;
53 }
54
55 public void setHeading(Double heading) {
56 this.heading = heading;
57 }
58
59 public Double getTilt() {
60 return tilt;
61 }
62
63 public void setTilt(Double tilt) {
64 this.tilt = tilt;
65 }
66
67 public Double getRoll() {
68 return roll;
69 }
70
71 public void setRoll(Double roll) {
72 this.roll = roll;
73 }
74
75 public Double getScaleX() {
76 return scaleX;
77 }
78
79 public void setScaleX(Double scaleX) {
80 this.scaleX = scaleX;
81 }
82
83 public Double getScaleY() {
84 return scaleY;
85 }
86
87 public void setScaleY(Double scaleY) {
88 this.scaleY = scaleY;
89 }
90
91 public Double getScaleZ() {
92 return scaleZ;
93 }
94
95 public void setScaleZ(Double scaleZ) {
96 this.scaleZ = scaleZ;
97 }
98
99 public Link getLink() {
100 return link;
101 }
102
103 public void setLink(Link link) {
104 this.link = link;
105 }
106
107 public List<Alias> getResourceMap() {
108 return resourceMap;
109 }
110
111 public void setResourceMap(List<Alias> resourceMap) {
112 this.resourceMap = resourceMap;
113 }
114
115 public void write(KmlDocument kmlDocument) throws KmlException {
116 kmlDocument.println("<Model" + getIdAndTargetIdFormatted() + ">", 1);
117 if (altitudeMode != null) {
118 kmlDocument.println("<altitudeMode>" + altitudeMode + "</altitudeMode>");
119 }
120 if (longitude != null || latitude != null || altitude != null) {
121 kmlDocument.println("<Location>", 1);
122 if (longitude != null) {
123 kmlDocument.println("<longitude>" + longitude + "</longitude>");
124 }
125 if (latitude != null) {
126 kmlDocument.println("<latitude>" + latitude + "</latitude>");
127 }
128 if (altitude != null) {
129 kmlDocument.println("<altitude>" + altitude + "</altitude>");
130 }
131 kmlDocument.println(-1, "</Location>");
132 }
133 if (heading != null || tilt != null || roll != null) {
134 kmlDocument.println("<Orientation>", 1);
135 if (heading != null) {
136 kmlDocument.println("<heading>" + heading + "</heading>");
137 }
138 if (tilt != null) {
139 kmlDocument.println("<tilt>" + tilt + "</tilt>");
140 }
141 if (roll != null) {
142 kmlDocument.println("<roll>" + roll + "</roll>");
143 }
144 kmlDocument.println(-1, "</Orientation>");
145 }
146 if (scaleX != null || scaleY != null || scaleZ != null) {
147 kmlDocument.println("<Scale>", 1);
148 if (scaleX != null) {
149 kmlDocument.println("<x>" + scaleX + "</x>");
150 }
151 if (scaleY != null) {
152 kmlDocument.println("<y>" + scaleY+ "</y>");
153 }
154 if (scaleZ != null) {
155 kmlDocument.println("<z>" + scaleZ + "</z>");
156 }
157 kmlDocument.println(-1, "</Scale>");
158 }
159 if (link != null) {
160 link.write(kmlDocument);
161 }
162 if (resourceMap != null) {
163 kmlDocument.println("<ResourceMap>", -1);
164 for (Alias alias : resourceMap) {
165 alias.write(kmlDocument);
166 }
167 kmlDocument.println(-1, "</ResourceMap>");
168 }
169 kmlDocument.println(-1, "</Model>");
170 }
171 }
+0
-16
src/org/boehn/kmlframework/ModelElement.java less more
0 package org.boehn.kmlframework;
1
2 import java.io.IOException;
3 import java.io.Writer;
4
5 import org.w3c.dom.Document;
6 import org.w3c.dom.Element;
7 import org.xmlpull.v1.XmlSerializer;
8
9 public interface ModelElement {
10
11 public void addKml(Element parentElement, Model model, Document xmlDocument) throws ModelException;
12 public void addKmlXPP(Model model, XmlSerializer serializer) throws IllegalArgumentException, IllegalStateException, IOException;
13 public void addKmlDirect(Model model, Writer writer) throws IOException;
14
15 }
+0
-23
src/org/boehn/kmlframework/ModelException.java less more
0 package org.boehn.kmlframework;
1
2 public class ModelException extends Exception {
3
4 private static final long serialVersionUID = 1L;
5
6 public ModelException() {
7 super();
8 }
9
10 public ModelException(String arg0) {
11 super(arg0);
12 }
13
14 public ModelException(String arg0, Throwable arg1) {
15 super(arg0, arg1);
16 }
17
18 public ModelException(Throwable arg0) {
19 super(arg0);
20 }
21
22 }
+0
-147
src/org/boehn/kmlframework/ModelObjectFactory.java less more
0 package org.boehn.kmlframework;
1
2 import java.io.File;
3 import java.io.IOException;
4 import java.util.Hashtable;
5
6 import javax.xml.parsers.DocumentBuilder;
7 import javax.xml.parsers.DocumentBuilderFactory;
8 import javax.xml.parsers.ParserConfigurationException;
9
10 import org.boehn.kmlframework.coordinates.CartesianCoordinate;
11 import org.boehn.kmlframework.coordinates.Coordinate;
12 import org.w3c.dom.Document;
13 import org.w3c.dom.NamedNodeMap;
14 import org.w3c.dom.Node;
15 import org.w3c.dom.NodeList;
16 import org.xml.sax.SAXException;
17
18 public class ModelObjectFactory {
19
20 private String fileName;
21 private Hashtable<String, MapObjectClass> mapObjectClasses;
22
23 public ModelObjectFactory(String fileName) throws IOException, ParserConfigurationException, SAXException {
24 this.fileName = fileName;
25 loadFile();
26 }
27
28 public MapObject createMapObject(String className) {
29 return new MapObject(getMapObjectClass(className));
30 }
31
32 public MapObjectClass getMapObjectClass(String className) {
33 MapObjectClass mapObjectClass = mapObjectClasses.get(className);
34 if (mapObjectClass == null) {
35 mapObjectClass = new MapObjectClass(className);
36 mapObjectClasses.put(className, mapObjectClass);
37 }
38 return mapObjectClass;
39 }
40
41 public void loadFile() throws IOException, ParserConfigurationException, SAXException {
42 mapObjectClasses = new Hashtable<String, MapObjectClass>();
43 DocumentBuilder documentBuilder;
44
45 documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
46 Document document = documentBuilder.parse(new File(fileName));
47 NodeList documentNodes = document.getChildNodes();
48 for (int i = 0; i < documentNodes.getLength(); i++) {
49 Node objectClassesNode = documentNodes.item(i);
50 if ("mapObjectClasses".equals(objectClassesNode.getNodeName()) && objectClassesNode.getChildNodes().getLength() > 0) {
51 NodeList objectClassesChildren = objectClassesNode.getChildNodes();
52 for (int j = 0; j < objectClassesChildren.getLength(); j ++) {
53 Node mapObjectClassNode = objectClassesChildren.item(j);
54 if ("mapObjectClass".equals(mapObjectClassNode.getNodeName())) {
55 NamedNodeMap mapObjectClassAttributes = mapObjectClassNode.getAttributes();
56
57 // We make the mapObject class
58 MapObjectClass mapObjectClass = new MapObjectClass(mapObjectClassAttributes.getNamedItem("className").getNodeValue());
59
60 // We read all optional parameters for the mapObject class
61 if (mapObjectClassAttributes.getNamedItem("showTail") != null) {
62 mapObjectClass.setShowTail(new Boolean(mapObjectClassAttributes.getNamedItem("showTail").getNodeValue()));
63 }
64 if (mapObjectClassAttributes.getNamedItem("showModel") != null) {
65 mapObjectClass.setShowModels(new Boolean(mapObjectClassAttributes.getNamedItem("showModel").getNodeValue()));
66 }
67 if (mapObjectClassAttributes.getNamedItem("visibleFrom") != null) {
68 mapObjectClass.setVisibleFrom(new Integer(mapObjectClassAttributes.getNamedItem("visibleFrom").getNodeValue()));
69 }
70 if (mapObjectClassAttributes.getNamedItem("visibleTo") != null) {
71 mapObjectClass.setVisibleTo(new Integer(mapObjectClassAttributes.getNamedItem("visibleTo").getNodeValue()));
72 }
73 if (mapObjectClassAttributes.getNamedItem("tailHistoryLimit") != null) {
74 mapObjectClass.setTailHistoryLimit(new Integer(mapObjectClassAttributes.getNamedItem("tailHistoryLimit").getNodeValue()));
75 }
76 if (mapObjectClassAttributes.getNamedItem("tailVisibleFrom") != null) {
77 mapObjectClass.setTailVisibleFrom(new Integer(mapObjectClassAttributes.getNamedItem("tailVisibleFrom").getNodeValue()));
78 }
79 if (mapObjectClassAttributes.getNamedItem("tailVisibleTo") != null) {
80 mapObjectClass.setTailVisibleTo(new Integer(mapObjectClassAttributes.getNamedItem("tailVisibleTo").getNodeValue()));
81 }
82 if (mapObjectClassAttributes.getNamedItem("styleUrl") != null) {
83 mapObjectClass.setStyleUrl(mapObjectClassAttributes.getNamedItem("styleUrl").getNodeValue());
84 }
85
86 // We load the children to the mapObjectClass
87 NodeList mapObjectClassChildren = mapObjectClassNode.getChildNodes();
88 for (int k = 0; k < mapObjectClassChildren.getLength(); k++) {
89 Node mapObjectClassChild = mapObjectClassChildren.item(k);
90 if ("model".equals(mapObjectClassChild.getNodeName())) {
91 GraphicalModel model = new GraphicalModel();
92
93 // We read the attributes to the model element
94 NamedNodeMap modelAttributes = mapObjectClassChild.getAttributes();
95 if (modelAttributes.getNamedItem("visibleFrom") != null) {
96 model.setVisibleFrom(new Integer(modelAttributes.getNamedItem("visibleFrom").getNodeValue()));
97 }
98 if (modelAttributes.getNamedItem("visibleTo") != null) {
99 model.setVisibleTo(new Integer(modelAttributes.getNamedItem("visibleTo").getNodeValue()));
100 }
101
102 NodeList modelChildren = mapObjectClassChild.getChildNodes();
103 for (int l = 0; l < modelChildren.getLength(); l++) {
104 Node modelChild =modelChildren.item(l);
105 if ("polygon".equals(modelChild.getNodeName()) || "path".equals(modelChild.getNodeName())) {
106 Path path;
107 if ("polygon".equals(modelChild.getNodeName())) {
108 path = new Polygon();
109 } else {
110 path = new Path();
111 }
112
113 // We read the attributes to the path/polygon element
114 NamedNodeMap modelChildAttributes = modelChild.getAttributes();
115 if (modelChildAttributes.getNamedItem("altitudeMode") != null) {
116 path.setAltitudeMode(AltitudeModes.valueOf(modelChildAttributes.getNamedItem("altitudeMode").getNodeValue()));
117 }
118 if (modelChildAttributes.getNamedItem("extrude") != null) {
119 path.setExtrude(new Boolean(modelChildAttributes.getNamedItem("extrude").getNodeValue()));
120 }
121
122 // We read the children to the path/polygon
123 NodeList pathChildren = modelChild.getChildNodes();
124 for (int m = 0; m < pathChildren.getLength(); m++) {
125 Node pathChild = pathChildren.item(m);
126 if ("coordinate".equals(pathChild.getNodeName())) {
127 NamedNodeMap coordinateAttributes = pathChild.getAttributes();
128 Coordinate coordinate = new CartesianCoordinate(Double.parseDouble(coordinateAttributes.getNamedItem("x").getNodeValue()), Double.parseDouble(coordinateAttributes.getNamedItem("y").getNodeValue()), Double.parseDouble(coordinateAttributes.getNamedItem("z").getNodeValue()));
129 path.addCoordinate(coordinate);
130 }
131 }
132 model.addGraphicalModelElement(path);
133 }
134 }
135 mapObjectClass.addModel(model);
136 }
137 }
138 // We add the object class to the hashtable
139 mapObjectClasses.put(mapObjectClass.getClassName(), mapObjectClass);
140 }
141 }
142 break;
143 }
144 }
145 }
146 }
0 package org.boehn.kmlframework;
1
2 import java.util.List;
3
4 public class MultiGeometry extends Geometry {
5
6 private List<Geometry> geometries;
7
8 public List<Geometry> getGeometries() {
9 return geometries;
10 }
11
12 public void setGeometries(List<Geometry> geometries) {
13 this.geometries = geometries;
14 }
15
16 public void write(KmlDocument kmlDocument) throws KmlException {
17 kmlDocument.println("<MultiGeometry" + getIdAndTargetIdFormatted() + ">", 1);
18 if (geometries != null) {
19 for (Geometry geometry : geometries) {
20 geometry.write(kmlDocument);
21 }
22 }
23 kmlDocument.println(-1, "</MultiGeometry>");
24 }
25 }
0 package org.boehn.kmlframework;
1
2 public class NetworkLink extends Feature {
3
4 private Boolean refreshVisibility;
5 private Boolean flyToView;
6 private Link link;
7
8 public boolean isRefreshVisibility() {
9 return refreshVisibility;
10 }
11
12 public void setRefreshVisibility(boolean refreshVisibility) {
13 this.refreshVisibility = refreshVisibility;
14 }
15
16 public Boolean isFlyToView() {
17 return flyToView;
18 }
19
20 public void setFlyToView(Boolean flyToView) {
21 this.flyToView = flyToView;
22 }
23
24 public Link getLink() {
25 return link;
26 }
27
28 public void setLink(Link link) {
29 this.link = link;
30 }
31
32 public void write(KmlDocument kmlDocument) throws KmlException {
33 kmlDocument.println("<NetworkLink" + getIdAndTargetIdFormatted() + ">", 1);
34 writeInner(kmlDocument);
35 if (refreshVisibility != null) {
36 kmlDocument.println("<refreshVisibility>" + booleanToInt(refreshVisibility) + "</refreshVisibility>");
37 }
38 if (flyToView != null) {
39 kmlDocument.println("<flyToView>" + booleanToInt(flyToView) + "</flyToView>");
40 }
41 if (link != null) {
42 link.write(kmlDocument);
43 }
44 kmlDocument.println(-1, "</NetworkLink>");
45 }
46 }
0 package org.boehn.kmlframework;
1
2 public abstract class Overlay extends Feature {
3
4 private String color; // TODO change to Java color classes + separate transparency?
5 private Integer drawOrder;
6 private Icon icon;
7
8 public String getColor() {
9 return color;
10 }
11
12 public void setColor(String color) {
13 this.color = color;
14 }
15
16 public Integer getDrawOrder() {
17 return drawOrder;
18 }
19
20 public void setDrawOrder(Integer drawOrder) {
21 this.drawOrder = drawOrder;
22 }
23
24 public Icon getIcon() {
25 return icon;
26 }
27
28 public void setIcon(Icon icon) {
29 this.icon = icon;
30 }
31
32 public void writeInner(KmlDocument kmlDocument) throws KmlException {
33 super.writeInner(kmlDocument);
34 if (color != null) {
35 kmlDocument.println("<color>" + color + "</color>");
36 }
37 if (drawOrder != null) {
38 kmlDocument.println("<drawOrder>" + drawOrder + "</drawOrder>");
39 }
40 if (icon != null) {
41 icon.write(kmlDocument);
42 }
43 }
44 }
0 package org.boehn.kmlframework;
1
2 public class Pair extends KmlObject {
3
4 private StyleStateEnum key;
5 private String styleUrl;
6
7 public Pair(StyleStateEnum key, String styleUrl) {
8 this.key = key;
9 this.styleUrl = styleUrl;
10 }
11
12 public StyleStateEnum getKey() {
13 return key;
14 }
15
16 public void setKey(StyleStateEnum key) {
17 this.key = key;
18 }
19
20 public String getStyleUrl() {
21 return styleUrl;
22 }
23
24 public void setStyleUrl(String styleUrl) {
25 this.styleUrl = styleUrl;
26 }
27
28 public void write(KmlDocument kmlDocument) throws KmlException {
29 // We validate the data
30 if (key == null) {
31 throw new KmlException("Key missing for Pair");
32 }
33 if (styleUrl == null) {
34 throw new KmlException("StyleUrl missing for Pair");
35 }
36 kmlDocument.println("<Pair" + getIdAndTargetIdFormatted() + ">", 1);
37 kmlDocument.println("<key>" + key + "</key>");
38 kmlDocument.println("<styleUrl>" + styleUrl + "</styleUrl>");
39 kmlDocument.println(-1, "</Pair>");
40 }
41 }
+0
-132
src/org/boehn/kmlframework/Path.java less more
0 package org.boehn.kmlframework;
1
2 import java.util.ArrayList;
3 import java.util.List;
4
5 import org.boehn.kmlframework.coordinates.CartesianCoordinate;
6 import org.boehn.kmlframework.coordinates.Coordinate;
7 import org.boehn.kmlframework.coordinates.EarthCoordinate;
8 import org.w3c.dom.Document;
9 import org.w3c.dom.Element;
10
11 public class Path implements GraphicalModelElement {
12
13 private List<Coordinate> coordinates;
14 private Boolean extrude;
15 private Boolean tessellate;
16 private AltitudeModes altitudeMode;
17
18 public Path() {}
19
20 public Path(List<Coordinate> coordinates) {
21 this(coordinates, null, null, null);
22 }
23
24 public Path(List<Coordinate> coordinates, Boolean extrude, Boolean tessellate, AltitudeModes altitudeMode) {
25 this.coordinates = coordinates;
26 this.extrude = extrude;
27 this.tessellate = tessellate;
28 this.altitudeMode = altitudeMode;
29 }
30
31 public AltitudeModes getAltitudeMode() {
32 return altitudeMode;
33 }
34
35 public void setAltitudeMode(AltitudeModes altitudeMode) {
36 this.altitudeMode = altitudeMode;
37 }
38
39 public Boolean getExtrude() {
40 return extrude;
41 }
42
43 public void setExtrude(Boolean extrude) {
44 this.extrude = extrude;
45 }
46
47 public Boolean getTessellate() {
48 return tessellate;
49 }
50
51 public void setTessellate(Boolean tessellate) {
52 this.tessellate = tessellate;
53 }
54
55 public List<Coordinate> getCoordinates() {
56 return coordinates;
57 }
58
59 public void setCoordinates(List<Coordinate> coordinates) {
60 this.coordinates = coordinates;
61 }
62
63 public void addCoordinate(Coordinate coordinate) {
64 if (coordinates == null) {
65 coordinates = new ArrayList<Coordinate>();
66 }
67 coordinates.add(coordinate);
68 }
69
70 public void addCoordinates(List<Coordinate> coordinates) {
71 if (this.coordinates == null) {
72 this.coordinates = coordinates;
73 } else {
74 this.coordinates.addAll(coordinates);
75 }
76 }
77
78 public Element getCoordinates(Document xmlDocument, EarthCoordinate location, Double rotation, CartesianCoordinate localReferenceCoordinate, CartesianCoordinate scale) {
79 Element coordinatesElement = xmlDocument.createElement("coordinates");
80
81 StringBuffer coordinatesText = new StringBuffer();
82 for (Coordinate coordinate : coordinates) {
83 EarthCoordinate earthCoordinate = coordinate.toEarthCoordinate(location, rotation, localReferenceCoordinate, scale);
84 coordinatesText.append(earthCoordinate.getLongitude() + "," + earthCoordinate.getLatitude() + "," + earthCoordinate.getAltitude() + " ");
85 }
86 // We remove the extra space added to the end of the string
87 coordinatesText.deleteCharAt(coordinatesText.length()-1);
88
89 coordinatesElement.appendChild(xmlDocument.createTextNode(coordinatesText.toString()));
90
91 return coordinatesElement;
92 }
93
94 public void addKml(Element parentElement, Model model, Document xmlDocument, EarthCoordinate location, Double rotation, CartesianCoordinate localReferenceCoordinate, CartesianCoordinate scale) {
95 Element pathElement = xmlDocument.createElement("LineString");
96
97 if (coordinates != null) {
98 pathElement.appendChild(getCoordinates(xmlDocument, location, rotation, localReferenceCoordinate, scale));
99 }
100
101 if (extrude != null) {
102 Element extrudeElement = xmlDocument.createElement("extrude");
103 extrudeElement.appendChild(xmlDocument.createTextNode((extrude) ? "1" : "0"));
104 pathElement.appendChild(extrudeElement);
105 }
106
107 if (tessellate != null) {
108 Element tessellateElement = xmlDocument.createElement("tessellate");
109 tessellateElement.appendChild(xmlDocument.createTextNode((tessellate) ? "1" : "0"));
110 pathElement.appendChild(tessellateElement);
111 }
112
113 if (altitudeMode != null) {
114 Element altitudeModeElement = xmlDocument.createElement("altitudeMode");
115 altitudeModeElement.appendChild(xmlDocument.createTextNode(altitudeMode.toString()));
116 pathElement.appendChild(altitudeModeElement);
117 }
118
119 parentElement.appendChild(pathElement);
120 }
121
122 public String toString() {
123 StringBuffer text = new StringBuffer("Path");
124 text.append("altitudeMode: " + altitudeMode + "\n");
125 text.append("extrude: " + extrude + "\n");
126 text.append("tessellate: " + tessellate + "\n");
127 text.append("coordinates: " + coordinates + "\n");
128 return text.toString();
129 }
130
131 }
0 package org.boehn.kmlframework;
1
2 public class PhotoOverlay extends Overlay {
3
4 private Double rotation; // TODO check if Double is working fine for kml:angle180
5 private Double leftFov;
6 private Double rightFov;
7 private Double bottomFov;
8 private Double topFov;
9 private Double near;
10 private Integer tileSize;
11 private Integer maxWidth;
12 private Integer maxHeight;
13 private GridOriginEnum gridOrigin;
14 private Point point;
15 private ShapeEnum shape;
16
17 public Double getRotation() {
18 return rotation;
19 }
20
21 public void setRotation(Double rotation) {
22 this.rotation = rotation;
23 }
24
25 public Double getLeftFov() {
26 return leftFov;
27 }
28
29 public void setLeftFov(Double leftFov) {
30 this.leftFov = leftFov;
31 }
32
33 public Double getRightFov() {
34 return rightFov;
35 }
36
37 public void setRightFov(Double rightFov) {
38 this.rightFov = rightFov;
39 }
40
41 public Double getBottomFov() {
42 return bottomFov;
43 }
44
45 public void setBottomFov(Double bottomFov) {
46 this.bottomFov = bottomFov;
47 }
48
49 public Double getTopFov() {
50 return topFov;
51 }
52
53 public void setTopFov(Double topFov) {
54 this.topFov = topFov;
55 }
56
57 public Double getNear() {
58 return near;
59 }
60
61 public void setNear(Double near) {
62 this.near = near;
63 }
64
65 public Integer getTileSize() {
66 return tileSize;
67 }
68
69 public void setTileSize(Integer tileSize) {
70 this.tileSize = tileSize;
71 }
72
73 public Integer getMaxWidth() {
74 return maxWidth;
75 }
76
77 public void setMaxWidth(Integer maxWidth) {
78 this.maxWidth = maxWidth;
79 }
80
81 public Integer getMaxHeight() {
82 return maxHeight;
83 }
84
85 public void setMaxHeight(Integer maxHeight) {
86 this.maxHeight = maxHeight;
87 }
88
89 public GridOriginEnum getGridOrigin() {
90 return gridOrigin;
91 }
92
93 public void setGridOrigin(GridOriginEnum gridOrigin) {
94 this.gridOrigin = gridOrigin;
95 }
96
97 public Point getPoint() {
98 return point;
99 }
100
101 public void setPoint(Point point) {
102 this.point = point;
103 }
104
105 public ShapeEnum getShape() {
106 return shape;
107 }
108
109 public void setShape(ShapeEnum shape) {
110 this.shape = shape;
111 }
112
113 public void write(KmlDocument kmlDocument) throws KmlException {
114 kmlDocument.println("<PhotoOverlay" + getIdAndTargetIdFormatted() + ">", 1);
115 super.writeInner(kmlDocument);
116 if (rotation != null) {
117 kmlDocument.println("<rotation>" + rotation + "</rotation>");
118 }
119 if (leftFov != null || rightFov != null || bottomFov != null || topFov != null || near != null) {
120 kmlDocument.println("<ViewVolume>", 1);
121 if (leftFov != null) {
122 kmlDocument.println("<leftFov>" + leftFov + "</leftFov>");
123 }
124 if (rightFov != null) {
125 kmlDocument.println("<rightFov>" + rightFov + "</rightFov>");
126 }
127 if (bottomFov != null) {
128 kmlDocument.println("<bottomFov>" + bottomFov + "</bottomFov>");
129 }
130 if (topFov != null) {
131 kmlDocument.println("<topFov>" + topFov + "</topFov>");
132 }
133 if (near != null) {
134 kmlDocument.println("<near>" + near + "</near>");
135 }
136 kmlDocument.println(-1, "</ViewVolume>");
137 }
138 if (tileSize != null || maxWidth != null || maxHeight != null || gridOrigin != null) {
139 kmlDocument.println("<ImagePyramid>", 1);
140 if (tileSize != null) {
141 kmlDocument.println("<tileSize>" + tileSize + "</tileSize>");
142 }
143 if (maxWidth != null) {
144 kmlDocument.println("<maxWidth>" + maxWidth + "</maxWidth>");
145 }
146 if (maxHeight != null) {
147 kmlDocument.println("<maxHeight>" + maxHeight + "</maxHeight>");
148 }
149 if (gridOrigin != null) {
150 kmlDocument.println("<gridOrigin>" + gridOrigin + "</gridOrigin>");
151 }
152 kmlDocument.println(-1, "</ImagePyramid>");
153 if (point != null) {
154 point.write(kmlDocument);
155 }
156 if (shape != null) {
157 kmlDocument.println("<shape>" + shape + "</shape>");
158 }
159 }
160 kmlDocument.println(-1, "</PhotoOverlay>");
161 }
162
163 }
0 package org.boehn.kmlframework;
1
2 public class Placemark extends Feature {
3
4 private Geometry geometry;
5
6 public Placemark() {}
7
8 public Placemark(String name) {
9 setName(name);
10 }
11 public Geometry getGeometry() {
12 return geometry;
13 }
14
15 public void setGeometry(Geometry geometry) {
16 this.geometry = geometry;
17 }
18
19 public void write(KmlDocument kmlDocument) throws KmlException {
20 kmlDocument.println("<Placemark" + getIdAndTargetIdFormatted() + ">", 1);
21 writeInner(kmlDocument);
22 if (geometry != null) {
23 geometry.write(kmlDocument);
24 }
25 kmlDocument.println(-1, "</Placemark>");
26 }
27
28 public void setLocation(double longitude, double latitude) {
29 setGeometry(new Point(longitude, latitude));
30 }
31
32 }
0 package org.boehn.kmlframework;
1
2 public class Point extends Geometry {
3
4 private Boolean extrude;
5 private AltitudeModeEnum altitudeMode;
6 private Double longitude;
7 private Double latitude;
8 private Double altitude;
9
10 public Point() {}
11
12 public Point(Double longitude, Double latitude) {
13 setLongitude(longitude);
14 setLatitude(latitude);
15 }
16
17 public Boolean getExtrude() {
18 return extrude;
19 }
20
21 public void setExtrude(Boolean extrude) {
22 this.extrude = extrude;
23 }
24
25 public AltitudeModeEnum getAltitudeMode() {
26 return altitudeMode;
27 }
28
29 public void setAltitudeMode(AltitudeModeEnum altitudeMode) {
30 this.altitudeMode = altitudeMode;
31 }
32
33 public Double getLongitude() {
34 return longitude;
35 }
36
37 public void setLongitude(Double longitude) {
38 this.longitude = longitude;
39 }
40
41 public Double getLatitude() {
42 return latitude;
43 }
44
45 public void setLatitude(Double latitude) {
46 this.latitude = latitude;
47 }
48
49 public Double getAltitude() {
50 return altitude;
51 }
52
53 public void setAltitude(Double altitude) {
54 this.altitude = altitude;
55 }
56
57 public void write(KmlDocument kmlDocument) throws KmlException {
58 kmlDocument.println("<Point" + getIdAndTargetIdFormatted() + ">", 1);
59 if (extrude != null) {
60 kmlDocument.println("<extrude>" + booleanToInt(extrude) + "</extrude>");
61 }
62 if (altitudeMode!= null) {
63 kmlDocument.println("<altitudeMode>" + altitudeMode + "</altitudeMode>");
64 }
65 if (longitude != null && latitude != null) {
66 kmlDocument.println("<coordinates>" + getLongitudeLatitudeAltitudeString() + "</coordinates>");
67 }
68
69 kmlDocument.println(-1, "</Point>");
70 }
71
72 public String getLongitudeLatitudeAltitudeString() {
73 return longitude +"," + latitude + (altitude != null? "," + altitude : "");
74 }
75 }
0 package org.boehn.kmlframework;
1
2 public class PolyStyle extends ColorStyle {
3
4 private Boolean fill;
5 private Boolean outline;
6
7 public Boolean getFill() {
8 return fill;
9 }
10
11 public void setFill(Boolean fill) {
12 this.fill = fill;
13 }
14
15 public Boolean getOutline() {
16 return outline;
17 }
18
19 public void setOutline(Boolean outline) {
20 this.outline = outline;
21 }
22
23 public void write(KmlDocument kmlDocument) throws KmlException {
24 kmlDocument.println("<PolyStyle" + getIdAndTargetIdFormatted() + ">", 1);
25 super.writeInner(kmlDocument);
26 if (fill != null) {
27 kmlDocument.println("<fill>" + booleanToInt(fill) + "</fill>");
28 }
29 if (outline != null) {
30 kmlDocument.println("<outline>" + booleanToInt(outline) + "</outline>");
31 }
32 kmlDocument.println(-1, "</PolyStyle>");
33 }
34 }
0 package org.boehn.kmlframework;
1
2 import java.util.List;
3
4 public class Polygon extends Geometry {
5
6 private Boolean extrude;
7 private Boolean tessellate;
8 private AltitudeModeEnum altitudeMode;
9 private LinearRing outerBoundary;
10 private List<LinearRing> innerBoundaries;
11
12 public Boolean getExtrude() {
13 return extrude;
14 }
15
16 public void setExtrude(Boolean extrude) {
17 this.extrude = extrude;
18 }
19
20 public Boolean getTessellate() {
21 return tessellate;
22 }
23
24 public void setTessellate(Boolean tessellate) {
25 this.tessellate = tessellate;
26 }
27
28 public AltitudeModeEnum getAltitudeMode() {
29 return altitudeMode;
30 }
31
32 public void setAltitudeMode(AltitudeModeEnum altitudeMode) {
33 this.altitudeMode = altitudeMode;
34 }
35
36 public LinearRing getOuterBoundary() {
37 return outerBoundary;
38 }
39
40 public void setOuterBoundary(LinearRing outerBoundary) {
41 this.outerBoundary = outerBoundary;
42 }
43
44 public List<LinearRing> getInnerBoundaries() {
45 return innerBoundaries;
46 }
47
48 public void setInnerBoundaries(List<LinearRing> innerBoundaries) {
49 this.innerBoundaries = innerBoundaries;
50 }
51
52 public void write(KmlDocument kmlDocument) throws KmlException {
53 // We validate the data
54 if (outerBoundary == null) {
55 throw new KmlException("An outerBoundary is required in a Polygon");
56 }
57
58 kmlDocument.println("<Polygon" + getIdAndTargetIdFormatted() + ">", 1);
59 if (extrude != null) {
60 kmlDocument.println("<extrude>" + booleanToInt(extrude) + "</extrude>");
61 }
62 if (tessellate!= null) {
63 kmlDocument.println("<tessellate>" + booleanToInt(tessellate) + "</tessellate>");
64 }
65 if (altitudeMode!= null) {
66 kmlDocument.println("<altitudeMode>" + altitudeMode + "</altitudeMode>");
67 }
68
69 kmlDocument.println("<outerBoundaryIs>", 1);
70 outerBoundary.write(kmlDocument);
71 kmlDocument.println(-1, "</outerBoundaryIs>");
72
73 if (innerBoundaries != null) {
74 for (LinearRing innerBounadry : innerBoundaries) {
75 kmlDocument.println("<innerBoundaryIs>", 1);
76 innerBounadry.write(kmlDocument);
77 kmlDocument.println(-1, "</innerBoundaryIs>");
78 }
79 }
80 kmlDocument.println(-1, "</Polygon>");
81 }
82 }
0 package org.boehn.kmlframework;
1
2 public enum RefreshModeEnum {
3 onChange, onInterval, onExpire
4 }
0 package org.boehn.kmlframework;
1
2 public class Region extends KmlObject {
3
4 private Double north;
5 private Double south;
6 private Double east;
7 private Double west;
8 private Double minAltitude;
9 private Double maxAltitude;
10 private AltitudeModeEnum altitudeMode;
11 private Double minLodPixels;
12 private Double maxLodPixels;
13 private Double minFadeExtent;
14 private Double maxFadeExtent;
15
16 public Double getNorth() {
17 return north;
18 }
19
20 public void setNorth(Double north) {
21 this.north = north;
22 }
23
24 public Double getSouth() {
25 return south;
26 }
27
28 public void setSouth(Double south) {
29 this.south = south;
30 }
31
32 public Double getEast() {
33 return east;
34 }
35
36 public void setEast(Double east) {
37 this.east = east;
38 }
39
40 public Double getWest() {
41 return west;
42 }
43
44 public void setWest(Double west) {
45 this.west = west;
46 }
47
48 public Double getMinAltitude() {
49 return minAltitude;
50 }
51
52 public void setMinAltitude(Double minAltitude) {
53 this.minAltitude = minAltitude;
54 }
55
56 public Double getMaxAltitude() {
57 return maxAltitude;
58 }
59
60 public void setMaxAltitude(Double maxAltitude) {
61 this.maxAltitude = maxAltitude;
62 }
63
64 public AltitudeModeEnum getAltitudeMode() {
65 return altitudeMode;
66 }
67
68 public void setAltitudeMode(AltitudeModeEnum altitudeMode) {
69 this.altitudeMode = altitudeMode;
70 }
71
72 public Double getMinLodPixels() {
73 return minLodPixels;
74 }
75
76 public void setMinLodPixels(Double minLodPixels) {
77 this.minLodPixels = minLodPixels;
78 }
79
80 public Double getMaxLodPixels() {
81 return maxLodPixels;
82 }
83
84 public void setMaxLodPixels(Double maxLodPixels) {
85 this.maxLodPixels = maxLodPixels;
86 }
87
88 public Double getMinFadeExtent() {
89 return minFadeExtent;
90 }
91
92 public void setMinFadeExtent(Double minFadeExtent) {
93 this.minFadeExtent = minFadeExtent;
94 }
95
96 public Double getMaxFadeExtent() {
97 return maxFadeExtent;
98 }
99
100 public void setMaxFadeExtent(Double maxFadeExtent) {
101 this.maxFadeExtent = maxFadeExtent;
102 }
103
104 public void write(KmlDocument kmlDocument) throws KmlException {
105 // We validate the data
106 if (north == null) {
107 throw new KmlException("north is required in Region");
108 }
109 if (south == null) {
110 throw new KmlException("south is required in Region");
111 }
112 if (east == null) {
113 throw new KmlException("east is required in Region");
114 }
115 if (west == null) {
116 throw new KmlException("west is required in Region");
117 }
118
119 kmlDocument.println("<Region" + getIdAndTargetIdFormatted() + ">", 1);
120 kmlDocument.println("<LatLonAltBox>", 1);
121 kmlDocument.println("<north>" + north + "</north>");
122 kmlDocument.println("<south>" + south + "</south>");
123 kmlDocument.println("<east>" + east + "</east>");
124 kmlDocument.println("<west>" + west + "</west>");
125 kmlDocument.println(-1, "<LatLonAltBox>");
126 if (minAltitude != null) {
127 kmlDocument.println("<minAltitude>" + minAltitude + "</minAltitude>");
128 }
129 if (maxAltitude != null) {
130 kmlDocument.println("<maxAltitude>" + maxAltitude + "</maxAltitude>");
131 }
132 if (altitudeMode!= null) {
133 kmlDocument.println("<altitudeMode>" + altitudeMode + "</altitudeMode>");
134 }
135 if (minLodPixels != null || maxLodPixels != null || minFadeExtent != null || maxFadeExtent != null) {
136 kmlDocument.println("<Lod>", 1);
137 if (minLodPixels != null) {
138 kmlDocument.println("<minLodPixels>" + minLodPixels + "</minLodPixels>");
139 }
140 if (maxLodPixels != null) {
141 kmlDocument.println("<maxLodPixels>" + maxLodPixels + "</maxLodPixels>");
142 }
143 if (minFadeExtent != null) {
144 kmlDocument.println("<minFadeExtent>" + minFadeExtent + "</minFadeExtent>");
145 }
146 if (minFadeExtent != null) {
147 kmlDocument.println("<minFadeExtent>" + minFadeExtent + "</minFadeExtent>");
148 }
149 if (maxFadeExtent != null) {
150 kmlDocument.println("<maxFadeExtent>" + maxFadeExtent + "</maxFadeExtent>");
151 }
152 kmlDocument.println(-1, "<Lod>");
153 }
154 kmlDocument.println(-1, "</Region>");
155 }
156 }
0 package org.boehn.kmlframework;
1
2 public class ScreenOverlay extends Overlay {
3
4 private Double overlayX;
5 private Double overlayY;
6 private UnitEnum overlayXunits;
7 private UnitEnum overlayYunits;
8 private Double screenX;
9 private Double screenY;
10 private UnitEnum screenXunits;
11 private UnitEnum screenYunits;
12 private Double rotationX;
13 private Double rotationY;
14 private UnitEnum rotationXunits;
15 private UnitEnum rotationYunits;
16 private Double sizeX;
17 private Double sizeY;
18 private UnitEnum sizeXunits;
19 private UnitEnum sizeYunits;
20 private Double rotation;
21
22 public Double getOverlayX() {
23 return overlayX;
24 }
25
26 public void setOverlayX(Double overlayX) {
27 this.overlayX = overlayX;
28 }
29
30 public Double getOverlayY() {
31 return overlayY;
32 }
33
34 public void setOverlayY(Double overlayY) {
35 this.overlayY = overlayY;
36 }
37
38 public UnitEnum getOverlayXunits() {
39 return overlayXunits;
40 }
41
42 public void setOverlayXunits(UnitEnum overlayXunits) {
43 this.overlayXunits = overlayXunits;
44 }
45
46 public UnitEnum getOverlayYunits() {
47 return overlayYunits;
48 }
49
50 public void setOverlayYunits(UnitEnum overlayYunits) {
51 this.overlayYunits = overlayYunits;
52 }
53
54 public Double getScreenX() {
55 return screenX;
56 }
57
58 public void setScreenX(Double screenX) {
59 this.screenX = screenX;
60 }
61
62 public Double getScreenY() {
63 return screenY;
64 }
65
66 public void setScreenY(Double screenY) {
67 this.screenY = screenY;
68 }
69
70 public UnitEnum getScreenXunits() {
71 return screenXunits;
72 }
73
74 public void setScreenXunits(UnitEnum screenXunits) {
75 this.screenXunits = screenXunits;
76 }
77
78 public UnitEnum getScreenYunits() {
79 return screenYunits;
80 }
81
82 public void setScreenYunits(UnitEnum screenYunits) {
83 this.screenYunits = screenYunits;
84 }
85
86 public Double getRotationX() {
87 return rotationX;
88 }
89
90 public void setRotationX(Double rotationX) {
91 this.rotationX = rotationX;
92 }
93
94 public Double getRotationY() {
95 return rotationY;
96 }
97
98 public void setRotationY(Double rotationY) {
99 this.rotationY = rotationY;
100 }
101
102 public UnitEnum getRotationXunits() {
103 return rotationXunits;
104 }
105
106 public void setRotationXunits(UnitEnum rotationXunits) {
107 this.rotationXunits = rotationXunits;
108 }
109
110 public UnitEnum getRotationYunits() {
111 return rotationYunits;
112 }
113
114 public void setRotationYunits(UnitEnum rotationYunits) {
115 this.rotationYunits = rotationYunits;
116 }
117
118 public Double getSizeX() {
119 return sizeX;
120 }
121
122 public void setSizeX(Double sizeX) {
123 this.sizeX = sizeX;
124 }
125
126 public Double getSizeY() {
127 return sizeY;
128 }
129
130 public void setSizeY(Double sizeY) {
131 this.sizeY = sizeY;
132 }
133
134 public UnitEnum getSizeXunits() {
135 return sizeXunits;
136 }
137
138 public void setSizeXunits(UnitEnum sizeXunits) {
139 this.sizeXunits = sizeXunits;
140 }
141
142 public UnitEnum getSizeYunits() {
143 return sizeYunits;
144 }
145
146 public void setSizeYunits(UnitEnum sizeYunits) {
147 this.sizeYunits = sizeYunits;
148 }
149
150 public Double getRotation() {
151 return rotation;
152 }
153
154 public void setRotation(Double rotation) {
155 this.rotation = rotation;
156 }
157
158 public void write(KmlDocument kmlDocument) throws KmlException {
159 kmlDocument.println("<ScreenOverlay" + getIdAndTargetIdFormatted() + ">", 1);
160 super.writeInner(kmlDocument);
161 if (overlayX != null || overlayY != null || overlayXunits != null || overlayYunits != null) {
162 kmlDocument.println("<overlayXY" + (overlayX != null ? " x=\"" + overlayX + "\"" : "") + (overlayY != null ? " y=\"" + overlayY + "\"" : "") + (overlayXunits != null ? " xunits=\"" + overlayXunits + "\"" : "") + (overlayYunits != null ? " yunits=\"" + overlayYunits + "\"" : "") + "/>");
163 }
164 if (screenX != null || screenY != null || screenXunits != null || screenYunits != null) {
165 kmlDocument.println("<screenXY" + (screenX != null ? " x=\"" + screenX + "\"" : "") + (screenY != null ? " y=\"" + screenY + "\"" : "") + (screenXunits != null ? " xunits=\"" + screenXunits + "\"" : "") + (screenYunits != null ? " yunits=\"" + screenYunits + "\"" : "") + "/>");
166 }
167 if (rotationX != null || rotationY != null || rotationXunits != null || rotationYunits != null) {
168 kmlDocument.println("<rotationXY" + (rotationX != null ? " x=\"" + rotationX + "\"" : "") + (rotationY != null ? " y=\"" + rotationY + "\"" : "") + (rotationXunits != null ? " xunits=\"" + rotationXunits + "\"" : "") + (rotationYunits != null ? " yunits=\"" + rotationYunits + "\"" : "") + "/>");
169 }
170 if (sizeX != null || sizeY != null || sizeXunits != null || sizeYunits != null) {
171 kmlDocument.println("<sizeXY" + (sizeX != null ? " x=\"" + sizeX + "\"" : "") + (sizeY != null ? " y=\"" + sizeY + "\"" : "") + (sizeXunits != null ? " xunits=\"" + sizeXunits + "\"" : "") + (sizeYunits != null ? " yunits=\"" + sizeYunits + "\"" : "") + "/>");
172 }
173 if (rotation != null) {
174 kmlDocument.println("<rotation>" + rotation + "</rotation>");
175 }
176 kmlDocument.println(-1, "</ScreenOverlay>");
177 }
178
179 }
0 package org.boehn.kmlframework;
1
2 public enum ShapeEnum {
3 rectangle, cylinder, sphere
4 }
0 package org.boehn.kmlframework;
1
2 public class SimpleData extends KmlObject {
3
4 private String name;
5 private String value;
6
7 public SimpleData() {}
8
9 public SimpleData(String name, String value) {
10 this.name = name;
11 this.value = value;
12 }
13
14 public String getName() {
15 return name;
16 }
17
18 public void setName(String name) {
19 this.name = name;
20 }
21
22 public String getValue() {
23 return value;
24 }
25
26 public void setValue(String value) {
27 this.value = value;
28 }
29
30 public void write(KmlDocument kmlDocument) throws KmlException {
31 kmlDocument.println("<SimpleData name=\"" + name +"\">" + value + "</SimpleData>");
32 }
33
34 }
0 package org.boehn.kmlframework;
1
2 public class Style extends StyleSelector {
3
4 private IconStyle iconStyle;
5 private LabelStyle labelStyle;
6 private LineStyle lineStyle;
7 private PolyStyle polyStyle;
8 private BallonStyle ballonStyle;
9 private ListStyle listStyle;
10
11 public IconStyle getIconStyle() {
12 return iconStyle;
13 }
14
15 public void setIconStyle(IconStyle iconStyle) {
16 this.iconStyle = iconStyle;
17 }
18
19 public LabelStyle getLabelStyle() {
20 return labelStyle;
21 }
22
23 public void setLabelStyle(LabelStyle labelStyle) {
24 this.labelStyle = labelStyle;
25 }
26
27 public LineStyle getLineStyle() {
28 return lineStyle;
29 }
30
31 public void setLineStyle(LineStyle lineStyle) {
32 this.lineStyle = lineStyle;
33 }
34
35 public PolyStyle getPolyStyle() {
36 return polyStyle;
37 }
38
39 public void setPolyStyle(PolyStyle polyStyle) {
40 this.polyStyle = polyStyle;
41 }
42
43 public BallonStyle getBallonStyle() {
44 return ballonStyle;
45 }
46
47 public void setBallonStyle(BallonStyle ballonStyle) {
48 this.ballonStyle = ballonStyle;
49 }
50
51 public ListStyle getListStyle() {
52 return listStyle;
53 }
54
55 public void setListStyle(ListStyle listStyle) {
56 this.listStyle = listStyle;
57 }
58
59 public void write(KmlDocument kmlDocument) throws KmlException {
60 kmlDocument.println("<Style" + getIdAndTargetIdFormatted() + ">", 1);
61 if (iconStyle != null) {
62 iconStyle.write(kmlDocument);
63 }
64 if (labelStyle != null) {
65 labelStyle.write(kmlDocument);
66 }
67 if (lineStyle != null) {
68 lineStyle.write(kmlDocument);
69 }
70 if (polyStyle != null) {
71 polyStyle.write(kmlDocument);
72 }
73 if (ballonStyle != null) {
74 ballonStyle.write(kmlDocument);
75 }
76 if (listStyle != null) {
77 listStyle.write(kmlDocument);
78 }
79 kmlDocument.println(-1, "</Style>");
80 }
81 }
0 package org.boehn.kmlframework;
1
2 import java.util.List;
3
4 public class StyleMap extends StyleSelector {
5
6 private List<Pair> pairs;
7
8 public void write(KmlDocument kmlDocument) throws KmlException {
9 kmlDocument.println("<StyleMap" + getIdAndTargetIdFormatted() + ">", 1);
10 if (pairs != null) {
11 for (Pair pair : pairs) {
12 pair.write(kmlDocument);
13 }
14 }
15 kmlDocument.println(-1, "</StyleMap>");
16 }
17 }
0 package org.boehn.kmlframework;
1
2 public abstract class StyleSelector extends KmlObject {
3
4 }
0 package org.boehn.kmlframework;
1
2 public enum StyleStateEnum {
3 normal, highlight
4 }
0 package org.boehn.kmlframework;
1
2 public abstract class TimePrimitive extends KmlObject {
3 }
0 package org.boehn.kmlframework;
1
2 public class TimeSpan extends TimePrimitive {
3
4 private String begin;
5 private String end;
6
7 public String getBegin() {
8 return begin;
9 }
10
11 public void setBegin(String begin) {
12 this.begin = begin;
13 }
14
15 public String getEnd() {
16 return end;
17 }
18
19 public void setEnd(String end) {
20 this.end = end;
21 }
22
23 public void write(KmlDocument kmlDocument) throws KmlException {
24 kmlDocument.println("<TimeSpan" + getIdAndTargetIdFormatted() + ">", 1);
25 if (begin != null) {
26 kmlDocument.println("<begin>" + begin + "</begin>");
27 }
28 if (end != null) {
29 kmlDocument.println("<end>" + end + "</end>");
30 }
31 kmlDocument.println(-1, "</TimeSpan>");
32 }
33 }
0 package org.boehn.kmlframework;
1
2 public class TimeStamp extends TimePrimitive {
3
4 private String when;
5
6 public String getWhen() {
7 return when;
8 }
9
10 public void setWhen(String when) {
11 this.when = when;
12 }
13
14 public void write(KmlDocument kmlDocument) throws KmlException {
15 kmlDocument.println("<TimeStamp" + getIdAndTargetIdFormatted() + ">", 1);
16 if (when != null) {
17 kmlDocument.println("<when>" + when + "</when>");
18 }
19 kmlDocument.println(-1, "</TimeStamp>");
20 }
21 }
0 package org.boehn.kmlframework;
1
2 public enum UnitEnum {
3 pixels, fraction, insetPixels
4 }
0 package org.boehn.kmlframework;
1
2 public class ViewFormat extends KmlObject {
3
4 private boolean includeBBox = true;
5 private boolean includeCamera = true;
6 private boolean includeView = true;
7
8 public void write(KmlDocument kmlDocument) throws KmlException {
9 kmlDocument.print("<viewFormat" + getIdAndTargetIdFormatted() + ">");
10 if (includeBBox) {
11 kmlDocument.print("BBOX=[bboxWest],[bboxSouth],[bboxEast],[bboxNorth]");
12 }
13 if (includeBBox && includeCamera) {
14 kmlDocument.print(";");
15 }
16 if (includeCamera) {
17 kmlDocument.print("CAMERA=[lookatLon],[lookatLat],[lookatRange],[lookatTilt],[lookatHeading]");
18 }
19 if (includeCamera && includeView) {
20 kmlDocument.print(";");
21 }
22 if (includeView) {
23 kmlDocument.print("VIEW=[horizFov],[vertFov],[horizPixels],[vertPixels],[terrainEnabled]");
24 }
25 kmlDocument.println("</viewFormat>");
26 }
27
28 }
+0
-100
src/org/boehn/kmlframework/ViewPosition.java less more
0 package org.boehn.kmlframework;
1
2 import org.w3c.dom.Document;
3 import org.w3c.dom.Element;
4
5 public class ViewPosition {
6
7 private double longitude;
8 private double latitude;
9 private Double range;
10 private Double tilt;
11 private Double heading;
12
13 public ViewPosition() {
14 }
15
16 public ViewPosition(double latitude, double longitude) {
17 this(latitude, longitude, null, null, null);
18 }
19
20 public ViewPosition(double latitude, double longitude, Double range, Double tilt, Double heading) {
21 this.latitude = latitude;
22 this.longitude = longitude;
23 this.range = range;
24 this.tilt = tilt;
25 this.heading = heading;
26 }
27
28 public Double getHeading() {
29 return heading;
30 }
31
32 public void setHeading(Double heading) {
33 this.heading = heading;
34 }
35
36 public double getLatitude() {
37 return latitude;
38 }
39
40 public void setLatitude(double latitude) {
41 this.latitude = latitude;
42 }
43
44 public double getLongitude() {
45 return longitude;
46 }
47
48 public void setLongitude(double longitude) {
49 this.longitude = longitude;
50 }
51
52 public Double getRange() {
53 return range;
54 }
55
56 public void setRange(Double range) {
57 this.range = range;
58 }
59
60 public Double getTilt() {
61 return tilt;
62 }
63
64 public void setTilt(Double tilt) {
65 this.tilt = tilt;
66 }
67
68 public void addKml(Element parentElement, Model model, Document xmlDocument) {
69 Element lookAtElement = xmlDocument.createElement("LookAt");
70
71 Element longitudeElement = xmlDocument.createElement("longitude");
72 longitudeElement.appendChild(xmlDocument.createTextNode(Double.toString(longitude)));
73 lookAtElement.appendChild(longitudeElement);
74
75 Element latitudeElement = xmlDocument.createElement("latitude");
76 latitudeElement.appendChild(xmlDocument.createTextNode(Double.toString(latitude)));
77 lookAtElement.appendChild(latitudeElement);
78
79 if (range != null) {
80 Element rangeElement = xmlDocument.createElement("range");
81 rangeElement.appendChild(xmlDocument.createTextNode(range.toString()));
82 lookAtElement.appendChild(rangeElement);
83 }
84
85 if (tilt!= null) {
86 Element tiltElement = xmlDocument.createElement("tilt");
87 tiltElement.appendChild(xmlDocument.createTextNode(tilt.toString()));
88 lookAtElement.appendChild(tiltElement);
89 }
90
91 if (heading != null) {
92 Element headingElement = xmlDocument.createElement("heading");
93 headingElement.appendChild(xmlDocument.createTextNode(heading.toString()));
94 lookAtElement.appendChild(headingElement);
95 }
96
97 parentElement.appendChild(lookAtElement);
98 }
99 }
0 package org.boehn.kmlframework;
1
2 public enum ViewRefreshModeEnum {
3 never, onStop, onRequest, onRegion
4 }
0 package org.boehn.kmlframework.atom;
1
2 import org.boehn.kmlframework.KmlDocument;
3 import org.boehn.kmlframework.KmlException;
4
5 public class AtomAuthor {
6
7 private String name;
8 private String uri;
9 private String email;
10
11 public String getName() {
12 return name;
13 }
14
15 public void setName(String name) {
16 this.name = name;
17 }
18
19 public String getUri() {
20 return uri;
21 }
22
23 public void setUri(String uri) {
24 this.uri = uri;
25 }
26
27 public String getEmail() {
28 return email;
29 }
30
31 public void setEmail(String email) {
32 this.email = email;
33 }
34
35 public AtomAuthor(String name) {
36 this.name = name;
37 }
38
39 public AtomAuthor(String name, String uri, String email) {
40 this.name = name;
41 this.uri = uri;
42 this.email = email;
43 }
44
45 public void write(KmlDocument kmlDocument) throws KmlException {
46 kmlDocument.println("<atom:author>", 1);
47 if (name != null) {
48 kmlDocument.println("<atom:name>" + name + "</atom:name>");
49 }
50 if (uri != null) {
51 kmlDocument.println("<atom:uri>" + uri + "</atom:uri>");
52 }
53 if (email != null) {
54 kmlDocument.println("<atom:email>" + email + "</atom:email>");
55 }
56 kmlDocument.println(-1, "</atom:author>");
57 }
58 }
0 package org.boehn.kmlframework.atom;
1
2 import org.boehn.kmlframework.KmlDocument;
3 import org.boehn.kmlframework.KmlException;
4
5 public class AtomLink {
6
7 private String href;
8
9 public AtomLink() {}
10
11 public AtomLink(String href) {
12 this.href = href;
13 }
14
15 public String getHref() {
16 return href;
17 }
18
19 public void setHref(String href) {
20 this.href = href;
21 }
22
23 public void write(KmlDocument kmlDocument) throws KmlException {
24 if (href == null) {
25 throw new KmlException("href not set for atom:Link");
26 }
27 kmlDocument.println("<atom:link href=\"" + href + "\" />");
28 }
29
30 }
+0
-133
src/org/boehn/kmlframework/coordinates/CartesianCoordinate.java less more
0 package org.boehn.kmlframework.coordinates;
1
2 import org.boehn.kmlframework.utils.Ellipsoid;
3
4 public class CartesianCoordinate implements Coordinate {
5
6 private double x;
7 private double y;
8 private double z;
9
10 public CartesianCoordinate() {}
11
12 public CartesianCoordinate(double x, double y, double z) {
13 this.x = x;
14 this.y = y;
15 this.z = z;
16 }
17
18 public double getX() {
19 return x;
20 }
21
22 public void setX(double x) {
23 this.x = x;
24 }
25
26 public double getY() {
27 return y;
28 }
29
30 public void setY(double y) {
31 this.y = y;
32 }
33
34 public double getZ() {
35 return z;
36 }
37
38 public void setZ(double z) {
39 this.z = z;
40 }
41
42 public double distanceTo(CartesianCoordinate cartesianCoordinate) {
43 return Math.sqrt( Math.pow(Math.abs(cartesianCoordinate.getX()-x), 2) + Math.pow(Math.abs(cartesianCoordinate.getY()-y), 2) + Math.pow(Math.abs(cartesianCoordinate.getZ()-z), 2));
44 }
45
46 public void rotateAroundZAxis(double rotation) {
47 double xTemp = Math.cos(rotation) * x - Math.sin(rotation) * y;
48 y = Math.sin(rotation) * x + Math.cos(rotation) * y;
49 x = xTemp;
50 }
51
52 public void rotateAroundYAxis(double rotation) {
53 double xTemp = Math.cos(rotation) * x + Math.sin(rotation) * z;
54 z = - Math.sin(rotation) * x + Math.cos(rotation) * z;
55 x = xTemp;
56 }
57
58 public void rotateAroundXAxis(double rotation) {
59 double yTemp = Math.cos(rotation) * y - Math.sin(rotation) * z;
60 z = Math.sin(rotation) * y + Math.cos(rotation) * z;
61 y = yTemp;
62 }
63
64 public void add(CartesianCoordinate cartesianCoordinate) {
65 x += cartesianCoordinate.getX();
66 y += cartesianCoordinate.getY();
67 z += cartesianCoordinate.getZ();
68 }
69
70 public void subtract(CartesianCoordinate cartesianCoordinate) {
71 x -= cartesianCoordinate.getX();
72 y -= cartesianCoordinate.getY();
73 z -= cartesianCoordinate.getZ();
74 }
75
76 public double length() {
77 return Math.sqrt(x*x + y*y + z*z);
78 }
79
80 public void normalize() {
81 double length = length();
82 x /= length;
83 y /= length;
84 z /= length;
85 }
86
87 public void scale(double scalingFactor) {
88 x *= scalingFactor;
89 y *= scalingFactor;
90 z *= scalingFactor;
91 }
92
93 public String toString() {
94 return "[" + x + ", " + y + ", " + z + "]";
95 }
96
97 public EarthCoordinate toEarthCoordinate(EarthCoordinate location, Double rotation, CartesianCoordinate localReferenceCoordinate, CartesianCoordinate scale) {
98 // We scale the coordinates
99 double xTransformed = x;
100 double yTransformed = y;
101 double zTransformed = z;
102
103 if (scale != null) {
104 xTransformed = x * scale.getX();
105 yTransformed = y * scale.getY();
106 zTransformed = z * scale.getZ();
107 }
108
109 // We move the coordinates according to the local reference coordinate
110 if (localReferenceCoordinate != null) {
111 xTransformed -= localReferenceCoordinate.getX();
112 yTransformed -= localReferenceCoordinate.getY();
113 zTransformed -= localReferenceCoordinate.getZ();
114 }
115
116 //rotation = Math.PI/4;
117 // We rotate the coordinates according to the rotation. We do only support rotation around the z axis
118 if (rotation != null) {
119 double xTmp = xTransformed;
120 xTransformed = Math.cos(rotation) * xTmp + Math.sin(rotation) * yTransformed;
121 yTransformed = -Math.sin(rotation) * xTmp + Math.cos(rotation) * yTransformed;
122 }
123
124 // Move to world coordinates
125 if (location != null) {
126 xTransformed = location.getLongitude() + xTransformed * Ellipsoid.meterToLongitude(location.getLatitude());
127 yTransformed = location.getLatitude() + yTransformed * Ellipsoid.meterToLatitude(location.getLatitude());
128 zTransformed += location.getAltitude();
129 }
130 return new EarthCoordinate(zTransformed, yTransformed, xTransformed);
131 }
132 }
+0
-8
src/org/boehn/kmlframework/coordinates/Coordinate.java less more
0 package org.boehn.kmlframework.coordinates;
1
2
3 public interface Coordinate {
4
5 EarthCoordinate toEarthCoordinate(EarthCoordinate earthCoordinate, Double rotation, CartesianCoordinate localReferenceCoordinate, CartesianCoordinate scale);
6
7 }
+0
-194
src/org/boehn/kmlframework/coordinates/EarthCoordinate.java less more
0 package org.boehn.kmlframework.coordinates;
1
2 import java.io.IOException;
3 import java.io.Writer;
4
5 import org.boehn.kmlframework.AltitudeModes;
6 import org.boehn.kmlframework.Model;
7 import org.w3c.dom.Document;
8 import org.w3c.dom.Element;
9 import org.xmlpull.v1.XmlSerializer;
10
11 public class EarthCoordinate implements Coordinate {
12
13 private double altitude;
14 private double latitude;
15 private double longitude;
16 private Boolean extrude;
17 private Boolean tessellate;
18 private AltitudeModes altitudeMode;
19 public static double EARTHRADIUS = 6372795.477598; // in meters
20
21 public EarthCoordinate() {}
22
23 public EarthCoordinate(double altitude, double latitude, double longitude) {
24 this.altitude = altitude;
25 this.latitude = latitude;
26 this.longitude = longitude;
27 }
28
29 public EarthCoordinate(double latitude, double longitude) {
30 this(0, latitude, longitude);
31 }
32
33 public double getAltitude() {
34 return altitude;
35 }
36
37 public void setAltitude(double altitude) {
38 this.altitude = altitude;
39 }
40
41 public double getLatitude() {
42 return latitude;
43 }
44
45 public void setLatitude(double latitude) {
46 this.latitude = latitude;
47 }
48
49 public double getLongitude() {
50 return longitude;
51 }
52
53 public void setLongitude(double longitude) {
54 this.longitude = longitude;
55 }
56
57 public AltitudeModes getAltitudeMode() {
58 return altitudeMode;
59 }
60
61 public void setAltitudeMode(AltitudeModes altitudeMode) {
62 this.altitudeMode = altitudeMode;
63 }
64
65 public Boolean getExtrude() {
66 return extrude;
67 }
68
69 public void setExtrude(Boolean extrude) {
70 this.extrude = extrude;
71 }
72
73 public Boolean getTessellate() {
74 return tessellate;
75 }
76
77 public void setTessellate(Boolean tessellate) {
78 this.tessellate = tessellate;
79 }
80
81 public void addKml(Element parentElement, Model model, Document xmlDocument) {
82 Element pointElement = xmlDocument.createElement("Point");
83
84 Element coordinatesElement = xmlDocument.createElement("coordinates");
85 coordinatesElement.appendChild(xmlDocument.createTextNode(getLongitude() + "," + getLatitude() + "," + getAltitude()));
86 pointElement.appendChild(coordinatesElement);
87
88 if (extrude != null) {
89 Element extrudeElement = xmlDocument.createElement("extrude");
90 extrudeElement.appendChild(xmlDocument.createTextNode((extrude) ? "1" : "0"));
91 pointElement.appendChild(extrudeElement);
92 }
93
94 if (tessellate != null) {
95 Element tessellateElement = xmlDocument.createElement("tessellate");
96 tessellateElement.appendChild(xmlDocument.createTextNode((tessellate) ? "1" : "0"));
97 pointElement.appendChild(tessellateElement);
98 }
99
100 if (altitudeMode!= null) {
101 Element altitudeModeElement = xmlDocument.createElement("altitudeMode");
102 altitudeModeElement.appendChild(xmlDocument.createTextNode(altitudeMode.toString()));
103 pointElement.appendChild(altitudeModeElement);
104 }
105
106 parentElement.appendChild(pointElement);
107 }
108
109 public void addKmlXPP(Model model, XmlSerializer serializer) throws IllegalArgumentException, IllegalStateException, IOException {
110 serializer.startTag(null, "Point");
111 serializer.startTag(null, "coordinates");
112 serializer.text(getLongitude() + "," + getLatitude() + "," + getAltitude());
113 serializer.endTag(null, "coordinates");
114 serializer.endTag(null, "Point");
115
116 /*Element coordinatesElement = xmlDocument.createElement("coordinates");
117 coordinatesElement.appendChild(xmlDocument.createTextNode(getLongitude() + "," + getLatitude() + "," + getAltitude()));
118 pointElement.appendChild(coordinatesElement);
119
120 if (extrude != null) {
121 Element extrudeElement = xmlDocument.createElement("extrude");
122 extrudeElement.appendChild(xmlDocument.createTextNode((extrude) ? "1" : "0"));
123 pointElement.appendChild(extrudeElement);
124 }
125
126 if (tessellate != null) {
127 Element tessellateElement = xmlDocument.createElement("tessellate");
128 tessellateElement.appendChild(xmlDocument.createTextNode((tessellate) ? "1" : "0"));
129 pointElement.appendChild(tessellateElement);
130 }
131
132 if (altitudeMode!= null) {
133 Element altitudeModeElement = xmlDocument.createElement("altitudeMode");
134 altitudeModeElement.appendChild(xmlDocument.createTextNode(altitudeMode.toString()));
135 pointElement.appendChild(altitudeModeElement);
136 }
137
138 parentElement.appendChild(pointElement);*/
139 }
140
141 public void addKmlDirect(Model model, Writer writer) throws IOException {
142 writer.write("<Point><coordinates>" + getLongitude() + "," + getLatitude() + "," + getAltitude() + "</coordinates></Point>");
143
144 /*Element coordinatesElement = xmlDocument.createElement("coordinates");
145 coordinatesElement.appendChild(xmlDocument.createTextNode(getLongitude() + "," + getLatitude() + "," + getAltitude()));
146 pointElement.appendChild(coordinatesElement);
147
148 if (extrude != null) {
149 Element extrudeElement = xmlDocument.createElement("extrude");
150 extrudeElement.appendChild(xmlDocument.createTextNode((extrude) ? "1" : "0"));
151 pointElement.appendChild(extrudeElement);
152 }
153
154 if (tessellate != null) {
155 Element tessellateElement = xmlDocument.createElement("tessellate");
156 tessellateElement.appendChild(xmlDocument.createTextNode((tessellate) ? "1" : "0"));
157 pointElement.appendChild(tessellateElement);
158 }
159
160 if (altitudeMode!= null) {
161 Element altitudeModeElement = xmlDocument.createElement("altitudeMode");
162 altitudeModeElement.appendChild(xmlDocument.createTextNode(altitudeMode.toString()));
163 pointElement.appendChild(altitudeModeElement);
164 }
165
166 parentElement.appendChild(pointElement);*/
167 }
168
169 public double getRadius() {
170 return altitude + EARTHRADIUS;
171 }
172
173 public CartesianCoordinate toCartesianCoordinate() {
174 CartesianCoordinate cartesianCoordinate = new CartesianCoordinate();
175 cartesianCoordinate.setX(getRadius() * Math.sin(Math.PI/2 - latitude*(Math.PI/180)) * Math.cos(longitude*(Math.PI/180)));
176 cartesianCoordinate.setY(getRadius() * Math.sin(Math.PI/2 - latitude*(Math.PI/180)) * Math.sin(longitude*(Math.PI/180)));
177 cartesianCoordinate.setZ(getRadius() * Math.cos(Math.PI/2 - latitude*(Math.PI/180)));
178 return cartesianCoordinate;
179 }
180
181 public double distanceTo(EarthCoordinate earthCoordinate) {
182 return toCartesianCoordinate().distanceTo(earthCoordinate.toCartesianCoordinate());
183 }
184
185 public String toString() {
186 return "[" + altitude + ", " + latitude + ", " + longitude + "]";
187 }
188
189 public EarthCoordinate toEarthCoordinate(EarthCoordinate earthCoordinate, Double rotation, CartesianCoordinate localReferenceCoordinate, CartesianCoordinate scale) {
190 return this;
191 }
192
193 }
+0
-32
src/org/boehn/kmlframework/coordinates/TimeAndPlace.java less more
0 package org.boehn.kmlframework.coordinates;
1
2 import java.util.Date;
3
4
5 public class TimeAndPlace {
6
7 private EarthCoordinate place;
8 private Date time;
9
10 public TimeAndPlace(EarthCoordinate place, Date time) {
11 this.place = place;
12 this.time = time;
13 }
14
15 public EarthCoordinate getPlace() {
16 return place;
17 }
18
19 public void setPlace(EarthCoordinate place) {
20 this.place = place;
21 }
22
23 public Date getTime() {
24 return time;
25 }
26
27 public void setTime(Date time) {
28 this.time = time;
29 }
30
31 }
+0
-77
src/org/boehn/kmlframework/examples/GraphicalMapObjectExample.java less more
0 package org.boehn.kmlframework.examples;
1
2 import java.io.IOException;
3 import java.util.ArrayList;
4 import java.util.Calendar;
5 import java.util.GregorianCalendar;
6 import java.util.List;
7
8 import org.boehn.kmlframework.GraphicalModel;
9 import org.boehn.kmlframework.MapObject;
10 import org.boehn.kmlframework.MapObjectClass;
11 import org.boehn.kmlframework.Model;
12 import org.boehn.kmlframework.ModelException;
13 import org.boehn.kmlframework.Polygon;
14 import org.boehn.kmlframework.coordinates.CartesianCoordinate;
15 import org.boehn.kmlframework.coordinates.Coordinate;
16 import org.boehn.kmlframework.coordinates.EarthCoordinate;
17 import org.boehn.kmlframework.coordinates.TimeAndPlace;
18
19 public class GraphicalMapObjectExample {
20
21 public static void main(String[] args) throws ModelException, IOException {
22
23 // We create a model
24 Model model = new Model();
25
26 // We define a MapObjectClass for a boat
27 MapObjectClass boatClass = new MapObjectClass("boat");
28 GraphicalModel boatModel = new GraphicalModel();
29 List<Coordinate> coordinates = new ArrayList<Coordinate>();
30 coordinates.add(new CartesianCoordinate(0, 0, 1));
31 coordinates.add(new CartesianCoordinate(1, 0, 1));
32 coordinates.add(new CartesianCoordinate(1, 0.7, 1));
33 coordinates.add(new CartesianCoordinate(0.5, 1, 1));
34 coordinates.add(new CartesianCoordinate(0, 0.7, 1));
35 coordinates.add(new CartesianCoordinate(0, 0, 1));
36 Polygon polygon = new Polygon(coordinates);
37 boatModel.addGraphicalModelElement(polygon);
38 boatClass.addModel(boatModel);
39
40 // We create a boat object
41 MapObject boat = new MapObject("Titanic II");
42 boat.setLocation(new EarthCoordinate(59.8959, 10.6406));
43 boat.setMapObjectClass(boatClass);
44 // We define the size of the boat
45 boat.setScale(new CartesianCoordinate(30, 150, 30));
46 // We define the direction of the boat. 0 is North
47 boat.setRotation(Math.toRadians(45d));
48 // We define the gps position in the boat (according to the 3D model of the boat
49 boat.setLocalReferenceCoordinate(new CartesianCoordinate(2, 13, 0));
50
51 // We define how the boat has been moving the last period of time. This will draw a tail after the boat
52 GregorianCalendar calendar = new GregorianCalendar();
53 calendar.add(Calendar.MINUTE, -15);
54 boat.addMovement(new TimeAndPlace(new EarthCoordinate(59.895018, 10.638732), calendar.getTime()));
55 calendar.add(Calendar.MINUTE, -15);
56 boat.addMovement(new TimeAndPlace(new EarthCoordinate(59.892980, 10.638991), calendar.getTime()));
57 calendar.add(Calendar.MINUTE, -15);
58 boat.addMovement(new TimeAndPlace(new EarthCoordinate(59.891171, 10.640006), calendar.getTime()));
59 calendar.add(Calendar.MINUTE, -15);
60 boat.addMovement(new TimeAndPlace(new EarthCoordinate(59.890575, 10.645234), calendar.getTime()));
61 calendar.add(Calendar.MINUTE, -15);
62 boat.addMovement(new TimeAndPlace(new EarthCoordinate(59.889318, 10.644650), calendar.getTime()));
63
64 // We add the object to the model
65 model.add(boat);
66
67 // In order to make the kml more human readable we may activate indenting
68 model.XML_INDENT = true;
69
70 // We generate the kml file
71 model.write("boat.kml");
72
73 System.out.println("The kml file was generated.");
74 }
75
76 }
+0
-47
src/org/boehn/kmlframework/examples/ModelObjectFactoryExample.java less more
0 package org.boehn.kmlframework.examples;
1
2 import java.io.IOException;
3
4 import org.boehn.kmlframework.MapObject;
5 import org.boehn.kmlframework.Model;
6 import org.boehn.kmlframework.ModelException;
7 import org.boehn.kmlframework.ModelObjectFactory;
8 import org.boehn.kmlframework.coordinates.CartesianCoordinate;
9 import org.boehn.kmlframework.coordinates.EarthCoordinate;
10
11 public class ModelObjectFactoryExample {
12
13 public static void main(String[] args) throws ModelException, IOException {
14
15 try {
16
17 // We create a model
18 Model model = new Model();
19
20 // We create a ModelObjectFactory from a symbol file
21 ModelObjectFactory modelObjectFactory = new ModelObjectFactory("resources/symbols/symbols.xml");
22
23 // We create a boat object
24 MapObject boat = modelObjectFactory.createMapObject("boat");
25 boat.setLocation(new EarthCoordinate(59.8959, 10.6406));
26 // We define the size of the boat
27 boat.setScale(new CartesianCoordinate(30, 150, 30));
28 // We define the direction of the boat. 0 is North
29 boat.setRotation(Math.toRadians(45d));
30 // We define the gps position in the boat (according to the 3D model of the boat
31 boat.setLocalReferenceCoordinate(new CartesianCoordinate(2, 13, 0));
32
33 // We add the object to the model
34 model.add(boat);
35
36 // We generate the kml file
37 model.write("boat.kml");
38
39 System.out.println("The kml file was generated.");
40
41 } catch (Exception e) {
42 e.printStackTrace();
43 }
44 }
45
46 }
11
22 import java.io.IOException;
33
4 import org.boehn.kmlframework.MapObject;
5 import org.boehn.kmlframework.Model;
6 import org.boehn.kmlframework.ModelException;
7 import org.boehn.kmlframework.coordinates.EarthCoordinate;
4 import org.boehn.kmlframework.KmlDocument;
5 import org.boehn.kmlframework.KmlException;
6 import org.boehn.kmlframework.Placemark;
87
98 public class SimpleExample {
109
11 public static void main(String[] args) throws ModelException, IOException {
10 public static void main(String[] args) throws KmlException, IOException {
1211
13 // We create a model
14 Model model = new Model();
12 // We create a new KMLL Document
13 KmlDocument kmlDocument = new KmlDocument();
1514
16 // We create an object for the Department of Informatics at the university of Oslo
17 MapObject ifi = new MapObject("Department of Informatics");
15 // We create a Placemark for the Department of Informatics at the university of Oslo
16 Placemark ifi = new Placemark("Department of Informatics");
1817 ifi.setDescription("Web: http://www.ifi.uio.no<br/>Phone: +47 22852410");
19 ifi.setLocation(new EarthCoordinate(59.943355, 10.717344));
18 ifi.setLocation(59.943355, 10.717344);
2019
21 // We add the object to the model
22 model.add(ifi);
20 // We add the placemark to the KML Document
21 kmlDocument.add(ifi);
2322
2423 // We generate the kml file
25 model.write("Ifi.kml");
24 kmlDocument.createKml("Ifi.kml");
2625
26 // We are done
2727 System.out.println("The kml file was generated.");
2828 }
2929
+0
-39
src/org/boehn/kmlframework/examples/SimpleExampleServlet.java less more
0 package org.boehn.kmlframework.examples;
1
2 import java.io.IOException;
3
4 import javax.servlet.ServletException;
5 import javax.servlet.http.HttpServlet;
6 import javax.servlet.http.HttpServletRequest;
7 import javax.servlet.http.HttpServletResponse;
8
9 import org.boehn.kmlframework.MapObject;
10 import org.boehn.kmlframework.coordinates.EarthCoordinate;
11 import org.boehn.kmlframework.servlet.HttpServletModel;
12
13 public class SimpleExampleServlet extends HttpServlet {
14
15 private static final long serialVersionUID = 1L;
16
17 @Override
18 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
19 try {
20 // We create a model
21 HttpServletModel model = new HttpServletModel(request, response);
22
23 // We create an object for the Department of Informatics at the university of Oslo
24 MapObject ifi = new MapObject("Department of Informatics");
25 ifi.setDescription("Web: http://www.ifi.uio.no<br/>Phone: +47 22852410");
26 ifi.setLocation(new EarthCoordinate(59.943355, 10.717344));
27
28 // We add the object to the model
29 model.add(ifi);
30
31 // We generate the kml file
32 model.write();
33
34 } catch (Exception e) {
35 throw new ServletException(e);
36 }
37 }
38 }
+0
-126
src/org/boehn/kmlframework/overlays/GroundOverlay.java less more
0 package org.boehn.kmlframework.overlays;
1
2 import java.io.IOException;
3 import java.io.Writer;
4
5 import org.boehn.kmlframework.BoundingBox;
6 import org.boehn.kmlframework.Model;
7 import org.boehn.kmlframework.ModelException;
8 import org.boehn.kmlframework.ViewPosition;
9 import org.w3c.dom.Document;
10 import org.w3c.dom.Element;
11 import org.xmlpull.v1.XmlSerializer;
12
13 public class GroundOverlay extends Overlay {
14
15 private ViewPosition viewPosition;
16 private String color;
17 private BoundingBox boundingBox;
18
19 public GroundOverlay() {}
20
21 public BoundingBox getBoundingBox() {
22 return boundingBox;
23 }
24
25 public void setBoundingBox(BoundingBox boundingBox) {
26 this.boundingBox = boundingBox;
27 }
28
29 public String getColor() {
30 return color;
31 }
32
33 public void setColor(String color) {
34 this.color = color;
35 }
36
37 public ViewPosition getViewPosition() {
38 return viewPosition;
39 }
40
41 public void setViewPosition(ViewPosition viewPosition) {
42 this.viewPosition = viewPosition;
43 }
44
45 public void addKml(Element parentElement, Model model, Document xmlDocument) throws ModelException {
46 Element groundOverlayElement = xmlDocument.createElement("GroundOverlay");
47
48 if (name != null) {
49 Element nameElement = xmlDocument.createElement("name");
50 nameElement.appendChild(xmlDocument.createTextNode(name));
51 groundOverlayElement.appendChild(nameElement);
52 }
53
54 if (description != null) {
55 Element descriptionElement = xmlDocument.createElement("description");
56 descriptionElement.appendChild(xmlDocument.createCDATASection(description));
57 groundOverlayElement.appendChild(descriptionElement);
58 }
59
60 if (color != null) {
61 Element colorElement = xmlDocument.createElement("color");
62 colorElement.appendChild(xmlDocument.createTextNode(color));
63 groundOverlayElement.appendChild(colorElement);
64 }
65
66 if (viewPosition != null) {
67 viewPosition.addKml(groundOverlayElement, model, xmlDocument);
68 }
69
70 if (boundingBox != null) {
71 Element latLonBoxElement = xmlDocument.createElement("LatLonBox");
72 if (boundingBox.getNorth() != null) {
73 Element northElement = xmlDocument.createElement("north");
74 northElement.appendChild(xmlDocument.createTextNode(boundingBox.getNorth().toString()));
75 latLonBoxElement.appendChild(northElement);
76 }
77 if (boundingBox.getSouth() != null) {
78 Element southElement = xmlDocument.createElement("south");
79 southElement.appendChild(xmlDocument.createTextNode(boundingBox.getSouth().toString()));
80 latLonBoxElement.appendChild(southElement);
81 }
82 if (boundingBox.getWest() != null) {
83 Element westElement = xmlDocument.createElement("west");
84 westElement.appendChild(xmlDocument.createTextNode(boundingBox.getWest().toString()));
85 latLonBoxElement.appendChild(westElement);
86 }
87 if (boundingBox.getEast() != null) {
88 Element eastElement = xmlDocument.createElement("east");
89 eastElement.appendChild(xmlDocument.createTextNode(boundingBox.getEast().toString()));
90 latLonBoxElement.appendChild(eastElement);
91 }
92
93 if (icon != null) {
94 icon.addKml(groundOverlayElement, model, xmlDocument);
95 }
96
97 if (drawOrder != null) {
98 Element drawOrderElement = xmlDocument.createElement("drawOrder");
99 drawOrderElement.appendChild(xmlDocument.createTextNode(drawOrder.toString()));
100 groundOverlayElement.appendChild(drawOrderElement);
101 }
102
103 if (visibility != null) {
104 Element visibilityElement = xmlDocument.createElement("visibility");
105 visibilityElement.appendChild(xmlDocument.createTextNode((visibility) ? "1" : "0"));
106 groundOverlayElement.appendChild(visibilityElement);
107 }
108 groundOverlayElement.appendChild(latLonBoxElement);
109 }
110
111 parentElement.appendChild(groundOverlayElement);
112 }
113
114 public void addKmlXPP(Model model, XmlSerializer serializer) {
115 // TODO Auto-generated method stub
116
117 }
118
119 public void addKmlDirect(Model model, Writer writer) throws IOException {
120 // TODO Auto-generated method stub
121
122 }
123
124
125 }
+0
-106
src/org/boehn/kmlframework/overlays/Icon.java less more
0 package org.boehn.kmlframework.overlays;
1
2 import org.boehn.kmlframework.Model;
3 import org.boehn.kmlframework.ModelException;
4 import org.w3c.dom.Document;
5 import org.w3c.dom.Element;
6
7 public class Icon {
8
9 private String url;
10 private Integer x;
11 private Integer y;
12 private Integer width;
13 private Integer height;
14
15 public Icon() {}
16
17 public Icon(String url) {
18 this.url = url;
19 }
20
21 public Icon(String url, Integer x, Integer y, Integer width, Integer height) {
22 this.url = url;
23 this.x = x;
24 this.y = y;
25 this.width = width;
26 this.height = height;
27 }
28
29 public Integer getHeight() {
30 return height;
31 }
32
33 public void setHeight(Integer height) {
34 this.height = height;
35 }
36
37 public String getUrl() {
38 return url;
39 }
40
41 public void setUrl(String url) {
42 this.url = url;
43 }
44
45 public Integer getWidth() {
46 return width;
47 }
48
49 public void setWidth(Integer width) {
50 this.width = width;
51 }
52
53 public Integer getX() {
54 return x;
55 }
56
57 public void setX(Integer x) {
58 this.x = x;
59 }
60
61 public Integer getY() {
62 return y;
63 }
64
65 public void setY(Integer y) {
66 this.y = y;
67 }
68
69 public void addKml(Element parentElement, Model model, Document xmlDocument) throws ModelException {
70 Element iconElement = xmlDocument.createElement("Icon");
71
72 if (url != null) {
73 Element urlElement = xmlDocument.createElement("href");
74 urlElement.appendChild(xmlDocument.createTextNode(url));
75 iconElement.appendChild(urlElement);
76 }
77
78 if (x != null) {
79 Element xElement = xmlDocument.createElement("x");
80 xElement.appendChild(xmlDocument.createTextNode(x.toString()));
81 iconElement.appendChild(xElement);
82 }
83
84 if (y != null) {
85 Element yElement = xmlDocument.createElement("y");
86 yElement.appendChild(xmlDocument.createTextNode(y.toString()));
87 iconElement.appendChild(yElement);
88 }
89
90 if (width != null) {
91 Element widthElement = xmlDocument.createElement("w");
92 widthElement.appendChild(xmlDocument.createTextNode(width.toString()));
93 iconElement.appendChild(widthElement);
94 }
95
96 if (height != null) {
97 Element heightElement = xmlDocument.createElement("h");
98 heightElement.appendChild(xmlDocument.createTextNode(height.toString()));
99 iconElement.appendChild(heightElement);
100 }
101
102 parentElement.appendChild(iconElement);
103 }
104
105 }
+0
-53
src/org/boehn/kmlframework/overlays/Overlay.java less more
0 package org.boehn.kmlframework.overlays;
1
2 import org.boehn.kmlframework.ModelElement;
3
4 public abstract class Overlay implements ModelElement {
5
6 protected String name;
7 protected String description;
8 protected Icon icon;
9 protected Integer drawOrder;
10 protected Boolean visibility;
11
12 public String getDescription() {
13 return description;
14 }
15
16 public void setDescription(String description) {
17 this.description = description;
18 }
19
20 public Integer getDrawOrder() {
21 return drawOrder;
22 }
23
24 public void setDrawOrder(Integer drawOrder) {
25 this.drawOrder = drawOrder;
26 }
27
28 public Icon getIcon() {
29 return icon;
30 }
31
32 public void setIcon(Icon icon) {
33 this.icon = icon;
34 }
35
36 public String getName() {
37 return name;
38 }
39
40 public void setName(String name) {
41 this.name = name;
42 }
43
44 public Boolean getVisibility() {
45 return visibility;
46 }
47
48 public void setVisibility(Boolean visibility) {
49 this.visibility = visibility;
50 }
51
52 }
+0
-8
src/org/boehn/kmlframework/overlays/OverlayXY.java less more
0 package org.boehn.kmlframework.overlays;
1
2 public class OverlayXY extends ScreenOverlayUnitsCapsule {
3
4 public OverlayXY(Double x, Double y, Units xUnits, Units yUnits) {
5 super("overlayXY", x, y, xUnits, yUnits);
6 }
7 }
+0
-115
src/org/boehn/kmlframework/overlays/ScreenOverlay.java less more
0 package org.boehn.kmlframework.overlays;
1
2 import java.io.IOException;
3 import java.io.Writer;
4
5 import org.boehn.kmlframework.Model;
6 import org.boehn.kmlframework.ModelException;
7 import org.w3c.dom.Document;
8 import org.w3c.dom.Element;
9 import org.xmlpull.v1.XmlSerializer;
10
11 public class ScreenOverlay extends Overlay {
12
13 private OverlayXY overlayXY;
14 private ScreenXY screenXY;
15 private Size size;
16 private Double rotation;
17
18 public ScreenOverlay() {}
19
20 public ScreenOverlayUnitsCapsule getOverlayXY() {
21 return overlayXY;
22 }
23
24 public Double getRotation() {
25 return rotation;
26 }
27
28 public void setRotation(Double rotation) {
29 this.rotation = rotation;
30 }
31
32 public ScreenXY getScreenXY() {
33 return screenXY;
34 }
35
36 public void setScreenXY(ScreenXY screenXY) {
37 this.screenXY = screenXY;
38 }
39
40 public Size getSize() {
41 return size;
42 }
43
44 public void setSize(Size size) {
45 this.size = size;
46 }
47
48 public void setOverlayXY(OverlayXY overlayXY) {
49 this.overlayXY = overlayXY;
50 }
51
52 public void addKml(Element parentElement, Model model, Document xmlDocument) throws ModelException {
53 Element screenOverlayElement = xmlDocument.createElement("ScreenOverlay");
54
55 if (name != null) {
56 Element nameElement = xmlDocument.createElement("name");
57 nameElement.appendChild(xmlDocument.createTextNode(name));
58 screenOverlayElement.appendChild(nameElement);
59 }
60
61 if (description != null) {
62 Element descriptionElement = xmlDocument.createElement("description");
63 descriptionElement.appendChild(xmlDocument.createCDATASection(description));
64 screenOverlayElement.appendChild(descriptionElement);
65 }
66
67 if (rotation != null) {
68 Element rotationElement = xmlDocument.createElement("rotation");
69 rotationElement.appendChild(xmlDocument.createTextNode(rotation.toString()));
70 screenOverlayElement.appendChild(rotationElement);
71 }
72
73 if (overlayXY != null) {
74 overlayXY.addKml(screenOverlayElement, model, xmlDocument);
75 }
76
77 if (screenXY != null) {
78 screenXY.addKml(screenOverlayElement, model, xmlDocument);
79 }
80
81 if (size != null) {
82 size.addKml(screenOverlayElement, model, xmlDocument);
83 }
84
85 if (icon != null) {
86 icon.addKml(screenOverlayElement, model, xmlDocument);
87 }
88
89 if (drawOrder != null) {
90 Element drawOrderElement = xmlDocument.createElement("drawOrder");
91 drawOrderElement.appendChild(xmlDocument.createTextNode(drawOrder.toString()));
92 screenOverlayElement.appendChild(drawOrderElement);
93 }
94
95 if (visibility != null) {
96 Element visibilityElement = xmlDocument.createElement("visibility");
97 visibilityElement.appendChild(xmlDocument.createTextNode((visibility) ? "1" : "0"));
98 screenOverlayElement.appendChild(visibilityElement);
99 }
100
101 parentElement.appendChild(screenOverlayElement);
102 }
103
104 public void addKmlXPP(Model model, XmlSerializer serializer) {
105 // TODO Auto-generated method stub
106
107 }
108
109 public void addKmlDirect(Model model, Writer writer) throws IOException {
110 // TODO Auto-generated method stub
111
112 }
113
114 }
+0
-83
src/org/boehn/kmlframework/overlays/ScreenOverlayUnitsCapsule.java less more
0 package org.boehn.kmlframework.overlays;
1
2 import org.boehn.kmlframework.Model;
3 import org.boehn.kmlframework.ModelException;
4 import org.w3c.dom.Document;
5 import org.w3c.dom.Element;
6
7 public abstract class ScreenOverlayUnitsCapsule {
8
9 private String name;
10 private Double x;
11 private Double y;
12 private Units xUnits;
13 private Units yUnits;
14
15 public ScreenOverlayUnitsCapsule() {}
16
17 public ScreenOverlayUnitsCapsule(String name, Double x, Double y, Units xUnits, Units yUnits) {
18 this.name = name;
19 this.x = x;
20 this.y = y;
21 this.xUnits = xUnits;
22 this.yUnits = yUnits;
23 }
24
25 public String getName() {
26 return name;
27 }
28
29 public void setName(String name) {
30 this.name = name;
31 }
32
33 public Double getX() {
34 return x;
35 }
36
37 public void setX(Double x) {
38 this.x = x;
39 }
40
41 public Units getXUnits() {
42 return xUnits;
43 }
44
45 public void setXUnits(Units units) {
46 xUnits = units;
47 }
48
49 public Double getY() {
50 return y;
51 }
52
53 public void setY(Double y) {
54 this.y = y;
55 }
56
57 public Units getYUnits() {
58 return yUnits;
59 }
60
61 public void setYUnits(Units units) {
62 yUnits = units;
63 }
64
65 public void addKml(Element parentElement, Model model, Document xmlDocument) throws ModelException {
66 Element element = xmlDocument.createElement(name);
67 if (x != null) {
68 element.setAttribute("x", x.toString());
69 }
70 if (y != null) {
71 element.setAttribute("y", y.toString());
72 }
73 if (xUnits != null) {
74 element.setAttribute("xunits", xUnits.toString());
75 }
76 if (yUnits != null) {
77 element.setAttribute("yunits", yUnits.toString());
78 }
79 parentElement.appendChild(element);
80 }
81
82 }
+0
-8
src/org/boehn/kmlframework/overlays/ScreenXY.java less more
0 package org.boehn.kmlframework.overlays;
1
2 public class ScreenXY extends ScreenOverlayUnitsCapsule {
3
4 public ScreenXY(Double x, Double y, Units xUnits, Units yUnits) {
5 super("screenXY", x, y, xUnits, yUnits);
6 }
7 }
+0
-8
src/org/boehn/kmlframework/overlays/Size.java less more
0 package org.boehn.kmlframework.overlays;
1
2 public class Size extends ScreenOverlayUnitsCapsule {
3
4 public Size(Double x, Double y, Units xUnits, Units yUnits) {
5 super("size", x, y, xUnits, yUnits);
6 }
7 }
+0
-5
src/org/boehn/kmlframework/overlays/Units.java less more
0 package org.boehn.kmlframework.overlays;
1
2 public enum Units {
3 fraction, pixels
4 }
+0
-154
src/org/boehn/kmlframework/servlet/HttpServletModel.java less more
0 package org.boehn.kmlframework.servlet;
1
2 import java.io.IOException;
3 import java.util.StringTokenizer;
4
5 import javax.servlet.ServletOutputStream;
6 import javax.servlet.http.HttpServletRequest;
7 import javax.servlet.http.HttpServletResponse;
8 import javax.xml.parsers.DocumentBuilderFactory;
9 import javax.xml.parsers.ParserConfigurationException;
10
11 import org.boehn.kmlframework.BoundingBox;
12 import org.boehn.kmlframework.Model;
13 import org.boehn.kmlframework.ModelElement;
14 import org.boehn.kmlframework.ModelException;
15 import org.boehn.kmlframework.ViewPosition;
16 import org.boehn.kmlframework.style.Style;
17 import org.w3c.dom.Document;
18 import org.w3c.dom.Element;
19
20 public class HttpServletModel extends Model {
21
22 private NetworkLinkControl networkLinkControl;
23 private String baseUrl;
24 private HttpServletRequest request;
25 private HttpServletResponse response;
26 private String sessionId;
27
28 public boolean DISABLEHTTPCACHE = true;
29
30 public HttpServletModel(HttpServletRequest request, HttpServletResponse response) {
31 this(request, response, true);
32 }
33
34 public HttpServletModel(HttpServletRequest request, HttpServletResponse response, boolean handleTransactions) {
35 this.request = request;
36 this.response = response;
37 if (handleTransactions) {
38 networkLinkControl = new NetworkLinkControl();
39 networkLinkControl.setCookie("jsessionid=" + request.getSession().getId());
40 }
41 }
42
43
44 public NetworkLinkControl getNetworkLinkControl() {
45 return networkLinkControl;
46 }
47
48 public void setNetworkLinkControl(NetworkLinkControl networkLinkControl) {
49 this.networkLinkControl = networkLinkControl;
50 }
51
52 public String getBaseUrl() {
53 if (baseUrl != null) {
54 return baseUrl;
55 } else {
56 return "http://" + request.getLocalName() + ":" + request.getLocalPort() + request.getContextPath();
57 }
58 }
59
60 @Override
61 public Observer getObserver() {
62 if (super.getObserver() == null && request != null) {
63 try {
64 // We try to read the parameters from the http get
65 StringTokenizer parameters = new StringTokenizer(request.getParameter("gefObserver"), ",");
66
67 BoundingBox boundingBox = new BoundingBox(Double.parseDouble(parameters.nextToken().replace(' ', '+')), Double.parseDouble(parameters.nextToken().replace(' ', '+')), Double.parseDouble(parameters.nextToken().replace(' ', '+')), Double.parseDouble(parameters.nextToken().replace(' ', '+')));
68 ViewPosition viewPosition = new ViewPosition(Double.parseDouble(parameters.nextToken().replace(' ', '+')), Double.parseDouble(parameters.nextToken().replace(' ', '+')), Double.parseDouble(parameters.nextToken().replace(' ', '+')), Double.parseDouble(parameters.nextToken().replace(' ', '+')), Double.parseDouble(parameters.nextToken().replace(' ', '+')));
69 setObserver(new Observer(boundingBox, viewPosition));
70 } catch (Exception e) {
71 //log.warn("Could not create observer because of missing information in the http get.");
72 }
73 }
74 return super.getObserver();
75 }
76
77 public void setBaseUrl(String baseUrl) {
78 this.baseUrl = baseUrl;
79 }
80
81 public HttpServletRequest getRequest() {
82 return request;
83 }
84
85 public void setRequest(HttpServletRequest request) {
86 this.request = request;
87 setObserver(null);
88 }
89
90 public HttpServletResponse getResponse() {
91 return response;
92 }
93
94 public void setResponse(HttpServletResponse response) {
95 this.response = response;
96 }
97
98 public String getSessionId() {
99 return sessionId;
100 }
101
102 public void setSessionId(String sessionId) {
103 this.sessionId = sessionId;
104 }
105
106 @Override
107 public Document generateXmlDocument() throws ModelException {
108 Document xmlDocument;
109 try {
110 xmlDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
111 } catch (ParserConfigurationException e) {
112 throw new ModelException(e);
113 }
114
115 Element kmlElement = xmlDocument.createElement("kml");
116 kmlElement.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", "http://earth.google.com/kml/2.0");
117 xmlDocument.appendChild(kmlElement);
118
119 if (networkLinkControl != null) {
120 networkLinkControl.addKml(kmlElement, this, xmlDocument);
121 }
122
123 Element documentElement = xmlDocument.createElement("Document");
124 kmlElement.appendChild(documentElement);
125
126 if (getStyles() != null) {
127 for (Style style: getStyles().values()) {
128 style.addKml(documentElement, this, xmlDocument);
129 }
130 }
131 if (getModelElements() != null) {
132 for (ModelElement modelElement: getModelElements())
133 modelElement.addKml(documentElement, this, xmlDocument);
134 }
135
136 return xmlDocument;
137 }
138
139 public void write() throws ModelException, IOException {
140 response.setContentType("text/html");
141
142 if (DISABLEHTTPCACHE) {
143 response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
144 response.setHeader("Pragma","no-cache"); //HTTP 1.0
145 response.setDateHeader ("Expires", 0);
146 }
147
148 ServletOutputStream out = response.getOutputStream();
149 this.write(out);
150 out.close();
151 }
152
153 }
+0
-204
src/org/boehn/kmlframework/servlet/NetworkLink.java less more
0 package org.boehn.kmlframework.servlet;
1
2 import java.io.IOException;
3 import java.io.Writer;
4
5 import org.boehn.kmlframework.Model;
6 import org.boehn.kmlframework.ModelElement;
7 import org.boehn.kmlframework.ModelException;
8 import org.w3c.dom.Document;
9 import org.w3c.dom.Element;
10 import org.xmlpull.v1.XmlSerializer;
11
12 public class NetworkLink implements ModelElement {
13
14 private String name;
15 private Boolean flyToView;
16 private String url;
17 private RefreshModes refreshMode;
18 private Integer refreshInterval;
19 private ViewRefreshModes viewRefreshMode;
20 private Integer viewRefreshTime;
21 private String viewFormat;
22 private Boolean refreshVisibility;
23 private Boolean open;
24
25 public NetworkLink() {
26 // We set the default values
27 viewFormat = "gefObserver=[bboxNorth],[bboxEast],[bboxSouth],[bboxWest],[lookatLat],[lookatLon],[lookatRange],[lookatTilt],[lookatHeading]";
28 refreshMode = RefreshModes.once;
29 viewRefreshMode = ViewRefreshModes.onStop;
30 viewRefreshTime = 0;
31 open = true;
32 }
33
34 public NetworkLink(String url, String name) {
35 this();
36 this.url = url;
37 this.name = name;
38 }
39
40 public Boolean getFlyToView() {
41 return flyToView;
42 }
43
44 public void setFlyToView(Boolean flyToView) {
45 this.flyToView = flyToView;
46 }
47
48 public String getName() {
49 return name;
50 }
51
52 public void setName(String name) {
53 this.name = name;
54 }
55
56 public RefreshModes getRefreshMode() {
57 return refreshMode;
58 }
59
60 public void setRefreshMode(RefreshModes refreshMode) {
61 this.refreshMode = refreshMode;
62 }
63
64 public Integer getRefreshInterval() {
65 return refreshInterval;
66 }
67
68 public void setRefreshInterval(Integer refreshInterval) {
69 this.refreshInterval = refreshInterval;
70 }
71
72 public String getUrl() {
73 return url;
74 }
75
76 public void setUrl(String url) {
77 this.url = url;
78 }
79
80 public String getViewFormat() {
81 return viewFormat;
82 }
83
84 public void setViewFormat(String viewFormat) {
85 this.viewFormat = viewFormat;
86 }
87
88 public ViewRefreshModes getViewRefreshMode() {
89 return viewRefreshMode;
90 }
91
92 public void setViewRefreshMode(ViewRefreshModes viewRefreshMode) {
93 this.viewRefreshMode = viewRefreshMode;
94 }
95
96 public Integer getViewRefreshTime() {
97 return viewRefreshTime;
98 }
99
100 public void setViewRefreshTime(Integer viewRefreshTime) {
101 this.viewRefreshTime = viewRefreshTime;
102 }
103
104 public Boolean getRefreshVisibility() {
105 return refreshVisibility;
106 }
107
108 public void setRefreshVisibility(Boolean refreshVisibility) {
109 this.refreshVisibility = refreshVisibility;
110 }
111
112 public Boolean getOpen() {
113 return open;
114 }
115
116 public void setOpen(Boolean open) {
117 this.open = open;
118 }
119
120 public static void main(String[] args) throws ModelException, IOException {
121 if (args.length != 3) {
122 System.err.println("Usage: java org.boehn.gef.elements.NetworkLink <url> <name> <destinationFile>");
123 System.exit(-1);
124 } else {
125 Model model = new Model();
126 model.add(new NetworkLink(args[0], args[1]));
127 model.write(args[2]);
128 }
129 }
130
131 public void addKml(Element parentElement, Model model, Document xmlDocument) throws ModelException {
132
133 Element networkLinkElement = xmlDocument.createElement("NetworkLink");
134
135 if (name != null) {
136 Element nameElement = xmlDocument.createElement("name");
137 nameElement.appendChild(xmlDocument.createTextNode(name));
138 networkLinkElement.appendChild(nameElement);
139 }
140
141 if (open != null) {
142 Element openElement = xmlDocument.createElement("open");
143 openElement.appendChild(xmlDocument.createTextNode((open) ? "1" : "0"));
144 networkLinkElement.appendChild(openElement);
145 }
146
147 if (flyToView != null) {
148 Element flyToViewElement = xmlDocument.createElement("flyToView");
149 flyToViewElement.appendChild(xmlDocument.createTextNode((flyToView) ? "1" : "0"));
150 networkLinkElement.appendChild(flyToViewElement);
151 }
152
153 if (refreshVisibility != null) {
154 Element refreshVisibilityElement = xmlDocument.createElement("refreshVisibility");
155 refreshVisibilityElement.appendChild(xmlDocument.createTextNode((refreshVisibility) ? "1" : "0"));
156 networkLinkElement.appendChild(refreshVisibilityElement);
157 }
158
159 if (url != null) {
160 Element urlElement = xmlDocument.createElement("Url");
161 Element hrefElement = xmlDocument.createElement("href");
162 hrefElement.appendChild(xmlDocument.createTextNode(url));
163 urlElement.appendChild(hrefElement);
164 if (refreshMode != null) {
165 Element refreshModeElement = xmlDocument.createElement("refreshMode");
166 refreshModeElement.appendChild(xmlDocument.createTextNode(refreshMode.toString()));
167 urlElement.appendChild(refreshModeElement);
168 }
169 if (refreshInterval != null) {
170 Element refreshIntervalElement = xmlDocument.createElement("refreshInterval");
171 refreshIntervalElement.appendChild(xmlDocument.createTextNode(refreshInterval.toString()));
172 urlElement.appendChild(refreshIntervalElement);
173 }
174 if (viewRefreshMode != null) {
175 Element viewRefreshModeElement = xmlDocument.createElement("viewRefreshMode");
176 viewRefreshModeElement.appendChild(xmlDocument.createTextNode(viewRefreshMode.toString()));
177 urlElement.appendChild(viewRefreshModeElement);
178 }
179 if (viewRefreshTime != null) {
180 Element viewRefreshTimeElement = xmlDocument.createElement("viewRefreshTime");
181 viewRefreshTimeElement.appendChild(xmlDocument.createTextNode(viewRefreshTime.toString()));
182 urlElement.appendChild(viewRefreshTimeElement);
183 }
184 if (viewFormat != null) {
185 Element viewFormatElement = xmlDocument.createElement("viewFormat");
186 viewFormatElement.appendChild(xmlDocument.createTextNode(viewFormat));
187 urlElement.appendChild(viewFormatElement);
188 }
189 networkLinkElement.appendChild(urlElement);
190 }
191 parentElement.appendChild(networkLinkElement);
192 }
193
194 public void addKmlXPP(Model model, XmlSerializer serializer) throws IllegalArgumentException, IllegalStateException, IOException {
195 // TODO Auto-generated method stub
196
197 }
198
199 public void addKmlDirect(Model model, Writer writer) throws IOException {
200 // TODO Auto-generated method stub
201
202 }
203 }
+0
-101
src/org/boehn/kmlframework/servlet/NetworkLinkControl.java less more
0 package org.boehn.kmlframework.servlet;
1
2 import org.boehn.kmlframework.Model;
3 import org.boehn.kmlframework.ModelException;
4 import org.w3c.dom.Document;
5 import org.w3c.dom.Element;
6
7 public class NetworkLinkControl {
8
9 private String message;
10 private String cookie;
11 private String linkName;
12 private String linkDescription;
13 private Integer minRefreshPeriod;
14
15 public NetworkLinkControl() {}
16
17 public NetworkLinkControl(String message, String cookie, String linkName, String linkDescription, Integer minRefreshPeriod) {
18 this.message = message;
19 this.cookie = cookie;
20 this.linkName = linkName;
21 this.linkDescription = linkDescription;
22 this.minRefreshPeriod = minRefreshPeriod;
23 }
24
25 public String getCookie() {
26 return cookie;
27 }
28
29 public void setCookie(String cookie) {
30 this.cookie = cookie;
31 }
32
33 public String getLinkDescription() {
34 return linkDescription;
35 }
36
37 public void setLinkDescription(String linkDescription) {
38 this.linkDescription = linkDescription;
39 }
40
41 public String getLinkName() {
42 return linkName;
43 }
44
45 public void setLinkName(String linkName) {
46 this.linkName = linkName;
47 }
48
49 public String getMessage() {
50 return message;
51 }
52
53 public void setMessage(String message) {
54 this.message = message;
55 }
56
57 public Integer getMinRefreshPeriod() {
58 return minRefreshPeriod;
59 }
60
61 public void setMinRefreshPeriod(Integer minRefreshPeriod) {
62 this.minRefreshPeriod = minRefreshPeriod;
63 }
64
65 public void addKml(Element parentElement, Model model, Document xmlDocument) throws ModelException {
66 Element networkLinkControlElement = xmlDocument.createElement("NetworkLinkControl");
67
68 if (cookie != null) {
69 Element cookieElement = xmlDocument.createElement("cookie");
70 cookieElement.appendChild(xmlDocument.createCDATASection(cookie));
71 networkLinkControlElement.appendChild(cookieElement);
72 }
73
74 if (linkDescription != null) {
75 Element linkDescriptionElement = xmlDocument.createElement("linkDescription");
76 linkDescriptionElement.appendChild(xmlDocument.createCDATASection(linkDescription));
77 networkLinkControlElement.appendChild(linkDescriptionElement);
78 }
79
80 if (linkName != null) {
81 Element linkNameElement = xmlDocument.createElement("linkName");
82 linkNameElement.appendChild(xmlDocument.createCDATASection(linkName));
83 networkLinkControlElement.appendChild(linkNameElement);
84 }
85
86 if (message != null) {
87 Element messageElement = xmlDocument.createElement("message");
88 messageElement.appendChild(xmlDocument.createCDATASection(message));
89 networkLinkControlElement.appendChild(messageElement);
90 }
91
92 if (minRefreshPeriod != null) {
93 Element minRefreshPeriodElement = xmlDocument.createElement("minRefreshPeriod");
94 minRefreshPeriodElement.appendChild(xmlDocument.createTextNode(minRefreshPeriod.toString()));
95 networkLinkControlElement.appendChild(minRefreshPeriodElement);
96 }
97 parentElement.appendChild(networkLinkControlElement);
98 }
99
100 }
+0
-90
src/org/boehn/kmlframework/servlet/Observer.java less more
0 package org.boehn.kmlframework.servlet;
1
2 import org.boehn.kmlframework.BoundingBox;
3 import org.boehn.kmlframework.ViewPosition;
4 import org.boehn.kmlframework.coordinates.CartesianCoordinate;
5 import org.boehn.kmlframework.coordinates.EarthCoordinate;
6
7 public class Observer {
8
9 private BoundingBox boundingBox;
10 private ViewPosition viewPosition;
11 private CartesianCoordinate observerCoordinate;
12
13 public Observer() {}
14
15 public Observer(BoundingBox boundingBox, ViewPosition viewPosition) {
16 this.boundingBox = boundingBox;
17 this.viewPosition = viewPosition;
18 }
19
20 public Boolean isVisibleToObserver(EarthCoordinate earthCoordinate) {
21 if (boundingBox != null) {
22 return boundingBox.isInsideBoundingBox(earthCoordinate);
23 } else {
24 return null;
25 }
26 }
27
28 public Double distanceTo(EarthCoordinate earthCoordinate) {
29 if (earthCoordinate != null) {
30 return distanceTo(earthCoordinate.toCartesianCoordinate());
31 } else {
32 return null;
33 }
34 }
35
36 public Double distanceTo(CartesianCoordinate cartesianCoordinate) {
37 if (cartesianCoordinate != null) {
38 return getObserverCoordinate().distanceTo(cartesianCoordinate);
39 } else {
40 return null;
41 }
42 }
43
44 public CartesianCoordinate getObserverCoordinate() {
45 if (observerCoordinate == null) {
46
47 if (viewPosition != null && viewPosition.getRange() != null && viewPosition.getTilt() != null && viewPosition.getHeading() != null) {
48 // We make the vector starting in 0,0,0 and going straight up with the length = lookAtRange
49 observerCoordinate = new CartesianCoordinate(0, 0, viewPosition.getRange());
50
51 // We rotate the vector around the Z axis to get the correct tilt
52 observerCoordinate.rotateAroundZAxis(viewPosition.getTilt());
53
54 // We rotate the vector around the Y axis to get the correct heading
55 observerCoordinate.rotateAroundYAxis(viewPosition.getHeading());
56
57 // Now we have our vector finish in the local coordinate system. Now we have to place it out on the earth
58
59 // First we have to rotate our local coordinate system to the surface of the earth
60 observerCoordinate.rotateAroundZAxis(Math.toRadians(viewPosition.getLatitude()));
61 observerCoordinate.rotateAroundYAxis(Math.toRadians(viewPosition.getLongitude()));
62
63 // Now our vector has the correct length and direction. We only have to place it out at the lookAt coordinate
64 observerCoordinate.add(new EarthCoordinate(viewPosition.getLatitude(), viewPosition.getLongitude()).toCartesianCoordinate());
65 } else {
66 System.out.println("The observer coordinate is being requested, but the observer has not defined sufficient data for calculating this.");
67 }
68 }
69 return observerCoordinate;
70 }
71
72 public BoundingBox getBoundingBox() {
73 return boundingBox;
74 }
75
76 public void setBoundingBox(BoundingBox boundingBox) {
77 this.boundingBox = boundingBox;
78 }
79
80 public void setViewPosition(ViewPosition viewPosition) {
81 this.viewPosition = viewPosition;
82 observerCoordinate = null;
83 }
84
85 public ViewPosition getViewPosition() {
86 return viewPosition;
87 }
88
89 }
+0
-5
src/org/boehn/kmlframework/servlet/RefreshModes.java less more
0 package org.boehn.kmlframework.servlet;
1
2 public enum RefreshModes {
3 onInterval, once
4 }
+0
-5
src/org/boehn/kmlframework/servlet/ViewRefreshModes.java less more
0 package org.boehn.kmlframework.servlet;
1
2 public enum ViewRefreshModes {
3 never, onStop, onRequest
4 }
+0
-44
src/org/boehn/kmlframework/servlet/kmz/KmzFilter.java less more
0 package org.boehn.kmlframework.servlet.kmz;
1
2 import java.io.IOException;
3 import javax.servlet.Filter;
4 import javax.servlet.FilterChain;
5 import javax.servlet.FilterConfig;
6 import javax.servlet.ServletException;
7 import javax.servlet.ServletRequest;
8 import javax.servlet.ServletResponse;
9 import javax.servlet.http.HttpServletRequest;
10 import javax.servlet.http.HttpServletResponse;
11
12
13 public class KmzFilter implements Filter {
14
15 public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
16 if (req instanceof HttpServletRequest) {
17 HttpServletRequest request = (HttpServletRequest) req;
18 HttpServletResponse response = (HttpServletResponse) res;
19
20 String servletPath = request.getServletPath();
21 String kmlFileName="";
22 int extension = servletPath.indexOf(".");
23 if (extension >= 0) {
24 // strip extension so that kmz contains a file ending in kml
25 kmlFileName = servletPath.substring(1, extension) + ".kml";
26 }
27 KmzResponseWrapper wrappedResponse =
28 new KmzResponseWrapper(response);
29 wrappedResponse.setKMLFileName(kmlFileName);
30 chain.doFilter(req, wrappedResponse);
31 wrappedResponse.finishResponse();
32 return;
33 }
34 }
35
36 public void init(FilterConfig filterConfig) {
37 // Nothing to do here
38 }
39
40 public void destroy() {
41 // Nothing to do here
42 }
43 }
+0
-135
src/org/boehn/kmlframework/servlet/kmz/KmzResponseStream.java less more
0 package org.boehn.kmlframework.servlet.kmz;
1
2 import java.io.IOException;
3 import java.util.zip.ZipEntry;
4 import java.util.zip.ZipOutputStream;
5 import javax.servlet.ServletOutputStream;
6 import javax.servlet.http.HttpServletResponse;
7
8 public class KmzResponseStream extends ServletOutputStream {
9
10 protected ZipOutputStream zipstream = null;
11 protected boolean closed = false;
12 protected HttpServletResponse response = null;
13 protected ServletOutputStream output = null;
14 private String kmlFileName="index.kml";
15
16 protected int bufferCount = 0;
17 protected byte[] buffer = null;
18 protected int length = -1;
19
20
21 public KmzResponseStream(HttpServletResponse response) throws IOException {
22 super();
23 closed = false;
24 this.response = response;
25 this.output = response.getOutputStream();
26 buffer = new byte[128];
27 }
28
29 public void setKMLFileName(String kml){
30 kmlFileName = kml;
31 }
32
33 public void close() throws IOException {
34 if (closed) {
35 throw new IOException("This output stream has already been closed");
36 }
37
38 if (zipstream!=null) {
39 flushToZip();
40 zipstream.close();
41 zipstream = null;
42 } else {
43 if (bufferCount>0) {
44 output.write(buffer, 0, bufferCount);
45 bufferCount=0;
46 }
47 }
48
49 output.close();
50 closed = true;
51 }
52
53 public void flush() throws IOException {
54 if (closed) {
55 throw new IOException("Cannot flush a closed output stream");
56 }
57
58 if (zipstream != null) {
59 zipstream.flush();
60 }
61 }
62
63 public void flushToZip() throws IOException {
64 if (bufferCount > 0) {
65 writeToZip(buffer, 0, bufferCount);
66 bufferCount = 0;
67 }
68 }
69
70
71 public void write(int b) throws IOException {
72 if (closed) {
73 throw new IOException("Cannot write to a closed output stream");
74 }
75 if (bufferCount >= buffer.length) {
76 flushToZip();
77 }
78 buffer[bufferCount++] = (byte) b;
79 }
80
81 public void write(byte b[]) throws IOException {
82 write(b, 0, b.length);
83 }
84
85 public void write(byte b[], int off, int len) throws IOException {
86 if (closed) {
87 throw new IOException("Cannot write to a closed output stream");
88 }
89
90 if (len == 0)
91 return;
92
93 // Can we write into buffer ?
94 if (len <= (buffer.length - bufferCount)) {
95 System.arraycopy(b, off, buffer, bufferCount, len);
96 bufferCount += len;
97 return;
98 }
99
100 // There is not enough space in buffer. Flush it ...
101 flushToZip();
102
103 // ... and try again. Note, that bufferCount = 0 here !
104 if (len <= (buffer.length - bufferCount)) {
105 System.arraycopy(b, off, buffer, bufferCount, len);
106 bufferCount += len;
107 return;
108 }
109
110 // write direct to zip
111 writeToZip(b, off, len);
112 }
113
114 public void writeToZip(byte b[], int off, int len) throws IOException {
115
116 if (zipstream == null) {
117 //System.out.println("Content-Length: " + Integer.toString(b.length));
118 //response.setContentLength(b.length);
119 response.setContentType("application/vnd.google-earth.kmzl; charset=UTF-8");
120 zipstream = new ZipOutputStream(output);
121 zipstream.putNextEntry(new ZipEntry(kmlFileName));
122 }
123 zipstream.write(b, off, len);
124 }
125
126
127 public boolean closed() {
128 return (this.closed);
129 }
130
131 public void reset() {
132 // Nothing to do here
133 }
134 }
+0
-72
src/org/boehn/kmlframework/servlet/kmz/KmzResponseWrapper.java less more
0 package org.boehn.kmlframework.servlet.kmz;
1
2 import java.io.IOException;
3 import java.io.OutputStreamWriter;
4 import java.io.PrintWriter;
5 import javax.servlet.ServletOutputStream;
6 import javax.servlet.http.HttpServletResponse;
7 import javax.servlet.http.HttpServletResponseWrapper;
8
9 public class KmzResponseWrapper extends HttpServletResponseWrapper {
10 protected HttpServletResponse origResponse = null;
11 protected ServletOutputStream stream = null;
12 protected PrintWriter writer = null;
13 private String kmlFileName="index.kml";
14
15 public KmzResponseWrapper(HttpServletResponse response) {
16 super(response);
17 origResponse = response;
18 }
19
20 public ServletOutputStream createOutputStream() throws IOException {
21 KmzResponseStream krs = new KmzResponseStream(origResponse);
22 krs.setKMLFileName(kmlFileName);
23 return (krs);
24 }
25
26 public void setKMLFileName(String kml) {
27 kmlFileName = kml;
28 }
29
30 public void finishResponse() {
31 try {
32 if (writer != null) {
33 writer.close();
34 } else {
35 if (stream != null) {
36 stream.close();
37 }
38 }
39 } catch (IOException e) {}
40 }
41
42 public void flushBuffer() throws IOException {
43 stream.flush();
44 }
45
46 public ServletOutputStream getOutputStream() throws IOException {
47 if (writer != null) {
48 throw new IllegalStateException("getWriter() has already been called!");
49 }
50
51 if (stream == null)
52 stream = createOutputStream();
53 return (stream);
54 }
55
56 public PrintWriter getWriter() throws IOException {
57 if (writer != null) {
58 return (writer);
59 }
60
61 if (stream != null) {
62 throw new IllegalStateException("getOutputStream() has already been called!");
63 }
64
65 stream = createOutputStream();
66 writer = new PrintWriter(new OutputStreamWriter(stream, "UTF-8"));
67 return (writer);
68 }
69
70 public void setContentLength(int length) {}
71 }
+0
-105
src/org/boehn/kmlframework/style/Color.java less more
0 package org.boehn.kmlframework.style;
1
2 public class Color {
3
4 private int r;
5 private int g;
6 private int b;
7 private int alpha;
8
9 public static Color black = new Color(0, 0, 0);
10 public static Color blue = new Color(0, 0, 255);
11 public static Color cyan = new Color(0, 173, 239);
12 public static Color darkGrey = new Color(64, 64, 64);
13 public static Color gray = new Color(128, 128, 128);
14 public static Color green = new Color(0, 255, 0);
15 public static Color lightGray = new Color(191, 191, 191);
16 public static Color magenta = new Color(255, 0, 255);
17 public static Color orange = new Color(255, 127, 0);
18 public static Color pink = new Color(255, 127, 255);
19 public static Color red = new Color(255, 0, 0);
20 public static Color white = new Color(255, 255, 255);
21 public static Color yellow = new Color(255, 255, 0);
22
23 public Color() {}
24
25 public Color(int red, int green, int blue) {
26 this(red, green, blue, 255);
27 }
28
29 public Color(int red, int green, int blue, int alpha) {
30 setRed(red);
31 setGreen(green);
32 setBlue(blue);
33 setAlpha(alpha);
34 }
35
36 public int getAlpha() {
37 return alpha;
38 }
39
40 public void setAlpha(int alpha) {
41 verifyValue(alpha);
42 this.alpha = alpha;
43 }
44
45 public int getBlue() {
46 return b;
47 }
48
49 public void setBlue(int blue) {
50 verifyValue(blue);
51 this.b = blue;
52 }
53
54 public int getGreen() {
55 return g;
56 }
57
58 public void setGreen(int green) {
59 verifyValue(green);
60 this.g = green;
61 }
62
63 public int getRed() {
64 return r;
65 }
66
67 public void setRed(int red) {
68 verifyValue(red);
69 this.r = red;
70 }
71
72 public String toHexString() {
73 String result = "";
74
75 if (alpha < 16) {
76 result += "0";
77 }
78 result += Integer.toHexString(alpha);
79
80 if (b < 16) {
81 result += "0";
82 }
83 result += Integer.toHexString(b);
84
85 if (g < 16) {
86 result += "0";
87 }
88 result += Integer.toHexString(g);
89
90 if (r < 16) {
91 result += "0";
92 }
93 result += Integer.toHexString(r);
94
95 return result;
96 }
97
98 private static void verifyValue(int value) {
99 if (value < 0 || value > 255) {
100 throw new IllegalArgumentException("Value must be in the range (0 - 255). " + value + " is not valid.");
101 }
102 }
103
104 }
+0
-5
src/org/boehn/kmlframework/style/ColorModes.java less more
0 package org.boehn.kmlframework.style;
1
2 public enum ColorModes {
3 normal, random
4 }
+0
-317
src/org/boehn/kmlframework/style/Style.java less more
0 package org.boehn.kmlframework.style;
1
2 import org.boehn.kmlframework.Model;
3 import org.boehn.kmlframework.ModelException;
4 import org.boehn.kmlframework.overlays.Icon;
5 import org.w3c.dom.Document;
6 import org.w3c.dom.Element;
7
8 public class Style {
9
10 private String id;
11 private Color balloonTextColor;
12 private String balloonText;
13 private Color balloonColor;
14 private Color iconColor;
15 private ColorModes iconColorMode;
16 private Double iconHeading;
17 private Icon icon;
18 private Double iconScale;
19 private Color labelColor;
20 private ColorModes labelColorMode;
21 private Double labelScale;
22 private Color lineColor;
23 private ColorModes lineColorMode;
24 private Integer lineWidth;
25 private Color polygonColor;
26 private ColorModes polygonColorMode;
27 private Boolean polygonFill;
28 private Boolean polygonOutline;
29
30 public Style() {
31 }
32
33 public Style(String id) {
34 this.id = id;
35 }
36
37 public void addKml(Element parentElement, Model model, Document xmlDocument) throws ModelException {
38
39 Element styleElement = xmlDocument.createElement("Style");
40
41 if (id != null) {
42 styleElement.setAttribute("id", id);
43 }
44
45 // We check if a balloon style should be added
46 if (balloonText != null || balloonColor != null || balloonTextColor != null) {
47 Element balloonStyleElement = xmlDocument.createElement("BalloonStyle");
48 if (balloonText != null) {
49 Element ballonTextElement = xmlDocument.createElement("text");
50 ballonTextElement.appendChild(xmlDocument.createTextNode(balloonText));
51 balloonStyleElement.appendChild(ballonTextElement);
52 }
53 if (balloonTextColor != null) {
54 Element ballonTextColorElement = xmlDocument.createElement("textColor");
55 ballonTextColorElement.appendChild(xmlDocument.createTextNode(balloonTextColor.toHexString()));
56 balloonStyleElement.appendChild(ballonTextColorElement);
57 }
58 if (balloonColor != null) {
59 Element ballonColorElement = xmlDocument.createElement("color");
60 ballonColorElement.appendChild(xmlDocument.createTextNode(balloonColor.toHexString()));
61 balloonStyleElement.appendChild(ballonColorElement);
62 }
63 styleElement.appendChild(balloonStyleElement);
64 }
65
66 // We check if an icon style should be added (icon is required for this to be added)
67 if (icon != null) {
68 Element iconStyleElement = xmlDocument.createElement("IconStyle");
69 if (iconColor != null) {
70 Element iconColorElement = xmlDocument.createElement("color");
71 iconColorElement.appendChild(xmlDocument.createTextNode(iconColor.toHexString()));
72 iconStyleElement.appendChild(iconColorElement);
73 }
74 if (iconColorMode != null) {
75 Element iconColorModeElement = xmlDocument.createElement("colorMode");
76 iconColorModeElement.appendChild(xmlDocument.createTextNode(iconColorMode.toString()));
77 iconStyleElement.appendChild(iconColorModeElement);
78 }
79 if (iconHeading != null) {
80 Element iconHeadingElement = xmlDocument.createElement("heading");
81 iconHeadingElement.appendChild(xmlDocument.createTextNode(iconHeading.toString()));
82 iconStyleElement.appendChild(iconHeadingElement);
83 }
84 icon.addKml(iconStyleElement, model, xmlDocument);
85 if (iconScale != null) {
86 Element iconScaleElement = xmlDocument.createElement("scale");
87 iconScaleElement.appendChild(xmlDocument.createTextNode(iconScale.toString()));
88 iconStyleElement.appendChild(iconScaleElement);
89 }
90 styleElement.appendChild(iconStyleElement);
91 }
92
93 // We check if a label style should be added
94 if (labelColor != null || labelColorMode != null || labelScale != null) {
95 Element labelStyleElement = xmlDocument.createElement("LabelStyle");
96 if (labelColor != null) {
97 Element labelColorElement = xmlDocument.createElement("color");
98 labelColorElement.appendChild(xmlDocument.createTextNode(labelColor.toHexString()));
99 labelStyleElement.appendChild(labelColorElement);
100 }
101 if (labelColorMode != null) {
102 Element labelColorModeElement = xmlDocument.createElement("colorMode");
103 labelColorModeElement.appendChild(xmlDocument.createTextNode(labelColorMode.toString()));
104 labelStyleElement.appendChild(labelColorModeElement);
105 }
106 if (labelScale != null) {
107 Element labelScaleElement = xmlDocument.createElement("scale");
108 labelScaleElement.appendChild(xmlDocument.createTextNode(labelScale.toString()));
109 labelStyleElement.appendChild(labelScaleElement);
110 }
111 styleElement.appendChild(labelStyleElement);
112 }
113
114 // We check if a line style should be added
115 if (lineColor != null || lineColorMode != null || lineWidth != null) {
116 Element lineStyleElement = xmlDocument.createElement("LineStyle");
117 if (lineColor != null) {
118 Element lineColorElement = xmlDocument.createElement("color");
119 lineColorElement.appendChild(xmlDocument.createTextNode(lineColor.toHexString()));
120 lineStyleElement.appendChild(lineColorElement);
121 }
122 if (lineColorMode != null) {
123 Element lineColorModeElement = xmlDocument.createElement("colorMode");
124 lineColorModeElement.appendChild(xmlDocument.createTextNode(lineColorMode.toString()));
125 lineStyleElement.appendChild(lineColorModeElement);
126 }
127 if (lineWidth != null) {
128 Element lineWidthElement = xmlDocument.createElement("width");
129 lineWidthElement.appendChild(xmlDocument.createTextNode(lineWidth.toString()));
130 lineStyleElement.appendChild(lineWidthElement);
131 }
132 styleElement.appendChild(lineStyleElement);
133 }
134
135 // We check if a poly style should be added
136 if (polygonColor != null || polygonColorMode != null || polygonFill != null || polygonOutline != null) {
137 Element polyStyleElement = xmlDocument.createElement("PolyStyle");
138 if (polygonColor != null) {
139 Element polygonColorElement = xmlDocument.createElement("color");
140 polygonColorElement.appendChild(xmlDocument.createTextNode(polygonColor.toHexString()));
141 polyStyleElement.appendChild(polygonColorElement);
142 }
143 if (polygonColorMode != null) {
144 Element polygonColorModeElement = xmlDocument.createElement("colorMode");
145 polygonColorModeElement.appendChild(xmlDocument.createTextNode(polygonColorMode.toString()));
146 polyStyleElement.appendChild(polygonColorModeElement);
147 }
148 if (polygonFill != null) {
149 Element polygonFillElement = xmlDocument.createElement("fill");
150 polygonFillElement.appendChild(xmlDocument.createTextNode((polygonFill? "1" : "0")));
151 polyStyleElement.appendChild(polygonFillElement);
152 }
153 if (polygonOutline != null) {
154 Element polygonOutlineElement = xmlDocument.createElement("outline");
155 polygonOutlineElement.appendChild(xmlDocument.createTextNode((polygonOutline? "1" : "0")));
156 polyStyleElement.appendChild(polygonOutlineElement);
157 }
158 styleElement.appendChild(polyStyleElement);
159 }
160
161 parentElement.appendChild(styleElement);
162 }
163
164 public Color getBalloonColor() {
165 return balloonColor;
166 }
167
168 public void setBalloonColor(Color balloonColor) {
169 this.balloonColor = balloonColor;
170 }
171
172 public String getBalloonText() {
173 return balloonText;
174 }
175
176 public void setBalloonText(String balloonText) {
177 this.balloonText = balloonText;
178 }
179
180 public Icon getIcon() {
181 return icon;
182 }
183
184 public void setIcon(Icon icon) {
185 this.icon = icon;
186 }
187
188 public Color getIconColor() {
189 return iconColor;
190 }
191
192 public void setIconColor(Color iconColor) {
193 this.iconColor = iconColor;
194 }
195
196 public ColorModes getIconColorMode() {
197 return iconColorMode;
198 }
199
200 public void setIconColorMode(ColorModes iconColorMode) {
201 this.iconColorMode = iconColorMode;
202 }
203
204 public Double getIconHeading() {
205 return iconHeading;
206 }
207
208 public void setIconHeading(Double iconHeading) {
209 this.iconHeading = iconHeading;
210 }
211
212 public Double getIconScale() {
213 return iconScale;
214 }
215
216 public void setIconScale(Double iconScale) {
217 this.iconScale = iconScale;
218 }
219
220 public String getId() {
221 return id;
222 }
223
224 public void setId(String id) {
225 this.id = id;
226 }
227
228 public Color getLabelColor() {
229 return labelColor;
230 }
231
232 public void setLabelColor(Color labelColor) {
233 this.labelColor = labelColor;
234 }
235
236 public ColorModes getLabelColorMode() {
237 return labelColorMode;
238 }
239
240 public void setLabelColorMode(ColorModes labelColorMode) {
241 this.labelColorMode = labelColorMode;
242 }
243
244 public Double getLabelScale() {
245 return labelScale;
246 }
247
248 public void setLabelScale(Double labelScale) {
249 this.labelScale = labelScale;
250 }
251
252 public Color getLineColor() {
253 return lineColor;
254 }
255
256 public void setLineColor(Color lineColor) {
257 this.lineColor = lineColor;
258 }
259
260 public ColorModes getLineColorMode() {
261 return lineColorMode;
262 }
263
264 public void setLineColorMode(ColorModes lineColorMode) {
265 this.lineColorMode = lineColorMode;
266 }
267
268 public Integer getLineWidth() {
269 return lineWidth;
270 }
271
272 public void setLineWidth(Integer lineWidth) {
273 this.lineWidth = lineWidth;
274 }
275
276 public Color getPolygonColor() {
277 return polygonColor;
278 }
279
280 public void setPolygonColor(Color polygonColor) {
281 this.polygonColor = polygonColor;
282 }
283
284 public ColorModes getPolygonColorMode() {
285 return polygonColorMode;
286 }
287
288 public void setPolygonColorMode(ColorModes polygonColorMode) {
289 this.polygonColorMode = polygonColorMode;
290 }
291
292 public Boolean getPolygonFill() {
293 return polygonFill;
294 }
295
296 public void setPolygonFill(Boolean polygonFill) {
297 this.polygonFill = polygonFill;
298 }
299
300 public Boolean getPolygonOutline() {
301 return polygonOutline;
302 }
303
304 public void setPolygonOutline(Boolean polygonOutline) {
305 this.polygonOutline = polygonOutline;
306 }
307
308 public Color getBalloonTextColor() {
309 return balloonTextColor;
310 }
311
312 public void setBalloonTextColor(Color textColor) {
313 this.balloonTextColor = textColor;
314 }
315
316 }
0 package org.boehn.kmlframework.todo;
1
2 import org.boehn.kmlframework.todo.coordinates.EarthCoordinate;
3
4 public class BoundingBox {
5
6 private Double north;
7 private Double east;
8 private Double south;
9 private Double west;
10
11 public BoundingBox() {}
12
13 public BoundingBox(Double north, Double east, Double south, Double west) {
14 this.north = north;
15 this.east = east;
16 this.south = south;
17 this.west = west;
18 }
19
20 public boolean isInsideBoundingBox(EarthCoordinate earthCoordinate) {
21 return earthCoordinate.getLatitude() < north && earthCoordinate.getLatitude() > south && earthCoordinate.getLongitude() > west && earthCoordinate.getLongitude() < east;
22 }
23
24 public Double getEast() {
25 return east;
26 }
27
28 public void setEast(Double east) {
29 this.east = east;
30 }
31
32 public Double getNorth() {
33 return north;
34 }
35
36 public void setNorth(Double north) {
37 this.north = north;
38 }
39
40 public Double getSouth() {
41 return south;
42 }
43
44 public void setSouth(Double south) {
45 this.south = south;
46 }
47
48 public Double getWest() {
49 return west;
50 }
51
52 public void setWest(Double west) {
53 this.west = west;
54 }
55
56 }
0 package org.boehn.kmlframework.todo;
1
2 import java.io.UnsupportedEncodingException;
3 import java.net.URLEncoder;
4 import java.util.HashMap;
5 import java.util.Map;
6
7 import javax.servlet.http.HttpServletRequest;
8
9 import org.boehn.kmlframework.KmlDocument;
10 import org.boehn.kmlframework.todo.servlet.HttpServletModel;
11
12
13 public class Button {
14
15 private String url;
16 private String text;
17 private Map<String, String> parameters;
18
19 public Button() {
20 }
21
22 public Button(String text, String url) {
23 this.text = text;
24 this.url = url;
25 }
26
27 public Button(String text, String url, String parameterName, String parameterValue) {
28 this(text, url);
29 addParameter(parameterName, parameterValue);
30 }
31
32 public Button(String text, String url, Map<String, String> parameters) {
33 this(text, url);
34 this.parameters = parameters;
35 }
36
37 public void addParameter(String parameterName, String parameterValue) {
38 if (parameters == null) {
39 parameters = new HashMap<String, String>();
40 }
41 parameters.put(parameterName, parameterValue);
42 }
43
44 public String getText() {
45 return text;
46 }
47
48 public void setText(String text) {
49 this.text = text;
50 }
51
52 public Map<String, String> getParameters() {
53 return parameters;
54 }
55
56 public void setParameters(Map<String, String> parameters) {
57 this.parameters = parameters;
58 }
59
60 public String toHtml(KmlDocument model) {
61 try {
62 StringBuffer html = new StringBuffer();
63 StringBuffer urlToUse;
64 if (url.startsWith("http://")) {
65 urlToUse = new StringBuffer(url);
66 } else {
67 // The url is not absolute. We need info from the HttpServletModel
68 if (model instanceof HttpServletModel) {
69 HttpServletModel httpServleModel = (HttpServletModel) model;
70 urlToUse = new StringBuffer(encodeURL(httpServleModel.getBaseUrl() + url, httpServleModel.getRequest()));
71 } else {
72 throw new IllegalArgumentException("Button has an url that is not absolute (does not starts with 'http://'). Then the model must be an instance of the HttpServletModel class.");
73 }
74 }
75 if (parameters != null) {
76 urlToUse.append("?");
77 for (Object key: parameters.keySet()) {
78 urlToUse.append("&" + URLEncoder.encode(key.toString(), "UTF-8") + "=" + URLEncoder.encode(parameters.get(key).toString(), "UTF-8"));
79 }
80 }
81 html.append("<a href=\"" + urlToUse.toString() + "\">" + text + "</a>");
82 return html.toString();
83 } catch (UnsupportedEncodingException e) {
84 throw new RuntimeException(e);
85 }
86 }
87
88 public String encodeURL(String url, HttpServletRequest request) {
89 // TODO This method should not be necessarily. There is a method for doing this in the HttpServletResponse.
90 // At the moment that method is not doing the encoding. No idea why. It used to work...
91 int indexQuestionMark = url.indexOf("?");
92 if (indexQuestionMark < 0) {
93 return url + ";jsessionid=" + request.getSession().getId();
94 } else {
95 return url.substring(0, indexQuestionMark) + ";jsessionid=" + request.getSession().getId() + url.substring(indexQuestionMark);
96 }
97 }
98
99 public String getUrl() {
100 return url;
101 }
102
103 public void setUrl(String url) {
104 this.url = url;
105 }
106
107 }
0 package org.boehn.kmlframework.todo;
1
2 import java.util.ArrayList;
3 import java.util.Collection;
4
5 import org.boehn.kmlframework.KmlDocument;
6 import org.boehn.kmlframework.KmlException;
7 import org.boehn.kmlframework.todo.coordinates.CartesianCoordinate;
8 import org.boehn.kmlframework.todo.coordinates.Coordinate;
9 import org.boehn.kmlframework.todo.coordinates.EarthCoordinate;
10 import org.w3c.dom.Document;
11 import org.w3c.dom.Element;
12
13 public class GraphicalModel implements GraphicalModelElement {
14
15 private Collection<GraphicalModelElement> elements;
16 private Integer visibleFrom;
17 private Integer visibleTo;
18
19 public GraphicalModel() {}
20
21 public Collection<GraphicalModelElement> getElements() {
22 return elements;
23 }
24
25 public void setElements(Collection<GraphicalModelElement> elements) {
26 this.elements = elements;
27 }
28
29 public void addGraphicalModelElement(GraphicalModelElement graphicalModelElement) {
30 if (elements == null) {
31 elements = new ArrayList<GraphicalModelElement>();
32 }
33 elements.add(graphicalModelElement);
34 }
35
36 public Integer getVisibleFrom() {
37 return visibleFrom;
38 }
39
40 public void setVisibleFrom(Integer visibleFrom) {
41 this.visibleFrom = visibleFrom;
42 }
43
44 public Integer getVisibleTo() {
45 return visibleTo;
46 }
47
48 public void setVisibleTo(Integer visibleTo) {
49 this.visibleTo = visibleTo;
50 }
51
52 public Collection<Coordinate> getCoordinates() {
53 Collection<Coordinate> coordinates = new ArrayList<Coordinate>();
54 for (GraphicalModelElement element : elements) {
55 coordinates.addAll(element.getCoordinates());
56 }
57 return coordinates;
58 }
59
60 public void addKml(Element parentElement, KmlDocument model, Document xmlDocument, EarthCoordinate location, Double rotation, CartesianCoordinate localReferenceCoordinate, CartesianCoordinate scale) throws KmlException {
61 if (elements != null) {
62 for (GraphicalModelElement element : elements) {
63 element.addKml(parentElement, model, xmlDocument, location, rotation, localReferenceCoordinate, scale);
64 }
65 }
66 }
67
68 public String toString() {
69 StringBuffer text = new StringBuffer("GraphicalModel:\n");
70 text.append(" visibleFrom: " + visibleFrom + "\n");
71 text.append(" visibleTo: " + visibleTo + "\n");
72 text.append(" elements: " + elements);
73 return text.toString();
74 }
75
76 }
0 package org.boehn.kmlframework.todo;
1
2 import java.util.Collection;
3
4 import org.boehn.kmlframework.KmlDocument;
5 import org.boehn.kmlframework.KmlException;
6 import org.boehn.kmlframework.todo.coordinates.CartesianCoordinate;
7 import org.boehn.kmlframework.todo.coordinates.Coordinate;
8 import org.boehn.kmlframework.todo.coordinates.EarthCoordinate;
9 import org.w3c.dom.Document;
10 import org.w3c.dom.Element;
11
12 public interface GraphicalModelElement {
13
14 public Collection<Coordinate> getCoordinates();
15 public void addKml(Element parentElement, KmlDocument model, Document xmlDocument, EarthCoordinate earthCoordinate, Double rotation, CartesianCoordinate localReferenceCoordinate, CartesianCoordinate scale) throws KmlException;
16
17 }
0 package org.boehn.kmlframework.todo;
1
2 import java.io.IOException;
3 import java.io.PrintWriter;
4 import java.io.Writer;
5 import java.util.ArrayList;
6 import java.util.List;
7
8 import org.boehn.kmlframework.KmlDocument;
9 import org.boehn.kmlframework.KmlException;
10 import org.boehn.kmlframework.todo.coordinates.CartesianCoordinate;
11 import org.boehn.kmlframework.todo.coordinates.EarthCoordinate;
12 import org.boehn.kmlframework.todo.coordinates.TimeAndPlace;
13 import org.w3c.dom.Document;
14 import org.w3c.dom.Element;
15 //import org.xmlpull.v1.XmlSerializer;
16
17 public class MapObject /*implements KmlDocumentElement*/ {
18
19 private String name;
20 private String description;
21 private EarthCoordinate location;
22 private MapObjectClass mapObjectClass;
23 private List<Button> buttons;
24 private List<TimeAndPlace> movements;
25 private String snippet;
26 private Boolean visibility;
27
28 private Double rotation;
29 private CartesianCoordinate localReferenceCoordinate;
30 private CartesianCoordinate scale;
31
32 public MapObject() {}
33
34 public MapObject(String name) {
35 this.name = name;
36 }
37
38 public MapObject(MapObjectClass mapObjectClass) {
39 this.mapObjectClass = mapObjectClass;
40 }
41
42 public MapObject(String name, MapObjectClass mapObjectClass) {
43 this.name = name;
44 this.mapObjectClass = mapObjectClass;
45 }
46
47 public MapObjectClass getMapObjectClass() {
48 return mapObjectClass;
49 }
50
51 public void setMapObjectClass(MapObjectClass mapObjectClass) {
52 this.mapObjectClass = mapObjectClass;
53 }
54
55 public CartesianCoordinate getLocalReferenceCoordinate() {
56 return localReferenceCoordinate;
57 }
58
59 public void setLocalReferenceCoordinate(
60 CartesianCoordinate localReferenceCoordinate) {
61 this.localReferenceCoordinate = localReferenceCoordinate;
62 }
63
64 public Double getRotation() {
65 return rotation;
66 }
67
68 public void setRotation(Double rotation) {
69 this.rotation = rotation;
70 }
71
72 public CartesianCoordinate getScale() {
73 return scale;
74 }
75
76 public void setScale(CartesianCoordinate scale) {
77 this.scale = scale;
78 }
79
80 public Boolean getVisibility() {
81 return visibility;
82 }
83
84 public void setVisibility(Boolean visibility) {
85 this.visibility = visibility;
86 }
87
88 public void setButtons(List<Button> buttons) {
89 this.buttons = buttons;
90 }
91
92 public void addButton(Button button) {
93 if (buttons == null) {
94 buttons = new ArrayList<Button>();
95 }
96 buttons.add(button);
97 }
98
99 public void addButtons(List<Button> buttons) {
100 if (this.buttons == null) {
101 this.buttons = buttons;
102 } else {
103 this.buttons.addAll(buttons);
104 }
105 }
106
107 public String getDescription() {
108 return description;
109 }
110
111 public void setDescription(String description) {
112 this.description = description;
113 }
114
115 public String getDescriptionTextWithButtons(KmlDocument model) {
116 StringBuffer result = new StringBuffer();
117 if (buttons != null) {
118 for (Button button : buttons) {
119 result.append(button.toHtml(model) + "<br />");
120 }
121 }
122 if (description != null) {
123 result.append(description);
124 }
125
126 return (result.length() == 0) ? null : result.toString();
127 }
128
129 public EarthCoordinate getLocation() {
130 return location;
131 }
132
133 public void setLocation(EarthCoordinate earthCoordinate) {
134 this.location = earthCoordinate;
135 }
136
137 public String getName() {
138 return name;
139 }
140
141 public void setName(String name) {
142 this.name = name;
143 }
144
145 public String getSnippet() {
146 return snippet;
147 }
148
149 public void setSnippet(String snippet) {
150 this.snippet = snippet;
151 }
152
153 public void addKml(KmlDocument kmlDocument, PrintWriter printWriter) {
154 printWriter.println("<Placemark>");
155 if (name != null) {
156 printWriter.println("<name>" + name + "</name>");
157 }
158 printWriter.println("</Placemark>");
159 }
160
161 public void addKml(Element parentElement, KmlDocument model, Document xmlDocument) throws KmlException {
162
163 Element placemarkElement = xmlDocument.createElement("Placemark");
164
165 if (name != null) {
166 Element nameElement = xmlDocument.createElement("name");
167 nameElement.appendChild(xmlDocument.createTextNode(name));
168 placemarkElement.appendChild(nameElement);
169 }
170
171 if (snippet != null) {
172 Element snippetElement = xmlDocument.createElement("Snippet");
173 snippetElement.appendChild(xmlDocument.createTextNode(snippet));
174 placemarkElement.appendChild(snippetElement);
175 }
176
177 String descriptionText = getDescriptionTextWithButtons(model);
178 if (descriptionText != null) {
179 Element descriptionElement = xmlDocument.createElement("description");
180 descriptionElement.appendChild(xmlDocument.createCDATASection(descriptionText));
181 placemarkElement.appendChild(descriptionElement);
182 }
183
184 if (mapObjectClass != null) {
185
186 mapObjectClass.addKml(this, parentElement, model, xmlDocument, location, rotation, localReferenceCoordinate, scale, name);
187
188 if (mapObjectClass.getStyleUrl() != null || mapObjectClass.getStyle() != null) {
189 Element styleUrlElement = xmlDocument.createElement("styleUrl");
190 styleUrlElement.appendChild(xmlDocument.createTextNode((mapObjectClass.getStyleUrl() != null ? mapObjectClass.getStyleUrl() : "#" + mapObjectClass.getStyle().getId())));
191 placemarkElement.appendChild(styleUrlElement);
192 }
193 }
194
195 if (location != null) {
196 location.addKml(placemarkElement, model, xmlDocument);
197 }
198
199 if (visibility != null) {
200 Element visibilityElement = xmlDocument.createElement("visibility");
201 visibilityElement.appendChild(xmlDocument.createTextNode((visibility) ? "1" : "0"));
202 placemarkElement.appendChild(visibilityElement);
203 }
204
205 parentElement.appendChild(placemarkElement);
206 }
207
208 /*public void addKmlXPP(KmlDocument model, XmlSerializer serializer) throws IllegalArgumentException, IllegalStateException, IOException {
209 // TODO this is a temp method for speed testing
210 serializer.startTag(null, "Placemark");
211
212 if (name != null) {
213 serializer.startTag(null, "name");
214 serializer.text(name);
215 serializer.endTag(null, "name");
216 }
217
218 String descriptionText = getDescriptionTextWithButtons(model);
219 if (descriptionText != null) {
220 serializer.startTag(null, "description");
221 serializer.cdsect(descriptionText);
222 serializer.endTag(null, "description");
223 }
224
225 if (location != null) {
226 location.addKmlXPP(model, serializer);
227 }
228 serializer.endTag(null, "Placemark");
229 }*/
230
231 public void addKmlDirect(KmlDocument model, Writer writer) throws IOException {
232 // TODO this is a temp method for speed testing
233 writer.write("<Placemark>");
234
235 if (name != null) {
236 writer.write("<name>" + name + "</name>");
237 }
238
239 String descriptionText = getDescriptionTextWithButtons(model);
240 if (descriptionText != null) {
241 writer.write("<description>" + descriptionText + "</description>");
242 }
243
244 if (location != null) {
245 location.addKmlDirect(model, writer);
246 }
247 writer.write("</Placemark>");
248 }
249
250 public List<TimeAndPlace> getMovements() {
251 return movements;
252 }
253
254 public void setMovements(List<TimeAndPlace> movements) {
255 this.movements = movements;
256 }
257
258 public void addMovement(TimeAndPlace movement) {
259 if (this.movements == null) {
260 this.movements = new ArrayList<TimeAndPlace>();
261 }
262 this.movements.add(movement);
263 }
264
265 public String toString() {
266 StringBuffer text = new StringBuffer("MapObject:\n");
267 text.append(" name: '" + name + "'\n");
268 text.append(" description: '" + description + "'\n");
269 text.append(" rotation: " + rotation + "\n");
270 text.append(" scale: " + scale + "\n");
271 text.append(" localReferenceCoordinate: " + localReferenceCoordinate + "\n");
272 text.append(" location: " + location + "\n");
273 text.append(" buttons: " + buttons + "\n");
274 text.append(" movements: " + movements + "\n");
275 text.append(" mapObjectClass: " + mapObjectClass + "\n");
276 return text.toString();
277 }
278
279 }
0 package org.boehn.kmlframework.todo;
1
2 import java.util.ArrayList;
3 import java.util.Calendar;
4 import java.util.Date;
5 import java.util.GregorianCalendar;
6 import java.util.List;
7
8 import org.boehn.kmlframework.KmlDocument;
9 import org.boehn.kmlframework.KmlException;
10 import org.boehn.kmlframework.todo.coordinates.CartesianCoordinate;
11 import org.boehn.kmlframework.todo.coordinates.EarthCoordinate;
12 import org.boehn.kmlframework.todo.coordinates.TimeAndPlace;
13 import org.boehn.kmlframework.todo.style.Style;
14 import org.w3c.dom.Document;
15 import org.w3c.dom.Element;
16
17 public class MapObjectClass {
18
19 private String className;
20 private List<GraphicalModel> models;
21 private boolean showTail = true;
22 private boolean showModels = true;
23 private Integer visibleFrom;
24 private Integer visibleTo;
25 private Integer tailHistoryLimit;
26 private Integer tailVisibleFrom;
27 private Integer tailVisibleTo;
28 private String styleUrl;
29 private Style style;
30
31 public MapObjectClass(String className) {
32 this.className = className;
33 }
34
35 public String getClassName() {
36 return className;
37 }
38
39 public void setClassName(String className) {
40 this.className = className;
41 }
42
43 public List<GraphicalModel> getModels() {
44 return models;
45 }
46
47 public void setModels(List<GraphicalModel> models) {
48 this.models = models;
49 }
50
51 public void addModel(GraphicalModel model) {
52 if (models == null) {
53 models = new ArrayList<GraphicalModel>();
54 }
55 models.add(model);
56 }
57
58 public void addModels(List<GraphicalModel> models) {
59 if (this.models == null) {
60 this.models = models;
61 } else {
62 this.models.addAll(models);
63 }
64 }
65
66 public Integer getVisibleFrom() {
67 return visibleFrom;
68 }
69
70 public void setVisibleFrom(Integer visibleFrom) {
71 this.visibleFrom = visibleFrom;
72 }
73
74 public Integer getVisibleTo() {
75 return visibleTo;
76 }
77
78 public void setVisibleTo(Integer visibleTo) {
79 this.visibleTo = visibleTo;
80 }
81
82 public String getStyleUrl() {
83 return styleUrl;
84 }
85
86 public void setStyleUrl(String styleUrl) {
87 this.styleUrl = styleUrl;
88 // styleUrl and style cannot be set at the same time
89 this.style = null;
90 }
91
92 public Style getStyle() {
93 return style;
94 }
95
96 public void setStyle(Style style) {
97 this.style = style;
98 // styleUrl and style cannot be set at the same time
99 this.styleUrl = null;
100 }
101
102 public boolean getShowModels() {
103 return showModels;
104 }
105
106 public void setShowModels(boolean showModel) {
107 this.showModels = showModel;
108 }
109
110 public boolean getShowTail() {
111 return showTail;
112 }
113
114 public void setShowTail(boolean showTail) {
115 this.showTail = showTail;
116 }
117
118 public Integer getTailVisibleFrom() {
119 return tailVisibleFrom;
120 }
121
122 public void setTailVisibleFrom(Integer tailVisibleFrom) {
123 this.tailVisibleFrom = tailVisibleFrom;
124 }
125
126 public Integer getTailVisibleTo() {
127 return tailVisibleTo;
128 }
129
130 public void setTailVisibleTo(Integer tailVisibleTo) {
131 this.tailVisibleTo = tailVisibleTo;
132 }
133
134 public Integer getTailHistoryLimit() {
135 return tailHistoryLimit;
136 }
137
138 public void setTailHistoryLimit(Integer tailHistoryLimit) {
139 this.tailHistoryLimit = tailHistoryLimit;
140 }
141
142 public void addKml(MapObject mapObject, Element parentElement, KmlDocument model, Document xmlDocument, EarthCoordinate location, Double rotation, CartesianCoordinate localReferenceCoordinate, CartesianCoordinate scale, String name) throws KmlException {
143 if (models != null || (mapObject.getMovements() != null && showTail)) {
144
145 boolean objectHasGraphicalElementToDraw = false;
146
147 Element multiGeometryElement = xmlDocument.createElement("MultiGeometry");
148 // If we are going to draw a tail after this MapObject, we have to add another model containing the tail. We cannot add this
149 // model to models, because then it will be added to all MapObject using this MapObject class. Thus we have to make a new list
150 List<GraphicalModel> graphicalModelsTemp;
151 if (mapObject.getMovements() == null || !showTail) {
152 graphicalModelsTemp = models;
153 } else {
154 graphicalModelsTemp = new ArrayList<GraphicalModel>(models);
155 GraphicalModel graphicalModel = new GraphicalModel();
156 Path path = new Path();
157 path.addCoordinate(location);
158
159 // We stop drawing the tail if passing the timeHistoryLimit
160 Date timeHistoryLimitAbsolute;
161 if (tailHistoryLimit != null) {
162 GregorianCalendar calendar = new GregorianCalendar();
163 calendar.add(Calendar.SECOND, -tailHistoryLimit);
164 timeHistoryLimitAbsolute = calendar.getTime();
165 } else {
166 timeHistoryLimitAbsolute = null;
167 }
168
169 for (TimeAndPlace timeAndPlace : mapObject.getMovements()) {
170 if (timeHistoryLimitAbsolute != null && timeHistoryLimitAbsolute.after(timeAndPlace.getTime())) {
171 // We stop drawing the tail because the tail history has passed the timeHistoryLimit
172 break;
173 }
174 path.addCoordinate(timeAndPlace.getPlace());
175 }
176 graphicalModel.addGraphicalModelElement(path);
177 graphicalModel.setVisibleFrom(tailVisibleFrom);
178 graphicalModel.setVisibleTo(tailVisibleTo);
179 graphicalModelsTemp.add(graphicalModel);
180 }
181 Double distanceToObserver = (model.getObserver() != null && mapObject.getLocation() != null) ? model.getObserver().distanceTo(mapObject.getLocation()) : null;
182 for (GraphicalModel graphicalModel : graphicalModelsTemp) {
183 if (!model.ENABLE_DETAILS_DEPENDS_ON_DISTANCE_TO_OBSERVER || (distanceToObserver == null || (graphicalModel.getVisibleTo() == null || graphicalModel.getVisibleTo() > distanceToObserver) && (graphicalModel.getVisibleFrom() == null || graphicalModel.getVisibleFrom() < distanceToObserver))) {
184 graphicalModel.addKml(multiGeometryElement, model, xmlDocument, location, rotation, localReferenceCoordinate, scale);
185 objectHasGraphicalElementToDraw = true;
186 }
187 }
188
189 if (objectHasGraphicalElementToDraw) {
190 Element placemarkElement = xmlDocument.createElement("Placemark");
191 Element nameElement = xmlDocument.createElement("name");
192 nameElement.appendChild(xmlDocument.createTextNode((name != null) ? name + " model" : "model"));
193 placemarkElement.appendChild(nameElement);
194 if (styleUrl != null || style != null) {
195 Element styleUrlElement = xmlDocument.createElement("styleUrl");
196 styleUrlElement.appendChild(xmlDocument.createTextNode((styleUrl != null ? styleUrl : "#" + style.getId())));
197 placemarkElement.appendChild(styleUrlElement);
198 }
199 placemarkElement.appendChild(multiGeometryElement);
200 parentElement.appendChild(placemarkElement);
201 }
202 }
203 }
204
205 public String toString() {
206 StringBuffer text = new StringBuffer("MapObjectClass:\n");
207 text.append(" className: '" + className + "'\n");
208 text.append(" styleUrl: '" + styleUrl + "'\n");
209 text.append(" models: " + models + "\n");
210 text.append(" showModels: " + showModels + "\n");
211 text.append(" showTail: " + showTail + "\n");
212 text.append(" tailVisibleFrom: " + tailVisibleFrom + "\n");
213 text.append(" tailVisibleTo: " + tailVisibleTo + "\n");
214 text.append(" timeHistoryLimit: " + tailHistoryLimit + "\n");
215 return text.toString();
216 }
217 }
0 package org.boehn.kmlframework.todo;
1
2 import java.io.File;
3 import java.io.IOException;
4 import java.util.Hashtable;
5
6 import javax.xml.parsers.DocumentBuilder;
7 import javax.xml.parsers.DocumentBuilderFactory;
8 import javax.xml.parsers.ParserConfigurationException;
9
10 import org.boehn.kmlframework.AltitudeModeEnum;
11 import org.boehn.kmlframework.todo.coordinates.CartesianCoordinate;
12 import org.boehn.kmlframework.todo.coordinates.Coordinate;
13 import org.w3c.dom.Document;
14 import org.w3c.dom.NamedNodeMap;
15 import org.w3c.dom.Node;
16 import org.w3c.dom.NodeList;
17 import org.xml.sax.SAXException;
18
19 public class ModelObjectFactory {
20
21 private String fileName;
22 private Hashtable<String, MapObjectClass> mapObjectClasses;
23
24 public ModelObjectFactory(String fileName) throws IOException, ParserConfigurationException, SAXException {
25 this.fileName = fileName;
26 loadFile();
27 }
28
29 public MapObject createMapObject(String className) {
30 return new MapObject(getMapObjectClass(className));
31 }
32
33 public MapObjectClass getMapObjectClass(String className) {
34 MapObjectClass mapObjectClass = mapObjectClasses.get(className);
35 if (mapObjectClass == null) {
36 mapObjectClass = new MapObjectClass(className);
37 mapObjectClasses.put(className, mapObjectClass);
38 }
39 return mapObjectClass;
40 }
41
42 public void loadFile() throws IOException, ParserConfigurationException, SAXException {
43 mapObjectClasses = new Hashtable<String, MapObjectClass>();
44 DocumentBuilder documentBuilder;
45
46 documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
47 Document document = documentBuilder.parse(new File(fileName));
48 NodeList documentNodes = document.getChildNodes();
49 for (int i = 0; i < documentNodes.getLength(); i++) {
50 Node objectClassesNode = documentNodes.item(i);
51 if ("mapObjectClasses".equals(objectClassesNode.getNodeName()) && objectClassesNode.getChildNodes().getLength() > 0) {
52 NodeList objectClassesChildren = objectClassesNode.getChildNodes();
53 for (int j = 0; j < objectClassesChildren.getLength(); j ++) {
54 Node mapObjectClassNode = objectClassesChildren.item(j);
55 if ("mapObjectClass".equals(mapObjectClassNode.getNodeName())) {
56 NamedNodeMap mapObjectClassAttributes = mapObjectClassNode.getAttributes();
57
58 // We make the mapObject class
59 MapObjectClass mapObjectClass = new MapObjectClass(mapObjectClassAttributes.getNamedItem("className").getNodeValue());
60
61 // We read all optional parameters for the mapObject class
62 if (mapObjectClassAttributes.getNamedItem("showTail") != null) {
63 mapObjectClass.setShowTail(new Boolean(mapObjectClassAttributes.getNamedItem("showTail").getNodeValue()));
64 }
65 if (mapObjectClassAttributes.getNamedItem("showModel") != null) {
66 mapObjectClass.setShowModels(new Boolean(mapObjectClassAttributes.getNamedItem("showModel").getNodeValue()));
67 }
68 if (mapObjectClassAttributes.getNamedItem("visibleFrom") != null) {
69 mapObjectClass.setVisibleFrom(new Integer(mapObjectClassAttributes.getNamedItem("visibleFrom").getNodeValue()));
70 }
71 if (mapObjectClassAttributes.getNamedItem("visibleTo") != null) {
72 mapObjectClass.setVisibleTo(new Integer(mapObjectClassAttributes.getNamedItem("visibleTo").getNodeValue()));
73 }
74 if (mapObjectClassAttributes.getNamedItem("tailHistoryLimit") != null) {
75 mapObjectClass.setTailHistoryLimit(new Integer(mapObjectClassAttributes.getNamedItem("tailHistoryLimit").getNodeValue()));
76 }
77 if (mapObjectClassAttributes.getNamedItem("tailVisibleFrom") != null) {
78 mapObjectClass.setTailVisibleFrom(new Integer(mapObjectClassAttributes.getNamedItem("tailVisibleFrom").getNodeValue()));
79 }
80 if (mapObjectClassAttributes.getNamedItem("tailVisibleTo") != null) {
81 mapObjectClass.setTailVisibleTo(new Integer(mapObjectClassAttributes.getNamedItem("tailVisibleTo").getNodeValue()));
82 }
83 if (mapObjectClassAttributes.getNamedItem("styleUrl") != null) {
84 mapObjectClass.setStyleUrl(mapObjectClassAttributes.getNamedItem("styleUrl").getNodeValue());
85 }
86
87 // We load the children to the mapObjectClass
88 NodeList mapObjectClassChildren = mapObjectClassNode.getChildNodes();
89 for (int k = 0; k < mapObjectClassChildren.getLength(); k++) {
90 Node mapObjectClassChild = mapObjectClassChildren.item(k);
91 if ("model".equals(mapObjectClassChild.getNodeName())) {
92 GraphicalModel model = new GraphicalModel();
93
94 // We read the attributes to the model element
95 NamedNodeMap modelAttributes = mapObjectClassChild.getAttributes();
96 if (modelAttributes.getNamedItem("visibleFrom") != null) {
97 model.setVisibleFrom(new Integer(modelAttributes.getNamedItem("visibleFrom").getNodeValue()));
98 }
99 if (modelAttributes.getNamedItem("visibleTo") != null) {
100 model.setVisibleTo(new Integer(modelAttributes.getNamedItem("visibleTo").getNodeValue()));
101 }
102
103 NodeList modelChildren = mapObjectClassChild.getChildNodes();
104 for (int l = 0; l < modelChildren.getLength(); l++) {
105 Node modelChild =modelChildren.item(l);
106 if ("polygon".equals(modelChild.getNodeName()) || "path".equals(modelChild.getNodeName())) {
107 Path path;
108 if ("polygon".equals(modelChild.getNodeName())) {
109 path = new Polygon();
110 } else {
111 path = new Path();
112 }
113
114 // We read the attributes to the path/polygon element
115 NamedNodeMap modelChildAttributes = modelChild.getAttributes();
116 if (modelChildAttributes.getNamedItem("altitudeMode") != null) {
117 path.setAltitudeMode(AltitudeModeEnum.valueOf(modelChildAttributes.getNamedItem("altitudeMode").getNodeValue()));
118 }
119 if (modelChildAttributes.getNamedItem("extrude") != null) {
120 path.setExtrude(new Boolean(modelChildAttributes.getNamedItem("extrude").getNodeValue()));
121 }
122
123 // We read the children to the path/polygon
124 NodeList pathChildren = modelChild.getChildNodes();
125 for (int m = 0; m < pathChildren.getLength(); m++) {
126 Node pathChild = pathChildren.item(m);
127 if ("coordinate".equals(pathChild.getNodeName())) {
128 NamedNodeMap coordinateAttributes = pathChild.getAttributes();
129 Coordinate coordinate = new CartesianCoordinate(Double.parseDouble(coordinateAttributes.getNamedItem("x").getNodeValue()), Double.parseDouble(coordinateAttributes.getNamedItem("y").getNodeValue()), Double.parseDouble(coordinateAttributes.getNamedItem("z").getNodeValue()));
130 path.addCoordinate(coordinate);
131 }
132 }
133 model.addGraphicalModelElement(path);
134 }
135 }
136 mapObjectClass.addModel(model);
137 }
138 }
139 // We add the object class to the hashtable
140 mapObjectClasses.put(mapObjectClass.getClassName(), mapObjectClass);
141 }
142 }
143 break;
144 }
145 }
146 }
147 }
0 package org.boehn.kmlframework.todo;
1
2 import java.util.ArrayList;
3 import java.util.List;
4
5 import org.boehn.kmlframework.AltitudeModeEnum;
6 import org.boehn.kmlframework.KmlDocument;
7 import org.boehn.kmlframework.todo.coordinates.CartesianCoordinate;
8 import org.boehn.kmlframework.todo.coordinates.Coordinate;
9 import org.boehn.kmlframework.todo.coordinates.EarthCoordinate;
10 import org.w3c.dom.Document;
11 import org.w3c.dom.Element;
12
13 public class Path implements GraphicalModelElement {
14
15 private List<Coordinate> coordinates;
16 private Boolean extrude;
17 private Boolean tessellate;
18 private AltitudeModeEnum altitudeMode;
19
20 public Path() {}
21
22 public Path(List<Coordinate> coordinates) {
23 this(coordinates, null, null, null);
24 }
25
26 public Path(List<Coordinate> coordinates, Boolean extrude, Boolean tessellate, AltitudeModeEnum altitudeMode) {
27 this.coordinates = coordinates;
28 this.extrude = extrude;
29 this.tessellate = tessellate;
30 this.altitudeMode = altitudeMode;
31 }
32
33 public AltitudeModeEnum getAltitudeMode() {
34 return altitudeMode;
35 }
36
37 public void setAltitudeMode(AltitudeModeEnum altitudeMode) {
38 this.altitudeMode = altitudeMode;
39 }
40
41 public Boolean getExtrude() {
42 return extrude;
43 }
44
45 public void setExtrude(Boolean extrude) {
46 this.extrude = extrude;
47 }
48
49 public Boolean getTessellate() {
50 return tessellate;
51 }
52
53 public void setTessellate(Boolean tessellate) {
54 this.tessellate = tessellate;
55 }
56
57 public List<Coordinate> getCoordinates() {
58 return coordinates;
59 }
60
61 public void setCoordinates(List<Coordinate> coordinates) {
62 this.coordinates = coordinates;
63 }
64
65 public void addCoordinate(Coordinate coordinate) {
66 if (coordinates == null) {
67 coordinates = new ArrayList<Coordinate>();
68 }
69 coordinates.add(coordinate);
70 }
71
72 public void addCoordinates(List<Coordinate> coordinates) {
73 if (this.coordinates == null) {
74 this.coordinates = coordinates;
75 } else {
76 this.coordinates.addAll(coordinates);
77 }
78 }
79
80 public Element getCoordinates(Document xmlDocument, EarthCoordinate location, Double rotation, CartesianCoordinate localReferenceCoordinate, CartesianCoordinate scale) {
81 Element coordinatesElement = xmlDocument.createElement("coordinates");
82
83 StringBuffer coordinatesText = new StringBuffer();
84 for (Coordinate coordinate : coordinates) {
85 EarthCoordinate earthCoordinate = coordinate.toEarthCoordinate(location, rotation, localReferenceCoordinate, scale);
86 coordinatesText.append(earthCoordinate.getLongitude() + "," + earthCoordinate.getLatitude() + "," + earthCoordinate.getAltitude() + " ");
87 }
88 // We remove the extra space added to the end of the string
89 coordinatesText.deleteCharAt(coordinatesText.length()-1);
90
91 coordinatesElement.appendChild(xmlDocument.createTextNode(coordinatesText.toString()));
92
93 return coordinatesElement;
94 }
95
96 public void addKml(Element parentElement, KmlDocument model, Document xmlDocument, EarthCoordinate location, Double rotation, CartesianCoordinate localReferenceCoordinate, CartesianCoordinate scale) {
97 Element pathElement = xmlDocument.createElement("LineString");
98
99 if (coordinates != null) {
100 pathElement.appendChild(getCoordinates(xmlDocument, location, rotation, localReferenceCoordinate, scale));
101 }
102
103 if (extrude != null) {
104 Element extrudeElement = xmlDocument.createElement("extrude");
105 extrudeElement.appendChild(xmlDocument.createTextNode((extrude) ? "1" : "0"));
106 pathElement.appendChild(extrudeElement);
107 }
108
109 if (tessellate != null) {
110 Element tessellateElement = xmlDocument.createElement("tessellate");
111 tessellateElement.appendChild(xmlDocument.createTextNode((tessellate) ? "1" : "0"));
112 pathElement.appendChild(tessellateElement);
113 }
114
115 if (altitudeMode != null) {
116 Element altitudeModeElement = xmlDocument.createElement("altitudeMode");
117 altitudeModeElement.appendChild(xmlDocument.createTextNode(altitudeMode.toString()));
118 pathElement.appendChild(altitudeModeElement);
119 }
120
121 parentElement.appendChild(pathElement);
122 }
123
124 public String toString() {
125 StringBuffer text = new StringBuffer("Path");
126 text.append("altitudeMode: " + altitudeMode + "\n");
127 text.append("extrude: " + extrude + "\n");
128 text.append("tessellate: " + tessellate + "\n");
129 text.append("coordinates: " + coordinates + "\n");
130 return text.toString();
131 }
132
133 }
0 package org.boehn.kmlframework.todo;
1
2 import java.util.List;
3
4 import org.boehn.kmlframework.AltitudeModeEnum;
5 import org.boehn.kmlframework.KmlDocument;
6 import org.boehn.kmlframework.todo.coordinates.CartesianCoordinate;
7 import org.boehn.kmlframework.todo.coordinates.Coordinate;
8 import org.boehn.kmlframework.todo.coordinates.EarthCoordinate;
9 import org.w3c.dom.Document;
10 import org.w3c.dom.Element;
11
12 public class Polygon extends Path {
13
14 private Polygon subtractionPolygon;
15
16 public Polygon() {}
17
18 public Polygon(List<Coordinate> points) {
19 this(points, null, null, null, null);
20 }
21
22 public Polygon(List<Coordinate> points, Polygon subtractionPolygon, Boolean extrude, Boolean tessellate, AltitudeModeEnum altitudeMode) {
23 super(points, extrude, tessellate, altitudeMode);
24 this.subtractionPolygon = subtractionPolygon;
25 }
26
27 public Polygon getSubtractionPolygon() {
28 return subtractionPolygon;
29 }
30
31 public void setSubtractionPolygon(Polygon subtractionPolygon) {
32 this.subtractionPolygon = subtractionPolygon;
33 }
34
35 public Element getLinearRing(Document xmlDocument, EarthCoordinate location, Double rotation, CartesianCoordinate localReferenceCoordinate, CartesianCoordinate scale) {
36 Element linearRingElement = xmlDocument.createElement("LinearRing");
37 linearRingElement.appendChild(getCoordinates(xmlDocument, location, rotation, localReferenceCoordinate, scale));
38 return linearRingElement;
39 }
40
41 @Override
42 public void addKml(Element parentElement, KmlDocument model, Document xmlDocument, EarthCoordinate location, Double rotation, CartesianCoordinate localReferenceCoordinate, CartesianCoordinate scale) {
43 Element polygonElement = xmlDocument.createElement("Polygon");
44
45 if (getCoordinates() != null) {
46 Element outerBoundaryIsElement = xmlDocument.createElement("outerBoundaryIs");
47 outerBoundaryIsElement.appendChild(getLinearRing(xmlDocument, location, rotation, localReferenceCoordinate, scale));
48 polygonElement.appendChild(outerBoundaryIsElement);
49 }
50
51 if (subtractionPolygon != null) {
52 Element innerBoundaryIsElement = xmlDocument.createElement("innerBoundaryIs");
53 innerBoundaryIsElement.appendChild(subtractionPolygon.getLinearRing(xmlDocument, location, rotation, localReferenceCoordinate, scale));
54 polygonElement.appendChild(innerBoundaryIsElement);
55 }
56
57 if (getExtrude() != null) {
58 Element extrudeElement = xmlDocument.createElement("extrude");
59 extrudeElement.appendChild(xmlDocument.createTextNode((getExtrude()) ? "1" : "0"));
60 polygonElement.appendChild(extrudeElement);
61 }
62
63 if (getTessellate() != null) {
64 Element tessellateElement = xmlDocument.createElement("tessellate");
65 tessellateElement.appendChild(xmlDocument.createTextNode((getTessellate()) ? "1" : "0"));
66 polygonElement.appendChild(tessellateElement);
67 }
68
69 if (getAltitudeMode() != null) {
70 Element altitudeModeElement = xmlDocument.createElement("altitudeMode");
71 altitudeModeElement.appendChild(xmlDocument.createTextNode(getAltitudeMode().toString()));
72 polygonElement.appendChild(altitudeModeElement);
73 }
74
75 parentElement.appendChild(polygonElement);
76 }
77
78 public String toString() {
79 StringBuffer text = new StringBuffer("Path");
80 text.append("altitudeMode: " + getAltitudeMode() + "\n");
81 text.append("extrude: " + getExtrude() + "\n");
82 text.append("tessellate: " + getTessellate() + "\n");
83 text.append("coordinates: " + getCoordinates() + "\n");
84 text.append("subtractionPolygon: " + subtractionPolygon + "\n");
85 return text.toString();
86 }
87
88 }
0 package org.boehn.kmlframework.todo;
1
2 import org.boehn.kmlframework.KmlDocument;
3 import org.w3c.dom.Document;
4 import org.w3c.dom.Element;
5
6 public class ViewPosition {
7
8 private double longitude;
9 private double latitude;
10 private Double range;
11 private Double tilt;
12 private Double heading;
13
14 public ViewPosition() {
15 }
16
17 public ViewPosition(double latitude, double longitude) {
18 this(latitude, longitude, null, null, null);
19 }
20
21 public ViewPosition(double latitude, double longitude, Double range, Double tilt, Double heading) {
22 this.latitude = latitude;
23 this.longitude = longitude;
24 this.range = range;
25 this.tilt = tilt;
26 this.heading = heading;
27 }
28
29 public Double getHeading() {
30 return heading;
31 }
32
33 public void setHeading(Double heading) {
34 this.heading = heading;
35 }
36
37 public double getLatitude() {
38 return latitude;
39 }
40
41 public void setLatitude(double latitude) {
42 this.latitude = latitude;
43 }
44
45 public double getLongitude() {
46 return longitude;
47 }
48
49 public void setLongitude(double longitude) {
50 this.longitude = longitude;
51 }
52
53 public Double getRange() {
54 return range;
55 }
56
57 public void setRange(Double range) {
58 this.range = range;
59 }
60
61 public Double getTilt() {
62 return tilt;
63 }
64
65 public void setTilt(Double tilt) {
66 this.tilt = tilt;
67 }
68
69 public void addKml(Element parentElement, KmlDocument model, Document xmlDocument) {
70 Element lookAtElement = xmlDocument.createElement("LookAt");
71
72 Element longitudeElement = xmlDocument.createElement("longitude");
73 longitudeElement.appendChild(xmlDocument.createTextNode(Double.toString(longitude)));
74 lookAtElement.appendChild(longitudeElement);
75
76 Element latitudeElement = xmlDocument.createElement("latitude");
77 latitudeElement.appendChild(xmlDocument.createTextNode(Double.toString(latitude)));
78 lookAtElement.appendChild(latitudeElement);
79
80 if (range != null) {
81 Element rangeElement = xmlDocument.createElement("range");
82 rangeElement.appendChild(xmlDocument.createTextNode(range.toString()));
83 lookAtElement.appendChild(rangeElement);
84 }
85
86 if (tilt!= null) {
87 Element tiltElement = xmlDocument.createElement("tilt");
88 tiltElement.appendChild(xmlDocument.createTextNode(tilt.toString()));
89 lookAtElement.appendChild(tiltElement);
90 }
91
92 if (heading != null) {
93 Element headingElement = xmlDocument.createElement("heading");
94 headingElement.appendChild(xmlDocument.createTextNode(heading.toString()));
95 lookAtElement.appendChild(headingElement);
96 }
97
98 parentElement.appendChild(lookAtElement);
99 }
100 }
0 package org.boehn.kmlframework.todo.coordinates;
1
2 import org.boehn.kmlframework.todo.utils.Ellipsoid;
3
4 public class CartesianCoordinate implements Coordinate {
5
6 private double x;
7 private double y;
8 private double z;
9
10 public CartesianCoordinate() {}
11
12 public CartesianCoordinate(double x, double y, double z) {
13 this.x = x;
14 this.y = y;
15 this.z = z;
16 }
17
18 public double getX() {
19 return x;
20 }
21
22 public void setX(double x) {
23 this.x = x;
24 }
25
26 public double getY() {
27 return y;
28 }
29
30 public void setY(double y) {
31 this.y = y;
32 }
33
34 public double getZ() {
35 return z;
36 }
37
38 public void setZ(double z) {
39 this.z = z;
40 }
41
42 public double distanceTo(CartesianCoordinate cartesianCoordinate) {
43 return Math.sqrt( Math.pow(Math.abs(cartesianCoordinate.getX()-x), 2) + Math.pow(Math.abs(cartesianCoordinate.getY()-y), 2) + Math.pow(Math.abs(cartesianCoordinate.getZ()-z), 2));
44 }
45
46 public void rotateAroundZAxis(double rotation) {
47 double xTemp = Math.cos(rotation) * x - Math.sin(rotation) * y;
48 y = Math.sin(rotation) * x + Math.cos(rotation) * y;
49 x = xTemp;
50 }
51
52 public void rotateAroundYAxis(double rotation) {
53 double xTemp = Math.cos(rotation) * x + Math.sin(rotation) * z;
54 z = - Math.sin(rotation) * x + Math.cos(rotation) * z;
55 x = xTemp;
56 }
57
58 public void rotateAroundXAxis(double rotation) {
59 double yTemp = Math.cos(rotation) * y - Math.sin(rotation) * z;
60 z = Math.sin(rotation) * y + Math.cos(rotation) * z;
61 y = yTemp;
62 }
63
64 public void add(CartesianCoordinate cartesianCoordinate) {
65 x += cartesianCoordinate.getX();
66 y += cartesianCoordinate.getY();
67 z += cartesianCoordinate.getZ();
68 }
69
70 public void subtract(CartesianCoordinate cartesianCoordinate) {
71 x -= cartesianCoordinate.getX();
72 y -= cartesianCoordinate.getY();
73 z -= cartesianCoordinate.getZ();
74 }
75
76 public double length() {
77 return Math.sqrt(x*x + y*y + z*z);
78 }
79
80 public void normalize() {
81 double length = length();
82 x /= length;
83 y /= length;
84 z /= length;
85 }
86
87 public void scale(double scalingFactor) {
88 x *= scalingFactor;
89 y *= scalingFactor;
90 z *= scalingFactor;
91 }
92
93 public String toString() {
94 return "[" + x + ", " + y + ", " + z + "]";
95 }
96
97 public EarthCoordinate toEarthCoordinate(EarthCoordinate location, Double rotation, CartesianCoordinate localReferenceCoordinate, CartesianCoordinate scale) {
98 // We scale the coordinates
99 double xTransformed = x;
100 double yTransformed = y;
101 double zTransformed = z;
102
103 if (scale != null) {
104 xTransformed = x * scale.getX();
105 yTransformed = y * scale.getY();
106 zTransformed = z * scale.getZ();
107 }
108
109 // We move the coordinates according to the local reference coordinate
110 if (localReferenceCoordinate != null) {
111 xTransformed -= localReferenceCoordinate.getX();
112 yTransformed -= localReferenceCoordinate.getY();
113 zTransformed -= localReferenceCoordinate.getZ();
114 }
115
116 //rotation = Math.PI/4;
117 // We rotate the coordinates according to the rotation. We do only support rotation around the z axis
118 if (rotation != null) {
119 double xTmp = xTransformed;
120 xTransformed = Math.cos(rotation) * xTmp + Math.sin(rotation) * yTransformed;
121 yTransformed = -Math.sin(rotation) * xTmp + Math.cos(rotation) * yTransformed;
122 }
123
124 // Move to world coordinates
125 if (location != null) {
126 xTransformed = location.getLongitude() + xTransformed * Ellipsoid.meterToLongitude(location.getLatitude());
127 yTransformed = location.getLatitude() + yTransformed * Ellipsoid.meterToLatitude(location.getLatitude());
128 zTransformed += location.getAltitude();
129 }
130 return new EarthCoordinate(zTransformed, yTransformed, xTransformed);
131 }
132 }
0 package org.boehn.kmlframework.todo.coordinates;
1
2
3 public interface Coordinate {
4
5 EarthCoordinate toEarthCoordinate(EarthCoordinate earthCoordinate, Double rotation, CartesianCoordinate localReferenceCoordinate, CartesianCoordinate scale);
6
7 }
0 package org.boehn.kmlframework.todo.coordinates;
1
2 import java.io.IOException;
3 import java.io.Writer;
4
5 import org.boehn.kmlframework.AltitudeModeEnum;
6 import org.boehn.kmlframework.KmlDocument;
7 import org.w3c.dom.Document;
8 import org.w3c.dom.Element;
9
10 public class EarthCoordinate implements Coordinate {
11
12 private double altitude;
13 private double latitude;
14 private double longitude;
15 private Boolean extrude;
16 private Boolean tessellate;
17 private AltitudeModeEnum altitudeMode;
18 public static double EARTHRADIUS = 6372795.477598; // in meters
19
20 public EarthCoordinate() {}
21
22 public EarthCoordinate(double altitude, double latitude, double longitude) {
23 this.altitude = altitude;
24 this.latitude = latitude;
25 this.longitude = longitude;
26 }
27
28 public EarthCoordinate(double latitude, double longitude) {
29 this(0, latitude, longitude);
30 }
31
32 public double getAltitude() {
33 return altitude;
34 }
35
36 public void setAltitude(double altitude) {
37 this.altitude = altitude;
38 }
39
40 public double getLatitude() {
41 return latitude;
42 }
43
44 public void setLatitude(double latitude) {
45 this.latitude = latitude;
46 }
47
48 public double getLongitude() {
49 return longitude;
50 }
51
52 public void setLongitude(double longitude) {
53 this.longitude = longitude;
54 }
55
56 public AltitudeModeEnum getAltitudeMode() {
57 return altitudeMode;
58 }
59
60 public void setAltitudeMode(AltitudeModeEnum altitudeMode) {
61 this.altitudeMode = altitudeMode;
62 }
63
64 public Boolean getExtrude() {
65 return extrude;
66 }
67
68 public void setExtrude(Boolean extrude) {
69 this.extrude = extrude;
70 }
71
72 public Boolean getTessellate() {
73 return tessellate;
74 }
75
76 public void setTessellate(Boolean tessellate) {
77 this.tessellate = tessellate;
78 }
79
80 public void addKml(Element parentElement, KmlDocument model, Document xmlDocument) {
81 Element pointElement = xmlDocument.createElement("Point");
82
83 Element coordinatesElement = xmlDocument.createElement("coordinates");
84 coordinatesElement.appendChild(xmlDocument.createTextNode(getLongitude() + "," + getLatitude() + "," + getAltitude()));
85 pointElement.appendChild(coordinatesElement);
86
87 if (extrude != null) {
88 Element extrudeElement = xmlDocument.createElement("extrude");
89 extrudeElement.appendChild(xmlDocument.createTextNode((extrude) ? "1" : "0"));
90 pointElement.appendChild(extrudeElement);
91 }
92
93 if (tessellate != null) {
94 Element tessellateElement = xmlDocument.createElement("tessellate");
95 tessellateElement.appendChild(xmlDocument.createTextNode((tessellate) ? "1" : "0"));
96 pointElement.appendChild(tessellateElement);
97 }
98
99 if (altitudeMode!= null) {
100 Element altitudeModeElement = xmlDocument.createElement("altitudeMode");
101 altitudeModeElement.appendChild(xmlDocument.createTextNode(altitudeMode.toString()));
102 pointElement.appendChild(altitudeModeElement);
103 }
104
105 parentElement.appendChild(pointElement);
106 }
107
108 /*public void addKmlXPP(KmlDocument model, XmlSerializer serializer) throws IllegalArgumentException, IllegalStateException, IOException {
109 serializer.startTag(null, "Point");
110 serializer.startTag(null, "coordinates");
111 serializer.text(getLongitude() + "," + getLatitude() + "," + getAltitude());
112 serializer.endTag(null, "coordinates");
113 serializer.endTag(null, "Point");
114
115 Element coordinatesElement = xmlDocument.createElement("coordinates");
116 coordinatesElement.appendChild(xmlDocument.createTextNode(getLongitude() + "," + getLatitude() + "," + getAltitude()));
117 pointElement.appendChild(coordinatesElement);
118
119 if (extrude != null) {
120 Element extrudeElement = xmlDocument.createElement("extrude");
121 extrudeElement.appendChild(xmlDocument.createTextNode((extrude) ? "1" : "0"));
122 pointElement.appendChild(extrudeElement);
123 }
124
125 if (tessellate != null) {
126 Element tessellateElement = xmlDocument.createElement("tessellate");
127 tessellateElement.appendChild(xmlDocument.createTextNode((tessellate) ? "1" : "0"));
128 pointElement.appendChild(tessellateElement);
129 }
130
131 if (altitudeMode!= null) {
132 Element altitudeModeElement = xmlDocument.createElement("altitudeMode");
133 altitudeModeElement.appendChild(xmlDocument.createTextNode(altitudeMode.toString()));
134 pointElement.appendChild(altitudeModeElement);
135 }
136
137 parentElement.appendChild(pointElement);
138 }*/
139
140 public void addKmlDirect(KmlDocument model, Writer writer) throws IOException {
141 writer.write("<Point><coordinates>" + getLongitude() + "," + getLatitude() + "," + getAltitude() + "</coordinates></Point>");
142
143 /*Element coordinatesElement = xmlDocument.createElement("coordinates");
144 coordinatesElement.appendChild(xmlDocument.createTextNode(getLongitude() + "," + getLatitude() + "," + getAltitude()));
145 pointElement.appendChild(coordinatesElement);
146
147 if (extrude != null) {
148 Element extrudeElement = xmlDocument.createElement("extrude");
149 extrudeElement.appendChild(xmlDocument.createTextNode((extrude) ? "1" : "0"));
150 pointElement.appendChild(extrudeElement);
151 }
152
153 if (tessellate != null) {
154 Element tessellateElement = xmlDocument.createElement("tessellate");
155 tessellateElement.appendChild(xmlDocument.createTextNode((tessellate) ? "1" : "0"));
156 pointElement.appendChild(tessellateElement);
157 }
158
159 if (altitudeMode!= null) {
160 Element altitudeModeElement = xmlDocument.createElement("altitudeMode");
161 altitudeModeElement.appendChild(xmlDocument.createTextNode(altitudeMode.toString()));
162 pointElement.appendChild(altitudeModeElement);
163 }
164
165 parentElement.appendChild(pointElement);*/
166 }
167
168 public double getRadius() {
169 return altitude + EARTHRADIUS;
170 }
171
172 public CartesianCoordinate toCartesianCoordinate() {
173 CartesianCoordinate cartesianCoordinate = new CartesianCoordinate();
174 cartesianCoordinate.setX(getRadius() * Math.sin(Math.PI/2 - latitude*(Math.PI/180)) * Math.cos(longitude*(Math.PI/180)));
175 cartesianCoordinate.setY(getRadius() * Math.sin(Math.PI/2 - latitude*(Math.PI/180)) * Math.sin(longitude*(Math.PI/180)));
176 cartesianCoordinate.setZ(getRadius() * Math.cos(Math.PI/2 - latitude*(Math.PI/180)));
177 return cartesianCoordinate;
178 }
179
180 public double distanceTo(EarthCoordinate earthCoordinate) {
181 return toCartesianCoordinate().distanceTo(earthCoordinate.toCartesianCoordinate());
182 }
183
184 public String toString() {
185 return "[" + altitude + ", " + latitude + ", " + longitude + "]";
186 }
187
188 public EarthCoordinate toEarthCoordinate(EarthCoordinate earthCoordinate, Double rotation, CartesianCoordinate localReferenceCoordinate, CartesianCoordinate scale) {
189 return this;
190 }
191
192 }
0 package org.boehn.kmlframework.todo.coordinates;
1
2 import java.util.Date;
3
4
5 public class TimeAndPlace {
6
7 private EarthCoordinate place;
8 private Date time;
9
10 public TimeAndPlace(EarthCoordinate place, Date time) {
11 this.place = place;
12 this.time = time;
13 }
14
15 public EarthCoordinate getPlace() {
16 return place;
17 }
18
19 public void setPlace(EarthCoordinate place) {
20 this.place = place;
21 }
22
23 public Date getTime() {
24 return time;
25 }
26
27 public void setTime(Date time) {
28 this.time = time;
29 }
30
31 }
0 package org.boehn.kmlframework.todo.examples;
1
2 import java.io.IOException;
3 import java.util.ArrayList;
4 import java.util.Calendar;
5 import java.util.GregorianCalendar;
6 import java.util.List;
7
8 import org.boehn.kmlframework.KmlDocument;
9 import org.boehn.kmlframework.KmlException;
10 import org.boehn.kmlframework.todo.GraphicalModel;
11 import org.boehn.kmlframework.todo.MapObject;
12 import org.boehn.kmlframework.todo.MapObjectClass;
13 import org.boehn.kmlframework.todo.Polygon;
14 import org.boehn.kmlframework.todo.coordinates.CartesianCoordinate;
15 import org.boehn.kmlframework.todo.coordinates.Coordinate;
16 import org.boehn.kmlframework.todo.coordinates.EarthCoordinate;
17 import org.boehn.kmlframework.todo.coordinates.TimeAndPlace;
18
19 public class GraphicalMapObjectExample {
20
21 public static void main(String[] args) throws KmlException, IOException {
22
23 // We create a model
24 KmlDocument model = new KmlDocument();
25
26 // We define a MapObjectClass for a boat
27 MapObjectClass boatClass = new MapObjectClass("boat");
28 GraphicalModel boatModel = new GraphicalModel();
29 List<Coordinate> coordinates = new ArrayList<Coordinate>();
30 coordinates.add(new CartesianCoordinate(0, 0, 1));
31 coordinates.add(new CartesianCoordinate(1, 0, 1));
32 coordinates.add(new CartesianCoordinate(1, 0.7, 1));
33 coordinates.add(new CartesianCoordinate(0.5, 1, 1));
34 coordinates.add(new CartesianCoordinate(0, 0.7, 1));
35 coordinates.add(new CartesianCoordinate(0, 0, 1));
36 Polygon polygon = new Polygon(coordinates);
37 boatModel.addGraphicalModelElement(polygon);
38 boatClass.addModel(boatModel);
39
40 // We create a boat object
41 MapObject boat = new MapObject("Titanic II");
42 boat.setLocation(new EarthCoordinate(59.8959, 10.6406));
43 boat.setMapObjectClass(boatClass);
44 // We define the size of the boat
45 boat.setScale(new CartesianCoordinate(30, 150, 30));
46 // We define the direction of the boat. 0 is North
47 boat.setRotation(Math.toRadians(45d));
48 // We define the gps position in the boat (according to the 3D model of the boat
49 boat.setLocalReferenceCoordinate(new CartesianCoordinate(2, 13, 0));
50
51 // We define how the boat has been moving the last period of time. This will draw a tail after the boat
52 GregorianCalendar calendar = new GregorianCalendar();
53 calendar.add(Calendar.MINUTE, -15);
54 boat.addMovement(new TimeAndPlace(new EarthCoordinate(59.895018, 10.638732), calendar.getTime()));
55 calendar.add(Calendar.MINUTE, -15);
56 boat.addMovement(new TimeAndPlace(new EarthCoordinate(59.892980, 10.638991), calendar.getTime()));
57 calendar.add(Calendar.MINUTE, -15);
58 boat.addMovement(new TimeAndPlace(new EarthCoordinate(59.891171, 10.640006), calendar.getTime()));
59 calendar.add(Calendar.MINUTE, -15);
60 boat.addMovement(new TimeAndPlace(new EarthCoordinate(59.890575, 10.645234), calendar.getTime()));
61 calendar.add(Calendar.MINUTE, -15);
62 boat.addMovement(new TimeAndPlace(new EarthCoordinate(59.889318, 10.644650), calendar.getTime()));
63
64 // We add the object to the model
65 //model.add(boat);
66
67 // In order to make the kml more human readable we may activate indenting
68 model.XML_INDENT = true;
69
70 // We generate the kml file
71 //model.write("boat.kml");
72
73 System.out.println("The kml file was generated.");
74 }
75
76 }
0 package org.boehn.kmlframework.todo.examples;
1
2 import java.io.IOException;
3
4 import org.boehn.kmlframework.KmlDocument;
5 import org.boehn.kmlframework.KmlException;
6 import org.boehn.kmlframework.todo.MapObject;
7 import org.boehn.kmlframework.todo.ModelObjectFactory;
8 import org.boehn.kmlframework.todo.coordinates.CartesianCoordinate;
9 import org.boehn.kmlframework.todo.coordinates.EarthCoordinate;
10
11 public class ModelObjectFactoryExample {
12
13 public static void main(String[] args) throws KmlException, IOException {
14
15 try {
16
17 // We create a model
18 KmlDocument model = new KmlDocument();
19
20 // We create a ModelObjectFactory from a symbol file
21 ModelObjectFactory modelObjectFactory = new ModelObjectFactory("resources/symbols/symbols.xml");
22
23 // We create a boat object
24 MapObject boat = modelObjectFactory.createMapObject("boat");
25 boat.setLocation(new EarthCoordinate(59.8959, 10.6406));
26 // We define the size of the boat
27 boat.setScale(new CartesianCoordinate(30, 150, 30));
28 // We define the direction of the boat. 0 is North
29 boat.setRotation(Math.toRadians(45d));
30 // We define the gps position in the boat (according to the 3D model of the boat
31 boat.setLocalReferenceCoordinate(new CartesianCoordinate(2, 13, 0));
32
33 // We add the object to the model
34 //model.add(boat);
35
36 // We generate the kml file
37 //model.write("boat.kml");
38
39 System.out.println("The kml file was generated.");
40
41 } catch (Exception e) {
42 e.printStackTrace();
43 }
44 }
45
46 }
0 package org.boehn.kmlframework.todo.examples;
1
2 import java.io.IOException;
3
4 import javax.servlet.ServletException;
5 import javax.servlet.http.HttpServlet;
6 import javax.servlet.http.HttpServletRequest;
7 import javax.servlet.http.HttpServletResponse;
8
9 import org.boehn.kmlframework.todo.MapObject;
10 import org.boehn.kmlframework.todo.coordinates.EarthCoordinate;
11 import org.boehn.kmlframework.todo.servlet.HttpServletModel;
12
13 public class SimpleExampleServlet extends HttpServlet {
14
15 private static final long serialVersionUID = 1L;
16
17 @Override
18 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
19 try {
20 // We create a model
21 HttpServletModel model = new HttpServletModel(request, response);
22
23 // We create an object for the Department of Informatics at the university of Oslo
24 MapObject ifi = new MapObject("Department of Informatics");
25 ifi.setDescription("Web: http://www.ifi.uio.no<br/>Phone: +47 22852410");
26 ifi.setLocation(new EarthCoordinate(59.943355, 10.717344));
27
28 // We add the object to the model
29 //model.add(ifi);
30
31 // We generate the kml file
32 model.write();
33
34 } catch (Exception e) {
35 throw new ServletException(e);
36 }
37 }
38 }
0 package org.boehn.kmlframework.todo.overlays;
1
2 import java.io.IOException;
3 import java.io.Writer;
4
5 import org.boehn.kmlframework.KmlDocument;
6 import org.boehn.kmlframework.KmlException;
7 import org.boehn.kmlframework.todo.BoundingBox;
8 import org.boehn.kmlframework.todo.ViewPosition;
9 import org.w3c.dom.Document;
10 import org.w3c.dom.Element;
11
12 public class GroundOverlay extends Overlay {
13
14 private ViewPosition viewPosition;
15 private String color;
16 private BoundingBox boundingBox;
17
18 public GroundOverlay() {}
19
20 public BoundingBox getBoundingBox() {
21 return boundingBox;
22 }
23
24 public void setBoundingBox(BoundingBox boundingBox) {
25 this.boundingBox = boundingBox;
26 }
27
28 public String getColor() {
29 return color;
30 }
31
32 public void setColor(String color) {
33 this.color = color;
34 }
35
36 public ViewPosition getViewPosition() {
37 return viewPosition;
38 }
39
40 public void setViewPosition(ViewPosition viewPosition) {
41 this.viewPosition = viewPosition;
42 }
43
44 public void addKml(Element parentElement, KmlDocument model, Document xmlDocument) throws KmlException {
45 Element groundOverlayElement = xmlDocument.createElement("GroundOverlay");
46
47 if (name != null) {
48 Element nameElement = xmlDocument.createElement("name");
49 nameElement.appendChild(xmlDocument.createTextNode(name));
50 groundOverlayElement.appendChild(nameElement);
51 }
52
53 if (description != null) {
54 Element descriptionElement = xmlDocument.createElement("description");
55 descriptionElement.appendChild(xmlDocument.createCDATASection(description));
56 groundOverlayElement.appendChild(descriptionElement);
57 }
58
59 if (color != null) {
60 Element colorElement = xmlDocument.createElement("color");
61 colorElement.appendChild(xmlDocument.createTextNode(color));
62 groundOverlayElement.appendChild(colorElement);
63 }
64
65 if (viewPosition != null) {
66 viewPosition.addKml(groundOverlayElement, model, xmlDocument);
67 }
68
69 if (boundingBox != null) {
70 Element latLonBoxElement = xmlDocument.createElement("LatLonBox");
71 if (boundingBox.getNorth() != null) {
72 Element northElement = xmlDocument.createElement("north");
73 northElement.appendChild(xmlDocument.createTextNode(boundingBox.getNorth().toString()));
74 latLonBoxElement.appendChild(northElement);
75 }
76 if (boundingBox.getSouth() != null) {
77 Element southElement = xmlDocument.createElement("south");
78 southElement.appendChild(xmlDocument.createTextNode(boundingBox.getSouth().toString()));
79 latLonBoxElement.appendChild(southElement);
80 }
81 if (boundingBox.getWest() != null) {
82 Element westElement = xmlDocument.createElement("west");
83 westElement.appendChild(xmlDocument.createTextNode(boundingBox.getWest().toString()));
84 latLonBoxElement.appendChild(westElement);
85 }
86 if (boundingBox.getEast() != null) {
87 Element eastElement = xmlDocument.createElement("east");
88 eastElement.appendChild(xmlDocument.createTextNode(boundingBox.getEast().toString()));
89 latLonBoxElement.appendChild(eastElement);
90 }
91
92 if (icon != null) {
93 icon.addKml(groundOverlayElement, model, xmlDocument);
94 }
95
96 if (drawOrder != null) {
97 Element drawOrderElement = xmlDocument.createElement("drawOrder");
98 drawOrderElement.appendChild(xmlDocument.createTextNode(drawOrder.toString()));
99 groundOverlayElement.appendChild(drawOrderElement);
100 }
101
102 if (visibility != null) {
103 Element visibilityElement = xmlDocument.createElement("visibility");
104 visibilityElement.appendChild(xmlDocument.createTextNode((visibility) ? "1" : "0"));
105 groundOverlayElement.appendChild(visibilityElement);
106 }
107 groundOverlayElement.appendChild(latLonBoxElement);
108 }
109
110 parentElement.appendChild(groundOverlayElement);
111 }
112
113 /*public void addKmlXPP(KmlDocument model, XmlSerializer serializer) {
114 // TODO Auto-generated method stub
115
116 }*/
117
118 public void addKmlDirect(KmlDocument model, Writer writer) throws IOException {
119 // TODO Auto-generated method stub
120
121 }
122
123
124 }
0 package org.boehn.kmlframework.todo.overlays;
1
2 import org.boehn.kmlframework.KmlDocument;
3 import org.boehn.kmlframework.KmlException;
4 import org.w3c.dom.Document;
5 import org.w3c.dom.Element;
6
7 public class Icon {
8
9 private String url;
10 private Integer x;
11 private Integer y;
12 private Integer width;
13 private Integer height;
14
15 public Icon() {}
16
17 public Icon(String url) {
18 this.url = url;
19 }
20
21 public Icon(String url, Integer x, Integer y, Integer width, Integer height) {
22 this.url = url;
23 this.x = x;
24 this.y = y;
25 this.width = width;
26 this.height = height;
27 }
28
29 public Integer getHeight() {
30 return height;
31 }
32
33 public void setHeight(Integer height) {
34 this.height = height;
35 }
36
37 public String getUrl() {
38 return url;
39 }
40
41 public void setUrl(String url) {
42 this.url = url;
43 }
44
45 public Integer getWidth() {
46 return width;
47 }
48
49 public void setWidth(Integer width) {
50 this.width = width;
51 }
52
53 public Integer getX() {
54 return x;
55 }
56
57 public void setX(Integer x) {
58 this.x = x;
59 }
60
61 public Integer getY() {
62 return y;
63 }
64
65 public void setY(Integer y) {
66 this.y = y;
67 }
68
69 public void addKml(Element parentElement, KmlDocument model, Document xmlDocument) throws KmlException {
70 Element iconElement = xmlDocument.createElement("Icon");
71
72 if (url != null) {
73 Element urlElement = xmlDocument.createElement("href");
74 urlElement.appendChild(xmlDocument.createTextNode(url));
75 iconElement.appendChild(urlElement);
76 }
77
78 if (x != null) {
79 Element xElement = xmlDocument.createElement("x");
80 xElement.appendChild(xmlDocument.createTextNode(x.toString()));
81 iconElement.appendChild(xElement);
82 }
83
84 if (y != null) {
85 Element yElement = xmlDocument.createElement("y");
86 yElement.appendChild(xmlDocument.createTextNode(y.toString()));
87 iconElement.appendChild(yElement);
88 }
89
90 if (width != null) {
91 Element widthElement = xmlDocument.createElement("w");
92 widthElement.appendChild(xmlDocument.createTextNode(width.toString()));
93 iconElement.appendChild(widthElement);
94 }
95
96 if (height != null) {
97 Element heightElement = xmlDocument.createElement("h");
98 heightElement.appendChild(xmlDocument.createTextNode(height.toString()));
99 iconElement.appendChild(heightElement);
100 }
101
102 parentElement.appendChild(iconElement);
103 }
104
105 }
0 package org.boehn.kmlframework.todo.overlays;
1
2 //import org.boehn.kmlframework.KmlDocumentElement;
3
4 public abstract class Overlay /*implements KmlDocumentElement*/ {
5
6 protected String name;
7 protected String description;
8 protected Icon icon;
9 protected Integer drawOrder;
10 protected Boolean visibility;
11
12 public String getDescription() {
13 return description;
14 }
15
16 public void setDescription(String description) {
17 this.description = description;
18 }
19
20 public Integer getDrawOrder() {
21 return drawOrder;
22 }
23
24 public void setDrawOrder(Integer drawOrder) {
25 this.drawOrder = drawOrder;
26 }
27
28 public Icon getIcon() {
29 return icon;
30 }
31
32 public void setIcon(Icon icon) {
33 this.icon = icon;
34 }
35
36 public String getName() {
37 return name;
38 }
39
40 public void setName(String name) {
41 this.name = name;
42 }
43
44 public Boolean getVisibility() {
45 return visibility;
46 }
47
48 public void setVisibility(Boolean visibility) {
49 this.visibility = visibility;
50 }
51
52 }
0 package org.boehn.kmlframework.todo.overlays;
1
2 public class OverlayXY extends ScreenOverlayUnitsCapsule {
3
4 public OverlayXY(Double x, Double y, Units xUnits, Units yUnits) {
5 super("overlayXY", x, y, xUnits, yUnits);
6 }
7 }
0 package org.boehn.kmlframework.todo.overlays;
1
2 import java.io.IOException;
3 import java.io.Writer;
4
5 import org.boehn.kmlframework.KmlDocument;
6 import org.boehn.kmlframework.KmlException;
7 import org.w3c.dom.Document;
8 import org.w3c.dom.Element;
9
10 public class ScreenOverlay extends Overlay {
11
12 private OverlayXY overlayXY;
13 private ScreenXY screenXY;
14 private Size size;
15 private Double rotation;
16
17 public ScreenOverlay() {}
18
19 public ScreenOverlayUnitsCapsule getOverlayXY() {
20 return overlayXY;
21 }
22
23 public Double getRotation() {
24 return rotation;
25 }
26
27 public void setRotation(Double rotation) {
28 this.rotation = rotation;
29 }
30
31 public ScreenXY getScreenXY() {
32 return screenXY;
33 }
34
35 public void setScreenXY(ScreenXY screenXY) {
36 this.screenXY = screenXY;
37 }
38
39 public Size getSize() {
40 return size;
41 }
42
43 public void setSize(Size size) {
44 this.size = size;
45 }
46
47 public void setOverlayXY(OverlayXY overlayXY) {
48 this.overlayXY = overlayXY;
49 }
50
51 public void addKml(Element parentElement, KmlDocument model, Document xmlDocument) throws KmlException {
52 Element screenOverlayElement = xmlDocument.createElement("ScreenOverlay");
53
54 if (name != null) {
55 Element nameElement = xmlDocument.createElement("name");
56 nameElement.appendChild(xmlDocument.createTextNode(name));
57 screenOverlayElement.appendChild(nameElement);
58 }
59
60 if (description != null) {
61 Element descriptionElement = xmlDocument.createElement("description");
62 descriptionElement.appendChild(xmlDocument.createCDATASection(description));
63 screenOverlayElement.appendChild(descriptionElement);
64 }
65
66 if (rotation != null) {
67 Element rotationElement = xmlDocument.createElement("rotation");
68 rotationElement.appendChild(xmlDocument.createTextNode(rotation.toString()));
69 screenOverlayElement.appendChild(rotationElement);
70 }
71
72 if (overlayXY != null) {
73 overlayXY.addKml(screenOverlayElement, model, xmlDocument);
74 }
75
76 if (screenXY != null) {
77 screenXY.addKml(screenOverlayElement, model, xmlDocument);
78 }
79
80 if (size != null) {
81 size.addKml(screenOverlayElement, model, xmlDocument);
82 }
83
84 if (icon != null) {
85 icon.addKml(screenOverlayElement, model, xmlDocument);
86 }
87
88 if (drawOrder != null) {
89 Element drawOrderElement = xmlDocument.createElement("drawOrder");
90 drawOrderElement.appendChild(xmlDocument.createTextNode(drawOrder.toString()));
91 screenOverlayElement.appendChild(drawOrderElement);
92 }
93
94 if (visibility != null) {
95 Element visibilityElement = xmlDocument.createElement("visibility");
96 visibilityElement.appendChild(xmlDocument.createTextNode((visibility) ? "1" : "0"));
97 screenOverlayElement.appendChild(visibilityElement);
98 }
99
100 parentElement.appendChild(screenOverlayElement);
101 }
102
103 /*public void addKmlXPP(KmlDocument model, XmlSerializer serializer) {
104 // TODO Auto-generated method stub
105
106 }*/
107
108 public void addKmlDirect(KmlDocument model, Writer writer) throws IOException {
109 // TODO Auto-generated method stub
110
111 }
112
113 }
0 package org.boehn.kmlframework.todo.overlays;
1
2 import org.boehn.kmlframework.KmlDocument;
3 import org.boehn.kmlframework.KmlException;
4 import org.w3c.dom.Document;
5 import org.w3c.dom.Element;
6
7 public abstract class ScreenOverlayUnitsCapsule {
8
9 private String name;
10 private Double x;
11 private Double y;
12 private Units xUnits;
13 private Units yUnits;
14
15 public ScreenOverlayUnitsCapsule() {}
16
17 public ScreenOverlayUnitsCapsule(String name, Double x, Double y, Units xUnits, Units yUnits) {
18 this.name = name;
19 this.x = x;
20 this.y = y;
21 this.xUnits = xUnits;
22 this.yUnits = yUnits;
23 }
24
25 public String getName() {
26 return name;
27 }
28
29 public void setName(String name) {
30 this.name = name;
31 }
32
33 public Double getX() {
34 return x;
35 }
36
37 public void setX(Double x) {
38 this.x = x;
39 }
40
41 public Units getXUnits() {
42 return xUnits;
43 }
44
45 public void setXUnits(Units units) {
46 xUnits = units;
47 }
48
49 public Double getY() {
50 return y;
51 }
52
53 public void setY(Double y) {
54 this.y = y;
55 }
56
57 public Units getYUnits() {
58 return yUnits;
59 }
60
61 public void setYUnits(Units units) {
62 yUnits = units;
63 }
64
65 public void addKml(Element parentElement, KmlDocument model, Document xmlDocument) throws KmlException {
66 Element element = xmlDocument.createElement(name);
67 if (x != null) {
68 element.setAttribute("x", x.toString());
69 }
70 if (y != null) {
71 element.setAttribute("y", y.toString());
72 }
73 if (xUnits != null) {
74 element.setAttribute("xunits", xUnits.toString());
75 }
76 if (yUnits != null) {
77 element.setAttribute("yunits", yUnits.toString());
78 }
79 parentElement.appendChild(element);
80 }
81
82 }
0 package org.boehn.kmlframework.todo.overlays;
1
2 public class ScreenXY extends ScreenOverlayUnitsCapsule {
3
4 public ScreenXY(Double x, Double y, Units xUnits, Units yUnits) {
5 super("screenXY", x, y, xUnits, yUnits);
6 }
7 }
0 package org.boehn.kmlframework.todo.overlays;
1
2 public class Size extends ScreenOverlayUnitsCapsule {
3
4 public Size(Double x, Double y, Units xUnits, Units yUnits) {
5 super("size", x, y, xUnits, yUnits);
6 }
7 }
0 package org.boehn.kmlframework.todo.overlays;
1
2 public enum Units {
3 fraction, pixels
4 }
0 package org.boehn.kmlframework.todo.servlet;
1
2 import java.io.IOException;
3 import java.util.StringTokenizer;
4
5 import javax.servlet.ServletOutputStream;
6 import javax.servlet.http.HttpServletRequest;
7 import javax.servlet.http.HttpServletResponse;
8 import javax.xml.parsers.DocumentBuilderFactory;
9 import javax.xml.parsers.ParserConfigurationException;
10
11 import org.boehn.kmlframework.KmlDocument;
12 //import org.boehn.kmlframework.KmlDocumentElement;
13 import org.boehn.kmlframework.KmlException;
14 import org.boehn.kmlframework.todo.BoundingBox;
15 import org.boehn.kmlframework.todo.ViewPosition;
16 import org.boehn.kmlframework.todo.style.Style;
17 import org.w3c.dom.Document;
18 import org.w3c.dom.Element;
19
20 public class HttpServletModel extends KmlDocument {
21
22 private NetworkLinkControl networkLinkControl;
23 private String baseUrl;
24 private HttpServletRequest request;
25 private HttpServletResponse response;
26 private String sessionId;
27
28 public boolean DISABLEHTTPCACHE = true;
29
30 public HttpServletModel(HttpServletRequest request, HttpServletResponse response) {
31 this(request, response, true);
32 }
33
34 public HttpServletModel(HttpServletRequest request, HttpServletResponse response, boolean handleTransactions) {
35 this.request = request;
36 this.response = response;
37 if (handleTransactions) {
38 networkLinkControl = new NetworkLinkControl();
39 networkLinkControl.setCookie("jsessionid=" + request.getSession().getId());
40 }
41 }
42
43
44 public NetworkLinkControl getNetworkLinkControl() {
45 return networkLinkControl;
46 }
47
48 public void setNetworkLinkControl(NetworkLinkControl networkLinkControl) {
49 this.networkLinkControl = networkLinkControl;
50 }
51
52 public String getBaseUrl() {
53 if (baseUrl != null) {
54 return baseUrl;
55 } else {
56 return "http://" + request.getLocalName() + ":" + request.getLocalPort() + request.getContextPath();
57 }
58 }
59
60 @Override
61 public Observer getObserver() {
62 if (super.getObserver() == null && request != null) {
63 try {
64 // We try to read the parameters from the http get
65 StringTokenizer parameters = new StringTokenizer(request.getParameter("gefObserver"), ",");
66
67 BoundingBox boundingBox = new BoundingBox(Double.parseDouble(parameters.nextToken().replace(' ', '+')), Double.parseDouble(parameters.nextToken().replace(' ', '+')), Double.parseDouble(parameters.nextToken().replace(' ', '+')), Double.parseDouble(parameters.nextToken().replace(' ', '+')));
68 ViewPosition viewPosition = new ViewPosition(Double.parseDouble(parameters.nextToken().replace(' ', '+')), Double.parseDouble(parameters.nextToken().replace(' ', '+')), Double.parseDouble(parameters.nextToken().replace(' ', '+')), Double.parseDouble(parameters.nextToken().replace(' ', '+')), Double.parseDouble(parameters.nextToken().replace(' ', '+')));
69 setObserver(new Observer(boundingBox, viewPosition));
70 } catch (Exception e) {
71 //log.warn("Could not create observer because of missing information in the http get.");
72 }
73 }
74 return super.getObserver();
75 }
76
77 public void setBaseUrl(String baseUrl) {
78 this.baseUrl = baseUrl;
79 }
80
81 public HttpServletRequest getRequest() {
82 return request;
83 }
84
85 public void setRequest(HttpServletRequest request) {
86 this.request = request;
87 setObserver(null);
88 }
89
90 public HttpServletResponse getResponse() {
91 return response;
92 }
93
94 public void setResponse(HttpServletResponse response) {
95 this.response = response;
96 }
97
98 public String getSessionId() {
99 return sessionId;
100 }
101
102 public void setSessionId(String sessionId) {
103 this.sessionId = sessionId;
104 }
105
106 /*@Override
107 public Document generateXmlDocument() throws KmlException {
108 Document xmlDocument;
109 try {
110 xmlDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
111 } catch (ParserConfigurationException e) {
112 throw new KmlException(e);
113 }
114
115 Element kmlElement = xmlDocument.createElement("kml");
116 kmlElement.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", "http://earth.google.com/kml/2.0");
117 xmlDocument.appendChild(kmlElement);
118
119 if (networkLinkControl != null) {
120 networkLinkControl.addKml(kmlElement, this, xmlDocument);
121 }
122
123 Element documentElement = xmlDocument.createElement("Document");
124 kmlElement.appendChild(documentElement);
125
126 if (getStyles() != null) {
127 for (Style style: getStyles().values()) {
128 style.addKml(documentElement, this, xmlDocument);
129 }
130 }
131 if (getKmlDocumentElements() != null) {
132 for (KmlDocumentElement modelElement: getKmlDocumentElements())
133 modelElement.addKml(documentElement, this, xmlDocument);
134 }
135
136 return xmlDocument;
137 }*/
138
139 public void write() throws KmlException, IOException {
140 response.setContentType("text/html");
141
142 if (DISABLEHTTPCACHE) {
143 response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
144 response.setHeader("Pragma","no-cache"); //HTTP 1.0
145 response.setDateHeader ("Expires", 0);
146 }
147
148 ServletOutputStream out = response.getOutputStream();
149 //this.write(out);
150 out.close();
151 }
152
153 }
0 package org.boehn.kmlframework.todo.servlet;
1
2 import java.io.IOException;
3 import java.io.Writer;
4
5 import org.boehn.kmlframework.KmlDocument;
6 //import org.boehn.kmlframework.KmlDocumentElement;
7 import org.boehn.kmlframework.KmlException;
8 import org.w3c.dom.Document;
9 import org.w3c.dom.Element;
10 //import org.xmlpull.v1.XmlSerializer;
11
12 public class NetworkLink /*implements KmlDocumentElement*/ {
13
14 private String name;
15 private Boolean flyToView;
16 private String url;
17 private RefreshModes refreshMode;
18 private Integer refreshInterval;
19 private ViewRefreshModes viewRefreshMode;
20 private Integer viewRefreshTime;
21 private String viewFormat;
22 private Boolean refreshVisibility;
23 private Boolean open;
24
25 public NetworkLink() {
26 // We set the default values
27 viewFormat = "gefObserver=[bboxNorth],[bboxEast],[bboxSouth],[bboxWest],[lookatLat],[lookatLon],[lookatRange],[lookatTilt],[lookatHeading]";
28 refreshMode = RefreshModes.once;
29 viewRefreshMode = ViewRefreshModes.onStop;
30 viewRefreshTime = 0;
31 open = true;
32 }
33
34 public NetworkLink(String url, String name) {
35 this();
36 this.url = url;
37 this.name = name;
38 }
39
40 public Boolean getFlyToView() {
41 return flyToView;
42 }
43
44 public void setFlyToView(Boolean flyToView) {
45 this.flyToView = flyToView;
46 }
47
48 public String getName() {
49 return name;
50 }
51
52 public void setName(String name) {
53 this.name = name;
54 }
55
56 public RefreshModes getRefreshMode() {
57 return refreshMode;
58 }
59
60 public void setRefreshMode(RefreshModes refreshMode) {
61 this.refreshMode = refreshMode;
62 }
63
64 public Integer getRefreshInterval() {
65 return refreshInterval;
66 }
67
68 public void setRefreshInterval(Integer refreshInterval) {
69 this.refreshInterval = refreshInterval;
70 }
71
72 public String getUrl() {
73 return url;
74 }
75
76 public void setUrl(String url) {
77 this.url = url;
78 }
79
80 public String getViewFormat() {
81 return viewFormat;
82 }
83
84 public void setViewFormat(String viewFormat) {
85 this.viewFormat = viewFormat;
86 }
87
88 public ViewRefreshModes getViewRefreshMode() {
89 return viewRefreshMode;
90 }
91
92 public void setViewRefreshMode(ViewRefreshModes viewRefreshMode) {
93 this.viewRefreshMode = viewRefreshMode;
94 }
95
96 public Integer getViewRefreshTime() {
97 return viewRefreshTime;
98 }
99
100 public void setViewRefreshTime(Integer viewRefreshTime) {
101 this.viewRefreshTime = viewRefreshTime;
102 }
103
104 public Boolean getRefreshVisibility() {
105 return refreshVisibility;
106 }
107
108 public void setRefreshVisibility(Boolean refreshVisibility) {
109 this.refreshVisibility = refreshVisibility;
110 }
111
112 public Boolean getOpen() {
113 return open;
114 }
115
116 public void setOpen(Boolean open) {
117 this.open = open;
118 }
119
120 public static void main(String[] args) throws KmlException, IOException {
121 if (args.length != 3) {
122 System.err.println("Usage: java org.boehn.gef.elements.NetworkLink <url> <name> <destinationFile>");
123 System.exit(-1);
124 } else {
125 KmlDocument model = new KmlDocument();
126 //model.add(new NetworkLink(args[0], args[1]));
127 //model.write(args[2]);
128 }
129 }
130
131 public void addKml(Element parentElement, KmlDocument model, Document xmlDocument) throws KmlException {
132
133 Element networkLinkElement = xmlDocument.createElement("NetworkLink");
134
135 if (name != null) {
136 Element nameElement = xmlDocument.createElement("name");
137 nameElement.appendChild(xmlDocument.createTextNode(name));
138 networkLinkElement.appendChild(nameElement);
139 }
140
141 if (open != null) {
142 Element openElement = xmlDocument.createElement("open");
143 openElement.appendChild(xmlDocument.createTextNode((open) ? "1" : "0"));
144 networkLinkElement.appendChild(openElement);
145 }
146
147 if (flyToView != null) {
148 Element flyToViewElement = xmlDocument.createElement("flyToView");
149 flyToViewElement.appendChild(xmlDocument.createTextNode((flyToView) ? "1" : "0"));
150 networkLinkElement.appendChild(flyToViewElement);
151 }
152
153 if (refreshVisibility != null) {
154 Element refreshVisibilityElement = xmlDocument.createElement("refreshVisibility");
155 refreshVisibilityElement.appendChild(xmlDocument.createTextNode((refreshVisibility) ? "1" : "0"));
156 networkLinkElement.appendChild(refreshVisibilityElement);
157 }
158
159 if (url != null) {
160 Element urlElement = xmlDocument.createElement("Url");
161 Element hrefElement = xmlDocument.createElement("href");
162 hrefElement.appendChild(xmlDocument.createTextNode(url));
163 urlElement.appendChild(hrefElement);
164 if (refreshMode != null) {
165 Element refreshModeElement = xmlDocument.createElement("refreshMode");
166 refreshModeElement.appendChild(xmlDocument.createTextNode(refreshMode.toString()));
167 urlElement.appendChild(refreshModeElement);
168 }
169 if (refreshInterval != null) {
170 Element refreshIntervalElement = xmlDocument.createElement("refreshInterval");
171 refreshIntervalElement.appendChild(xmlDocument.createTextNode(refreshInterval.toString()));
172 urlElement.appendChild(refreshIntervalElement);
173 }
174 if (viewRefreshMode != null) {
175 Element viewRefreshModeElement = xmlDocument.createElement("viewRefreshMode");
176 viewRefreshModeElement.appendChild(xmlDocument.createTextNode(viewRefreshMode.toString()));
177 urlElement.appendChild(viewRefreshModeElement);
178 }
179 if (viewRefreshTime != null) {
180 Element viewRefreshTimeElement = xmlDocument.createElement("viewRefreshTime");
181 viewRefreshTimeElement.appendChild(xmlDocument.createTextNode(viewRefreshTime.toString()));
182 urlElement.appendChild(viewRefreshTimeElement);
183 }
184 if (viewFormat != null) {
185 Element viewFormatElement = xmlDocument.createElement("viewFormat");
186 viewFormatElement.appendChild(xmlDocument.createTextNode(viewFormat));
187 urlElement.appendChild(viewFormatElement);
188 }
189 networkLinkElement.appendChild(urlElement);
190 }
191 parentElement.appendChild(networkLinkElement);
192 }
193
194 /*public void addKmlXPP(KmlDocument model, XmlSerializer serializer) throws IllegalArgumentException, IllegalStateException, IOException {
195 // TODO Auto-generated method stub
196
197 }*/
198
199 public void addKmlDirect(KmlDocument model, Writer writer) throws IOException {
200 // TODO Auto-generated method stub
201
202 }
203 }
0 package org.boehn.kmlframework.todo.servlet;
1
2 import org.boehn.kmlframework.KmlDocument;
3 import org.boehn.kmlframework.KmlException;
4 import org.w3c.dom.Document;
5 import org.w3c.dom.Element;
6
7 public class NetworkLinkControl {
8
9 private String message;
10 private String cookie;
11 private String linkName;
12 private String linkDescription;
13 private Integer minRefreshPeriod;
14
15 public NetworkLinkControl() {}
16
17 public NetworkLinkControl(String message, String cookie, String linkName, String linkDescription, Integer minRefreshPeriod) {
18 this.message = message;
19 this.cookie = cookie;
20 this.linkName = linkName;
21 this.linkDescription = linkDescription;
22 this.minRefreshPeriod = minRefreshPeriod;
23 }
24
25 public String getCookie() {
26 return cookie;
27 }
28
29 public void setCookie(String cookie) {
30 this.cookie = cookie;
31 }
32
33 public String getLinkDescription() {
34 return linkDescription;
35 }
36
37 public void setLinkDescription(String linkDescription) {
38 this.linkDescription = linkDescription;
39 }
40
41 public String getLinkName() {
42 return linkName;
43 }
44
45 public void setLinkName(String linkName) {
46 this.linkName = linkName;
47 }
48
49 public String getMessage() {
50 return message;
51 }
52
53 public void setMessage(String message) {
54 this.message = message;
55 }
56
57 public Integer getMinRefreshPeriod() {
58 return minRefreshPeriod;
59 }
60
61 public void setMinRefreshPeriod(Integer minRefreshPeriod) {
62 this.minRefreshPeriod = minRefreshPeriod;
63 }
64
65 public void addKml(Element parentElement, KmlDocument model, Document xmlDocument) throws KmlException {
66 Element networkLinkControlElement = xmlDocument.createElement("NetworkLinkControl");
67
68 if (cookie != null) {
69 Element cookieElement = xmlDocument.createElement("cookie");
70 cookieElement.appendChild(xmlDocument.createCDATASection(cookie));
71 networkLinkControlElement.appendChild(cookieElement);
72 }
73
74 if (linkDescription != null) {
75 Element linkDescriptionElement = xmlDocument.createElement("linkDescription");
76 linkDescriptionElement.appendChild(xmlDocument.createCDATASection(linkDescription));
77 networkLinkControlElement.appendChild(linkDescriptionElement);
78 }
79
80 if (linkName != null) {
81 Element linkNameElement = xmlDocument.createElement("linkName");
82 linkNameElement.appendChild(xmlDocument.createCDATASection(linkName));
83 networkLinkControlElement.appendChild(linkNameElement);
84 }
85
86 if (message != null) {
87 Element messageElement = xmlDocument.createElement("message");
88 messageElement.appendChild(xmlDocument.createCDATASection(message));
89 networkLinkControlElement.appendChild(messageElement);
90 }
91
92 if (minRefreshPeriod != null) {
93 Element minRefreshPeriodElement = xmlDocument.createElement("minRefreshPeriod");
94 minRefreshPeriodElement.appendChild(xmlDocument.createTextNode(minRefreshPeriod.toString()));
95 networkLinkControlElement.appendChild(minRefreshPeriodElement);
96 }
97 parentElement.appendChild(networkLinkControlElement);
98 }
99
100 }
0 package org.boehn.kmlframework.todo.servlet;
1
2 import org.boehn.kmlframework.todo.BoundingBox;
3 import org.boehn.kmlframework.todo.ViewPosition;
4 import org.boehn.kmlframework.todo.coordinates.CartesianCoordinate;
5 import org.boehn.kmlframework.todo.coordinates.EarthCoordinate;
6
7 public class Observer {
8
9 private BoundingBox boundingBox;
10 private ViewPosition viewPosition;
11 private CartesianCoordinate observerCoordinate;
12
13 public Observer() {}
14
15 public Observer(BoundingBox boundingBox, ViewPosition viewPosition) {
16 this.boundingBox = boundingBox;
17 this.viewPosition = viewPosition;
18 }
19
20 public Boolean isVisibleToObserver(EarthCoordinate earthCoordinate) {
21 if (boundingBox != null) {
22 return boundingBox.isInsideBoundingBox(earthCoordinate);
23 } else {
24 return null;
25 }
26 }
27
28 public Double distanceTo(EarthCoordinate earthCoordinate) {
29 if (earthCoordinate != null) {
30 return distanceTo(earthCoordinate.toCartesianCoordinate());
31 } else {
32 return null;
33 }
34 }
35
36 public Double distanceTo(CartesianCoordinate cartesianCoordinate) {
37 if (cartesianCoordinate != null) {
38 return getObserverCoordinate().distanceTo(cartesianCoordinate);
39 } else {
40 return null;
41 }
42 }
43
44 public CartesianCoordinate getObserverCoordinate() {
45 if (observerCoordinate == null) {
46
47 if (viewPosition != null && viewPosition.getRange() != null && viewPosition.getTilt() != null && viewPosition.getHeading() != null) {
48 // We make the vector starting in 0,0,0 and going straight up with the length = lookAtRange
49 observerCoordinate = new CartesianCoordinate(0, 0, viewPosition.getRange());
50
51 // We rotate the vector around the Z axis to get the correct tilt
52 observerCoordinate.rotateAroundZAxis(viewPosition.getTilt());
53
54 // We rotate the vector around the Y axis to get the correct heading
55 observerCoordinate.rotateAroundYAxis(viewPosition.getHeading());
56
57 // Now we have our vector finish in the local coordinate system. Now we have to place it out on the earth
58
59 // First we have to rotate our local coordinate system to the surface of the earth
60 observerCoordinate.rotateAroundZAxis(Math.toRadians(viewPosition.getLatitude()));
61 observerCoordinate.rotateAroundYAxis(Math.toRadians(viewPosition.getLongitude()));
62
63 // Now our vector has the correct length and direction. We only have to place it out at the lookAt coordinate
64 observerCoordinate.add(new EarthCoordinate(viewPosition.getLatitude(), viewPosition.getLongitude()).toCartesianCoordinate());
65 } else {
66 System.out.println("The observer coordinate is being requested, but the observer has not defined sufficient data for calculating this.");
67 }
68 }
69 return observerCoordinate;
70 }
71
72 public BoundingBox getBoundingBox() {
73 return boundingBox;
74 }
75
76 public void setBoundingBox(BoundingBox boundingBox) {
77 this.boundingBox = boundingBox;
78 }
79
80 public void setViewPosition(ViewPosition viewPosition) {
81 this.viewPosition = viewPosition;
82 observerCoordinate = null;
83 }
84
85 public ViewPosition getViewPosition() {
86 return viewPosition;
87 }
88
89 }
0 package org.boehn.kmlframework.todo.servlet;
1
2 public enum RefreshModes {
3 onInterval, once
4 }
0 package org.boehn.kmlframework.todo.servlet;
1
2 public enum ViewRefreshModes {
3 never, onStop, onRequest
4 }
0 package org.boehn.kmlframework.todo.servlet.kmz;
1
2 import java.io.IOException;
3 import javax.servlet.Filter;
4 import javax.servlet.FilterChain;
5 import javax.servlet.FilterConfig;
6 import javax.servlet.ServletException;
7 import javax.servlet.ServletRequest;
8 import javax.servlet.ServletResponse;
9 import javax.servlet.http.HttpServletRequest;
10 import javax.servlet.http.HttpServletResponse;
11
12
13 public class KmzFilter implements Filter {
14
15 public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
16 if (req instanceof HttpServletRequest) {
17 HttpServletRequest request = (HttpServletRequest) req;
18 HttpServletResponse response = (HttpServletResponse) res;
19
20 String servletPath = request.getServletPath();
21 String kmlFileName="";
22 int extension = servletPath.indexOf(".");
23 if (extension >= 0) {
24 // strip extension so that kmz contains a file ending in kml
25 kmlFileName = servletPath.substring(1, extension) + ".kml";
26 }
27 KmzResponseWrapper wrappedResponse =
28 new KmzResponseWrapper(response);
29 wrappedResponse.setKMLFileName(kmlFileName);
30 chain.doFilter(req, wrappedResponse);
31 wrappedResponse.finishResponse();
32 return;
33 }
34 }
35
36 public void init(FilterConfig filterConfig) {
37 // Nothing to do here
38 }
39
40 public void destroy() {
41 // Nothing to do here
42 }
43 }
0 package org.boehn.kmlframework.todo.servlet.kmz;
1
2 import java.io.IOException;
3 import java.util.zip.ZipEntry;
4 import java.util.zip.ZipOutputStream;
5 import javax.servlet.ServletOutputStream;
6 import javax.servlet.http.HttpServletResponse;
7
8 public class KmzResponseStream extends ServletOutputStream {
9
10 protected ZipOutputStream zipstream = null;
11 protected boolean closed = false;
12 protected HttpServletResponse response = null;
13 protected ServletOutputStream output = null;
14 private String kmlFileName="index.kml";
15
16 protected int bufferCount = 0;
17 protected byte[] buffer = null;
18 protected int length = -1;
19
20
21 public KmzResponseStream(HttpServletResponse response) throws IOException {
22 super();
23 closed = false;
24 this.response = response;
25 this.output = response.getOutputStream();
26 buffer = new byte[128];
27 }
28
29 public void setKMLFileName(String kml){
30 kmlFileName = kml;
31 }
32
33 public void close() throws IOException {
34 if (closed) {
35 throw new IOException("This output stream has already been closed");
36 }
37
38 if (zipstream!=null) {
39 flushToZip();
40 zipstream.close();
41 zipstream = null;
42 } else {
43 if (bufferCount>0) {
44 output.write(buffer, 0, bufferCount);
45 bufferCount=0;
46 }
47 }
48
49 output.close();
50 closed = true;
51 }
52
53 public void flush() throws IOException {
54 if (closed) {
55 throw new IOException("Cannot flush a closed output stream");
56 }
57
58 if (zipstream != null) {
59 zipstream.flush();
60 }
61 }
62
63 public void flushToZip() throws IOException {
64 if (bufferCount > 0) {
65 writeToZip(buffer, 0, bufferCount);
66 bufferCount = 0;
67 }
68 }
69
70
71 public void write(int b) throws IOException {
72 if (closed) {
73 throw new IOException("Cannot write to a closed output stream");
74 }
75 if (bufferCount >= buffer.length) {
76 flushToZip();
77 }
78 buffer[bufferCount++] = (byte) b;
79 }
80
81 public void write(byte b[]) throws IOException {
82 write(b, 0, b.length);
83 }
84
85 public void write(byte b[], int off, int len) throws IOException {
86 if (closed) {
87 throw new IOException("Cannot write to a closed output stream");
88 }
89
90 if (len == 0)
91 return;
92
93 // Can we write into buffer ?
94 if (len <= (buffer.length - bufferCount)) {
95 System.arraycopy(b, off, buffer, bufferCount, len);
96 bufferCount += len;
97 return;
98 }
99
100 // There is not enough space in buffer. Flush it ...
101 flushToZip();
102
103 // ... and try again. Note, that bufferCount = 0 here !
104 if (len <= (buffer.length - bufferCount)) {
105 System.arraycopy(b, off, buffer, bufferCount, len);
106 bufferCount += len;
107 return;
108 }
109
110 // write direct to zip
111 writeToZip(b, off, len);
112 }
113
114 public void writeToZip(byte b[], int off, int len) throws IOException {
115
116 if (zipstream == null) {
117 //System.out.println("Content-Length: " + Integer.toString(b.length));
118 //response.setContentLength(b.length);
119 response.setContentType("application/vnd.google-earth.kmzl; charset=UTF-8");
120 zipstream = new ZipOutputStream(output);
121 zipstream.putNextEntry(new ZipEntry(kmlFileName));
122 }
123 zipstream.write(b, off, len);
124 }
125
126
127 public boolean closed() {
128 return (this.closed);
129 }
130
131 public void reset() {
132 // Nothing to do here
133 }
134 }
0 package org.boehn.kmlframework.todo.servlet.kmz;
1
2 import java.io.IOException;
3 import java.io.OutputStreamWriter;
4 import java.io.PrintWriter;
5 import javax.servlet.ServletOutputStream;
6 import javax.servlet.http.HttpServletResponse;
7 import javax.servlet.http.HttpServletResponseWrapper;
8
9 public class KmzResponseWrapper extends HttpServletResponseWrapper {
10 protected HttpServletResponse origResponse = null;
11 protected ServletOutputStream stream = null;
12 protected PrintWriter writer = null;
13 private String kmlFileName="index.kml";
14
15 public KmzResponseWrapper(HttpServletResponse response) {
16 super(response);
17 origResponse = response;
18 }
19
20 public ServletOutputStream createOutputStream() throws IOException {
21 KmzResponseStream krs = new KmzResponseStream(origResponse);
22 krs.setKMLFileName(kmlFileName);
23 return (krs);
24 }
25
26 public void setKMLFileName(String kml) {
27 kmlFileName = kml;
28 }
29
30 public void finishResponse() {
31 try {
32 if (writer != null) {
33 writer.close();
34 } else {
35 if (stream != null) {
36 stream.close();
37 }
38 }
39 } catch (IOException e) {}
40 }
41
42 public void flushBuffer() throws IOException {
43 stream.flush();
44 }
45
46 public ServletOutputStream getOutputStream() throws IOException {
47 if (writer != null) {
48 throw new IllegalStateException("getWriter() has already been called!");
49 }
50
51 if (stream == null)
52 stream = createOutputStream();
53 return (stream);
54 }
55
56 public PrintWriter getWriter() throws IOException {
57 if (writer != null) {
58 return (writer);
59 }
60
61 if (stream != null) {
62 throw new IllegalStateException("getOutputStream() has already been called!");
63 }
64
65 stream = createOutputStream();
66 writer = new PrintWriter(new OutputStreamWriter(stream, "UTF-8"));
67 return (writer);
68 }
69
70 public void setContentLength(int length) {}
71 }
0 package org.boehn.kmlframework.todo.style;
1
2 public class Color {
3
4 private int r;
5 private int g;
6 private int b;
7 private int alpha;
8
9 public static Color black = new Color(0, 0, 0);
10 public static Color blue = new Color(0, 0, 255);
11 public static Color cyan = new Color(0, 173, 239);
12 public static Color darkGrey = new Color(64, 64, 64);
13 public static Color gray = new Color(128, 128, 128);
14 public static Color green = new Color(0, 255, 0);
15 public static Color lightGray = new Color(191, 191, 191);
16 public static Color magenta = new Color(255, 0, 255);
17 public static Color orange = new Color(255, 127, 0);
18 public static Color pink = new Color(255, 127, 255);
19 public static Color red = new Color(255, 0, 0);
20 public static Color white = new Color(255, 255, 255);
21 public static Color yellow = new Color(255, 255, 0);
22
23 public Color() {}
24
25 public Color(int red, int green, int blue) {
26 this(red, green, blue, 255);
27 }
28
29 public Color(int red, int green, int blue, int alpha) {
30 setRed(red);
31 setGreen(green);
32 setBlue(blue);
33 setAlpha(alpha);
34 }
35
36 public int getAlpha() {
37 return alpha;
38 }
39
40 public void setAlpha(int alpha) {
41 verifyValue(alpha);
42 this.alpha = alpha;
43 }
44
45 public int getBlue() {
46 return b;
47 }
48
49 public void setBlue(int blue) {
50 verifyValue(blue);
51 this.b = blue;
52 }
53
54 public int getGreen() {
55 return g;
56 }
57
58 public void setGreen(int green) {
59 verifyValue(green);
60 this.g = green;
61 }
62
63 public int getRed() {
64 return r;
65 }
66
67 public void setRed(int red) {
68 verifyValue(red);
69 this.r = red;
70 }
71
72 public String toHexString() {
73 String result = "";
74
75 if (alpha < 16) {
76 result += "0";
77 }
78 result += Integer.toHexString(alpha);
79
80 if (b < 16) {
81 result += "0";
82 }
83 result += Integer.toHexString(b);
84
85 if (g < 16) {
86 result += "0";
87 }
88 result += Integer.toHexString(g);
89
90 if (r < 16) {
91 result += "0";
92 }
93 result += Integer.toHexString(r);
94
95 return result;
96 }
97
98 private static void verifyValue(int value) {
99 if (value < 0 || value > 255) {
100 throw new IllegalArgumentException("Value must be in the range (0 - 255). " + value + " is not valid.");
101 }
102 }
103
104 }
0 package org.boehn.kmlframework.todo.style;
1
2 public enum ColorModes {
3 normal, random
4 }
0 package org.boehn.kmlframework.todo.style;
1
2 import org.boehn.kmlframework.KmlDocument;
3 import org.boehn.kmlframework.KmlException;
4 import org.boehn.kmlframework.todo.overlays.Icon;
5 import org.w3c.dom.Document;
6 import org.w3c.dom.Element;
7
8 public class Style {
9
10 private String id;
11 private Color balloonTextColor;
12 private String balloonText;
13 private Color balloonColor;
14 private Color iconColor;
15 private ColorModes iconColorMode;
16 private Double iconHeading;
17 private Icon icon;
18 private Double iconScale;
19 private Color labelColor;
20 private ColorModes labelColorMode;
21 private Double labelScale;
22 private Color lineColor;
23 private ColorModes lineColorMode;
24 private Integer lineWidth;
25 private Color polygonColor;
26 private ColorModes polygonColorMode;
27 private Boolean polygonFill;
28 private Boolean polygonOutline;
29
30 public Style() {
31 }
32
33 public Style(String id) {
34 this.id = id;
35 }
36
37 public void addKml(Element parentElement, KmlDocument model, Document xmlDocument) throws KmlException {
38
39 Element styleElement = xmlDocument.createElement("Style");
40
41 if (id != null) {
42 styleElement.setAttribute("id", id);
43 }
44
45 // We check if a balloon style should be added
46 if (balloonText != null || balloonColor != null || balloonTextColor != null) {
47 Element balloonStyleElement = xmlDocument.createElement("BalloonStyle");
48 if (balloonText != null) {
49 Element ballonTextElement = xmlDocument.createElement("text");
50 ballonTextElement.appendChild(xmlDocument.createTextNode(balloonText));
51 balloonStyleElement.appendChild(ballonTextElement);
52 }
53 if (balloonTextColor != null) {
54 Element ballonTextColorElement = xmlDocument.createElement("textColor");
55 ballonTextColorElement.appendChild(xmlDocument.createTextNode(balloonTextColor.toHexString()));
56 balloonStyleElement.appendChild(ballonTextColorElement);
57 }
58 if (balloonColor != null) {
59 Element ballonColorElement = xmlDocument.createElement("color");
60 ballonColorElement.appendChild(xmlDocument.createTextNode(balloonColor.toHexString()));
61 balloonStyleElement.appendChild(ballonColorElement);
62 }
63 styleElement.appendChild(balloonStyleElement);
64 }
65
66 // We check if an icon style should be added (icon is required for this to be added)
67 if (icon != null) {
68 Element iconStyleElement = xmlDocument.createElement("IconStyle");
69 if (iconColor != null) {
70 Element iconColorElement = xmlDocument.createElement("color");
71 iconColorElement.appendChild(xmlDocument.createTextNode(iconColor.toHexString()));
72 iconStyleElement.appendChild(iconColorElement);
73 }
74 if (iconColorMode != null) {
75 Element iconColorModeElement = xmlDocument.createElement("colorMode");
76 iconColorModeElement.appendChild(xmlDocument.createTextNode(iconColorMode.toString()));
77 iconStyleElement.appendChild(iconColorModeElement);
78 }
79 if (iconHeading != null) {
80 Element iconHeadingElement = xmlDocument.createElement("heading");
81 iconHeadingElement.appendChild(xmlDocument.createTextNode(iconHeading.toString()));
82 iconStyleElement.appendChild(iconHeadingElement);
83 }
84 icon.addKml(iconStyleElement, model, xmlDocument);
85 if (iconScale != null) {
86 Element iconScaleElement = xmlDocument.createElement("scale");
87 iconScaleElement.appendChild(xmlDocument.createTextNode(iconScale.toString()));
88 iconStyleElement.appendChild(iconScaleElement);
89 }
90 styleElement.appendChild(iconStyleElement);
91 }
92
93 // We check if a label style should be added
94 if (labelColor != null || labelColorMode != null || labelScale != null) {
95 Element labelStyleElement = xmlDocument.createElement("LabelStyle");
96 if (labelColor != null) {
97 Element labelColorElement = xmlDocument.createElement("color");
98 labelColorElement.appendChild(xmlDocument.createTextNode(labelColor.toHexString()));
99 labelStyleElement.appendChild(labelColorElement);
100 }
101 if (labelColorMode != null) {
102 Element labelColorModeElement = xmlDocument.createElement("colorMode");
103 labelColorModeElement.appendChild(xmlDocument.createTextNode(labelColorMode.toString()));
104 labelStyleElement.appendChild(labelColorModeElement);
105 }
106 if (labelScale != null) {
107 Element labelScaleElement = xmlDocument.createElement("scale");
108 labelScaleElement.appendChild(xmlDocument.createTextNode(labelScale.toString()));
109 labelStyleElement.appendChild(labelScaleElement);
110 }
111 styleElement.appendChild(labelStyleElement);
112 }
113
114 // We check if a line style should be added
115 if (lineColor != null || lineColorMode != null || lineWidth != null) {
116 Element lineStyleElement = xmlDocument.createElement("LineStyle");
117 if (lineColor != null) {
118 Element lineColorElement = xmlDocument.createElement("color");
119 lineColorElement.appendChild(xmlDocument.createTextNode(lineColor.toHexString()));
120 lineStyleElement.appendChild(lineColorElement);
121 }
122 if (lineColorMode != null) {
123 Element lineColorModeElement = xmlDocument.createElement("colorMode");
124 lineColorModeElement.appendChild(xmlDocument.createTextNode(lineColorMode.toString()));
125 lineStyleElement.appendChild(lineColorModeElement);
126 }
127 if (lineWidth != null) {
128 Element lineWidthElement = xmlDocument.createElement("width");
129 lineWidthElement.appendChild(xmlDocument.createTextNode(lineWidth.toString()));
130 lineStyleElement.appendChild(lineWidthElement);
131 }
132 styleElement.appendChild(lineStyleElement);
133 }
134
135 // We check if a poly style should be added
136 if (polygonColor != null || polygonColorMode != null || polygonFill != null || polygonOutline != null) {
137 Element polyStyleElement = xmlDocument.createElement("PolyStyle");
138 if (polygonColor != null) {
139 Element polygonColorElement = xmlDocument.createElement("color");
140 polygonColorElement.appendChild(xmlDocument.createTextNode(polygonColor.toHexString()));
141 polyStyleElement.appendChild(polygonColorElement);
142 }
143 if (polygonColorMode != null) {
144 Element polygonColorModeElement = xmlDocument.createElement("colorMode");
145 polygonColorModeElement.appendChild(xmlDocument.createTextNode(polygonColorMode.toString()));
146 polyStyleElement.appendChild(polygonColorModeElement);
147 }
148 if (polygonFill != null) {
149 Element polygonFillElement = xmlDocument.createElement("fill");
150 polygonFillElement.appendChild(xmlDocument.createTextNode((polygonFill? "1" : "0")));
151 polyStyleElement.appendChild(polygonFillElement);
152 }
153 if (polygonOutline != null) {
154 Element polygonOutlineElement = xmlDocument.createElement("outline");
155 polygonOutlineElement.appendChild(xmlDocument.createTextNode((polygonOutline? "1" : "0")));
156 polyStyleElement.appendChild(polygonOutlineElement);
157 }
158 styleElement.appendChild(polyStyleElement);
159 }
160
161 parentElement.appendChild(styleElement);
162 }
163
164 public Color getBalloonColor() {
165 return balloonColor;
166 }
167
168 public void setBalloonColor(Color balloonColor) {
169 this.balloonColor = balloonColor;
170 }
171
172 public String getBalloonText() {
173 return balloonText;
174 }
175
176 public void setBalloonText(String balloonText) {
177 this.balloonText = balloonText;
178 }
179
180 public Icon getIcon() {
181 return icon;
182 }
183
184 public void setIcon(Icon icon) {
185 this.icon = icon;
186 }
187
188 public Color getIconColor() {
189 return iconColor;
190 }
191
192 public void setIconColor(Color iconColor) {
193 this.iconColor = iconColor;
194 }
195
196 public ColorModes getIconColorMode() {
197 return iconColorMode;
198 }
199
200 public void setIconColorMode(ColorModes iconColorMode) {
201 this.iconColorMode = iconColorMode;
202 }
203
204 public Double getIconHeading() {
205 return iconHeading;
206 }
207
208 public void setIconHeading(Double iconHeading) {
209 this.iconHeading = iconHeading;
210 }
211
212 public Double getIconScale() {
213 return iconScale;
214 }
215
216 public void setIconScale(Double iconScale) {
217 this.iconScale = iconScale;
218 }
219
220 public String getId() {
221 return id;
222 }
223
224 public void setId(String id) {
225 this.id = id;
226 }
227
228 public Color getLabelColor() {
229 return labelColor;
230 }
231
232 public void setLabelColor(Color labelColor) {
233 this.labelColor = labelColor;
234 }
235
236 public ColorModes getLabelColorMode() {
237 return labelColorMode;
238 }
239
240 public void setLabelColorMode(ColorModes labelColorMode) {
241 this.labelColorMode = labelColorMode;
242 }
243
244 public Double getLabelScale() {
245 return labelScale;
246 }
247
248 public void setLabelScale(Double labelScale) {
249 this.labelScale = labelScale;
250 }
251
252 public Color getLineColor() {
253 return lineColor;
254 }
255
256 public void setLineColor(Color lineColor) {
257 this.lineColor = lineColor;
258 }
259
260 public ColorModes getLineColorMode() {
261 return lineColorMode;
262 }
263
264 public void setLineColorMode(ColorModes lineColorMode) {
265 this.lineColorMode = lineColorMode;
266 }
267
268 public Integer getLineWidth() {
269 return lineWidth;
270 }
271
272 public void setLineWidth(Integer lineWidth) {
273 this.lineWidth = lineWidth;
274 }
275
276 public Color getPolygonColor() {
277 return polygonColor;
278 }
279
280 public void setPolygonColor(Color polygonColor) {
281 this.polygonColor = polygonColor;
282 }
283
284 public ColorModes getPolygonColorMode() {
285 return polygonColorMode;
286 }
287
288 public void setPolygonColorMode(ColorModes polygonColorMode) {
289 this.polygonColorMode = polygonColorMode;
290 }
291
292 public Boolean getPolygonFill() {
293 return polygonFill;
294 }
295
296 public void setPolygonFill(Boolean polygonFill) {
297 this.polygonFill = polygonFill;
298 }
299
300 public Boolean getPolygonOutline() {
301 return polygonOutline;
302 }
303
304 public void setPolygonOutline(Boolean polygonOutline) {
305 this.polygonOutline = polygonOutline;
306 }
307
308 public Color getBalloonTextColor() {
309 return balloonTextColor;
310 }
311
312 public void setBalloonTextColor(Color textColor) {
313 this.balloonTextColor = textColor;
314 }
315
316 }
0 package org.boehn.kmlframework.todo.utils;
1
2 public class Ellipsoid {
3
4 private static double K1;
5 private static double K2;
6 private static double Eps2;
7
8 static {
9 Init();
10 }
11
12 public static void Init(double a, double f) {
13 CreateConstants(a, f);
14 }
15
16 public static void Init() {
17 CreateConstants(6378137, 298.257223563); // default to wgs 84
18 }
19
20 public static double foo() {
21 return 1d;
22 }
23
24 protected static void CreateConstants(double a, double f) {
25 double fInverted = 1 / f;
26 Eps2 = (fInverted) * (2d - fInverted);
27 K1 = Math.toRadians(a * (1d - Eps2));
28 K2 = Math.toRadians(a);
29 }
30
31 /**
32 * Convert meter to longitude at ref latitude
33 */
34 public static final double meterToLongitude(double latitude) {
35 return 1.0 / longitudeToMeter(latitude);
36 }
37
38 /**
39 * Convert meter to latitude at ref latitude
40 */
41 public static final double meterToLatitude(double latitude) {
42 return 1.0 / latitudeToMeter(latitude);
43 }
44
45 /**
46 * Convert longitude to meter at ref latitude
47 */
48 public static final double longitudeToMeter(double latitude) {
49 return (Math.cos(Math.toRadians(latitude)) * K2) / Math.sqrt(getDiv0(latitude));
50 }
51
52 /**
53 * Convert latitude to meter at ref latitude
54 */
55 public static final double latitudeToMeter(double latitude) {
56 return (K1 / Math.sqrt(Math.pow(getDiv0(latitude), 3)));
57 }
58
59 private static final double getDiv0(double latitude) {
60 return 1.0 - Eps2 * Math.pow(Math.sin(Math.toRadians(latitude)), 2);
61 }
62
63 }
0 package org.boehn.kmlframework.todo.utils;
1
2 public class MathUtils {
3
4 public static double degreesToDecimal(String input) {
5
6 char direction = input.charAt(0);
7 int degrees;
8 int minutes;
9 int seconds;
10 if (direction == 'E' || direction == 'W') {
11 degrees = Integer.parseInt(input.substring(1,4));
12 minutes = Integer.parseInt(input.substring(4,6));
13 seconds = Integer.parseInt(input.substring(6));
14 } else {
15 degrees = Integer.parseInt(input.substring(1,3));
16 minutes = Integer.parseInt(input.substring(3,5));
17 seconds = Integer.parseInt(input.substring(5));
18 }
19
20 double decimal = degrees + (float) minutes / 60 + (float) seconds / 3600;
21
22 if (direction == 'W' || direction == 'S') {
23 decimal *= -1;
24 }
25 return decimal;
26 }
27 }
+0
-64
src/org/boehn/kmlframework/utils/Ellipsoid.java less more
0 package org.boehn.kmlframework.utils;
1
2 public class Ellipsoid {
3
4 private static double K1;
5 private static double K2;
6 private static double Eps2;
7
8 static {
9 Init();
10 }
11
12 public static void Init(double a, double f) {
13 CreateConstants(a, f);
14 }
15
16 public static void Init() {
17 CreateConstants(6378137, 298.257223563); // default to wgs 84
18 }
19
20 public static double foo() {
21 return 1d;
22 }
23
24 protected static void CreateConstants(double a, double f) {
25 double fInverted = 1 / f;
26 Eps2 = (fInverted) * (2d - fInverted);
27 K1 = Math.toRadians(a * (1d - Eps2));
28 K2 = Math.toRadians(a);
29 }
30
31 /**
32 * Convert meter to longitude at ref latitude
33 */
34 public static final double meterToLongitude(double latitude) {
35 return 1.0 / longitudeToMeter(latitude);
36 }
37
38 /**
39 * Convert meter to latitude at ref latitude
40 */
41 public static final double meterToLatitude(double latitude) {
42 return 1.0 / latitudeToMeter(latitude);
43 }
44
45 /**
46 * Convert longitude to meter at ref latitude
47 */
48 public static final double longitudeToMeter(double latitude) {
49 return (Math.cos(Math.toRadians(latitude)) * K2) / Math.sqrt(getDiv0(latitude));
50 }
51
52 /**
53 * Convert latitude to meter at ref latitude
54 */
55 public static final double latitudeToMeter(double latitude) {
56 return (K1 / Math.sqrt(Math.pow(getDiv0(latitude), 3)));
57 }
58
59 private static final double getDiv0(double latitude) {
60 return 1.0 - Eps2 * Math.pow(Math.sin(Math.toRadians(latitude)), 2);
61 }
62
63 }
+0
-28
src/org/boehn/kmlframework/utils/MathUtils.java less more
0 package org.boehn.kmlframework.utils;
1
2 public class MathUtils {
3
4 public static double degreesToDecimal(String input) {
5
6 char direction = input.charAt(0);
7 int degrees;
8 int minutes;
9 int seconds;
10 if (direction == 'E' || direction == 'W') {
11 degrees = Integer.parseInt(input.substring(1,4));
12 minutes = Integer.parseInt(input.substring(4,6));
13 seconds = Integer.parseInt(input.substring(6));
14 } else {
15 degrees = Integer.parseInt(input.substring(1,3));
16 minutes = Integer.parseInt(input.substring(3,5));
17 seconds = Integer.parseInt(input.substring(5));
18 }
19
20 double decimal = degrees + (float) minutes / 60 + (float) seconds / 3600;
21
22 if (direction == 'W' || direction == 'S') {
23 decimal *= -1;
24 }
25 return decimal;
26 }
27 }