Search in sources :

Example 1 with Icon

use of de.micromata.opengis.kml.v_2_2_0.Icon in project java-mapollage by trixon.

the class Operation method addPhoto.

private void addPhoto(File file) throws ImageProcessingException, IOException {
    mPhotoInfo = new PhotoInfo(file, mProfileSource.isIncludeNullCoordinate());
    try {
        mPhotoInfo.init();
    } catch (ImageProcessingException | IOException e) {
        if (mPhotoInfo.hasExif()) {
            mNumOfExif++;
        }
        throw e;
    }
    boolean hasLocation = false;
    if (mPhotoInfo.hasExif()) {
        mNumOfExif++;
        hasLocation = mPhotoInfo.hasGps() && !mPhotoInfo.isZeroCoordinate();
        if (hasLocation) {
            mNumOfGps++;
        }
    } else {
        throw new ImageProcessingException(String.format("E010 %s", file.getAbsolutePath()));
    }
    Date exifDate = mPhotoInfo.getDate();
    if (hasLocation && mProfilePath.isDrawPath()) {
        mLineNodes.add(new LineNode(exifDate, mPhotoInfo.getLat(), mPhotoInfo.getLon()));
    }
    if (hasLocation || mProfileSource.isIncludeNullCoordinate()) {
        Folder folder = getFolder(file, exifDate);
        String imageId = String.format("%08x", FileUtils.checksumCRC32(file));
        String styleNormalId = String.format("s_%s", imageId);
        String styleHighlightId = String.format("s_%s_hl", imageId);
        String styleMapId = String.format("m_%s", imageId);
        Style normalStyle = mDocument.createAndAddStyle().withId(styleNormalId);
        IconStyle normalIconStyle = normalStyle.createAndSetIconStyle().withScale(1.0);
        Style highlightStyle = mDocument.createAndAddStyle().withBalloonStyle(mBalloonStyle).withId(styleHighlightId);
        IconStyle highlightIconStyle = highlightStyle.createAndSetIconStyle().withScale(1.1);
        if (mProfilePlacemark.isSymbolAsPhoto()) {
            Icon icon = KmlFactory.createIcon().withHref(String.format("%s/%s.jpg", mThumbsDir.getName(), imageId));
            normalIconStyle.setIcon(icon);
            normalIconStyle.setScale(mProfilePlacemark.getScale());
            double highlightZoom = mProfilePlacemark.getZoom() * mProfilePlacemark.getScale();
            highlightIconStyle.setIcon(icon);
            highlightIconStyle.setScale(highlightZoom);
        }
        if (mProfilePlacemark.isSymbolAsPhoto() || mProfilePhoto.getReference() == ProfilePhoto.Reference.THUMBNAIL) {
            File thumbFile = new File(mThumbsDir, imageId + ".jpg");
            mFileThumbMap.put(file, thumbFile);
            if (Files.isWritable(thumbFile.getParentFile().toPath())) {
                mPhotoInfo.createThumbnail(thumbFile);
            } else {
                mListener.onOperationLog(String.format(mBundle.getString("insufficient_privileges"), mDestinationFile.getAbsolutePath()));
                Thread.currentThread().interrupt();
                return;
            }
        }
        mDocument.createAndAddStyleMap().withId(styleMapId).addToPair(KmlFactory.createPair().withKey(StyleState.NORMAL).withStyleUrl("#" + styleNormalId)).addToPair(KmlFactory.createPair().withKey(StyleState.HIGHLIGHT).withStyleUrl("#" + styleHighlightId));
        Placemark placemark = KmlFactory.createPlacemark().withName(getSafeXmlString(getPlacemarkName(file, exifDate))).withOpen(Boolean.TRUE).withStyleUrl("#" + styleMapId);
        String desc = getPlacemarkDescription(file, mPhotoInfo, exifDate);
        if (!StringUtils.isBlank(desc)) {
            placemark.setDescription(desc);
        }
        placemark.createAndSetPoint().addToCoordinates(mPhotoInfo.getLon(), mPhotoInfo.getLat(), 0F);
        if (mProfilePlacemark.isTimestamp()) {
            TimeStamp timeStamp = KmlFactory.createTimeStamp();
            timeStamp.setWhen(mTimeStampDateFormat.format(exifDate));
            placemark.setTimePrimitive(timeStamp);
        }
        folder.addToFeature(placemark);
        mNumOfPlacemarks++;
    }
    mListener.onOperationLog(file.getAbsolutePath());
}
Also used : ImageProcessingException(com.drew.imaging.ImageProcessingException) ProfilePlacemark(se.trixon.mapollage.profile.ProfilePlacemark) Placemark(de.micromata.opengis.kml.v_2_2_0.Placemark) IOException(java.io.IOException) LineString(de.micromata.opengis.kml.v_2_2_0.LineString) Folder(de.micromata.opengis.kml.v_2_2_0.Folder) ProfileFolder(se.trixon.mapollage.profile.ProfileFolder) Date(java.util.Date) TimeStamp(de.micromata.opengis.kml.v_2_2_0.TimeStamp) IconStyle(de.micromata.opengis.kml.v_2_2_0.IconStyle) LineStyle(de.micromata.opengis.kml.v_2_2_0.LineStyle) PolyStyle(de.micromata.opengis.kml.v_2_2_0.PolyStyle) Style(de.micromata.opengis.kml.v_2_2_0.Style) IconStyle(de.micromata.opengis.kml.v_2_2_0.IconStyle) BalloonStyle(de.micromata.opengis.kml.v_2_2_0.BalloonStyle) Icon(de.micromata.opengis.kml.v_2_2_0.Icon) File(java.io.File)

Aggregations

ImageProcessingException (com.drew.imaging.ImageProcessingException)1 BalloonStyle (de.micromata.opengis.kml.v_2_2_0.BalloonStyle)1 Folder (de.micromata.opengis.kml.v_2_2_0.Folder)1 Icon (de.micromata.opengis.kml.v_2_2_0.Icon)1 IconStyle (de.micromata.opengis.kml.v_2_2_0.IconStyle)1 LineString (de.micromata.opengis.kml.v_2_2_0.LineString)1 LineStyle (de.micromata.opengis.kml.v_2_2_0.LineStyle)1 Placemark (de.micromata.opengis.kml.v_2_2_0.Placemark)1 PolyStyle (de.micromata.opengis.kml.v_2_2_0.PolyStyle)1 Style (de.micromata.opengis.kml.v_2_2_0.Style)1 TimeStamp (de.micromata.opengis.kml.v_2_2_0.TimeStamp)1 File (java.io.File)1 IOException (java.io.IOException)1 Date (java.util.Date)1 ProfileFolder (se.trixon.mapollage.profile.ProfileFolder)1 ProfilePlacemark (se.trixon.mapollage.profile.ProfilePlacemark)1