@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();
    final Collection<Property> placemarkProperties = placemark.getProperties();
    placemarkProperties.add(FF.createAttribute("BalloonStyle", KmlModelConstants.ATT_NAME, null));
    placemarkProperties.add(
        FF.createAttribute("An example of BalloonStyle", KmlModelConstants.ATT_DESCRIPTION, null));
    placemarkProperties.add(
        FF.createAttribute(new URI("#exampleBalloonStyle"), KmlModelConstants.ATT_STYLE_URL, null));
    placemarkProperties.add(
        FF.createAttribute(point, KmlModelConstants.ATT_PLACEMARK_GEOMETRY, null));

    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();
    final Collection<Property> documentProperties = document.getProperties();
    documentProperties.add(
        FF.createAttribute("BalloonStyle.kml", KmlModelConstants.ATT_NAME, null));
    document.getProperty(KmlModelConstants.ATT_OPEN.getName()).setValue(Boolean.TRUE);
    documentProperties.add(FF.createAttribute(style, KmlModelConstants.ATT_STYLE_SELECTOR, null));
    documentProperties.add(
        FeatureUtilities.wrapProperty(placemark, KmlModelConstants.ATT_DOCUMENT_FEATURES));
    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);
  }
Пример #2
0
  @Test
  public void groundOverlayWriteTest()
      throws KmlException, IOException, XMLStreamException, ParserConfigurationException,
          SAXException {
    final KmlFactory kmlFactory = DefaultKmlFactory.getInstance();

    final double north = 37.83234;
    final double south = 37.832122;
    final double east = -122.373033;
    final double west = -122.373724;
    final double rotation = 45;

    final LatLonBox latLonBox =
        kmlFactory.createLatLonBox(
            null, null, north, south, east, west, null, null, rotation, null, null);

    final String href = "http://www.google.com/intl/en/images/logo.gif";
    final RefreshMode refreshMode = RefreshMode.ON_INTERVAL;
    final double refreshInterval = 86400;
    final double viewBoundScale = 0.75;
    final Link link = kmlFactory.createLink();
    link.setHref(href);
    link.setRefreshMode(refreshMode);
    link.setRefreshInterval(refreshInterval);
    link.setViewBoundScale(viewBoundScale);
    final Icon icon = kmlFactory.createIcon(link);

    final String name = "GroundOverlay.kml";
    final Color color = new Color(255, 255, 255, 127);
    final int drawOrder = 1;

    final Feature groundOverlay = kmlFactory.createGroundOverlay();
    groundOverlay.setPropertyValue(KmlConstants.TAG_NAME, name);
    groundOverlay.setPropertyValue(KmlConstants.TAG_COLOR, color);
    groundOverlay.setPropertyValue(KmlConstants.TAG_DRAW_ORDER, drawOrder);
    groundOverlay.setPropertyValue(KmlConstants.TAG_ICON, icon);
    groundOverlay.setPropertyValue(KmlConstants.TAG_LAT_LON_BOX, latLonBox);

    final Kml kml = kmlFactory.createKml(null, groundOverlay, null, null);

    final File temp = File.createTempFile("testGroundOverlay", ".kml");
    temp.deleteOnExit();

    final KmlWriter writer = new KmlWriter();
    writer.setOutput(temp);
    writer.write(kml);
    writer.dispose();

    DomCompare.compare(new File(pathToTestFile), temp);
  }
