Search in sources :

Example 21 with OpenstreetmapPoint

use of net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint in project Osmand by osmandapp.

the class EditPOIMenuController method getRightIconId.

@Override
public int getRightIconId() {
    if (osmPoint.getGroup() == OsmPoint.Group.POI) {
        OpenstreetmapPoint osmP = (OpenstreetmapPoint) osmPoint;
        int iconResId = 0;
        String poiTranslation = osmP.getEntity().getTag(POI_TYPE_TAG);
        MapActivity mapActivity = getMapActivity();
        if (poiTranslation != null && mapActivity != null) {
            Map<String, PoiType> poiTypeMap = mapActivity.getMyApplication().getPoiTypes().getAllTranslatedNames(false);
            PoiType poiType = poiTypeMap.get(poiTranslation.toLowerCase());
            if (poiType != null) {
                String id = null;
                if (RenderingIcons.containsBigIcon(poiType.getIconKeyName())) {
                    id = poiType.getIconKeyName();
                } else if (RenderingIcons.containsBigIcon(poiType.getOsmTag() + "_" + poiType.getOsmValue())) {
                    id = poiType.getOsmTag() + "_" + poiType.getOsmValue();
                }
                if (id != null) {
                    iconResId = RenderingIcons.getBigIconResourceId(id);
                }
            }
        }
        if (iconResId == 0) {
            iconResId = R.drawable.ic_action_info_dark;
        }
        return iconResId;
    } else if (osmPoint.getGroup() == OsmPoint.Group.BUG) {
        return R.drawable.ic_action_osm_note_add;
    } else {
        return 0;
    }
}
Also used : OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) PoiType(net.osmand.osm.PoiType) OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) OsmNotesPoint(net.osmand.plus.plugins.osmedit.data.OsmNotesPoint) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) MapActivity(net.osmand.plus.activities.MapActivity)

Example 22 with OpenstreetmapPoint

use of net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint in project Osmand by osmandapp.

the class AddPOIAction method execute.

