Search in sources :

Example 6 with MBookmark

use of org.mapton.api.MBookmark in project mapton by trixon.

the class GoogleSearchEngine method getResults.

public ArrayList<MBookmark> getResults(String searchString) {
    ArrayList<MBookmark> bookmarks = new ArrayList<>();
    mDone = false;
    GeocodingServiceCallback callback = (GeocodingResult[] results, GeocoderStatus status) -> {
        if (status != GeocoderStatus.OK) {
            mDone = true;
            return;
        }
        for (GeocodingResult result : results) {
            GeocoderGeometry geometry = result.getGeometry();
            LatLong latLon = geometry.getLocation();
            MBookmark bookmark = new MBookmark();
            bookmark.setName(result.getFormattedAddress());
            bookmark.setLatitude(latLon.getLatitude());
            bookmark.setLongitude(latLon.getLongitude());
            LatLongBounds bounds = geometry.getBounds();
            MLatLon southWest = new MLatLon(bounds.getSouthWest().getLatitude(), bounds.getSouthWest().getLongitude());
            MLatLon northEast = new MLatLon(bounds.getNorthEast().getLatitude(), bounds.getNorthEast().getLongitude());
            MLatLonBox latLonBox = new MLatLonBox(southWest, northEast);
            bookmark.setLatLonBox(latLonBox);
            bookmarks.add(bookmark);
        }
        mDone = true;
    };
    Platform.runLater(() -> {
        GeocodingService service = new GeocodingService();
        service.geocode(searchString, callback);
    });
    do {
        try {
            TimeUnit.MILLISECONDS.sleep(1000);
        } catch (InterruptedException ex) {
            Exceptions.printStackTrace(ex);
        }
    } while (!mDone);
    return bookmarks;
}
Also used : MLatLon(org.mapton.api.MLatLon) GeocodingResult(com.dlsc.gmapsfx.service.geocoding.GeocodingResult) ArrayList(java.util.ArrayList) GeocoderStatus(com.dlsc.gmapsfx.service.geocoding.GeocoderStatus) GeocoderGeometry(com.dlsc.gmapsfx.service.geocoding.GeocoderGeometry) GeocodingService(com.dlsc.gmapsfx.service.geocoding.GeocodingService) MBookmark(org.mapton.api.MBookmark) GeocodingServiceCallback(com.dlsc.gmapsfx.service.geocoding.GeocodingServiceCallback) LatLongBounds(com.dlsc.gmapsfx.javascript.object.LatLongBounds) LatLong(com.dlsc.gmapsfx.javascript.object.LatLong) MLatLonBox(org.mapton.api.MLatLonBox)

Example 7 with MBookmark

use of org.mapton.api.MBookmark in project mapton by trixon.

the class FileImportAction method importCsv.

