Search in sources :

Example 1 with PlayList

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

the class SoundCueTest method soundCueReadTest.

@Test
public void soundCueReadTest() 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:SoundCue 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("example", 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 SoundCue soundCue = (SoundCue) playList.getTourPrimitives().get(0);
    assertEquals("http://monsite.com/maressource", soundCue.getHref());
    assertFalse("Expected exactly one element.", i.hasNext());
}
Also used : PlayList(org.geotoolkit.data.gx.model.PlayList) KmlReader(org.geotoolkit.data.kml.xml.KmlReader) Kml(org.geotoolkit.data.kml.model.Kml) SoundCue(org.geotoolkit.data.gx.model.SoundCue) Feature(org.opengis.feature.Feature) GxReader(org.geotoolkit.data.gx.xml.GxReader) File(java.io.File) Test(org.junit.Test)

Example 2 with PlayList

use of org.geotoolkit.data.gx.model.PlayList 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 3 with PlayList

use of org.geotoolkit.data.gx.model.PlayList 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 4 with PlayList

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

the class Tour3Test method tour3WriteTest.

/*
     * Méthode de test en écriture
     */
@Test
public void tour3WriteTest() throws KmlException, IOException, XMLStreamException, ParserConfigurationException, SAXException, URISyntaxException {
    // Récupération des instances de deux fabriques (Kml et extensions Gx)
    final GxFactory gxFactory = DefaultGxFactory.getInstance();
    final KmlFactory kmlFactory = DefaultKmlFactory.getInstance();
    // Construction de l'objet Kml
    final PlayList playList = gxFactory.createPlayList();
    final Feature tour = gxFactory.createTour();
    tour.setPropertyValue(KmlConstants.ATT_PLAYLIST, playList);
    final Delete delete = kmlFactory.createDelete();
    delete.setFeatures(Arrays.asList(tour));
    final Update update = kmlFactory.createUpdate();
    update.setTargetHref(new URI("http://myserver.com/Bof.kml"));
    update.setUpdates(Arrays.asList((Object) delete));
    final NetworkLinkControl networkLinkControl = kmlFactory.createNetworkLinkControl();
    networkLinkControl.setUpdate(update);
    final Kml kml = kmlFactory.createKml(networkLinkControl, null, null, null);
    // Ajout de l'espace de nom des extensions avec un préfixe
    kml.addExtensionUri(GxConstants.URI_GX, "gx");
    // Création du fichier d'écriture
    final File temp = File.createTempFile("testTour3", ".kml");
    temp.deleteOnExit();
    // Instanciation du writer Kml
    final KmlWriter writer = new KmlWriter();
    // Instanciation du writer d'extensions à partir du writer Kml
    final GxWriter gxWriter = new GxWriter(writer);
    // Affectation du fichier de sortie et du writer d'extensions au writer Kml
    writer.setOutput(temp);
    writer.addExtensionWriter(GxConstants.URI_GX, gxWriter);
    // Écriture, puis libération du writer Kml
    writer.write(kml);
    writer.dispose();
    // Vérification du contenu écrit...
    DomCompare.compare(new File(pathToTestFile), temp);
}
Also used : PlayList(org.geotoolkit.data.gx.model.PlayList) Delete(org.geotoolkit.data.kml.model.Delete) 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) Update(org.geotoolkit.data.kml.model.Update) Feature(org.opengis.feature.Feature) URI(java.net.URI) File(java.io.File) NetworkLinkControl(org.geotoolkit.data.kml.model.NetworkLinkControl) Test(org.junit.Test)

Example 5 with PlayList

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

the class TourControlTest method tourControlReadTest.

@Test
public void tourControlReadTest() 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:TourControl 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("example", 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 TourControl tourControl = (TourControl) playList.getTourPrimitives().get(0);
    assertEquals(EnumPlayMode.PAUSE, tourControl.getPlayMode());
    assertFalse("Expected exactly one element.", i.hasNext());
}
Also used : PlayList(org.geotoolkit.data.gx.model.PlayList) KmlReader(org.geotoolkit.data.kml.xml.KmlReader) TourControl(org.geotoolkit.data.gx.model.TourControl) Kml(org.geotoolkit.data.kml.model.Kml) Feature(org.opengis.feature.Feature) GxReader(org.geotoolkit.data.gx.xml.GxReader) File(java.io.File) Test(org.junit.Test)

Aggregations

PlayList (org.geotoolkit.data.gx.model.PlayList)15 File (java.io.File)14 Kml (org.geotoolkit.data.kml.model.Kml)14 Test (org.junit.Test)14 Feature (org.opengis.feature.Feature)14 URI (java.net.URI)7 GxReader (org.geotoolkit.data.gx.xml.GxReader)7 GxWriter (org.geotoolkit.data.gx.xml.GxWriter)7 DefaultKmlFactory (org.geotoolkit.data.kml.DefaultKmlFactory)7 KmlFactory (org.geotoolkit.data.kml.KmlFactory)7 KmlReader (org.geotoolkit.data.kml.xml.KmlReader)7 KmlWriter (org.geotoolkit.data.kml.xml.KmlWriter)7 Update (org.geotoolkit.data.kml.model.Update)6 AnimatedUpdate (org.geotoolkit.data.gx.model.AnimatedUpdate)4 FlyTo (org.geotoolkit.data.gx.model.FlyTo)4 SoundCue (org.geotoolkit.data.gx.model.SoundCue)4 TourControl (org.geotoolkit.data.gx.model.TourControl)4 Wait (org.geotoolkit.data.gx.model.Wait)4 Change (org.geotoolkit.data.kml.model.Change)4 IconStyle (org.geotoolkit.data.kml.model.IconStyle)4