Search in sources :

Example 26 with OsmPoint

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

the class OsmEditsLayer method drawPoints.

private List<OsmPoint> drawPoints(Canvas canvas, RotatedTileBox tileBox, List<? extends OsmPoint> objects, List<LatLon> fullObjectsLatLon) {
    float iconSize = getIconSize(app);
    List<OsmPoint> fullObjects = new ArrayList<>();
    for (OsmPoint o : objects) {
        if (contextMenuLayer.getMoveableObject() != o) {
            float x = tileBox.getPixXFromLatLon(o.getLatitude(), o.getLongitude());
            float y = tileBox.getPixYFromLatLon(o.getLatitude(), o.getLongitude());
            if (tileBox.containsPoint(x, y, iconSize)) {
                drawPoint(canvas, o, x, y);
                fullObjects.add(o);
                fullObjectsLatLon.add(new LatLon(o.getLatitude(), o.getLongitude()));
            }
        }
    }
    return fullObjects;
}
Also used : LatLon(net.osmand.data.LatLon) OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) ArrayList(java.util.ArrayList)

Example 27 with OsmPoint

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

the class OsmEditsLayer method getFromPoint.

private int getFromPoint(RotatedTileBox tileBox, List<? super OsmPoint> am, int ex, int ey, int compare, int radius, List<? extends OsmPoint> points) {
    for (OsmPoint n : points) {
        int x = (int) tileBox.getPixXFromLatLon(n.getLatitude(), n.getLongitude());
        int y = (int) tileBox.getPixYFromLatLon(n.getLatitude(), n.getLongitude());
        if (calculateBelongs(ex, ey, x, y, compare)) {
            compare = radius;
            am.add(n);
        }
    }
    return compare;
}
Also used : OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) OsmNotesPoint(net.osmand.plus.plugins.osmedit.data.OsmNotesPoint) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint)

Example 28 with OsmPoint

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

the class OsmEditsLayer method onDraw.

@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
    if (contextMenuLayer.getMoveableObject() instanceof OsmPoint) {
        OsmPoint objectInMotion = (OsmPoint) contextMenuLayer.getMoveableObject();
        PointF pf = contextMenuLayer.getMovableCenterPoint(tileBox);
        drawPoint(canvas, objectInMotion, pf.x, pf.y);
    }
}
Also used : OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) PointF(android.graphics.PointF)

Example 29 with OsmPoint

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

the class EditPoiDialogFragment method save.

public void save() {
    Entity original = editPoiData.getEntity();
    final boolean offlineEdit = mOpenstreetmapUtil instanceof OpenstreetmapLocalUtil;
    Entity entity;
    if (original instanceof Node) {
        entity = new Node(original.getLatitude(), original.getLongitude(), original.getId());
    } else if (original instanceof Way) {
        entity = new Way(original.getId(), ((Way) original).getNodeIds(), original.getLatitude(), original.getLongitude());
    } else {
        return;
    }
    Action action = entity.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(POI_TYPE_TAG)) {
            entity.putTagNoLC(tag.getKey(), tag.getValue());
        }
    }
    String poiTypeTag = editPoiData.getTagValues().get(POI_TYPE_TAG);
    String comment = "";
    if (poiTypeTag != null) {
        final PoiType poiType = editPoiData.getAllTranslatedSubTypes().get(poiTypeTag.trim().toLowerCase());
        if (poiType != null) {
            entity.putTagNoLC(poiType.getEditOsmTag(), poiType.getEditOsmValue());
            entity.removeTag(Entity.REMOVE_TAG_PREFIX + poiType.getEditOsmTag());
            if (poiType.getOsmTag2() != null) {
                entity.putTagNoLC(poiType.getOsmTag2(), poiType.getOsmValue2());
                entity.removeTag(Entity.REMOVE_TAG_PREFIX + poiType.getOsmTag2());
            }
            if (poiType.getEditOsmTag2() != null) {
                entity.putTagNoLC(poiType.getEditOsmTag2(), poiType.getEditOsmValue2());
                entity.removeTag(Entity.REMOVE_TAG_PREFIX + poiType.getEditOsmTag2());
            }
        } else if (!Algorithms.isEmpty(poiTypeTag)) {
            PoiCategory category = editPoiData.getPoiCategory();
            if (category != null) {
                entity.putTagNoLC(category.getDefaultTag(), poiTypeTag);
            }
        }
        if (offlineEdit && !Algorithms.isEmpty(poiTypeTag)) {
            entity.putTagNoLC(POI_TYPE_TAG, poiTypeTag);
        }
        String actionString = action == Action.CREATE ? getString(R.string.default_changeset_add) : getString(R.string.default_changeset_edit);
        comment = actionString + " " + poiTypeTag;
    }
    commitEntity(action, entity, mOpenstreetmapUtil.getEntityInfo(entity.getId()), comment, false, result -> {
        OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
        if (result != null) {
            if (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);
                    mapActivity.getMapLayers().getContextMenuLayer().updateContextMenu();
                }
            }
            if (getActivity() instanceof MapActivity) {
                ((MapActivity) getActivity()).getMapView().refreshMap(true);
            }
            dismissAllowingStateLoss();
        } else {
            mOpenstreetmapUtil = plugin.getPoiModificationLocalUtil();
            Button saveButton = 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 : Entity(net.osmand.osm.edit.Entity) Action(net.osmand.plus.plugins.osmedit.data.OsmPoint.Action) OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) Node(net.osmand.osm.edit.Node) PoiType(net.osmand.osm.PoiType) Way(net.osmand.osm.edit.Way) OsmEditingPlugin(net.osmand.plus.plugins.osmedit.OsmEditingPlugin) OpenstreetmapLocalUtil(net.osmand.plus.plugins.osmedit.helpers.OpenstreetmapLocalUtil) LatLon(net.osmand.data.LatLon) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) OpenstreetmapRemoteUtil(net.osmand.plus.plugins.osmedit.helpers.OpenstreetmapRemoteUtil) ImageButton(android.widget.ImageButton) Button(android.widget.Button) AppCompatImageButton(androidx.appcompat.widget.AppCompatImageButton) PoiCategory(net.osmand.osm.PoiCategory) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) MapActivity(net.osmand.plus.activities.MapActivity)

Aggregations

OsmPoint (net.osmand.plus.plugins.osmedit.data.OsmPoint)29 OpenstreetmapPoint (net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint)21 OsmNotesPoint (net.osmand.plus.plugins.osmedit.data.OsmNotesPoint)15 PoiType (net.osmand.osm.PoiType)6 Map (java.util.Map)5 Entity (net.osmand.osm.edit.Entity)5 View (android.view.View)4 LinearLayout (android.widget.LinearLayout)4 LatLon (net.osmand.data.LatLon)4 TextView (android.widget.TextView)3 FragmentActivity (androidx.fragment.app.FragmentActivity)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 MapActivity (net.osmand.plus.activities.MapActivity)3 SimpleBottomSheetItem (net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem)3 ProgressDialogFragment (net.osmand.plus.dialogs.ProgressDialogFragment)3 OsmEditingPlugin (net.osmand.plus.plugins.osmedit.OsmEditingPlugin)3 ContextThemeWrapper (android.view.ContextThemeWrapper)2 CompoundButton (android.widget.CompoundButton)2 ImageButton (android.widget.ImageButton)2