private void importCsv() throws IOException {
    String[] requiredColumns = new String[] { MBookmarkManager.COL_NAME, MBookmarkManager.COL_LATITUDE, MBookmarkManager.COL_LONGITUDE };
    try (CSVParser records = CSVParser.parse(mFile, Charset.forName("utf-8"), CSVFormat.DEFAULT.withFirstRecordAsHeader().withDelimiter(';'))) {
        String default_zoom = "0.85";
        if (isValidCsv(records, requiredColumns)) {
            ArrayList<MBookmark> bookmarks = new ArrayList<>();
            for (CSVRecord record : records) {
                String category = getOrDefault(record, MBookmarkManager.COL_CATEGORY, Dict.DEFAULT.toString());
                String description = getOrDefault(record, MBookmarkManager.COL_DESCRIPTION, "");
                String url = getOrDefault(record, MBookmarkManager.COL_URL, "");
                String color = getOrDefault(record, MBookmarkManager.COL_COLOR, "FFFF00");
                String displayMarker = getOrDefault(record, MBookmarkManager.COL_DISPLAY_MARKER, "1");
                String zoomString = getOrDefault(record, MBookmarkManager.COL_ZOOM, default_zoom);
                if (!NumberUtils.isCreatable(zoomString)) {
                    zoomString = default_zoom;
                }
                Double lat = MathHelper.convertStringToDouble(record.get(MBookmarkManager.COL_LATITUDE));
                Double lon = MathHelper.convertStringToDouble(record.get(MBookmarkManager.COL_LONGITUDE));
                Double zoom = MathHelper.convertStringToDouble(zoomString);
                MBookmark bookmark = new MBookmark();
                bookmark.setCategory(category);
                bookmark.setName(record.get(MBookmarkManager.COL_NAME));
                bookmark.setDescription(description);
                bookmark.setUrl(url);
                bookmark.setColor(color);
                bookmark.setDisplayMarker(displayMarker.equalsIgnoreCase("1"));
                bookmark.setLatitude(lat);
                bookmark.setLongitude(lon);
                bookmark.setZoom(zoom);
                bookmarks.add(bookmark);
            }
            Point result = mManager.dbInsert(bookmarks);
            mImports = result.x;
            mErrors = result.y;
        } else {
            String message = String.format(mBundle.getString("bookmark_import_error_csv_message"), String.join("\n ▶ ", requiredColumns));
            NotificationDisplayer.getDefault().notify(mBundle.getString("bookmark_import_error_csv_title"), MNotificationIcons.getErrorIcon(), message, null, Priority.HIGH);
        }
    }
}
Also used : MBookmark(org.mapton.api.MBookmark) CSVParser(org.apache.commons.csv.CSVParser) ArrayList(java.util.ArrayList) CSVRecord(org.apache.commons.csv.CSVRecord) Point(java.awt.Point) GeoPoint(se.trixon.almond.util.io.GeoPoint)

Example 8 with MBookmark

use of org.mapton.api.MBookmark in project mapton by trixon.

the class BookmarkPlotter method updatePlacemarks.

private void updatePlacemarks() {
    HashSet<Waypoint> waypoints = new HashSet<Waypoint>();
    for (MBookmark bookmark : mBookmarkManager.getItems()) {
        if (bookmark.isDisplayMarker()) {
            GeoPosition geoPosition = new GeoPosition(bookmark.getLatitude(), bookmark.getLongitude());
            DefaultWaypoint defaultWaypoint = new DefaultWaypoint(geoPosition);
            waypoints.add(defaultWaypoint);
        }
    }
    WaypointPainter<Waypoint> waypointPainter = new WaypointPainter<>();
    waypointPainter.setWaypoints(waypoints);
    mEngine.getMap().setOverlayPainter(waypointPainter);
}
Also used : MBookmark(org.mapton.api.MBookmark) WaypointPainter(org.jxmapviewer.viewer.WaypointPainter) DefaultWaypoint(org.jxmapviewer.viewer.DefaultWaypoint) Waypoint(org.jxmapviewer.viewer.Waypoint) GeoPosition(org.jxmapviewer.viewer.GeoPosition) DefaultWaypoint(org.jxmapviewer.viewer.DefaultWaypoint) HashSet(java.util.HashSet)

Example 9 with MBookmark

use of org.mapton.api.MBookmark in project mapton by trixon.

the class BookmarkPlotter method updatePlacemarks.

