use of net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint in project Osmand by osmandapp.
the class ShareOsmPointsAsyncTask method saveGpxFile.
private String saveGpxFile(OsmPoint[] points) {
GPXFile gpx = new GPXFile(Version.getFullVersion(app));
for (OsmPoint point : points) {
if (point.getGroup() == Group.POI) {
OpenstreetmapPoint p = (OpenstreetmapPoint) point;
WptPt wpt = new WptPt();
wpt.name = p.getTagsString();
wpt.lat = p.getLatitude();
wpt.lon = p.getLongitude();
wpt.desc = "id: " + p.getId() + " node" + " " + OsmPoint.stringAction.get(p.getAction());
gpx.addPoint(wpt);
} else if (point.getGroup() == Group.BUG) {
OsmNotesPoint p = (OsmNotesPoint) point;
WptPt wpt = new WptPt();
wpt.name = p.getText();
wpt.lat = p.getLatitude();
wpt.lon = p.getLongitude();
wpt.desc = "id: " + p.getId() + " note" + " " + OsmPoint.stringAction.get(p.getAction());
gpx.addPoint(wpt);
}
}
Exception exception = GPXUtilities.writeGpxFile(srcFile, gpx);
if (exception != null) {
return exception.getMessage();
}
return null;
}
use of net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint in project Osmand by osmandapp.
the class OsmEditsSettingsItem method writeItemsToJson.
@NonNull
@Override
JSONObject writeItemsToJson(@NonNull JSONObject json) {
JSONArray jsonArray = new JSONArray();
if (!items.isEmpty()) {
try {
for (OpenstreetmapPoint point : items) {
JSONObject jsonPoint = new JSONObject();
JSONObject jsonEntity = new JSONObject();
jsonEntity.put(ID_KEY, point.getId());
jsonEntity.put(NAME_KEY, point.getTagsString());
jsonEntity.put(LAT_KEY, point.getLatitude());
jsonEntity.put(LON_KEY, point.getLongitude());
jsonEntity.put(TYPE_KEY, Entity.EntityType.valueOf(point.getEntity()));
JSONObject jsonTags = new JSONObject(point.getEntity().getTags());
jsonEntity.put(TAGS_KEY, jsonTags);
jsonPoint.put(COMMENT_KEY, point.getComment());
jsonEntity.put(ACTION_KEY, OsmPoint.stringAction.get(point.getAction()));
jsonPoint.put(ENTITY_KEY, jsonEntity);
jsonArray.put(jsonPoint);
}
json.put("items", jsonArray);
} catch (JSONException e) {
warnings.add(app.getString(R.string.settings_item_write_error, String.valueOf(getType())));
SettingsHelper.LOG.error("Failed write to json", e);
}
}
return json;
}
use of net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint in project Osmand by osmandapp.
the class OsmEditsSettingsItem method readItemsFromJson.
@Override
void readItemsFromJson(@NonNull JSONObject json) throws IllegalArgumentException {
try {
if (!json.has("items")) {
return;
}
JSONArray jsonArray = json.getJSONArray("items");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonPoint = jsonArray.getJSONObject(i);
String comment = jsonPoint.optString(COMMENT_KEY);
comment = comment.isEmpty() ? null : comment;
JSONObject entityJson = jsonPoint.getJSONObject(ENTITY_KEY);
long id = entityJson.getLong(ID_KEY);
double lat = entityJson.getDouble(LAT_KEY);
double lon = entityJson.getDouble(LON_KEY);
String tags = entityJson.getString(TAGS_KEY);
Map<String, String> tagMap = new Gson().fromJson(tags, new TypeToken<HashMap<String, String>>() {
}.getType());
String action = entityJson.getString(ACTION_KEY);
Entity entity;
if (entityJson.get(TYPE_KEY).equals(Entity.EntityType.NODE.name())) {
entity = new Node(lat, lon, id);
} else {
entity = new Way(id);
entity.setLatitude(lat);
entity.setLongitude(lon);
}
entity.replaceTags(tagMap);
OpenstreetmapPoint point = new OpenstreetmapPoint();
point.setComment(comment);
point.setEntity(entity);
point.setAction(action);
items.add(point);
}
} catch (JSONException e) {
warnings.add(app.getString(R.string.settings_item_read_error, String.valueOf(getType())));
throw new IllegalArgumentException("Json parse error", e);
}
}
use of net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint in project Osmand by osmandapp.
the class OsmEditsSettingsItem method apply.
@Override
public void apply() {
List<OpenstreetmapPoint> newItems = getNewItems();
if (!newItems.isEmpty() || !duplicateItems.isEmpty()) {
appliedItems = new ArrayList<>(newItems);
OsmEditingPlugin osmEditingPlugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
if (osmEditingPlugin != null) {
OpenstreetmapsDbHelper db = osmEditingPlugin.getDBPOI();
for (OpenstreetmapPoint duplicate : duplicateItems) {
db.deletePOI(duplicate);
db.addOpenstreetmap(duplicate);
}
for (OpenstreetmapPoint point : appliedItems) {
db.addOpenstreetmap(point);
}
}
}
}
use of net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint in project Osmand by osmandapp.
the class SettingsHelper method getMyPlacesItems.
private Map<ExportSettingsType, List<?>> getMyPlacesItems(@Nullable List<ExportSettingsType> settingsTypes, boolean addEmptyItems) {
Map<ExportSettingsType, List<?>> myPlacesItems = new LinkedHashMap<>();
List<FavoriteGroup> favoriteGroups = settingsTypes == null || settingsTypes.contains(ExportSettingsType.FAVORITES) ? app.getFavoritesHelper().getFavoriteGroups() : Collections.emptyList();
if (!favoriteGroups.isEmpty() || addEmptyItems) {
myPlacesItems.put(ExportSettingsType.FAVORITES, favoriteGroups);
}
List<GpxDataItem> gpxItems = settingsTypes == null || settingsTypes.contains(ExportSettingsType.TRACKS) ? app.getGpxDbHelper().getItems() : Collections.emptyList();
if (!gpxItems.isEmpty() || addEmptyItems) {
List<File> files = new ArrayList<>();
for (GpxDataItem gpxItem : gpxItems) {
File file = gpxItem.getFile();
if (file.exists() && !file.isDirectory()) {
files.add(file);
}
}
if (!files.isEmpty() || addEmptyItems) {
myPlacesItems.put(ExportSettingsType.TRACKS, files);
}
}
OsmEditingPlugin osmEditingPlugin = OsmandPlugin.getActivePlugin(OsmEditingPlugin.class);
if (osmEditingPlugin != null) {
List<OsmNotesPoint> notesPointList = settingsTypes == null || settingsTypes.contains(ExportSettingsType.OSM_NOTES) ? osmEditingPlugin.getDBBug().getOsmbugsPoints() : Collections.emptyList();
if (!notesPointList.isEmpty() || addEmptyItems) {
myPlacesItems.put(ExportSettingsType.OSM_NOTES, notesPointList);
}
List<OpenstreetmapPoint> editsPointList = settingsTypes == null || settingsTypes.contains(ExportSettingsType.OSM_EDITS) ? osmEditingPlugin.getDBPOI().getOpenstreetmapPoints() : Collections.emptyList();
if (!editsPointList.isEmpty() || addEmptyItems) {
myPlacesItems.put(ExportSettingsType.OSM_EDITS, editsPointList);
}
}
AudioVideoNotesPlugin avNotesPlugin = OsmandPlugin.getActivePlugin(AudioVideoNotesPlugin.class);
if (avNotesPlugin != null) {
List<File> files = new ArrayList<>();
if (settingsTypes == null || settingsTypes.contains(ExportSettingsType.MULTIMEDIA_NOTES)) {
for (Recording rec : avNotesPlugin.getAllRecordings()) {
File file = rec.getFile();
if (file != null && file.exists()) {
files.add(file);
}
}
}
if (!files.isEmpty() || addEmptyItems) {
myPlacesItems.put(ExportSettingsType.MULTIMEDIA_NOTES, files);
}
}
List<MapMarker> mapMarkers = settingsTypes == null || settingsTypes.contains(ExportSettingsType.ACTIVE_MARKERS) ? app.getMapMarkersHelper().getMapMarkers() : Collections.emptyList();
if (!mapMarkers.isEmpty() || addEmptyItems) {
String name = app.getString(R.string.map_markers);
String groupId = ExportSettingsType.ACTIVE_MARKERS.name();
MapMarkersGroup markersGroup = new MapMarkersGroup(groupId, name, ItineraryType.MARKERS);
markersGroup.setMarkers(mapMarkers);
myPlacesItems.put(ExportSettingsType.ACTIVE_MARKERS, Collections.singletonList(markersGroup));
}
List<MapMarker> markersHistory = settingsTypes == null || settingsTypes.contains(ExportSettingsType.HISTORY_MARKERS) ? app.getMapMarkersHelper().getMapMarkersHistory() : Collections.emptyList();
if (!markersHistory.isEmpty() || addEmptyItems) {
String name = app.getString(R.string.shared_string_history);
String groupId = ExportSettingsType.HISTORY_MARKERS.name();
MapMarkersGroup markersGroup = new MapMarkersGroup(groupId, name, ItineraryType.MARKERS);
markersGroup.setMarkers(markersHistory);
myPlacesItems.put(ExportSettingsType.HISTORY_MARKERS, Collections.singletonList(markersGroup));
}
List<HistoryEntry> historyEntries = settingsTypes == null || settingsTypes.contains(ExportSettingsType.SEARCH_HISTORY) ? SearchHistoryHelper.getInstance(app).getHistoryEntries(false) : Collections.emptyList();
if (!historyEntries.isEmpty() || addEmptyItems) {
myPlacesItems.put(ExportSettingsType.SEARCH_HISTORY, historyEntries);
}
List<MapMarkersGroup> markersGroups = settingsTypes == null || settingsTypes.contains(ExportSettingsType.ITINERARY_GROUPS) ? app.getMapMarkersHelper().getVisibleMapMarkersGroups() : Collections.emptyList();
if (!markersGroups.isEmpty() || addEmptyItems) {
myPlacesItems.put(ExportSettingsType.ITINERARY_GROUPS, markersGroups);
}
return myPlacesItems;
}
Aggregations