@Override
public void execute(@NonNull final MapActivity mapActivity) {
    OsmandApplication app = mapActivity.getMyApplication();
    OsmandSettings settings = app.getSettings();
    OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
    if (plugin == null)
        return;
    LatLon latLon = mapActivity.getMapView().getCurrentRotatedTileBox().getCenterLatLon();
    Node node = new Node(latLon.getLatitude(), latLon.getLongitude(), -1);
    node.replaceTags(getTagsFromParams());
    EditPoiData editPoiData = new EditPoiData(node, mapActivity.getMyApplication());
    if (Boolean.parseBoolean(getParams().get(KEY_DIALOG)) || editPoiData.hasEmptyValue()) {
        Entity newEntity = editPoiData.getEntity();
        EditPoiDialogFragment editPoiDialogFragment = EditPoiDialogFragment.createInstance(newEntity, true, getTagsFromParams());
        editPoiDialogFragment.show(mapActivity.getSupportFragmentManager(), EditPoiDialogFragment.TAG);
    } else {
        OpenstreetmapUtil mOpenstreetmapUtil;
        if (plugin.OFFLINE_EDITION.get() || !settings.isInternetConnectionAvailable(true)) {
            mOpenstreetmapUtil = plugin.getPoiModificationLocalUtil();
        } else {
            mOpenstreetmapUtil = plugin.getPoiModificationRemoteUtil();
        }
        final boolean offlineEdit = mOpenstreetmapUtil instanceof OpenstreetmapLocalUtil;
        Node newNode = new Node(node.getLatitude(), node.getLongitude(), node.getId());
        Action action = newNode.getId() < 0 ? OsmPoint.Action.CREATE : OsmPoint.Action.MODIFY;
        for (Map.Entry<String, String> tag : editPoiData.getTagValues().entrySet()) {
            if (tag.getKey().equals(POI_TYPE_TAG)) {
                final PoiType poiType = editPoiData.getAllTranslatedSubTypes().get(tag.getValue().trim().toLowerCase());
                if (poiType != null) {
                    newNode.putTagNoLC(poiType.getEditOsmTag(), poiType.getEditOsmValue());
                    if (poiType.getOsmTag2() != null) {
                        newNode.putTagNoLC(poiType.getOsmTag2(), poiType.getOsmValue2());
                    }
                    if (poiType.getEditOsmTag2() != null) {
                        newNode.putTagNoLC(poiType.getEditOsmTag2(), poiType.getEditOsmValue2());
                    }
                } else if (!Algorithms.isEmpty(tag.getValue())) {
                    PoiCategory category = editPoiData.getPoiCategory();
                    if (category != null) {
                        newNode.putTagNoLC(category.getDefaultTag(), tag.getValue());
                    }
                }
                if (offlineEdit && !Algorithms.isEmpty(tag.getValue())) {
                    newNode.putTagNoLC(tag.getKey(), tag.getValue());
                }
            } else if (!Algorithms.isEmpty(tag.getKey()) && !Algorithms.isEmpty(tag.getValue())) {
                newNode.putTagNoLC(tag.getKey(), tag.getValue());
            }
        }
        EditPoiDialogFragment.commitEntity(action, newNode, mOpenstreetmapUtil.getEntityInfo(newNode.getId()), "", false, result -> {
            if (result != null) {
                OsmEditingPlugin plugin1 = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
                if (plugin1 != null && offlineEdit) {
                    List<OpenstreetmapPoint> points = plugin1.getDBPOI().getOpenstreetmapPoints();
                    if (points.size() > 0) {
                        OsmPoint point = points.get(points.size() - 1);
                        mapActivity.getContextMenu().showOrUpdate(new LatLon(point.getLatitude(), point.getLongitude()), plugin1.getOsmEditsLayer(mapActivity).getObjectName(point), point);
                    }
                }
                mapActivity.getMapView().refreshMap(true);
            }
            return false;
        }, mapActivity, mOpenstreetmapUtil, null);
    }
}
Also used : Entity(net.osmand.osm.edit.Entity) QuickAction(net.osmand.plus.quickaction.QuickAction) Action(net.osmand.plus.plugins.osmedit.data.OsmPoint.Action) OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) OsmandApplication(net.osmand.plus.OsmandApplication) Node(net.osmand.osm.edit.Node) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType) EditPoiDialogFragment(net.osmand.plus.plugins.osmedit.dialogs.EditPoiDialogFragment) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) OsmEditingPlugin(net.osmand.plus.plugins.osmedit.OsmEditingPlugin) LatLon(net.osmand.data.LatLon) OpenstreetmapLocalUtil(net.osmand.plus.plugins.osmedit.helpers.OpenstreetmapLocalUtil) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) PoiCategory(net.osmand.osm.PoiCategory) EditPoiData(net.osmand.plus.plugins.osmedit.data.EditPoiData) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) OpenstreetmapUtil(net.osmand.plus.plugins.osmedit.helpers.OpenstreetmapUtil)

Example 23 with OpenstreetmapPoint

use of net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint in project Osmand by osmandapp.

the class OsmEditOptionsBottomSheetDialogFragment method createMenuItems.

