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;
}
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);
}
}
}
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);
}
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);
}
}
}
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);
}
}
}
Aggregations