Search in sources :

Example 1 with Wait

use of org.geotoolkit.data.gx.model.Wait in project geotoolkit by Geomatys.

the class Tour2Test method tour2WriteTest.

@Test
public void tour2WriteTest() throws KmlException, IOException, XMLStreamException, ParserConfigurationException, SAXException, URISyntaxException {
    final GxFactory gxFactory = DefaultGxFactory.getInstance();
    final KmlFactory kmlFactory = DefaultKmlFactory.getInstance();
    final FlyTo flyTo = gxFactory.createFlyTo();
    flyTo.setDuration(5);
    flyTo.setFlyToMode(EnumFlyToMode.SMOOTH);
    final LookAt lookAt = kmlFactory.createLookAt();
    lookAt.setLongitude(-79.387);
    lookAt.setLatitude(43.643);
    lookAt.setAltitude(10);
    lookAt.setHeading(-172.3);
    lookAt.setTilt(10);
    lookAt.setRange(1200);
    lookAt.setAltitudeMode(EnumAltitudeMode.RELATIVE_TO_GROUND);
    flyTo.setView(lookAt);
    final TourControl tourControl = gxFactory.createTourControl();
    tourControl.setPlayMode(EnumPlayMode.PAUSE);
    final SoundCue soundCue = gxFactory.createSoundCue();
    soundCue.setHref("http://dev.keyhole.com/codesite/cntowerfacts.mp3");
    final Wait wait = gxFactory.createWait();
    wait.setDuration(10);
    final PlayList playList = gxFactory.createPlayList();
    playList.setTourPrimitives(Arrays.asList(flyTo, tourControl, soundCue, wait));
    final Feature tour = gxFactory.createTour();
    tour.setPropertyValue(KmlConstants.ATT_PLAYLIST, playList);
    final Kml kml = kmlFactory.createKml(null, tour, null, null);
    kml.addExtensionUri(GxConstants.URI_GX, "gx");
    final File temp = File.createTempFile("testTour2", ".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) FlyTo(org.geotoolkit.data.gx.model.FlyTo) 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) Kml(org.geotoolkit.data.kml.model.Kml) Feature(org.opengis.feature.Feature) LookAt(org.geotoolkit.data.kml.model.LookAt) TourControl(org.geotoolkit.data.gx.model.TourControl) SoundCue(org.geotoolkit.data.gx.model.SoundCue) Wait(org.geotoolkit.data.gx.model.Wait) File(java.io.File) Test(org.junit.Test)

Example 2 with Wait

use of org.geotoolkit.data.gx.model.Wait in project geotoolkit by Geomatys.

the class Tour2Test method tour2ReadTest.

@Test
public void tour2ReadTest() throws IOException, XMLStreamException, URISyntaxException, KmlException {
    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();
    final Feature tour = kmlObjects.getAbstractFeature();
    assertEquals(GxModelConstants.TYPE_TOUR, tour.getType());
    final PlayList playList = (PlayList) ((List) tour.getPropertyValue(KmlConstants.ATT_PLAYLIST)).get(0);
    assertEquals(4, playList.getTourPrimitives().size());
    final FlyTo flyTo = (FlyTo) playList.getTourPrimitives().get(0);
    assertEquals(5, flyTo.getDuration(), DELTA);
    assertEquals(EnumFlyToMode.SMOOTH, flyTo.getFlyToMode());
    final LookAt lookAt = (LookAt) flyTo.getView();
    assertEquals(-79.387, lookAt.getLongitude(), DELTA);
    assertEquals(43.643, lookAt.getLatitude(), DELTA);
    assertEquals(10, lookAt.getAltitude(), DELTA);
    assertEquals(-172.3, lookAt.getHeading(), DELTA);
    assertEquals(10, lookAt.getTilt(), DELTA);
    assertEquals(1200, lookAt.getRange(), DELTA);
    assertEquals(EnumAltitudeMode.RELATIVE_TO_GROUND, lookAt.getAltitudeMode());
    final TourControl tourControl = (TourControl) playList.getTourPrimitives().get(1);
    assertEquals(EnumPlayMode.PAUSE, tourControl.getPlayMode());
    final SoundCue soundCue = (SoundCue) playList.getTourPrimitives().get(2);
    assertEquals("http://dev.keyhole.com/codesite/cntowerfacts.mp3", soundCue.getHref());
    final Wait wait = (Wait) playList.getTourPrimitives().get(3);
    assertEquals(10, wait.getDuration(), DELTA);
}
Also used : PlayList(org.geotoolkit.data.gx.model.PlayList) LookAt(org.geotoolkit.data.kml.model.LookAt) FlyTo(org.geotoolkit.data.gx.model.FlyTo) KmlReader(org.geotoolkit.data.kml.xml.KmlReader) TourControl(org.geotoolkit.data.gx.model.TourControl) Kml(org.geotoolkit.data.kml.model.Kml) SoundCue(org.geotoolkit.data.gx.model.SoundCue) Wait(org.geotoolkit.data.gx.model.Wait) GxReader(org.geotoolkit.data.gx.xml.GxReader) File(java.io.File) Feature(org.opengis.feature.Feature) Test(org.junit.Test)

Example 3 with Wait

use of org.geotoolkit.data.gx.model.Wait in project geotoolkit by Geomatys.

the class AnimatedUpdateTest method animatedUpdateReadTest.

@Test
public void animatedUpdateReadTest() 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.FALSE, 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("pushpin", style.getIdAttributes().getId());
        assertEquals("mystyle", style.getIconStyle().getIdAttributes().getId());
        assertEquals("http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png", style.getIconStyle().getIcon().getHref());
        assertEquals(2.0, style.getIconStyle().getScale(), DELTA);
    }
    assertFalse("Expected exactly one element.", i.hasNext());
    i = ((Iterable<?>) document.getPropertyValue(KmlConstants.TAG_FEATURES)).iterator();
    assertTrue("Expected at least one element.", i.hasNext());
    {
        final Feature placemark = (Feature) i.next();
        assertEquals(placemark.getType(), KmlModelConstants.TYPE_PLACEMARK);
        assertEquals("mountainpin1", ((IdAttributes) placemark.getPropertyValue(KmlConstants.ATT_ID)).getId());
        assertEquals("Pin on a mountaintop", placemark.getPropertyValue(KmlConstants.TAG_NAME));
        assertEquals(new URI("#pushpin"), placemark.getPropertyValue(KmlConstants.TAG_STYLE_URL));
        Point point = (Point) placemark.getPropertyValue(KmlConstants.TAG_GEOMETRY);
        CoordinateSequence coordinates = point.getCoordinateSequence();
        assertEquals(1, coordinates.size());
        Coordinate coordinate = coordinates.getCoordinate(0);
        assertEquals(170.1435558771009, coordinate.x, DELTA);
        assertEquals(-43.60505741890396, coordinate.y, DELTA);
        assertEquals(0, coordinate.z, DELTA);
    }
    assertTrue("Expected at least 2 elements.", i.hasNext());
    final Feature tour = (Feature) i.next();
    assertEquals(GxModelConstants.TYPE_TOUR, tour.getType());
    assertEquals("Play me!", tour.getPropertyValue(KmlConstants.TAG_NAME));
    assertFalse("Expected exactly 2 elements.", i.hasNext());
    i = ((Iterable<?>) tour.getPropertyValue(KmlConstants.ATT_PLAYLIST)).iterator();
    assertTrue("Expected at least one element.", i.hasNext());
    {
        final PlayList playList = (PlayList) i.next();
        assertEquals(3, playList.getTourPrimitives().size());
        final FlyTo flyTo = (FlyTo) playList.getTourPrimitives().get(0);
        assertEquals(3, flyTo.getDuration(), DELTA);
        assertEquals(EnumFlyToMode.SMOOTH, flyTo.getFlyToMode());
        final Camera camera = (Camera) flyTo.getView();
        assertEquals(170.157, camera.getLongitude(), DELTA);
        assertEquals(-43.671, camera.getLatitude(), DELTA);
        assertEquals(9700, camera.getAltitude(), DELTA);
        assertEquals(-6.333, camera.getHeading(), DELTA);
        assertEquals(33.5, camera.getTilt(), DELTA);
        final AnimatedUpdate animatedUpdate = (AnimatedUpdate) playList.getTourPrimitives().get(1);
        assertEquals(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("mystyle", iconStyle.getIdAttributes().getTargetId());
        assertEquals(10.0, iconStyle.getScale(), DELTA);
        final Wait wait = (Wait) playList.getTourPrimitives().get(2);
        assertEquals(5, wait.getDuration(), DELTA);
    }
    assertFalse("Expected exactly one element.", i.hasNext());
}
Also used : CoordinateSequence(org.locationtech.jts.geom.CoordinateSequence) PlayList(org.geotoolkit.data.gx.model.PlayList) FlyTo(org.geotoolkit.data.gx.model.FlyTo) Kml(org.geotoolkit.data.kml.model.Kml) Point(org.geotoolkit.data.kml.model.Point) 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) IdAttributes(org.geotoolkit.data.kml.model.IdAttributes) IconStyle(org.geotoolkit.data.kml.model.IconStyle) Coordinate(org.locationtech.jts.geom.Coordinate) AnimatedUpdate(org.geotoolkit.data.gx.model.AnimatedUpdate) IconStyle(org.geotoolkit.data.kml.model.IconStyle) Style(org.geotoolkit.data.kml.model.Style) KmlReader(org.geotoolkit.data.kml.xml.KmlReader) Camera(org.geotoolkit.data.kml.model.Camera) Wait(org.geotoolkit.data.gx.model.Wait) GxReader(org.geotoolkit.data.gx.xml.GxReader) File(java.io.File) Test(org.junit.Test)