Пример #3
0
  @Test
  public void altitudeModeWriteTest()
      throws KmlException, IOException, XMLStreamException, ParserConfigurationException,
          SAXException, URISyntaxException {
    final KmlFactory kmlFactory = DefaultKmlFactory.getInstance();

    final Coordinate coordinate0 = kmlFactory.createCoordinate("146.825,12.233,400.0");
    final Coordinate coordinate1 = kmlFactory.createCoordinate("146.820,12.222,400.0");
    final Coordinate coordinate2 = kmlFactory.createCoordinate("146.812,12.212,400.0");
    final Coordinate coordinate3 = kmlFactory.createCoordinate("146.796,12.209,400.0");
    final Coordinate coordinate4 = kmlFactory.createCoordinate("146.788,12.205,400.0");

    final CoordinateSequence coordinates =
        kmlFactory.createCoordinates(
            Arrays.asList(coordinate0, coordinate1, coordinate2, coordinate3, coordinate4));

    final LineString lineString = kmlFactory.createLineString(coordinates);
    lineString.setAltitudeMode(EnumAltitudeMode.RELATIVE_TO_SEA_FLOOR);
    lineString.setExtrude(true);

    final LookAt lookAt = kmlFactory.createLookAt();
    lookAt.setLongitude(146.806);
    lookAt.setLatitude(12.219);
    lookAt.setHeading(-60);
    lookAt.setTilt(70);
    lookAt.setRange(6300);
    lookAt.setAltitudeMode(EnumAltitudeMode.RELATIVE_TO_SEA_FLOOR);

    final Feature placemark = kmlFactory.createPlacemark();
    placemark.setPropertyValue(KmlConstants.TAG_NAME, "gx:altitudeMode Example");
    placemark.setPropertyValue(KmlConstants.TAG_VIEW, lookAt);
    placemark.setPropertyValue(KmlConstants.TAG_GEOMETRY, lineString);

    final Kml kml = kmlFactory.createKml(null, placemark, null, null);
    kml.addExtensionUri(GxConstants.URI_GX, "gx");

    final File temp = File.createTempFile("testAltitudeMode", ".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);
  }
Пример #4
0
  @Test
  public void placemarkWriteTest()
      throws KmlException, IOException, XMLStreamException, ParserConfigurationException,
          SAXException {
    final KmlFactory kmlFactory = DefaultKmlFactory.getInstance();

    final Coordinate coordinate =
        kmlFactory.createCoordinate(-90.86948943473118, 48.25450093195546, 0);
    final CoordinateSequence coordinates = kmlFactory.createCoordinates(Arrays.asList(coordinate));
    final Point point = kmlFactory.createPoint(coordinates);

    final LookAt lookAt = kmlFactory.createLookAt();
    lookAt.setLongitude(-90.86879847669974);
    lookAt.setLatitude(48.25330383601299);
    lookAt.setHeading(2.7);
    lookAt.setTilt(8.3);
    lookAt.setRange(440.8);

    final Feature placemark = kmlFactory.createPlacemark();
    final Collection<Property> placemarkProperties = placemark.getProperties();
    placemarkProperties.add(
        FF.createAttribute("Google Earth - New Placemark", KmlModelConstants.ATT_NAME, null));
    placemarkProperties.add(
        FF.createAttribute("Some Descriptive text.", KmlModelConstants.ATT_DESCRIPTION, null));
    placemarkProperties.add(FF.createAttribute(lookAt, KmlModelConstants.ATT_VIEW, null));
    placemarkProperties.add(
        FF.createAttribute(point, KmlModelConstants.ATT_PLACEMARK_GEOMETRY, null));

    final Kml kml = kmlFactory.createKml(null, placemark, null, null);

    final File temp = File.createTempFile("testPlacemark", ".kml");
    temp.deleteOnExit();

    final KmlWriter writer = new KmlWriter();
    writer.setOutput(temp);
    writer.write(kml);
    writer.dispose();

    DomCompare.compare(new File(pathToTestFile), temp);
  }
  @Test
  public void lineStringWriteTest()
      throws KmlException, IOException, XMLStreamException, ParserConfigurationException,
          SAXException {
    final KmlFactory kmlFactory = DefaultKmlFactory.getInstance();

    final Coordinate coordinate00 = kmlFactory.createCoordinate(-122.364383, 37.824664, 0.0);
    final Coordinate coordinate01 = kmlFactory.createCoordinate(-122.364152, 37.824322, 0.0);
    final Coordinate coordinate10 = kmlFactory.createCoordinate(-122.364167, 37.824787, 50.0);
    final Coordinate coordinate11 = kmlFactory.createCoordinate(-122.363917, 37.824423, 50.0);

    final CoordinateSequence coordinates0 =
        kmlFactory.createCoordinates(Arrays.asList(coordinate00, coordinate01));
    final CoordinateSequence coordinates1 =
        kmlFactory.createCoordinates(Arrays.asList(coordinate10, coordinate11));

    final LineString lineString0 = kmlFactory.createLineString(coordinates0);
    lineString0.setExtrude(true);
    lineString0.setTessellate(true);

    final LineString lineString1 = kmlFactory.createLineString(coordinates1);
    lineString1.setExtrude(true);
    lineString1.setTessellate(true);
    lineString1.setAltitudeMode(EnumAltitudeMode.RELATIVE_TO_GROUND);

    final Feature placemark0 = kmlFactory.createPlacemark();
    final Collection<Property> placemark0Properties = placemark0.getProperties();
    placemark0Properties.add(FF.createAttribute("unextruded", KmlModelConstants.ATT_NAME, null));
    placemark0Properties.add(
        FF.createAttribute(lineString0, KmlModelConstants.ATT_PLACEMARK_GEOMETRY, null));

    final Feature placemark1 = kmlFactory.createPlacemark();
    final Collection<Property> placemark1Properties = placemark1.getProperties();
    placemark1Properties.add(FF.createAttribute("extruded", KmlModelConstants.ATT_NAME, null));
    placemark1Properties.add(
        FF.createAttribute(lineString1, KmlModelConstants.ATT_PLACEMARK_GEOMETRY, null));

    final LookAt lookAt = kmlFactory.createLookAt();
    lookAt.setLongitude(-122.36415);
    lookAt.setLatitude(37.824553);
    lookAt.setAltitude(1);
    lookAt.setHeading(2);
    lookAt.setTilt(50);
    lookAt.setRange(150);

    final Feature document = kmlFactory.createDocument();
    final Collection<Property> documentProperties = document.getProperties();
    documentProperties.add(FF.createAttribute("LineString.kml", KmlModelConstants.ATT_NAME, null));
    document.getProperty(KmlModelConstants.ATT_OPEN.getName()).setValue(Boolean.TRUE);
    documentProperties.add(FF.createAttribute(lookAt, KmlModelConstants.ATT_VIEW, null));
    documentProperties.add(
        FeatureUtilities.wrapProperty(placemark0, KmlModelConstants.ATT_DOCUMENT_FEATURES));
    documentProperties.add(
        FeatureUtilities.wrapProperty(placemark1, KmlModelConstants.ATT_DOCUMENT_FEATURES));

    final Kml kml = kmlFactory.createKml(null, document, null, null);

    final File temp = File.createTempFile("testLineString", ".kml");
    temp.deleteOnExit();

    final KmlWriter writer = new KmlWriter();
    writer.setOutput(temp);
    writer.write(kml);
    writer.dispose();

    DomCompare.compare(new File(pathToTestFile), temp);
  }