Search in sources :

Example 1 with OpenstreetmapUtil

use of net.osmand.plus.osmedit.OpenstreetmapUtil in project Osmand by osmandapp.

the class AddPOIAction method execute.

@Override
public void execute(final MapActivity activity) {
    LatLon latLon = activity.getMapView().getCurrentRotatedTileBox().getCenterLatLon();
    OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
    if (plugin == null)
        return;
    Node node = new Node(latLon.getLatitude(), latLon.getLongitude(), -1);
    node.replaceTags(getTagsFromParams());
    EditPoiData editPoiData = new EditPoiData(node, activity.getMyApplication());
    if (Boolean.valueOf(getParams().get(KEY_DIALOG))) {
        Node newNode = editPoiData.getEntity();
        EditPoiDialogFragment editPoiDialogFragment = EditPoiDialogFragment.createInstance(newNode, true, getTagsFromParams());
        editPoiDialogFragment.show(activity.getSupportFragmentManager(), EditPoiDialogFragment.TAG);
    } else {
        OpenstreetmapUtil mOpenstreetmapUtil;
        if (activity.getMyApplication().getSettings().OFFLINE_EDITION.get() || !activity.getMyApplication().getSettings().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());
        OsmPoint.Action action = newNode.getId() < 0 ? OsmPoint.Action.CREATE : OsmPoint.Action.MODIFY;
        for (Map.Entry<String, String> tag : editPoiData.getTagValues().entrySet()) {
            if (tag.getKey().equals(EditPoiData.POI_TYPE_TAG)) {
                final PoiType poiType = editPoiData.getAllTranslatedSubTypes().get(tag.getValue().trim().toLowerCase());
                if (poiType != null) {
                    newNode.putTagNoLC(poiType.getOsmTag(), poiType.getOsmValue());
                    if (poiType.getOsmTag2() != null) {
                        newNode.putTagNoLC(poiType.getOsmTag2(), poiType.getOsmValue2());
                    }
                } else if (!Algorithms.isEmpty(tag.getValue())) {
                    newNode.putTagNoLC(editPoiData.getPoiCategory().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.commitNode(action, newNode, mOpenstreetmapUtil.getEntityInfo(newNode.getId()), "", 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 (activity instanceof MapActivity && points.size() > 0) {
                            OsmPoint point = points.get(points.size() - 1);
                            activity.getContextMenu().showOrUpdate(new LatLon(point.getLatitude(), point.getLongitude()), plugin.getOsmEditsLayer(activity).getObjectName(point), point);
                        }
                    }
                    if (activity instanceof MapActivity) {
                        activity.getMapView().refreshMap(true);
                    }
                } 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;
            }
        }, activity, mOpenstreetmapUtil, null);
    }
}
Also used : OsmPoint(net.osmand.plus.osmedit.OsmPoint) Node(net.osmand.osm.edit.Node) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType) EditPoiDialogFragment(net.osmand.plus.osmedit.EditPoiDialogFragment) OsmEditingPlugin(net.osmand.plus.osmedit.OsmEditingPlugin) LatLon(net.osmand.data.LatLon) OpenstreetmapLocalUtil(net.osmand.plus.osmedit.OpenstreetmapLocalUtil) EditPoiData(net.osmand.plus.osmedit.EditPoiData) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) OpenstreetmapUtil(net.osmand.plus.osmedit.OpenstreetmapUtil) MapActivity(net.osmand.plus.activities.MapActivity)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 LatLon (net.osmand.data.LatLon)1 AbstractPoiType (net.osmand.osm.AbstractPoiType)1 PoiType (net.osmand.osm.PoiType)1 Node (net.osmand.osm.edit.Node)1 MapActivity (net.osmand.plus.activities.MapActivity)1 EditPoiData (net.osmand.plus.osmedit.EditPoiData)1 EditPoiDialogFragment (net.osmand.plus.osmedit.EditPoiDialogFragment)1 OpenstreetmapLocalUtil (net.osmand.plus.osmedit.OpenstreetmapLocalUtil)1 OpenstreetmapUtil (net.osmand.plus.osmedit.OpenstreetmapUtil)1 OsmEditingPlugin (net.osmand.plus.osmedit.OsmEditingPlugin)1 OsmPoint (net.osmand.plus.osmedit.OsmPoint)1