eivind@boehn.org
15 years ago
0 | package org.boehn.kmlframework; | |
1 | ||
2 | import java.util.List; | |
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 class Polygon extends Path { | |
11 | ||
12 | private Polygon subtractionPolygon; | |
13 | ||
14 | public Polygon() {} | |
15 | ||
16 | public Polygon(List<Coordinate> points) { | |
17 | this(points, null, null, null, null); | |
18 | } | |
19 | ||
20 | public Polygon(List<Coordinate> points, Polygon subtractionPolygon, Boolean extrude, Boolean tessellate, AltitudeModes altitudeMode) { | |
21 | super(points, extrude, tessellate, altitudeMode); | |
22 | this.subtractionPolygon = subtractionPolygon; | |
23 | } | |
24 | ||
25 | public Polygon getSubtractionPolygon() { | |
26 | return subtractionPolygon; | |
27 | } | |
28 | ||
29 | public void setSubtractionPolygon(Polygon subtractionPolygon) { | |
30 | this.subtractionPolygon = subtractionPolygon; | |
31 | } | |
32 | ||
33 | public Element getLinearRing(Document xmlDocument, EarthCoordinate location, Double rotation, CartesianCoordinate localReferenceCoordinate, CartesianCoordinate scale) { | |
34 | Element linearRingElement = xmlDocument.createElement("LinearRing"); | |
35 | linearRingElement.appendChild(getCoordinates(xmlDocument, location, rotation, localReferenceCoordinate, scale)); | |
36 | return linearRingElement; | |
37 | } | |
38 | ||
39 | @Override | |
40 | public void addKml(Element parentElement, Model model, Document xmlDocument, EarthCoordinate location, Double rotation, CartesianCoordinate localReferenceCoordinate, CartesianCoordinate scale) { | |
41 | Element polygonElement = xmlDocument.createElement("Polygon"); | |
42 | ||
43 | if (getCoordinates() != null) { | |
44 | Element outerBoundaryIsElement = xmlDocument.createElement("outerBoundaryIs"); | |
45 | outerBoundaryIsElement.appendChild(getLinearRing(xmlDocument, location, rotation, localReferenceCoordinate, scale)); | |
46 | polygonElement.appendChild(outerBoundaryIsElement); | |
47 | } | |
48 | ||
49 | if (subtractionPolygon != null) { | |
50 | Element innerBoundaryIsElement = xmlDocument.createElement("innerBoundaryIs"); | |
51 | innerBoundaryIsElement.appendChild(subtractionPolygon.getLinearRing(xmlDocument, location, rotation, localReferenceCoordinate, scale)); | |
52 | polygonElement.appendChild(innerBoundaryIsElement); | |
53 | } | |
54 | ||
55 | if (getExtrude() != null) { | |
56 | Element extrudeElement = xmlDocument.createElement("extrude"); | |
57 | extrudeElement.appendChild(xmlDocument.createTextNode((getExtrude()) ? "1" : "0")); | |
58 | polygonElement.appendChild(extrudeElement); | |
59 | } | |
60 | ||
61 | if (getTessellate() != null) { | |
62 | Element tessellateElement = xmlDocument.createElement("tessellate"); | |
63 | tessellateElement.appendChild(xmlDocument.createTextNode((getTessellate()) ? "1" : "0")); | |
64 | polygonElement.appendChild(tessellateElement); | |
65 | } | |
66 | ||
67 | if (getAltitudeMode() != null) { | |
68 | Element altitudeModeElement = xmlDocument.createElement("altitudeMode"); | |
69 | altitudeModeElement.appendChild(xmlDocument.createTextNode(getAltitudeMode().toString())); | |
70 | polygonElement.appendChild(altitudeModeElement); | |
71 | } | |
72 | ||
73 | parentElement.appendChild(polygonElement); | |
74 | } | |
75 | ||
76 | public String toString() { | |
77 | StringBuffer text = new StringBuffer("Path"); | |
78 | text.append("altitudeMode: " + getAltitudeMode() + "\n"); | |
79 | text.append("extrude: " + getExtrude() + "\n"); | |
80 | text.append("tessellate: " + getTessellate() + "\n"); | |
81 | text.append("coordinates: " + getCoordinates() + "\n"); | |
82 | text.append("subtractionPolygon: " + subtractionPolygon + "\n"); | |
83 | return text.toString(); | |
84 | } | |
85 | ||
86 | } |