Search in sources :

Example 11 with Kml

use of org.geotoolkit.data.kml.model.Kml in project geotoolkit by Geomatys.

the class BalloonStyleTest method balloonStyleWriteTest.

@Test
public void balloonStyleWriteTest() throws KmlException, IOException, XMLStreamException, ParserConfigurationException, SAXException, URISyntaxException {
    final KmlFactory kmlFactory = DefaultKmlFactory.getInstance();
    final Coordinate coordinate = kmlFactory.createCoordinate(-122.370533, 37.823842, 0.0);
    final CoordinateSequence coordinates = kmlFactory.createCoordinates(Arrays.asList(coordinate));
    final Point point = kmlFactory.createPoint(coordinates);
    final Feature placemark = kmlFactory.createPlacemark();
    placemark.setPropertyValue(KmlConstants.TAG_NAME, "BalloonStyle");
    placemark.setPropertyValue(KmlConstants.TAG_DESCRIPTION, "An example of BalloonStyle");
    placemark.setPropertyValue(KmlConstants.TAG_STYLE_URL, new URI("#exampleBalloonStyle"));
    placemark.setPropertyValue(KmlConstants.TAG_GEOMETRY, point);
    final BalloonStyle balloonStyle = kmlFactory.createBalloonStyle();
    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" + "      ");
    balloonStyle.setText(text);
    balloonStyle.setBgColor(new Color(187, 255, 255, 255));
    final IdAttributes idAttributes = kmlFactory.createIdAttributes("exampleBalloonStyle", null);
    final Style style = kmlFactory.createStyle();
    style.setIdAttributes(idAttributes);
    style.setBalloonStyle(balloonStyle);
    final Feature document = kmlFactory.createDocument();
    document.setPropertyValue(KmlConstants.TAG_NAME, "BalloonStyle.kml");
    document.setPropertyValue(KmlConstants.TAG_OPEN, Boolean.TRUE);
    document.setPropertyValue(KmlConstants.TAG_STYLE_SELECTOR, style);
    document.setPropertyValue(KmlConstants.TAG_FEATURES, placemark);
    final Kml kml = kmlFactory.createKml(null, document, null, null);
    final File temp = File.createTempFile("testBalloonStyle", ".kml");
    temp.deleteOnExit();
    final KmlWriter writer = new KmlWriter();
    writer.setOutput(temp);
    writer.write(kml);
    writer.dispose();
    DomCompare.compare(new File(pathToTestFile), temp);
}
Also used : CoordinateSequence(org.locationtech.jts.geom.CoordinateSequence) BalloonStyle(org.geotoolkit.data.kml.model.BalloonStyle) KmlWriter(org.geotoolkit.data.kml.xml.KmlWriter) Color(java.awt.Color) Point(org.geotoolkit.data.kml.model.Point) Kml(org.geotoolkit.data.kml.model.Kml) Feature(org.opengis.feature.Feature) URI(java.net.URI) IdAttributes(org.geotoolkit.data.kml.model.IdAttributes) 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) DefaultCdata(org.geotoolkit.data.kml.xsd.DefaultCdata) File(java.io.File) Test(org.junit.Test)

Example 12 with Kml

use of org.geotoolkit.data.kml.model.Kml in project geotoolkit by Geomatys.

the class ChangeTest method changeReadTest.

