Search in sources :

Example 6 with LabelStyle

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());
}
Also used : CoordinateSequence(org.locationtech.jts.geom.CoordinateSequence) Color(java.awt.Color) LabelStyle(org.geotoolkit.data.kml.model.LabelStyle) Kml(org.geotoolkit.data.kml.model.Kml) Point(org.geotoolkit.data.kml.model.Point) Feature(org.opengis.feature.Feature) URI(java.net.URI) Coordinate(org.locationtech.jts.geom.Coordinate) LabelStyle(org.geotoolkit.data.kml.model.LabelStyle) Style(org.geotoolkit.data.kml.model.Style) KmlReader(org.geotoolkit.data.kml.xml.KmlReader) File(java.io.File) Test(org.junit.Test)

Example 7 with LabelStyle

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);
}
Also used : CoordinateSequence(org.locationtech.jts.geom.CoordinateSequence) KmlWriter(org.geotoolkit.data.kml.xml.KmlWriter) Color(java.awt.Color) LabelStyle(org.geotoolkit.data.kml.model.LabelStyle) 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) Coordinate(org.locationtech.jts.geom.Coordinate) LabelStyle(org.geotoolkit.data.kml.model.LabelStyle) Style(org.geotoolkit.data.kml.model.Style) File(java.io.File) Test(org.junit.Test)

Example 8 with LabelStyle

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());
    }
}
Also used : LineStyle(org.geotoolkit.data.kml.model.LineStyle) Color(java.awt.Color) LabelStyle(org.geotoolkit.data.kml.model.LabelStyle) Kml(org.geotoolkit.data.kml.model.Kml) Feature(org.opengis.feature.Feature) PolyStyle(org.geotoolkit.data.kml.model.PolyStyle) URI(java.net.URI) BasicLink(org.geotoolkit.data.kml.model.BasicLink) IconStyle(org.geotoolkit.data.kml.model.IconStyle) LabelStyle(org.geotoolkit.data.kml.model.LabelStyle) LineStyle(org.geotoolkit.data.kml.model.LineStyle) IconStyle(org.geotoolkit.data.kml.model.IconStyle) Style(org.geotoolkit.data.kml.model.Style) PolyStyle(org.geotoolkit.data.kml.model.PolyStyle) KmlReader(org.geotoolkit.data.kml.xml.KmlReader) File(java.io.File) Test(org.junit.Test)

Aggregations

LabelStyle (org.geotoolkit.data.kml.model.LabelStyle)8 Color (java.awt.Color)7 File (java.io.File)6 URI (java.net.URI)6 Kml (org.geotoolkit.data.kml.model.Kml)6 Style (org.geotoolkit.data.kml.model.Style)6 Test (org.junit.Test)6 Feature (org.opengis.feature.Feature)6 IconStyle (org.geotoolkit.data.kml.model.IconStyle)4 IdAttributes (org.geotoolkit.data.kml.model.IdAttributes)4 LineStyle (org.geotoolkit.data.kml.model.LineStyle)4 Point (org.geotoolkit.data.kml.model.Point)4 PolyStyle (org.geotoolkit.data.kml.model.PolyStyle)4 Coordinate (org.locationtech.jts.geom.Coordinate)4 CoordinateSequence (org.locationtech.jts.geom.CoordinateSequence)4 BasicLink (org.geotoolkit.data.kml.model.BasicLink)3 KmlReader (org.geotoolkit.data.kml.xml.KmlReader)3 KmlWriter (org.geotoolkit.data.kml.xml.KmlWriter)3 ArrayList (java.util.ArrayList)1 Entry (java.util.Map.Entry)1