private void updatePlacemarks() {
    mMarkers.forEach((marker) -> {
        mEngine.getMapView().removeMarker(marker);
    });
    mMarkers.clear();
    BufferedImage whitePinBufferedImage = GraphicsHelper.getBufferedImage(getClass().getResource("plain-white.png"));
    Image si = GraphicsHelper.scaleImage(whitePinBufferedImage, new Dimension(48, 48));
    whitePinBufferedImage = GraphicsHelper.toBufferedImage(si);
    for (MBookmark bookmark : mBookmarkManager.getItems()) {
        if (bookmark.isDisplayMarker()) {
            String markerFilename = String.format("%s.png", bookmark.getColor());
            File markerFile = new File(mEngine.getCacheDir(), markerFilename);
            if (!markerFile.isFile()) {
                BufferedImage colorizedImage = GraphicsHelper.colorize(whitePinBufferedImage, Color.decode("#" + bookmark.getColor()));
                try {
                    ImageIO.write(colorizedImage, "png", markerFile);
                } catch (IOException ex) {
                    Exceptions.printStackTrace(ex);
                }
            }
            Coordinate coordinate = new Coordinate(bookmark.getLatitude(), bookmark.getLongitude());
            MapLabel mapLabel = new MapLabel(bookmark.getName()).setPosition(coordinate).setVisible(true);
            // Marker marker = Marker.createProvided(Marker.Provided.RED).setPosition(coordinate).setVisible(true).attachLabel(mapLabel);
            // Marker marker = new Marker(getClass().getResource("plain-white.png")).setPosition(coordinate).setVisible(true).attachLabel(mapLabel);
            Marker marker = null;
            try {
                int x = -whitePinBufferedImage.getWidth() / 2 + 10;
                int y = -whitePinBufferedImage.getHeight();
                marker = new Marker(markerFile.toURI().toURL(), x, y).setPosition(coordinate).setVisible(true).attachLabel(mapLabel);
            } catch (MalformedURLException ex) {
                Exceptions.printStackTrace(ex);
            }
            mEngine.getMapView().addMarker(marker);
            mMarkers.add(marker);
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) MBookmark(org.mapton.api.MBookmark) Coordinate(com.sothawo.mapjfx.Coordinate) MapLabel(com.sothawo.mapjfx.MapLabel) Dimension(java.awt.Dimension) IOException(java.io.IOException) Marker(com.sothawo.mapjfx.Marker) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) File(java.io.File) BufferedImage(java.awt.image.BufferedImage)

Example 10 with MBookmark

use of org.mapton.api.MBookmark in project mapton by trixon.

the class BookmarkPlotter method updatePlacemarks.

private void updatePlacemarks() {
    mEngine.getMap().clearMarkers();
    for (MBookmark bookmark : mBookmarkManager.getItems()) {
        if (bookmark.isDisplayMarker()) {
            LatLong latLong = new LatLong(bookmark.getLatitude(), bookmark.getLongitude());
            MarkerOptions markerOptions = new MarkerOptions();
            markerOptions.position(latLong);
            markerOptions.title(bookmark.getName());
            Marker marker = new Marker(markerOptions);
            mEngine.getMap().addMarker(marker);
        }
    }
}
Also used : MarkerOptions(com.dlsc.gmapsfx.javascript.object.MarkerOptions) MBookmark(org.mapton.api.MBookmark) Marker(com.dlsc.gmapsfx.javascript.object.Marker) LatLong(com.dlsc.gmapsfx.javascript.object.LatLong)

Aggregations

MBookmark (org.mapton.api.MBookmark)12 ArrayList (java.util.ArrayList)5 Point (java.awt.Point)3 GeoPoint (se.trixon.almond.util.io.GeoPoint)3 LatLong (com.dlsc.gmapsfx.javascript.object.LatLong)2 MLatLon (org.mapton.api.MLatLon)2 LatLongBounds (com.dlsc.gmapsfx.javascript.object.LatLongBounds)1 Marker (com.dlsc.gmapsfx.javascript.object.Marker)1 MarkerOptions (com.dlsc.gmapsfx.javascript.object.MarkerOptions)1 GeocoderGeometry (com.dlsc.gmapsfx.service.geocoding.GeocoderGeometry)1 GeocoderStatus (com.dlsc.gmapsfx.service.geocoding.GeocoderStatus)1 GeocodingResult (com.dlsc.gmapsfx.service.geocoding.GeocodingResult)1 GeocodingService (com.dlsc.gmapsfx.service.geocoding.GeocodingService)1 GeocodingServiceCallback (com.dlsc.gmapsfx.service.geocoding.GeocodingServiceCallback)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 TypeToken (com.google.gson.reflect.TypeToken)1 Coordinate (com.sothawo.mapjfx.Coordinate)1 MapLabel (com.sothawo.mapjfx.MapLabel)1 Marker (com.sothawo.mapjfx.Marker)1