Search in sources :

Example 21 with PoiType

use of net.osmand.osm.PoiType 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(EditPoiData.POI_TYPE_TAG);
        if (poiTranslation != null) {
            Map<String, PoiType> poiTypeMap = getMapActivity().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_type_info;
        }
        return iconResId;
    } else if (osmPoint.getGroup() == OsmPoint.Group.BUG) {
        return R.drawable.ic_type_bug;
    } else {
        return 0;
    }
}
Also used : PoiType(net.osmand.osm.PoiType)

Example 22 with PoiType

use of net.osmand.osm.PoiType in project Osmand by osmandapp.

the class EditPoiData method updateTypeTag.

public void updateTypeTag(String string, boolean userChanges) {
    tagValues.put(POI_TYPE_TAG, string);
    if (userChanges) {
        changedTags.add(POI_TYPE_TAG);
    }
    retrieveType();
    PoiType pt = getPoiTypeDefined();
    if (pt != null) {
        tagValues.put(REMOVE_TAG_PREFIX + pt.getOsmTag(), REMOVE_TAG_VALUE);
        tagValues.put(REMOVE_TAG_PREFIX + pt.getOsmTag2(), REMOVE_TAG_VALUE);
        tagValues.remove(pt.getOsmTag());
        tagValues.remove(pt.getOsmTag2());
        changedTags.removeAll(Arrays.asList(pt.getOsmTag(), pt.getOsmTag2()));
        category = pt.getCategory();
    }
    notifyDatasetChanged(POI_TYPE_TAG);
}
Also used : PoiType(net.osmand.osm.PoiType)

Example 23 with PoiType

use of net.osmand.osm.PoiType in project Osmand by osmandapp.

the class EditPoiDialogFragment method save.

private void save() {
    Node original = editPoiData.getEntity();
    final boolean offlineEdit = mOpenstreetmapUtil instanceof OpenstreetmapLocalUtil;
    Node node = new Node(original.getLatitude(), original.getLongitude(), original.getId());
    Action action = node.getId() < 0 ? Action.CREATE : Action.MODIFY;
    for (Map.Entry<String, String> tag : editPoiData.getTagValues().entrySet()) {
        if (!Algorithms.isEmpty(tag.getKey()) && !Algorithms.isEmpty(tag.getValue()) && !tag.getKey().equals(EditPoiData.POI_TYPE_TAG)) {
            node.putTagNoLC(tag.getKey(), tag.getValue());
        }
    }
    String poiTypeTag = editPoiData.getTagValues().get(EditPoiData.POI_TYPE_TAG);
    String comment = "";
    if (poiTypeTag != null) {
        final PoiType poiType = editPoiData.getAllTranslatedSubTypes().get(poiTypeTag.trim().toLowerCase());
        if (poiType != null) {
            node.putTagNoLC(poiType.getOsmTag(), poiType.getOsmValue());
            node.removeTag(EditPoiData.REMOVE_TAG_PREFIX + poiType.getOsmTag());
            if (poiType.getOsmTag2() != null) {
                node.putTagNoLC(poiType.getOsmTag2(), poiType.getOsmValue2());
                node.removeTag(EditPoiData.REMOVE_TAG_PREFIX + poiType.getOsmTag2());
            }
        } else if (!Algorithms.isEmpty(poiTypeTag)) {
            node.putTagNoLC(editPoiData.getPoiCategory().getDefaultTag(), poiTypeTag);
        }
        if (offlineEdit && !Algorithms.isEmpty(poiTypeTag)) {
            node.putTagNoLC(EditPoiData.POI_TYPE_TAG, poiTypeTag);
        }
        String actionString = action == Action.CREATE ? getString(R.string.default_changeset_add) : getString(R.string.default_changeset_edit);
        comment = actionString + " " + poiTypeTag;
    }
    commitNode(action, node, mOpenstreetmapUtil.getEntityInfo(node.getId()), comment, false, new CallbackWithObject<Node>() {

        @Override
        public boolean processResult(Node result) {
            if (result != null) {
                OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
                if (plugin != null && offlineEdit) {
                    List<OpenstreetmapPoint> points = plugin.getDBPOI().getOpenstreetmapPoints();
                    if (getActivity() instanceof MapActivity && points.size() > 0) {
                        OsmPoint point = points.get(points.size() - 1);
                        MapActivity mapActivity = (MapActivity) getActivity();
                        mapActivity.getContextMenu().showOrUpdate(new LatLon(point.getLatitude(), point.getLongitude()), plugin.getOsmEditsLayer(mapActivity).getObjectName(point), point);
                    }
                }
                if (getActivity() instanceof MapActivity) {
                    ((MapActivity) getActivity()).getMapView().refreshMap(true);
                }
                dismiss();
            } else {
                OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
                mOpenstreetmapUtil = plugin.getPoiModificationLocalUtil();
                Button saveButton = (Button) view.findViewById(R.id.saveButton);
                saveButton.setText(mOpenstreetmapUtil instanceof OpenstreetmapRemoteUtil ? R.string.shared_string_upload : R.string.shared_string_save);
            }
            return false;
        }
    }, getActivity(), mOpenstreetmapUtil, action == Action.MODIFY ? editPoiData.getChangedTags() : null);
}
Also used : Action(net.osmand.plus.osmedit.OsmPoint.Action) Node(net.osmand.osm.edit.Node) PoiType(net.osmand.osm.PoiType) LatLon(net.osmand.data.LatLon) ImageButton(android.widget.ImageButton) Button(android.widget.Button) List(java.util.List) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) MapActivity(net.osmand.plus.activities.MapActivity)

