use of org.geotoolkit.data.kml.model.IdAttributes in project geotoolkit by Geomatys.
the class GxReader method readLatLonQuad.
public LatLonQuad readLatLonQuad() throws XMLStreamException {
// AbstractObject
List<SimpleTypeContainer> objectSimpleExtensions = null;
IdAttributes idAttributes = kmlReader.readIdAttributes();
// LatLonQuad
CoordinateSequence coordinates = null;
boucle: while (reader.hasNext()) {
switch(reader.next()) {
case XMLStreamConstants.START_ELEMENT:
final String eName = reader.getLocalName();
final String eUri = reader.getNamespaceURI();
if (this.kmlReader.getVersionUri().equals(eUri)) {
if (KmlConstants.TAG_COORDINATES.equals(eName)) {
coordinates = kmlReader.readCoordinates(reader.getElementText());
}
}
break;
case XMLStreamConstants.END_ELEMENT:
if (TAG_SOUND_CUE.equals(reader.getLocalName()) && URI_GX.contains(reader.getNamespaceURI())) {
break boucle;
}
break;
}
}
return GxReader.GX_FACTORY.createLatLonQuad(objectSimpleExtensions, idAttributes, coordinates);
}
use of org.geotoolkit.data.kml.model.IdAttributes in project geotoolkit by Geomatys.
the class GxReader method readTourControl.
/**
* @return
* @throws XMLStreamException
*/
private TourControl readTourControl() throws XMLStreamException {
// AbstractObject
List<SimpleTypeContainer> objectSimpleExtensions = null;
IdAttributes idAttributes = kmlReader.readIdAttributes();
// TourControl
EnumPlayMode playMode = DEF_PLAY_MODE;
boucle: while (reader.hasNext()) {
switch(reader.next()) {
case XMLStreamConstants.START_ELEMENT:
final String eName = reader.getLocalName();
final String eUri = reader.getNamespaceURI();
if (URI_GX.equals(eUri)) {
if (TAG_PLAY_MODE.equals(eName)) {
playMode = EnumPlayMode.transform(reader.getElementText());
}
}
break;
case XMLStreamConstants.END_ELEMENT:
if (TAG_TOUR_CONTROL.equals(reader.getLocalName()) && URI_GX.contains(reader.getNamespaceURI())) {
break boucle;
}
break;
}
}
return GxReader.GX_FACTORY.createTourControl(objectSimpleExtensions, idAttributes, playMode);
}
use of org.geotoolkit.data.kml.model.IdAttributes 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);
}
use of org.geotoolkit.data.kml.model.IdAttributes 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);
}
use of org.geotoolkit.data.kml.model.IdAttributes 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());
}
Aggregations