@Override
public void createMenuItems(Bundle savedInstanceState) {
    Bundle args = getArguments();
    if (args != null) {
        final OsmPoint osmPoint = (OsmPoint) args.getSerializable(OSM_POINT);
        String name = OsmEditingPlugin.getName(osmPoint);
        if (Algorithms.isEmpty(name)) {
            name = OsmEditingPlugin.getCategory(osmPoint, getContext());
        }
        items.add(new TitleItem(name + ":"));
        BaseBottomSheetItem uploadItem = new SimpleBottomSheetItem.Builder().setIcon(getContentIcon(R.drawable.ic_action_export)).setTitle(getString(R.string.local_openstreetmap_upload)).setLayoutId(R.layout.bottom_sheet_item_simple).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onUploadClick(osmPoint);
                }
                dismiss();
            }
        }).create();
        items.add(uploadItem);
        BaseBottomSheetItem showOnMapItem = new SimpleBottomSheetItem.Builder().setIcon(getContentIcon(R.drawable.ic_show_on_map)).setTitle(getString(R.string.shared_string_show_on_map)).setLayoutId(R.layout.bottom_sheet_item_simple).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onShowOnMapClick(osmPoint);
                }
                dismiss();
            }
        }).create();
        items.add(showOnMapItem);
        items.add(new DividerHalfItem(getContext()));
        if (osmPoint instanceof OpenstreetmapPoint && osmPoint.getAction() != OsmPoint.Action.DELETE) {
            BaseBottomSheetItem modifyOsmChangeItem = new SimpleBottomSheetItem.Builder().setIcon(getContentIcon(R.drawable.ic_action_edit_dark)).setTitle(getString(R.string.poi_context_menu_modify_osm_change)).setLayoutId(R.layout.bottom_sheet_item_simple).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (listener != null) {
                        listener.onModifyOsmChangeClick(osmPoint);
                    }
                    dismiss();
                }
            }).create();
            items.add(modifyOsmChangeItem);
        }
        if (osmPoint instanceof OsmNotesPoint) {
            BaseBottomSheetItem modifyOsmNoteItem = new SimpleBottomSheetItem.Builder().setIcon(getContentIcon(R.drawable.ic_action_edit_dark)).setTitle(getString(R.string.context_menu_item_modify_note)).setLayoutId(R.layout.bottom_sheet_item_simple).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (listener != null) {
                        listener.onModifyOsmNoteClick(osmPoint);
                    }
                    dismiss();
                }
            }).create();
            items.add(modifyOsmNoteItem);
        }
        BaseBottomSheetItem deleteItem = new SimpleBottomSheetItem.Builder().setIcon(getContentIcon(R.drawable.ic_action_delete_dark)).setTitle(getString(R.string.shared_string_delete)).setLayoutId(R.layout.bottom_sheet_item_simple).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onDeleteClick(osmPoint);
                }
                dismiss();
            }
        }).create();
        items.add(deleteItem);
    }
}
Also used : BaseBottomSheetItem(net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem) SimpleBottomSheetItem(net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem) OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) Bundle(android.os.Bundle) OsmNotesPoint(net.osmand.plus.plugins.osmedit.data.OsmNotesPoint) DividerHalfItem(net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem) TitleItem(net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem) View(android.view.View)

Example 24 with OpenstreetmapPoint

use of net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint in project Osmand by osmandapp.

the class SendPoiBottomSheetFragment method createDefaultChangeSet.

