Search in sources :

Example 1 with OpenstreetmapPoint

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;
}
Also used : WptPt(net.osmand.GPXUtilities.WptPt) OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) OsmNotesPoint(net.osmand.plus.plugins.osmedit.data.OsmNotesPoint) GPXFile(net.osmand.GPXUtilities.GPXFile) IOException(java.io.IOException)

Example 2 with OpenstreetmapPoint

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;
}
Also used : OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) NonNull(androidx.annotation.NonNull)

Example 3 with OpenstreetmapPoint

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);
    }
}
Also used : Entity(net.osmand.osm.edit.Entity) Node(net.osmand.osm.edit.Node) JSONArray(org.json.JSONArray) Gson(com.google.gson.Gson) JSONException(org.json.JSONException) OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) Way(net.osmand.osm.edit.Way) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) JSONObject(org.json.JSONObject) TypeToken(com.google.gson.reflect.TypeToken)

Example 4 with OpenstreetmapPoint

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);
            }
        }
    }
}
Also used : OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) OpenstreetmapsDbHelper(net.osmand.plus.plugins.osmedit.helpers.OpenstreetmapsDbHelper) OsmEditingPlugin(net.osmand.plus.plugins.osmedit.OsmEditingPlugin)

Example 5 with OpenstreetmapPoint

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;
}
Also used : AudioVideoNotesPlugin(net.osmand.plus.plugins.audionotes.AudioVideoNotesPlugin) MapMarker(net.osmand.plus.mapmarkers.MapMarker) OsmNotesPoint(net.osmand.plus.plugins.osmedit.data.OsmNotesPoint) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) GpxDataItem(net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem) List(java.util.List) ArrayList(java.util.ArrayList) MapMarkersGroup(net.osmand.plus.mapmarkers.MapMarkersGroup) ExportSettingsType(net.osmand.plus.settings.backend.ExportSettingsType) FavoriteGroup(net.osmand.plus.myplaces.FavoriteGroup) OsmEditingPlugin(net.osmand.plus.plugins.osmedit.OsmEditingPlugin) HistoryEntry(net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry) Recording(net.osmand.plus.plugins.audionotes.AudioVideoNotesPlugin.Recording) File(java.io.File)

Aggregations

OpenstreetmapPoint (net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint)30 OsmPoint (net.osmand.plus.plugins.osmedit.data.OsmPoint)18 OsmNotesPoint (net.osmand.plus.plugins.osmedit.data.OsmNotesPoint)17 Entity (net.osmand.osm.edit.Entity)10 ArrayList (java.util.ArrayList)8 PoiType (net.osmand.osm.PoiType)8 File (java.io.File)5 Node (net.osmand.osm.edit.Node)5 HistoryEntry (net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry)5 MapMarkersGroup (net.osmand.plus.mapmarkers.MapMarkersGroup)5 FavoriteGroup (net.osmand.plus.myplaces.FavoriteGroup)5 OsmEditingPlugin (net.osmand.plus.plugins.osmedit.OsmEditingPlugin)5 QuickAction (net.osmand.plus.quickaction.QuickAction)5 List (java.util.List)4 ITileSource (net.osmand.map.ITileSource)4 MapActivity (net.osmand.plus.activities.MapActivity)4 AvoidRoadInfo (net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo)4 OnlineRoutingEngine (net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine)4 PoiUIFilter (net.osmand.plus.poi.PoiUIFilter)4 View (android.view.View)3