Example 24 with PoiType

use of net.osmand.osm.PoiType in project Osmand by osmandapp.

the class OpenstreetmapLocalUtil method loadNode.

@Override
public Node loadNode(Amenity n) {
    PoiType poiType = n.getType().getPoiTypeByKeyName(n.getSubType());
    if (n.getId() % 2 == 1 || poiType == null) {
        // that's way id
        return null;
    }
    long nodeId = n.getId() >> 1;
    // EntityId id = new Entity.EntityId(EntityType.NODE, nodeId);
    Node entity = new Node(n.getLocation().getLatitude(), n.getLocation().getLongitude(), nodeId);
    entity.putTagNoLC(EditPoiData.POI_TYPE_TAG, poiType.getTranslation());
    if (poiType.getOsmTag2() != null) {
        entity.putTagNoLC(poiType.getOsmTag2(), poiType.getOsmValue2());
    }
    if (!Algorithms.isEmpty(n.getName())) {
        entity.putTagNoLC(OSMTagKey.NAME.getValue(), n.getName());
    }
    if (!Algorithms.isEmpty(n.getOpeningHours())) {
        entity.putTagNoLC(OSMTagKey.OPENING_HOURS.getValue(), n.getOpeningHours());
    }
    for (Map.Entry<String, String> entry : n.getAdditionalInfo().entrySet()) {
        AbstractPoiType abstractPoi = MapPoiTypes.getDefault().getAnyPoiAdditionalTypeByKey(entry.getKey());
        if (abstractPoi != null && abstractPoi instanceof PoiType) {
            PoiType p = (PoiType) abstractPoi;
            if (!p.isNotEditableOsm() && !Algorithms.isEmpty(p.getOsmTag())) {
                entity.putTagNoLC(p.getOsmTag(), entry.getValue());
            }
        }
    }
    // check whether this is node (because id of node could be the same as relation)
    if (entity != null && MapUtils.getDistance(entity.getLatLon(), n.getLocation()) < 50) {
        return entity;
    }
    return null;
}
Also used : Node(net.osmand.osm.edit.Node) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType) AbstractPoiType(net.osmand.osm.AbstractPoiType) Map(java.util.Map)

Example 25 with PoiType

use of net.osmand.osm.PoiType in project Osmand by osmandapp.

the class OsmEditingPlugin method registerMapContextMenuActions.