Example 4 with Wait

use of org.geotoolkit.data.gx.model.Wait in project geotoolkit by Geomatys.

the class AnimatedUpdateTest method animatedUpdateWriteTest.

@Test
public void animatedUpdateWriteTest() throws KmlException, IOException, XMLStreamException, ParserConfigurationException, SAXException, URISyntaxException {
    final GxFactory gxFactory = DefaultGxFactory.getInstance();
    final KmlFactory kmlFactory = DefaultKmlFactory.getInstance();
    final Camera camera = kmlFactory.createCamera();
    camera.setLongitude(170.157);
    camera.setLatitude(-43.671);
    camera.setAltitude(9700);
    camera.setHeading(-6.333);
    camera.setTilt(33.5);
    final FlyTo flyTo = gxFactory.createFlyTo();
    flyTo.setDuration(3);
    flyTo.setFlyToMode(EnumFlyToMode.SMOOTH);
    flyTo.setView(camera);
    final IdAttributes style1IdAttAtributes = kmlFactory.createIdAttributes(null, "mystyle");
    final IconStyle iconStyle1 = kmlFactory.createIconStyle();
    iconStyle1.setIdAttributes(style1IdAttAtributes);
    iconStyle1.setScale(10.0);
    final Change change = kmlFactory.createChange();
    change.setObjects(Arrays.asList((Object) iconStyle1));
    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(5);
    animatedUpdate.setUpdate(update);
    final Wait wait = gxFactory.createWait();
    wait.setDuration(5);
    final PlayList playList = gxFactory.createPlayList();
    playList.setTourPrimitives(Arrays.asList(flyTo, animatedUpdate, wait));
    final Feature tour = gxFactory.createTour();
    tour.setPropertyValue(KmlConstants.TAG_NAME, "Play me!");
    tour.setPropertyValue(KmlConstants.ATT_PLAYLIST, playList);
    final Coordinate coordinate = kmlFactory.createCoordinate("170.1435558771009,-43.60505741890396,0.0");
    final CoordinateSequence coordinates = kmlFactory.createCoordinates(Arrays.asList(coordinate));
    final Point point = kmlFactory.createPoint(coordinates);
    final Feature placemark = kmlFactory.createPlacemark();
    IdAttributes placemarkIdAttributes = kmlFactory.createIdAttributes("mountainpin1", null);
    placemark.setPropertyValue(KmlConstants.ATT_ID, placemarkIdAttributes);
    placemark.setPropertyValue(KmlConstants.TAG_NAME, "Pin on a mountaintop");
    placemark.setPropertyValue(KmlConstants.TAG_STYLE_URL, new URI("#pushpin"));
    placemark.setPropertyValue(KmlConstants.TAG_GEOMETRY, point);
    final BasicLink icon = kmlFactory.createBasicLink();
    icon.setHref("http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png");
    final IconStyle iconStyle2 = kmlFactory.createIconStyle();
    final IdAttributes style2IdAttributes = kmlFactory.createIdAttributes("mystyle", null);
    iconStyle2.setScale(2);
    iconStyle2.setIcon(icon);
    iconStyle2.setIdAttributes(style2IdAttributes);
    final Style style = kmlFactory.createStyle();
    style.setIconStyle(iconStyle2);
    final IdAttributes styleIdAttributes = kmlFactory.createIdAttributes("pushpin", null);
    style.setIdAttributes(styleIdAttributes);
    final Feature document = kmlFactory.createDocument();
    document.setPropertyValue(KmlConstants.TAG_NAME, "gx:AnimatedUpdate example");
    document.setPropertyValue(KmlConstants.TAG_STYLE_SELECTOR, style);
    document.setPropertyValue(KmlConstants.TAG_FEATURES, Arrays.asList(placemark, tour));
    document.setPropertyValue(KmlConstants.TAG_OPEN, Boolean.FALSE);
    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) CoordinateSequence(org.locationtech.jts.geom.CoordinateSequence) FlyTo(org.geotoolkit.data.gx.model.FlyTo) 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) Point(org.geotoolkit.data.kml.model.Point) 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) BasicLink(org.geotoolkit.data.kml.model.BasicLink) IconStyle(org.geotoolkit.data.kml.model.IconStyle) Coordinate(org.locationtech.jts.geom.Coordinate) AnimatedUpdate(org.geotoolkit.data.gx.model.AnimatedUpdate) IconStyle(org.geotoolkit.data.kml.model.IconStyle) Style(org.geotoolkit.data.kml.model.Style) Camera(org.geotoolkit.data.kml.model.Camera) Wait(org.geotoolkit.data.gx.model.Wait) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)4 FlyTo (org.geotoolkit.data.gx.model.FlyTo)4 PlayList (org.geotoolkit.data.gx.model.PlayList)4 Wait (org.geotoolkit.data.gx.model.Wait)4 Kml (org.geotoolkit.data.kml.model.Kml)4 Test (org.junit.Test)4 Feature (org.opengis.feature.Feature)4 URI (java.net.URI)2 AnimatedUpdate (org.geotoolkit.data.gx.model.AnimatedUpdate)2 SoundCue (org.geotoolkit.data.gx.model.SoundCue)2 TourControl (org.geotoolkit.data.gx.model.TourControl)2 GxReader (org.geotoolkit.data.gx.xml.GxReader)2 GxWriter (org.geotoolkit.data.gx.xml.GxWriter)2 DefaultKmlFactory (org.geotoolkit.data.kml.DefaultKmlFactory)2 KmlFactory (org.geotoolkit.data.kml.KmlFactory)2 Camera (org.geotoolkit.data.kml.model.Camera)2 Change (org.geotoolkit.data.kml.model.Change)2 IconStyle (org.geotoolkit.data.kml.model.IconStyle)2 IdAttributes (org.geotoolkit.data.kml.model.IdAttributes)2 LookAt (org.geotoolkit.data.kml.model.LookAt)2