@Test
public void changeReadTest() throws IOException, XMLStreamException, KmlException, URISyntaxException {
    final KmlReader reader = new KmlReader();
    reader.setInput(new File(pathToTestFile));
    final Kml kmlObjects = reader.read();
    reader.dispose();
    final NetworkLinkControl networkLinkControl = kmlObjects.getNetworkLinkControl();
    final Update update = networkLinkControl.getUpdate();
    final URI targetHref = update.getTargetHref();
    assertEquals("http://www/~sam/January14Data/Point.kml", targetHref.toString());
    assertEquals(1, update.getUpdates().size());
    Change change = (Change) update.getUpdates().get(0);
    assertEquals(1, change.getObjects().size());
    Point point = (Point) change.getObjects().get(0);
    point.getIdAttributes();
    assertEquals("point123", point.getIdAttributes().getTargetId());
    CoordinateSequence coordinates = point.getCoordinateSequence();
    assertEquals(1, point.getCoordinateSequence().size());
    Coordinate coordinate = point.getCoordinateSequence().getCoordinate(0);
    assertEquals(-95.48, coordinate.x, DELTA);
    assertEquals(40.43, coordinate.y, DELTA);
    assertEquals(0, coordinate.z, DELTA);
}
Also used : CoordinateSequence(org.locationtech.jts.geom.CoordinateSequence) Coordinate(org.locationtech.jts.geom.Coordinate) KmlReader(org.geotoolkit.data.kml.xml.KmlReader) Kml(org.geotoolkit.data.kml.model.Kml) Change(org.geotoolkit.data.kml.model.Change) Point(org.geotoolkit.data.kml.model.Point) Update(org.geotoolkit.data.kml.model.Update) File(java.io.File) URI(java.net.URI) NetworkLinkControl(org.geotoolkit.data.kml.model.NetworkLinkControl) Test(org.junit.Test)

Example 13 with Kml

use of org.geotoolkit.data.kml.model.Kml in project geotoolkit by Geomatys.

the class ChangeTest method changeWriteTest.

@Test
public void changeWriteTest() throws KmlException, IOException, XMLStreamException, ParserConfigurationException, SAXException, URISyntaxException {
    final KmlFactory kmlFactory = DefaultKmlFactory.getInstance();
    final Coordinate coordinate = kmlFactory.createCoordinate(-95.48, 40.43, 0);
    final CoordinateSequence coordinates = kmlFactory.createCoordinates(Arrays.asList(coordinate));
    final Point point = kmlFactory.createPoint(coordinates);
    point.setIdAttributes(kmlFactory.createIdAttributes(null, "point123"));
    final Change change = kmlFactory.createChange(Arrays.asList((Object) point));
    final Update update = kmlFactory.createUpdate();
    update.setUpdates(Arrays.asList((Object) change));
    update.setTargetHref(new URI("http://www/~sam/January14Data/Point.kml"));
    final NetworkLinkControl networkLinkControl = kmlFactory.createNetworkLinkControl();
    networkLinkControl.setUpdate(update);
    final Kml kml = kmlFactory.createKml(networkLinkControl, null, null, null);
    final File temp = File.createTempFile("testChange", ".kml");
    temp.deleteOnExit();
    final KmlWriter writer = new KmlWriter();
    writer.setOutput(temp);
    writer.write(kml);
    writer.dispose();
    DomCompare.compare(new File(pathToTestFile), temp);
}
Also used : CoordinateSequence(org.locationtech.jts.geom.CoordinateSequence) Coordinate(org.locationtech.jts.geom.Coordinate) KmlWriter(org.geotoolkit.data.kml.xml.KmlWriter) Point(org.geotoolkit.data.kml.model.Point) Change(org.geotoolkit.data.kml.model.Change) Kml(org.geotoolkit.data.kml.model.Kml) Update(org.geotoolkit.data.kml.model.Update) URI(java.net.URI) File(java.io.File) NetworkLinkControl(org.geotoolkit.data.kml.model.NetworkLinkControl) Test(org.junit.Test)

Example 14 with Kml

use of org.geotoolkit.data.kml.model.Kml in project geotoolkit by Geomatys.

the class AnimatedUpdateSimpleTest method animatedUpdateReadSimpleTest.