@Override
public void registerMapContextMenuActions(final MapActivity mapActivity, final double latitude, final double longitude, ContextMenuAdapter adapter, final Object selectedObj) {
    ContextMenuAdapter.ItemClickListener listener = new ContextMenuAdapter.ItemClickListener() {

        @Override
        public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int resId, int pos, boolean isChecked, int[] viewCoordinates) {
            if (resId == R.string.context_menu_item_create_poi) {
                // getPoiActions(mapActivity).showCreateDialog(latitude, longitude);
                EditPoiDialogFragment editPoiDialogFragment = EditPoiDialogFragment.createAddPoiInstance(latitude, longitude, mapActivity.getMyApplication());
                editPoiDialogFragment.show(mapActivity.getSupportFragmentManager(), EditPoiDialogFragment.TAG);
            } else if (resId == R.string.context_menu_item_open_note) {
                openOsmNote(mapActivity, latitude, longitude);
            } else if (resId == R.string.context_menu_item_modify_note) {
                modifyOsmNote(mapActivity, (OsmNotesPoint) selectedObj);
            } else if (resId == R.string.poi_context_menu_modify) {
                EditPoiDialogFragment.showEditInstance((Amenity) selectedObj, mapActivity);
            } else if (resId == R.string.poi_context_menu_modify_osm_change) {
                final Node entity = ((OpenstreetmapPoint) selectedObj).getEntity();
                EditPoiDialogFragment.createInstance(entity, false).show(mapActivity.getSupportFragmentManager(), EditPoiDialogFragment.TAG);
            }
            return true;
        }
    };
    boolean isEditable = false;
    if (selectedObj instanceof Amenity) {
        Amenity amenity = (Amenity) selectedObj;
        final PoiType poiType = amenity.getType().getPoiTypeByKeyName(amenity.getSubType());
        isEditable = !amenity.getType().isWiki() && poiType != null && !poiType.isNotEditableOsm();
    }
    if (isEditable) {
        adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.poi_context_menu_modify, mapActivity).setIcon(R.drawable.ic_action_edit_dark).setOrder(MODIFY_POI_ITEM_ORDER).setListener(listener).createItem());
    } else if (selectedObj instanceof OpenstreetmapPoint && ((OpenstreetmapPoint) selectedObj).getAction() != Action.DELETE) {
        adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.poi_context_menu_modify_osm_change, mapActivity).setIcon(R.drawable.ic_action_edit_dark).setOrder(MODIFY_OSM_CHANGE_ITEM_ORDER).setListener(listener).createItem());
    } else {
        adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.context_menu_item_create_poi, mapActivity).setIcon(R.drawable.ic_action_plus_dark).setOrder(CREATE_POI_ITEM_ORDER).setListener(listener).createItem());
    }
    if (selectedObj instanceof OsmNotesPoint) {
        adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.context_menu_item_modify_note, mapActivity).setIcon(R.drawable.ic_action_edit_dark).setOrder(MODIFY_OSM_NOTE_ITEM_ORDER).setListener(listener).createItem());
    } else {
        adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.context_menu_item_open_note, mapActivity).setIcon(R.drawable.ic_action_bug_dark).setOrder(OPEN_OSM_NOTE_ITEM_ORDER).setListener(listener).createItem());
    }
}
Also used : Amenity(net.osmand.data.Amenity) ItemClickListener(net.osmand.plus.ContextMenuAdapter.ItemClickListener) ContextMenuItem(net.osmand.plus.ContextMenuItem) Node(net.osmand.osm.edit.Node) PoiType(net.osmand.osm.PoiType) ItemClickListener(net.osmand.plus.ContextMenuAdapter.ItemClickListener) ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) ArrayAdapter(android.widget.ArrayAdapter)

Aggregations

PoiType (net.osmand.osm.PoiType)49 AbstractPoiType (net.osmand.osm.AbstractPoiType)30 PoiCategory (net.osmand.osm.PoiCategory)11 MapPoiTypes (net.osmand.osm.MapPoiTypes)10 View (android.view.View)8 TextView (android.widget.TextView)8 Map (java.util.Map)8 Amenity (net.osmand.data.Amenity)8 ArrayList (java.util.ArrayList)7 LinkedHashMap (java.util.LinkedHashMap)7 AdapterView (android.widget.AdapterView)5 HashMap (java.util.HashMap)5 List (java.util.List)5 OsmandApplication (net.osmand.plus.OsmandApplication)5 PoiUIFilter (net.osmand.plus.poi.PoiUIFilter)5 AutoCompleteTextView (android.widget.AutoCompleteTextView)4 LinkedHashSet (java.util.LinkedHashSet)4 LatLon (net.osmand.data.LatLon)4 PoiFilter (net.osmand.osm.PoiFilter)4 Node (net.osmand.osm.edit.Node)4