KmzExporter { static String createKml(KmlFeature kmlFeature) { StringBuilder result = new StringBuilder(); result.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); result.append("<kml xmlns=\"http: kmlFeature.createKml(result); result.append("</kml>"); return result.toString(); }  void export(KmlFeature kmlFeature, ZipOutputStream zipOutputStream, final ProgressMonitor pm);  }
@Test public void testKmlHierarchy() throws ParserConfigurationException, IOException, SAXException { RenderedImage layer = new DummyTestOpImage(10, 10); final BoundingBox boundBox = new ReferencedEnvelope(0, 20, 70, 30, DefaultGeographicCRS.WGS84); KmlFolder kmlFolder1 = new KmlFolder("folder1", null); KmlDocument kmlDocument1_1 = new KmlDocument("document1_1", null); kmlFolder1.addChild(kmlDocument1_1); KmlGroundOverlay layer1_1_1 = new KmlGroundOverlay("layer1_1_1", layer, boundBox); kmlDocument1_1.addChild(layer1_1_1); KmlGroundOverlay layer1_1_2 = new KmlGroundOverlay("layer1_1_2", layer, boundBox); kmlDocument1_1.addChild(layer1_1_2); KmlGroundOverlay kmlLayer1_2 = new KmlGroundOverlay("layer1_2", layer, boundBox); kmlFolder1.addChild(kmlLayer1_2); KmlFolder kmlFFolder1_2 = new KmlFolder("folder1_3", null); kmlFolder1.addChild(kmlFFolder1_2); KmlGroundOverlay layer1_2_1 = new KmlGroundOverlay("layer1_3_1", layer, boundBox); kmlFFolder1_2.addChild(layer1_2_1); KmlGroundOverlay layer1_2_2 = new KmlGroundOverlay("layer1_3_2", layer, boundBox); kmlFFolder1_2.addChild(layer1_2_2); String xml = KmzExporter.createKml(kmlFolder1); final Document document = convertToDocument(xml); final Element root = document.getRootElement(); Namespace nameSpace = root.getNamespace(); assertEquals("http: final List children = root.getChildren(); assertEquals(1, children.size()); final Element folder1 = root.getChild("Folder", nameSpace); assertEquals(4, folder1.getChildren().size()); final Element nameChild = folder1.getChild("name", nameSpace); assertEquals("folder1", nameChild.getValue()); List overlays; final Element document1_1 = folder1.getChild("Document", nameSpace); assertEquals("document1_1", document1_1.getChildText("name", nameSpace)); overlays = document1_1.getChildren("GroundOverlay", nameSpace); assertEquals(2, overlays.size()); validateGroundOverlay("layer1_1_1", overlays.get(0), nameSpace); validateGroundOverlay("layer1_1_2", overlays.get(1), nameSpace); overlays = folder1.getChildren("GroundOverlay", nameSpace); assertEquals(1, overlays.size()); validateGroundOverlay("layer1_2", overlays.get(0), nameSpace); Element folder1_3 = folder1.getChild("Folder", nameSpace); assertEquals("folder1_3", folder1_3.getChildText("name", nameSpace)); overlays = folder1_3.getChildren("GroundOverlay", nameSpace); assertEquals(2, overlays.size()); validateGroundOverlay("layer1_3_1", overlays.get(0), nameSpace); validateGroundOverlay("layer1_3_2", overlays.get(1), nameSpace); }
@Test public void testKmlPlacemarks() throws IOException, SAXException, ParserConfigurationException { KmlDocument doc1 = new KmlDocument("pins", null); doc1.addChild(new KmlPlacemark("placemark 1", null, new Point2D.Double(80.0, 89.0))); doc1.addChild(new KmlPlacemark("placemark 2", null, new Point2D.Double(70.0, 70.0))); doc1.addChild(new KmlPlacemark("placemark 3", null, new Point2D.Double(60.0, 60.0))); doc1.addChild(new KmlPlacemark("placemark 4", null, new Point2D.Double(40.0, 50.0))); final String xml = KmzExporter.createKml(doc1); final Document document = convertToDocument(xml); assertNotNull(document); final Element root = document.getRootElement(); assertNotNull(root); Namespace nameSpace = root.getNamespace(); final Element doc = root.getChild("Document", nameSpace); assertNotNull(doc); final List placemarks = doc.getChildren("Placemark", nameSpace); assertEquals(4, placemarks.size()); for (int i = 0; i < placemarks.size(); i++) { validatePlacemark((Element) placemarks.get(i), "placemark " + (i + 1), nameSpace); } }
@Test public void testLegend() throws IOException, SAXException, ParserConfigurationException { final String xml = KmzExporter.createKml(new KmlScreenOverlay("Legend", new DummyTestOpImage(4, 10))); final Document document = convertToDocument(xml); assertNotNull(document); final Element root = document.getRootElement(); assertNotNull(root); Namespace nameSpace = root.getNamespace(); final Element screenOverlay = root.getChild("ScreenOverlay", nameSpace); assertNotNull(screenOverlay); assertEquals("Legend", screenOverlay.getChildText("name", nameSpace)); final Element icon = screenOverlay.getChild("Icon", nameSpace); assertNotNull(icon); assertEquals("Legend.png", icon.getChildText("href", nameSpace)); assertNotNull(screenOverlay.getChild("overlayXY", nameSpace)); assertNotNull(screenOverlay.getChild("screenXY", nameSpace)); }