Search in sources :

Example 51 with KmlReader

use of org.geotoolkit.data.kml.xml.KmlReader in project geotoolkit by Geomatys.

the class BalloonStyleTest method balloonStyleReadTest.

@Test
public void balloonStyleReadTest() throws IOException, XMLStreamException, URISyntaxException, KmlException {
    final Feature document;
    {
        final KmlReader reader = new KmlReader();
        reader.setInput(new File(pathToTestFile));
        final Kml kmlObjects = reader.read();
        reader.dispose();
        document = kmlObjects.getAbstractFeature();
    }
    assertEquals(KmlModelConstants.TYPE_DOCUMENT, document.getType());
    assertEquals("BalloonStyle.kml", document.getPropertyValue(KmlConstants.TAG_NAME));
    assertEquals(Boolean.TRUE, document.getPropertyValue(KmlConstants.TAG_OPEN));
    Iterator<?> i = ((Iterable<?>) document.getPropertyValue(KmlConstants.TAG_STYLE_SELECTOR)).iterator();
    assertTrue("Expected at least one element.", i.hasNext());
    final Style style = (Style) i.next();
    assertEquals("exampleBalloonStyle", style.getIdAttributes().getId());
    final BalloonStyle balloonStyle = style.getBalloonStyle();
    assertEquals(new Color(187, 255, 255, 255), balloonStyle.getBgColor());
    final Cdata text = new DefaultCdata("\n" + "      <b><font color=\"#CC0000\" size=\"+3\">$[name]</font></b>\n" + "      <br/><br/>\n" + "      <font face=\"Courier\">$[description]</font>\n" + "      <br/><br/>\n" + "      Extra text that will appear in the description balloon\n" + "      <br/><br/>\n" + "      $[geDirections]\n" + "      ");
    assertEquals(text, balloonStyle.getText());
    assertFalse("Expected exactly one element.", i.hasNext());
    i = ((Iterable<?>) document.getPropertyValue(KmlConstants.TAG_FEATURES)).iterator();
    assertTrue("Expected at least one element.", i.hasNext());
    Feature placemark = (Feature) i.next();
    assertEquals(KmlModelConstants.TYPE_PLACEMARK, placemark.getType());
    assertEquals("BalloonStyle", placemark.getPropertyValue(KmlConstants.TAG_NAME));
    assertEquals("An example of BalloonStyle", placemark.getPropertyValue(KmlConstants.TAG_DESCRIPTION));
    assertEquals(new URI("#exampleBalloonStyle"), placemark.getPropertyValue(KmlConstants.TAG_STYLE_URL));
    final Point point = (Point) placemark.getPropertyValue(KmlConstants.TAG_GEOMETRY);
    final CoordinateSequence coordinates = point.getCoordinateSequence();
    assertEquals(1, coordinates.size());
    final Coordinate coordinate = coordinates.getCoordinate(0);
    assertEquals(-122.370533, coordinate.x, DELTA);
    assertEquals(37.823842, coordinate.y, DELTA);
    assertEquals(0, coordinate.z, DELTA);
    assertFalse("Expected exactly one element.", i.hasNext());
}
Also used : BalloonStyle(org.geotoolkit.data.kml.model.BalloonStyle) CoordinateSequence(org.locationtech.jts.geom.CoordinateSequence) Color(java.awt.Color) Kml(org.geotoolkit.data.kml.model.Kml) Point(org.geotoolkit.data.kml.model.Point) Feature(org.opengis.feature.Feature) URI(java.net.URI) Cdata(org.geotoolkit.data.kml.xsd.Cdata) DefaultCdata(org.geotoolkit.data.kml.xsd.DefaultCdata) Coordinate(org.locationtech.jts.geom.Coordinate) BalloonStyle(org.geotoolkit.data.kml.model.BalloonStyle) Style(org.geotoolkit.data.kml.model.Style) KmlReader(org.geotoolkit.data.kml.xml.KmlReader) DefaultCdata(org.geotoolkit.data.kml.xsd.DefaultCdata) File(java.io.File) Test(org.junit.Test)

Example 52 with KmlReader

use of org.geotoolkit.data.kml.xml.KmlReader in project geotoolkit by Geomatys.

the class CameraTest method cameraReadTest.

@Test
public void cameraReadTest() throws IOException, XMLStreamException, KmlException, URISyntaxException {
    final KmlReader reader = new KmlReader();
    reader.setInput(new File(pathToTestFile));
    final Kml kmlObjects = reader.read();
    reader.dispose();
    final Feature feature = kmlObjects.getAbstractFeature();
    assertEquals(KmlModelConstants.TYPE_PHOTO_OVERLAY, feature.getType());
    final Camera camera = (Camera) feature.getPropertyValue(KmlConstants.TAG_VIEW);
    assertEquals(4, camera.getLongitude(), DELTA);
    assertEquals(43, camera.getLatitude(), DELTA);
    assertEquals(625, camera.getAltitude(), DELTA);
    assertEquals(2, camera.getHeading(), DELTA);
    assertEquals(1, camera.getTilt(), DELTA);
    assertEquals(2, camera.getRoll(), DELTA);
    assertEquals(EnumAltitudeMode.RELATIVE_TO_GROUND, camera.getAltitudeMode());
}
Also used : KmlReader(org.geotoolkit.data.kml.xml.KmlReader) Kml(org.geotoolkit.data.kml.model.Kml) Camera(org.geotoolkit.data.kml.model.Camera) File(java.io.File) Feature(org.opengis.feature.Feature) Test(org.junit.Test)

Aggregations

File (java.io.File)52 Kml (org.geotoolkit.data.kml.model.Kml)52 KmlReader (org.geotoolkit.data.kml.xml.KmlReader)52 Test (org.junit.Test)52 Feature (org.opengis.feature.Feature)50 CoordinateSequence (org.locationtech.jts.geom.CoordinateSequence)23 Coordinate (org.locationtech.jts.geom.Coordinate)22 URI (java.net.URI)17 GxReader (org.geotoolkit.data.gx.xml.GxReader)14 Point (org.geotoolkit.data.kml.model.Point)14 Color (java.awt.Color)11 Style (org.geotoolkit.data.kml.model.Style)10 PlayList (org.geotoolkit.data.gx.model.PlayList)7 Update (org.geotoolkit.data.kml.model.Update)7 NetworkLinkControl (org.geotoolkit.data.kml.model.NetworkLinkControl)6 Calendar (java.util.Calendar)5 Icon (org.geotoolkit.data.kml.model.Icon)5 IconStyle (org.geotoolkit.data.kml.model.IconStyle)5 Boundary (org.geotoolkit.data.kml.model.Boundary)4 ExtendedData (org.geotoolkit.data.kml.model.ExtendedData)4