use of org.geotoolkit.data.kml.model.LabelStyle in project geotoolkit by Geomatys.
the class LabelStyleTest method labelStyleReadTest.
@Test
public void labelStyleReadTest() throws IOException, XMLStreamException, URISyntaxException, KmlException {
final KmlReader reader = new KmlReader();
reader.setInput(new File(pathToTestFile));
final Kml kmlObjects = reader.read();
reader.dispose();
final Feature document = kmlObjects.getAbstractFeature();
assertEquals(KmlModelConstants.TYPE_DOCUMENT, document.getType());
Iterator<?> i = ((Iterable<?>) document.getPropertyValue(KmlConstants.TAG_STYLE_SELECTOR)).iterator();
assertTrue("Expected at least one element.", i.hasNext());
Style style = (Style) i.next();
assertEquals("randomLabelColor", style.getIdAttributes().getId());
LabelStyle labelStyle = style.getLabelStyle();
assertEquals(new Color(204, 0, 0, 255), labelStyle.getColor());
assertEquals(ColorMode.RANDOM, labelStyle.getColorMode());
assertEquals(1.5, labelStyle.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());
Feature placemark = (Feature) i.next();
assertEquals("LabelStyle.kml", placemark.getPropertyValue(KmlConstants.TAG_NAME));
assertEquals(new URI("#randomLabelColor"), 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(-122.367375, coordinate.x, DELTA);
assertEquals(37.829192, coordinate.y, DELTA);
assertEquals(0, coordinate.z, DELTA);
assertFalse("Expected exactly one element.", i.hasNext());
}
use of org.geotoolkit.data.kml.model.LabelStyle in project geotoolkit by Geomatys.
the class LabelStyleTest method labelStyleWriteTest.
@Test
public void labelStyleWriteTest() throws KmlException, IOException, XMLStreamException, ParserConfigurationException, SAXException, URISyntaxException {
final KmlFactory kmlFactory = DefaultKmlFactory.getInstance();
final Coordinate coordinate = kmlFactory.createCoordinate(-122.367375, 37.829192, 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, "LabelStyle.kml");
placemark.setPropertyValue(KmlConstants.TAG_STYLE_URL, new URI("#randomLabelColor"));
placemark.setPropertyValue(KmlConstants.TAG_GEOMETRY, point);
final Style style = kmlFactory.createStyle();
LabelStyle labelStyle = kmlFactory.createLabelStyle();
labelStyle.setScale(1.5);
labelStyle.setColor(new Color(204, 0, 0, 255));
labelStyle.setColorMode(ColorMode.RANDOM);
style.setLabelStyle(labelStyle);
final IdAttributes idAttributes = kmlFactory.createIdAttributes("randomLabelColor", null);
style.setIdAttributes(idAttributes);
final Feature document = kmlFactory.createDocument();
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("testLabelStyle", ".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.LabelStyle in project geotoolkit by Geomatys.
the class StyleTest method styleReadTest.
@Test
public void styleReadTest() 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());
Iterator<?> i = ((Iterable<?>) document.getPropertyValue(KmlConstants.TAG_STYLE_SELECTOR)).iterator();
assertTrue("Expected at least one element.", i.hasNext());
{
Style style = (Style) i.next();
assertEquals("myDefaultStyles", style.getIdAttributes().getId());
IconStyle iconStyle = style.getIconStyle();
assertEquals(new Color(255, 0, 255, 161), iconStyle.getColor());
assertEquals(1.399999976158142, iconStyle.getScale(), DELTA);
BasicLink icon = iconStyle.getIcon();
assertEquals("http://myserver.com/icon.jpg", icon.getHref());
LabelStyle labelStyle = style.getLabelStyle();
assertEquals(new Color(255, 170, 255, 127), labelStyle.getColor());
assertEquals(1.5, labelStyle.getScale(), DELTA);
LineStyle lineStyle = style.getLineStyle();
assertEquals(new Color(255, 0, 0, 255), lineStyle.getColor());
assertEquals(15, lineStyle.getWidth(), DELTA);
PolyStyle polyStyle = style.getPolyStyle();
assertEquals(new Color(170, 170, 127, 127), polyStyle.getColor());
assertEquals(ColorMode.RANDOM, polyStyle.getColorMode());
}
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("Google Earth - New Polygon", placemark.getPropertyValue(KmlConstants.TAG_NAME));
assertEquals("Here is some descriptive text", placemark.getPropertyValue(KmlConstants.TAG_DESCRIPTION));
assertEquals(new URI("#myDefaultStyles"), placemark.getPropertyValue(KmlConstants.TAG_STYLE_URL));
}
assertTrue("Expected at least 2 elements.", i.hasNext());
{
Feature placemark = (Feature) i.next();
assertEquals("Google Earth - New Path", placemark.getPropertyValue(KmlConstants.TAG_NAME));
assertEquals(new URI("#myDefaultStyles"), placemark.getPropertyValue(KmlConstants.TAG_STYLE_URL));
assertFalse("Expected exactly 2 elements.", i.hasNext());
}
}
Aggregations