@Test
public void animatedUpdateReadSimpleTest() throws IOException, XMLStreamException, URISyntaxException, KmlException {
    final Feature document;
    {
        final KmlReader reader = new KmlReader();
        final GxReader gxReader = new GxReader(reader);
        reader.setInput(new File(pathToTestFile));
        reader.addExtensionReader(gxReader);
        final Kml kmlObjects = reader.read();
        reader.dispose();
        document = kmlObjects.getAbstractFeature();
    }
    assertEquals(KmlModelConstants.TYPE_DOCUMENT, document.getType());
    assertEquals("gx:AnimatedUpdate example", document.getPropertyValue(KmlConstants.TAG_NAME));
    assertEquals(Boolean.TRUE, document.getPropertyValue(KmlConstants.TAG_OPEN));
    final Feature tour = (Feature) document.getProperty(KmlConstants.TAG_FEATURES).getValue();
    assertEquals(GxModelConstants.TYPE_TOUR, tour.getType());
    assertEquals("Play me!", tour.getPropertyValue(KmlConstants.TAG_NAME));
    Iterator<?> i = ((Iterable<?>) tour.getPropertyValue(KmlConstants.ATT_PLAYLIST)).iterator();
    assertTrue("Expected at least one element.", i.hasNext());
    final PlayList playList = (PlayList) i.next();
    assertEquals(1, playList.getTourPrimitives().size());
    final AnimatedUpdate animatedUpdate = (AnimatedUpdate) playList.getTourPrimitives().get(0);
    assertEquals(6.5, animatedUpdate.getDuration(), DELTA);
    final Update update = animatedUpdate.getUpdate();
    assertEquals(new URI("http://moncoco.com"), update.getTargetHref());
    assertEquals(1, update.getUpdates().size());
    final Change change = (Change) update.getUpdates().get(0);
    assertEquals(1, change.getObjects().size());
    final IconStyle iconStyle = (IconStyle) change.getObjects().get(0);
    assertEquals("iconstyle1", iconStyle.getIdAttributes().getId());
    assertEquals(10.0, iconStyle.getScale(), DELTA);
    assertFalse("Expected exactly one element.", i.hasNext());
}
Also used : PlayList(org.geotoolkit.data.gx.model.PlayList) Kml(org.geotoolkit.data.kml.model.Kml) Change(org.geotoolkit.data.kml.model.Change) AnimatedUpdate(org.geotoolkit.data.gx.model.AnimatedUpdate) Update(org.geotoolkit.data.kml.model.Update) Feature(org.opengis.feature.Feature) URI(java.net.URI) IconStyle(org.geotoolkit.data.kml.model.IconStyle) AnimatedUpdate(org.geotoolkit.data.gx.model.AnimatedUpdate) KmlReader(org.geotoolkit.data.kml.xml.KmlReader) GxReader(org.geotoolkit.data.gx.xml.GxReader) File(java.io.File) Test(org.junit.Test)

Example 15 with Kml

use of org.geotoolkit.data.kml.model.Kml in project geotoolkit by Geomatys.

the class AnimatedUpdateSimpleTest method animatedUpdateWriteSimpleTest.