private String createDefaultChangeSet(OsmandApplication app) {
    Map<String, PoiType> allTranslatedSubTypes = app.getPoiTypes().getAllTranslatedNames(true);
    if (allTranslatedSubTypes == null) {
        return "";
    }
    Map<String, Integer> addGroup = new HashMap<>();
    Map<String, Integer> editGroup = new HashMap<>();
    Map<String, Integer> deleteGroup = new HashMap<>();
    Map<String, Integer> reopenGroup = new HashMap<>();
    String comment = "";
    for (OsmPoint p : poi) {
        if (p.getGroup() == OsmPoint.Group.POI) {
            OsmPoint.Action action = p.getAction();
            String type = ((OpenstreetmapPoint) p).getEntity().getTag(Entity.POI_TYPE_TAG);
            if (type == null) {
                continue;
            }
            PoiType localizedPoiType = allTranslatedSubTypes.get(type.toLowerCase().trim());
            if (localizedPoiType != null) {
                type = Algorithms.capitalizeFirstLetter(localizedPoiType.getKeyName().replace('_', ' '));
            }
            if (action == OsmPoint.Action.CREATE) {
                if (!addGroup.containsKey(type)) {
                    addGroup.put(type, 1);
                } else {
                    addGroup.put(type, addGroup.get(type) + 1);
                }
            } else if (action == OsmPoint.Action.MODIFY) {
                if (!editGroup.containsKey(type)) {
                    editGroup.put(type, 1);
                } else {
                    editGroup.put(type, editGroup.get(type) + 1);
                }
            } else if (action == OsmPoint.Action.DELETE) {
                if (!deleteGroup.containsKey(type)) {
                    deleteGroup.put(type, 1);
                } else {
                    deleteGroup.put(type, deleteGroup.get(type) + 1);
                }
            } else if (action == OsmPoint.Action.REOPEN) {
                if (!reopenGroup.containsKey(type)) {
                    reopenGroup.put(type, 1);
                } else {
                    reopenGroup.put(type, reopenGroup.get(type) + 1);
                }
            }
        }
    }
    int modifiedItemsOutOfLimit = 0;
    for (int i = 0; i < 4; i++) {
        String action;
        Map<String, Integer> group;
        switch(i) {
            case 0:
                action = getString(R.string.default_changeset_add);
                group = addGroup;
                break;
            case 1:
                action = getString(R.string.default_changeset_edit);
                group = editGroup;
                break;
            case 2:
                action = getString(R.string.default_changeset_delete);
                group = deleteGroup;
                break;
            case 3:
                action = getString(R.string.default_changeset_reopen);
                group = reopenGroup;
                break;
            default:
                action = "";
                group = new HashMap<>();
        }
        if (!group.isEmpty()) {
            int pos = 0;
            for (Map.Entry<String, Integer> entry : group.entrySet()) {
                String type = entry.getKey();
                int quantity = entry.getValue();
                if (comment.length() > 200) {
                    modifiedItemsOutOfLimit += quantity;
                } else {
                    if (pos == 0) {
                        comment = comment.concat(comment.length() == 0 ? "" : "; ").concat(action).concat(" ").concat(quantity == 1 ? "" : quantity + " ").concat(type);
                    } else {
                        comment = comment.concat(", ").concat(quantity == 1 ? "" : quantity + " ").concat(type);
                    }
                }
                pos++;
            }
        }
    }
    if (modifiedItemsOutOfLimit != 0) {
        comment = comment.concat("; ").concat(modifiedItemsOutOfLimit + " ").concat(getString(R.string.items_modified)).concat(".");
    } else if (!comment.isEmpty()) {
        comment = comment.concat(".");
    }
    return comment;
}
Also used : OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) HashMap(java.util.HashMap) PoiType(net.osmand.osm.PoiType) HashMap(java.util.HashMap) Map(java.util.Map) OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint)

Example 25 with OpenstreetmapPoint

use of net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint in project Osmand by osmandapp.

the class DashOsmEditsFragment method getOsmPoints.

private void getOsmPoints(ArrayList<OsmPoint> dataPoints) {
    List<OpenstreetmapPoint> l1 = plugin.getDBPOI().getOpenstreetmapPoints();
    List<OsmNotesPoint> l2 = plugin.getDBBug().getOsmbugsPoints();
    if (l1.isEmpty()) {
        int i = 0;
        for (OsmPoint point : l2) {
            if (i > 2) {
                break;
            }
            dataPoints.add(point);
            i++;
        }
    } else if (l2.isEmpty()) {
        int i = 0;
        for (OsmPoint point : l1) {
            if (i > 2) {
                break;
            }
            dataPoints.add(point);
            i++;
        }
    } else {
        dataPoints.add(l1.get(0));
        dataPoints.add(l2.get(0));
        if (l1.size() > 1) {
            dataPoints.add(l1.get(1));
        } else if (l2.size() > 1) {
            dataPoints.add(l2.get(1));
        }
    }
}
Also used : OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) OsmNotesPoint(net.osmand.plus.plugins.osmedit.data.OsmNotesPoint) OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) OsmNotesPoint(net.osmand.plus.plugins.osmedit.data.OsmNotesPoint) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint)

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