@Test
public void animatedUpdateWriteSimpleTest() throws KmlException, IOException, XMLStreamException, ParserConfigurationException, SAXException, URISyntaxException {
    final GxFactory gxFactory = DefaultGxFactory.getInstance();
    final KmlFactory kmlFactory = DefaultKmlFactory.getInstance();
    final IdAttributes styleIdAttAtributes = kmlFactory.createIdAttributes("iconstyle1", null);
    final IconStyle iconStyle = kmlFactory.createIconStyle();
    iconStyle.setIdAttributes(styleIdAttAtributes);
    iconStyle.setScale(10.0);
    final Change change = kmlFactory.createChange();
    change.setObjects(Arrays.asList((Object) iconStyle));
    final Update update = kmlFactory.createUpdate();
    update.setTargetHref(new URI("http://moncoco.com"));
    update.setUpdates(Arrays.asList((Object) change));
    final AnimatedUpdate animatedUpdate = gxFactory.createAnimatedUpdate();
    animatedUpdate.setDuration(6.5);
    animatedUpdate.setUpdate(update);
    final PlayList playList = gxFactory.createPlayList();
    playList.setTourPrimitives(Arrays.asList((AbstractTourPrimitive) animatedUpdate));
    final Feature tour = gxFactory.createTour();
    tour.setPropertyValue(KmlConstants.TAG_NAME, "Play me!");
    tour.setPropertyValue(KmlConstants.ATT_PLAYLIST, playList);
    final Feature document = kmlFactory.createDocument();
    document.setPropertyValue(KmlConstants.TAG_NAME, "gx:AnimatedUpdate example");
    document.setPropertyValue(KmlConstants.TAG_OPEN, Boolean.TRUE);
    document.setPropertyValue(KmlConstants.TAG_FEATURES, tour);
    final Kml kml = kmlFactory.createKml(null, document, null, null);
    kml.addExtensionUri(GxConstants.URI_GX, "gx");
    final File temp = File.createTempFile("testAnimatedUpdate", ".kml");
    temp.deleteOnExit();
    final KmlWriter writer = new KmlWriter();
    final GxWriter gxWriter = new GxWriter(writer);
    writer.setOutput(temp);
    writer.addExtensionWriter(GxConstants.URI_GX, gxWriter);
    writer.write(kml);
    writer.dispose();
    DomCompare.compare(new File(pathToTestFile), temp);
}
Also used : PlayList(org.geotoolkit.data.gx.model.PlayList) KmlWriter(org.geotoolkit.data.kml.xml.KmlWriter) GxWriter(org.geotoolkit.data.gx.xml.GxWriter) KmlFactory(org.geotoolkit.data.kml.KmlFactory) DefaultKmlFactory(org.geotoolkit.data.kml.DefaultKmlFactory) Change(org.geotoolkit.data.kml.model.Change) AbstractTourPrimitive(org.geotoolkit.data.gx.model.AbstractTourPrimitive) Kml(org.geotoolkit.data.kml.model.Kml) AnimatedUpdate(org.geotoolkit.data.gx.model.AnimatedUpdate) Update(org.geotoolkit.data.kml.model.Update) URI(java.net.URI) Feature(org.opengis.feature.Feature) IdAttributes(org.geotoolkit.data.kml.model.IdAttributes) IconStyle(org.geotoolkit.data.kml.model.IconStyle) AnimatedUpdate(org.geotoolkit.data.gx.model.AnimatedUpdate) File(java.io.File) Test(org.junit.Test)

Aggregations

Kml (org.geotoolkit.data.kml.model.Kml)105 File (java.io.File)103 Test (org.junit.Test)103 Feature (org.opengis.feature.Feature)100 KmlReader (org.geotoolkit.data.kml.xml.KmlReader)52 KmlWriter (org.geotoolkit.data.kml.xml.KmlWriter)52 CoordinateSequence (org.locationtech.jts.geom.CoordinateSequence)46 Coordinate (org.locationtech.jts.geom.Coordinate)44 URI (java.net.URI)34 Point (org.geotoolkit.data.kml.model.Point)28 Color (java.awt.Color)21 Style (org.geotoolkit.data.kml.model.Style)19 IdAttributes (org.geotoolkit.data.kml.model.IdAttributes)15 PlayList (org.geotoolkit.data.gx.model.PlayList)14 GxReader (org.geotoolkit.data.gx.xml.GxReader)14 GxWriter (org.geotoolkit.data.gx.xml.GxWriter)14 Update (org.geotoolkit.data.kml.model.Update)14 DefaultKmlFactory (org.geotoolkit.data.kml.DefaultKmlFactory)13 KmlFactory (org.geotoolkit.data.kml.KmlFactory)13 NetworkLinkControl (org.geotoolkit.data.kml.model.NetworkLinkControl)12