This commit is contained in:
Chumva 2018-07-26 15:08:07 +03:00
parent b2294a6c5c
commit 30681c6f64
15 changed files with 231 additions and 148 deletions

View file

@ -108,6 +108,8 @@ public abstract class Entity implements Serializable {
private boolean dataLoaded;
private int modify;
private int version;
private double latitude;
private double longitude;
public static final int MODIFY_UNKNOWN = 0;
public static final int MODIFY_DELETED = -1;
public static final int MODIFY_MODIFIED = 1;
@ -117,6 +119,11 @@ public abstract class Entity implements Serializable {
this.id = id;
}
public Entity(long id, double latitude, double longitude) {
this.id = id;
this.latitude = latitude;
this.longitude = longitude;
}
public Entity(Entity copy, long id) {
this.id = id;
@ -124,6 +131,8 @@ public abstract class Entity implements Serializable {
putTagNoLC(t, copy.getTag(t));
}
this.dataLoaded = copy.dataLoaded;
this.latitude = copy.latitude;
this.longitude = copy.longitude;
}
public Set<String> getChangedTags() {
@ -146,6 +155,22 @@ public abstract class Entity implements Serializable {
return id;
}
public double getLatitude() {
return latitude;
}
public double getLongitude() {
return longitude;
}
public void setLatitude(double latitude) {
this.latitude = latitude;
}
public void setLongitude(double longitude) {
this.longitude = longitude;
}
public String removeTag(String key) {
if (tags != null) {
return tags.remove(key);

View file

@ -8,42 +8,20 @@ import java.util.Map;
public class Node extends Entity implements Serializable {
private static final long serialVersionUID = -2981499160640211082L;
private double latitude;
private double longitude;
// currently not used
// private boolean visible = true;
public Node(double latitude, double longitude, long id){
super(id);
this.latitude = latitude;
this.longitude = longitude;
super(id, latitude,longitude);
}
public Node(Node n, long newId) {
super(n, newId);
this.latitude = n.latitude;
this.longitude = n.longitude;
}
public double getLatitude() {
return latitude;
}
public double getLongitude() {
return longitude;
}
public void setLatitude(double latitude) {
this.latitude = latitude;
}
public void setLongitude(double longitude) {
this.longitude = longitude;
}
@Override
public LatLon getLatLon() {
return new LatLon(latitude, longitude);
return new LatLon(getLatitude(), getLongitude());
}
@Override
@ -55,8 +33,8 @@ public class Node extends Entity implements Serializable {
@Override
public String toString() {
return "Node{" +
"latitude=" + latitude +
", longitude=" + longitude +
"latitude=" + getLatitude() +
", longitude=" + getLongitude() +
", tags=" + getTags() +
'}';
}

View file

@ -39,6 +39,11 @@ public class Way extends Entity {
}
}
public Way(long id, TLongArrayList nodeIds, double lat, double lon) {
super(id, lat, lon);
this.nodeIds = nodeIds;
}
public void addNode(long id) {
if (nodeIds == null) {
nodeIds = new TLongArrayList();

View file

@ -10,6 +10,7 @@
- For wording and consistency, please note http://osmand.net/help-online?id=technical-articles#Creating_a_Consistent_User_Experience
Thx - Hardy
-->
<string name="commiting_way">Committing way…</string>
<string name="increase_search_radius_to">Increase search radius to %1$s</string>
<string name="send_search_query_description"><![CDATA[We will send your search query: <b>\"%1$s\"</b>, as well as your location.<br/><br/>
We do not collect personal information, we only need search data to improve the search algorithm.<br/>]]></string>

View file

@ -5,7 +5,7 @@ import android.support.annotation.Nullable;
import net.osmand.PlatformUtil;
import net.osmand.osm.PoiCategory;
import net.osmand.osm.PoiType;
import net.osmand.osm.edit.Node;
import net.osmand.osm.edit.Entity;
import net.osmand.plus.OsmandApplication;
import net.osmand.util.Algorithms;
@ -23,7 +23,7 @@ public class EditPoiData {
private Set<TagsChangedListener> mListeners = new HashSet<>();
private LinkedHashMap<String, String > tagValues = new LinkedHashMap<String, String>();
private boolean isInEdit = false;
private Node entity;
private Entity entity;
public static final String POI_TYPE_TAG = "poi_type_tag";
public static final String REMOVE_TAG_PREFIX = "----";
@ -34,11 +34,11 @@ public class EditPoiData {
private Set<String> changedTags = new HashSet<>();
public EditPoiData(Node node, OsmandApplication app) {
public EditPoiData(Entity entity, OsmandApplication app) {
allTranslatedSubTypes = app.getPoiTypes().getAllTranslatedNames(true);
category = app.getPoiTypes().getOtherPoiCategory();
entity = node;
initTags(node);
this.entity = entity;
initTags(entity);
updateTypeTag(getPoiTypeString(), false);
}
@ -68,7 +68,7 @@ public class EditPoiData {
return s == null ? "" : s;
}
public Node getEntity() {
public Entity getEntity() {
return entity;
}
@ -90,7 +90,7 @@ public class EditPoiData {
}
}
private void initTags(Node node) {
private void initTags(Entity node) {
checkNotInEdit();
for (String s : node.getTagKeySet()) {
tryAddTag(s, node.getTag(s));

View file

@ -53,9 +53,11 @@ import net.osmand.data.Amenity;
import net.osmand.data.LatLon;
import net.osmand.osm.PoiCategory;
import net.osmand.osm.PoiType;
import net.osmand.osm.edit.Entity;
import net.osmand.osm.edit.EntityInfo;
import net.osmand.osm.edit.Node;
import net.osmand.osm.edit.OSMSettings;
import net.osmand.osm.edit.Way;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
@ -82,7 +84,7 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment {
public static final String TAG = "EditPoiDialogFragment";
private static final Log LOG = PlatformUtil.getLog(EditPoiDialogFragment.class);
private static final String KEY_AMENITY_NODE = "key_amenity_node";
private static final String KEY_AMENITY_ENTITY = "key_amenity_node";
private static final String TAGS_LIST = "tags_list";
private static final String IS_ADDING_POI = "is_adding_poi";
@ -115,8 +117,8 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment {
mOpenstreetmapUtil = plugin.getPoiModificationRemoteUtil();
}
Node node = (Node) getArguments().getSerializable(KEY_AMENITY_NODE);
editPoiData = new EditPoiData(node, getMyApplication());
Entity entity = (Entity) getArguments().getSerializable(KEY_AMENITY_ENTITY);
editPoiData = new EditPoiData(entity, getMyApplication());
}
@Override
@ -448,14 +450,23 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment {
}
private void save() {
Node original = editPoiData.getEntity();
Entity 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;
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(EditPoiData.POI_TYPE_TAG)) {
node.putTagNoLC(tag.getKey(), tag.getValue());
entity.putTagNoLC(tag.getKey(), tag.getValue());
}
}
String poiTypeTag = editPoiData.getTagValues().get(EditPoiData.POI_TYPE_TAG);
@ -463,29 +474,29 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment {
if (poiTypeTag != null) {
final PoiType poiType = editPoiData.getAllTranslatedSubTypes().get(poiTypeTag.trim().toLowerCase());
if (poiType != null) {
node.putTagNoLC(poiType.getEditOsmTag(), poiType.getEditOsmValue());
node.removeTag(EditPoiData.REMOVE_TAG_PREFIX + poiType.getEditOsmTag());
entity.putTagNoLC(poiType.getEditOsmTag(), poiType.getEditOsmValue());
entity.removeTag(EditPoiData.REMOVE_TAG_PREFIX + poiType.getEditOsmTag());
if (poiType.getOsmTag2() != null) {
node.putTagNoLC(poiType.getOsmTag2(), poiType.getOsmValue2());
node.removeTag(EditPoiData.REMOVE_TAG_PREFIX + poiType.getOsmTag2());
entity.putTagNoLC(poiType.getOsmTag2(), poiType.getOsmValue2());
entity.removeTag(EditPoiData.REMOVE_TAG_PREFIX + poiType.getOsmTag2());
}
} else if (!Algorithms.isEmpty(poiTypeTag)) {
PoiCategory category = editPoiData.getPoiCategory();
if (category != null) {
node.putTagNoLC(category.getDefaultTag(), poiTypeTag);
entity.putTagNoLC(category.getDefaultTag(), poiTypeTag);
}
}
if (offlineEdit && !Algorithms.isEmpty(poiTypeTag)) {
node.putTagNoLC(EditPoiData.POI_TYPE_TAG, poiTypeTag);
entity.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>() {
commitEntity(action, entity, mOpenstreetmapUtil.getEntityInfo(entity.getId()), comment, false,
new CallbackWithObject<Entity>() {
@Override
public boolean processResult(Node result) {
public boolean processResult(Entity result) {
if (result != null) {
OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
if (plugin != null && offlineEdit) {
@ -533,12 +544,12 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment {
poiTypeEditText.setText(subCategory);
}
public static void commitNode(final Action action,
final Node node,
public static void commitEntity(final Action action,
final Entity entity,
final EntityInfo info,
final String comment,
final boolean closeChangeSet,
final CallbackWithObject<Node> postExecute,
final CallbackWithObject<Entity> postExecute,
final Activity activity,
final OpenstreetmapUtil openstreetmapUtil,
@Nullable final Set<String> changedTags) {
@ -546,7 +557,7 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment {
Toast.makeText(activity, activity.getResources().getString(R.string.poi_error_info_not_loaded), Toast.LENGTH_LONG).show();
return;
}
new AsyncTask<Void, Void, Node>() {
new AsyncTask<Void, Void, Entity>() {
ProgressDialog progress;
@Override
@ -556,12 +567,12 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment {
}
@Override
protected Node doInBackground(Void... params) {
return openstreetmapUtil.commitNodeImpl(action, node, info, comment, closeChangeSet, changedTags);
protected Entity doInBackground(Void... params) {
return openstreetmapUtil.commitEntityImpl(action, entity, info, comment, closeChangeSet, changedTags);
}
@Override
protected void onPostExecute(Node result) {
protected void onPostExecute(Entity result) {
progress.dismiss();
if (postExecute != null) {
postExecute.processResult(result);
@ -652,19 +663,19 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment {
return createInstance(node, true);
}
public static EditPoiDialogFragment createInstance(Node node, boolean isAddingPoi) {
public static EditPoiDialogFragment createInstance(Entity entity, boolean isAddingPoi) {
EditPoiDialogFragment editPoiDialogFragment = new EditPoiDialogFragment();
Bundle args = new Bundle();
args.putSerializable(KEY_AMENITY_NODE, node);
args.putSerializable(KEY_AMENITY_ENTITY, entity);
args.putBoolean(IS_ADDING_POI, isAddingPoi);
editPoiDialogFragment.setArguments(args);
return editPoiDialogFragment;
}
public static EditPoiDialogFragment createInstance(Node node, boolean isAddingPoi, Map<String, String> tagList) {
public static EditPoiDialogFragment createInstance(Entity entity, boolean isAddingPoi, Map<String, String> tagList) {
EditPoiDialogFragment editPoiDialogFragment = new EditPoiDialogFragment();
Bundle args = new Bundle();
args.putSerializable(KEY_AMENITY_NODE, node);
args.putSerializable(KEY_AMENITY_ENTITY, entity);
args.putBoolean(IS_ADDING_POI, isAddingPoi);
args.putSerializable(TAGS_LIST, (Serializable) Collections.unmodifiableMap(tagList));
editPoiDialogFragment.setArguments(args);
@ -683,16 +694,16 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment {
} else {
openstreetmapUtilToLoad = plugin.getPoiModificationRemoteUtil();
}
new AsyncTask<Void, Void, Node>() {
new AsyncTask<Void, Void, Entity>() {
@Override
protected Node doInBackground(Void... params) {
return openstreetmapUtilToLoad.loadNode(amenity);
protected Entity doInBackground(Void... params) {
return openstreetmapUtilToLoad.loadEntity(amenity);
}
protected void onPostExecute(Node n) {
if (n != null) {
protected void onPostExecute(Entity entity) {
if (entity != null) {
EditPoiDialogFragment fragment =
EditPoiDialogFragment.createInstance(n, false);
EditPoiDialogFragment.createInstance(entity, false);
fragment.show(activity.getSupportFragmentManager(), TAG);
} else {
Toast.makeText(activity,
@ -750,22 +761,22 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment {
}
public void deletePoiWithDialog(Amenity amenity) {
new AsyncTask<Amenity, Void, Node>() {
new AsyncTask<Amenity, Void, Entity>() {
@Override
protected Node doInBackground(Amenity... params) {
return openstreetmapUtil.loadNode(params[0]);
protected Entity doInBackground(Amenity... params) {
return openstreetmapUtil.loadEntity(params[0]);
}
@Override
protected void onPostExecute(Node node) {
deletePoiWithDialog(node);
protected void onPostExecute(Entity entity) {
deletePoiWithDialog(entity);
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, amenity);
}
public void deletePoiWithDialog(final Node n) {
if (n == null) {
public void deletePoiWithDialog(final Entity entity) {
if (entity == null) {
Toast.makeText(activity, activity.getResources().getString(R.string.poi_error_poi_not_found), Toast.LENGTH_LONG).show();
return;
}
@ -793,24 +804,24 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment {
builder.setPositiveButton(isLocalEdit ? R.string.shared_string_save : R.string.shared_string_delete, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String c = comment == null ? null : comment.getText().toString();
boolean closeChangeSet = closeChangesetCheckBox != null
&& closeChangesetCheckBox.isChecked();
deleteNode(n, c, closeChangeSet);
if (entity instanceof Node) {
String c = comment == null ? null : comment.getText().toString();
boolean closeChangeSet = closeChangesetCheckBox != null
&& closeChangesetCheckBox.isChecked();
deleteNode((Node) entity, c, closeChangeSet);
}
}
});
builder.create().show();
}
private void deleteNode(final Node n, final String c, final boolean closeChangeSet) {
private void deleteNode(final Entity entity, final String c, final boolean closeChangeSet) {
final boolean isLocalEdit = openstreetmapUtil instanceof OpenstreetmapLocalUtil;
commitNode(Action.DELETE, n, openstreetmapUtil.getEntityInfo(n.getId()), c, closeChangeSet,
new CallbackWithObject<Node>() {
commitEntity(Action.DELETE, entity, openstreetmapUtil.getEntityInfo(entity.getId()), c, closeChangeSet,
new CallbackWithObject<Entity>() {
@Override
public boolean processResult(Node result) {
public boolean processResult(Entity result) {
if (result != null) {
if (callback != null) {
callback.poiDeleted();

View file

@ -5,9 +5,11 @@ import net.osmand.data.Amenity;
import net.osmand.osm.AbstractPoiType;
import net.osmand.osm.MapPoiTypes;
import net.osmand.osm.PoiType;
import net.osmand.osm.edit.Entity;
import net.osmand.osm.edit.EntityInfo;
import net.osmand.osm.edit.Node;
import net.osmand.osm.edit.OSMSettings.OSMTagKey;
import net.osmand.osm.edit.Way;
import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils;
@ -46,18 +48,24 @@ public class OpenstreetmapLocalUtil implements OpenstreetmapUtil {
}
@Override
public Node commitNodeImpl(OsmPoint.Action action, Node n, EntityInfo info, String comment,
boolean closeChangeSet, Set<String> changedTags){
Node newNode = n;
if (n.getId() == -1) {
newNode = new Node(n, Math.min(-2, plugin.getDBPOI().getMinID() - 1)); // generate local id for the created node
public Entity commitEntityImpl(OsmPoint.Action action, Entity entity, EntityInfo info, String comment,
boolean closeChangeSet, Set<String> changedTags) {
Entity newEntity = entity;
if (entity.getId() == -1) {
if (entity instanceof Node) {
newEntity = new Node((Node) entity, Math.min(-2, plugin.getDBPOI().getMinID() - 1));
} else if (entity instanceof Way) {
newEntity = new Way(Math.min(-2, plugin.getDBPOI().getMinID() - 1), ((Way) entity).getNodeIds(), entity.getLatitude(), entity.getLongitude());
} else {
return null;
}
}
OpenstreetmapPoint p = new OpenstreetmapPoint();
newNode.setChangedTags(changedTags);
p.setEntity(newNode);
newEntity.setChangedTags(changedTags);
p.setEntity(newEntity);
p.setAction(action);
p.setComment(comment);
if (p.getAction() == OsmPoint.Action.DELETE && newNode.getId() < 0) { //if it is our local poi
if (p.getAction() == OsmPoint.Action.DELETE && newEntity.getId() < 0) { //if it is our local poi
plugin.getDBPOI().deletePOI(p);
} else {
plugin.getDBPOI().addOpenstreetmap(p);
@ -65,11 +73,11 @@ public class OpenstreetmapLocalUtil implements OpenstreetmapUtil {
for (OnNodeCommittedListener listener : listeners) {
listener.onNoteCommitted();
}
return newNode;
return newEntity;
}
@Override
public Node loadNode(Amenity n) {
public Entity loadEntity(Amenity n) {
PoiType poiType = n.getType().getPoiTypeByKeyName(n.getSubType());
if(n.getId() % 2 == 1 || poiType == null){
// that's way id

View file

@ -1,12 +1,12 @@
package net.osmand.plus.osmedit;
import net.osmand.osm.edit.Node;
import net.osmand.osm.edit.Entity;
import net.osmand.osm.edit.OSMSettings.OSMTagKey;
import net.osmand.util.Algorithms;
public class OpenstreetmapPoint extends OsmPoint {
private static final long serialVersionUID = 729654300829771467L;
private Node entity;
private Entity entity;
private String comment;
public OpenstreetmapPoint(){
@ -59,7 +59,7 @@ public class OpenstreetmapPoint extends OsmPoint {
}
public Node getEntity() {
public Entity getEntity() {
return entity;
}
@ -67,7 +67,7 @@ public class OpenstreetmapPoint extends OsmPoint {
return comment;
}
public void setEntity(Node entity) {
public void setEntity(Entity entity) {
this.entity = entity;
}

View file

@ -5,12 +5,14 @@ import android.widget.Toast;
import net.osmand.PlatformUtil;
import net.osmand.data.Amenity;
import net.osmand.data.LatLon;
import net.osmand.osm.PoiType;
import net.osmand.osm.edit.Entity;
import net.osmand.osm.edit.Entity.EntityId;
import net.osmand.osm.edit.Entity.EntityType;
import net.osmand.osm.edit.EntityInfo;
import net.osmand.osm.edit.Node;
import net.osmand.osm.edit.Way;
import net.osmand.osm.io.Base64;
import net.osmand.osm.io.NetworkUtils;
import net.osmand.osm.io.OsmBaseStorage;
@ -234,6 +236,32 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
}
ser.endTag(null, "node"); //$NON-NLS-1$
}
private void writeWay(Way way, EntityInfo i, XmlSerializer ser, long changeSetId, String user)
throws IllegalArgumentException, IllegalStateException, IOException {
ser.startTag(null, "way"); //$NON-NLS-1$
ser.attribute(null, "id", way.getId() + ""); //$NON-NLS-1$ //$NON-NLS-2$
if (i != null) {
// ser.attribute(null, "timestamp", i.getETimestamp());
// ser.attribute(null, "uid", i.getUid());
// ser.attribute(null, "user", i.getUser());
ser.attribute(null, "visible", i.getVisible()); //$NON-NLS-1$
ser.attribute(null, "version", i.getVersion()); //$NON-NLS-1$
}
ser.attribute(null, "changeset", changeSetId + ""); //$NON-NLS-1$ //$NON-NLS-2$
for (String k : way.getTagKeySet()) {
String val = way.getTag(k);
if (val.length() == 0 || k.length() == 0 || EditPoiData.POI_TYPE_TAG.equals(k) ||
k.startsWith(EditPoiData.REMOVE_TAG_PREFIX) || k.contains(EditPoiData.REMOVE_TAG_PREFIX))
continue;
ser.startTag(null, "tag"); //$NON-NLS-1$
ser.attribute(null, "k", k); //$NON-NLS-1$
ser.attribute(null, "v", val); //$NON-NLS-1$
ser.endTag(null, "tag"); //$NON-NLS-1$
}
ser.endTag(null, "way"); //$NON-NLS-1$
}
private boolean isNewChangesetRequired() {
// first commit
@ -251,7 +279,7 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
}
@Override
public Node commitNodeImpl(OsmPoint.Action action, final Node n, EntityInfo info, String comment,
public Entity commitEntityImpl(OsmPoint.Action action, final Entity n, EntityInfo info, String comment,
boolean closeChangeSet, Set<String> changedTags) {
if (isNewChangesetRequired()) {
changeSetId = openChangeSet(comment);
@ -262,7 +290,7 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
}
try {
Node newN = n;
Entity newE = n;
StringWriter writer = new StringWriter(256);
XmlSerializer ser = Xml.newSerializer();
try {
@ -274,7 +302,12 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
ser.startTag(null, OsmPoint.stringAction.get(action));
ser.attribute(null, "version", "0.6"); //$NON-NLS-1$ //$NON-NLS-2$
ser.attribute(null, "generator", Version.getAppName(ctx)); //$NON-NLS-1$
writeNode(n, info, ser, changeSetId, settings.USER_NAME.get());
if (n instanceof Node) {
writeNode((Node) n, info, ser, changeSetId, settings.USER_NAME.get());
} else if (n instanceof Way) {
writeWay((Way) n, info, ser, changeSetId, settings.USER_NAME.get());
}
ser.endTag(null, OsmPoint.stringAction.get(action));
ser.endTag(null, "osmChange"); //$NON-NLS-1$
ser.endDocument();
@ -293,12 +326,16 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
int end = res.indexOf('\"', i); //$NON-NLS-1$
if (end > 0) {
newId = Long.parseLong(res.substring(i, end)); // << 1;
newN = new Node(n, newId);
if (n instanceof Node) {
newE = new Node((Node) n, newId);
} else if (n instanceof Way) {
newE = new Way(newId, ((Way) n).getNodeIds(), n.getLatitude(), n.getLongitude());
}
}
}
}
changeSetTimeStamp = System.currentTimeMillis();
return newN;
return newE;
}
return null;
} finally {
@ -374,39 +411,39 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
}
@Override
public Node loadNode(Amenity n) {
if (n.getId() % 2 == 1) {
// that's way id
return null;
}
long nodeId = n.getId() >> 1;
public Entity loadEntity(Amenity n) {
boolean isWay = n.getId() % 2 == 1;// check if amenity is a way
long entityId = n.getId() >> 1;
try {
String res = sendRequest(
getSiteApi() + "api/0.6/node/" + nodeId, "GET", null, ctx.getString(R.string.loading_poi_obj) + nodeId, false); //$NON-NLS-1$ //$NON-NLS-2$
String api = isWay ? "api/0.6/way/" : "api/0.6/node/";
String res = sendRequest(getSiteApi() + api + entityId, "GET", null,
ctx.getString(R.string.loading_poi_obj) + entityId, false); //$NON-NLS-1$ //$NON-NLS-2$
if (res != null) {
OsmBaseStorage st = new OsmBaseStorage();
st.setConvertTagsToLC(false);
st.parseOSM(new ByteArrayInputStream(res.getBytes("UTF-8")), null, null, true); //$NON-NLS-1$
EntityId id = new Entity.EntityId(EntityType.NODE, nodeId);
Node entity = (Node) st.getRegisteredEntities().get(id);
EntityId id = new Entity.EntityId(isWay ? EntityType.WAY : EntityType.NODE, entityId);
Entity entity = (Entity) st.getRegisteredEntities().get(id);
entityInfo = st.getRegisteredEntityInfo().get(id);
entityInfoId = id;
// 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) {
PoiType poiType = n.getType().getPoiTypeByKeyName(n.getSubType());
if(poiType.getEditOsmValue().equals(entity.getTag(poiType.getEditOsmTag()))) {
entity.removeTag(poiType.getEditOsmTag());
entity.putTagNoLC(EditPoiData.POI_TYPE_TAG, poiType.getTranslation());
} else {
// later we could try to determine tags
if (entity != null) {
if (!isWay && entity instanceof Node) {
// check whether this is node (because id of node could be the same as relation)
if (MapUtils.getDistance(entity.getLatLon(), n.getLocation()) < 50) {
return replaceEditOsnTags(n, entity);
}
} else if (isWay && entity instanceof Way) {
LatLon loc = n.getLocation();
entity.setLatitude(loc.getLatitude());
entity.setLongitude(loc.getLongitude());
return replaceEditOsnTags(n, entity);
}
return entity;
}
return null;
}
} catch (Exception e) {
log.error("Loading node failed " + nodeId, e); //$NON-NLS-1$
log.error("Loading entity failed " + entityId, e); //$NON-NLS-1$
ctx.runInUIThread(new Runnable() {
@Override
@ -419,6 +456,17 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
return null;
}
private Entity replaceEditOsnTags(Amenity amenity, Entity entity) {
PoiType poiType = amenity.getType().getPoiTypeByKeyName(amenity.getSubType());
if (poiType.getEditOsmValue().equals(entity.getTag(poiType.getEditOsmTag()))) {
entity.removeTag(poiType.getEditOsmTag());
entity.putTagNoLC(EditPoiData.POI_TYPE_TAG, poiType.getTranslation());
} else {
// later we could try to determine tags
}
return entity;
}
private void showWarning(final String msg) {
ctx.runInUIThread(new Runnable() {
@Override
@ -427,5 +475,4 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
}
});
}
}

View file

@ -3,8 +3,8 @@ package net.osmand.plus.osmedit;
import android.support.annotation.Nullable;
import net.osmand.data.Amenity;
import net.osmand.osm.edit.Entity;
import net.osmand.osm.edit.EntityInfo;
import net.osmand.osm.edit.Node;
import java.util.Set;
@ -12,9 +12,9 @@ public interface OpenstreetmapUtil {
EntityInfo getEntityInfo(long id);
Node commitNodeImpl(OsmPoint.Action action, Node n, EntityInfo info, String comment, boolean closeChangeSet, @Nullable Set<String> changedTags);
Entity commitEntityImpl(OsmPoint.Action action, Entity n, EntityInfo info, String comment, boolean closeChangeSet, @Nullable Set<String> changedTags);
void closeChangeSet();
Node loadNode(Amenity n);
Entity loadEntity(Amenity n);
}

View file

@ -21,7 +21,7 @@ import net.osmand.PlatformUtil;
import net.osmand.data.Amenity;
import net.osmand.data.TransportStop;
import net.osmand.osm.PoiType;
import net.osmand.osm.edit.Node;
import net.osmand.osm.edit.Entity;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.ItemClickListener;
import net.osmand.plus.ContextMenuItem;
@ -200,7 +200,7 @@ public class OsmEditingPlugin extends OsmandPlugin {
EditPoiDialogFragment.showEditInstance(selectedObj instanceof TransportStop ?
((TransportStop) selectedObj).getAmenity() : (Amenity) selectedObj, mapActivity);
} else if (resId == R.string.poi_context_menu_modify_osm_change) {
final Node entity = ((OpenstreetmapPoint) selectedObj).getEntity();
final Entity entity = ((OpenstreetmapPoint) selectedObj).getEntity();
EditPoiDialogFragment.createInstance(entity, false)
.show(mapActivity.getSupportFragmentManager(), EditPoiDialogFragment.TAG);
}

View file

@ -31,7 +31,7 @@ import android.widget.Toast;
import net.osmand.AndroidUtils;
import net.osmand.data.PointDescription;
import net.osmand.osm.edit.Node;
import net.osmand.osm.edit.Entity;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.WptPt;
@ -537,7 +537,7 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo
@Override
public void onModifyOsmChangeClick(OsmPoint osmPoint) {
OpenstreetmapPoint i = (OpenstreetmapPoint) getPointAfterModify(osmPoint);
final Node entity = i.getEntity();
final Entity entity = i.getEntity();
refreshId = entity.getId();
EditPoiDialogFragment.createInstance(entity, false).show(getActivity().getSupportFragmentManager(), "edit_poi");
}

View file

@ -13,7 +13,7 @@ import android.widget.Toast;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.RotatedTileBox;
import net.osmand.osm.edit.Node;
import net.osmand.osm.edit.Entity;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.ContextMenuLayer;
@ -209,9 +209,9 @@ public class OsmEditsLayer extends OsmandMapLayer implements ContextMenuLayer.IC
if (o instanceof OsmPoint) {
if (o instanceof OpenstreetmapPoint) {
OpenstreetmapPoint objectInMotion = (OpenstreetmapPoint) o;
Node node = objectInMotion.getEntity();
node.setLatitude(position.getLatitude());
node.setLongitude(position.getLongitude());
Entity entity = objectInMotion.getEntity();
entity.setLatitude(position.getLatitude());
entity.setLongitude(position.getLongitude());
new SaveOsmChangeAsyncTask(mOsmChangeUtil, callback, objectInMotion).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else if (o instanceof OsmNotesPoint) {
OsmNotesPoint objectInMotion = (OsmNotesPoint) o;
@ -223,7 +223,7 @@ public class OsmEditsLayer extends OsmandMapLayer implements ContextMenuLayer.IC
}
}
static class SaveOsmChangeAsyncTask extends AsyncTask<Void, Void, Node> {
static class SaveOsmChangeAsyncTask extends AsyncTask<Void, Void, Entity> {
private final OpenstreetmapLocalUtil mOpenstreetmapUtil;
@Nullable
private final ContextMenuLayer.ApplyMovedObjectCallback mCallback;
@ -237,16 +237,16 @@ public class OsmEditsLayer extends OsmandMapLayer implements ContextMenuLayer.IC
}
@Override
protected Node doInBackground(Void... params) {
Node node = objectInMotion.getEntity();
return mOpenstreetmapUtil.commitNodeImpl(objectInMotion.getAction(), node,
mOpenstreetmapUtil.getEntityInfo(node.getId()), "", false, null);
protected Entity doInBackground(Void... params) {
Entity entity = objectInMotion.getEntity();
return mOpenstreetmapUtil.commitEntityImpl(objectInMotion.getAction(), entity,
mOpenstreetmapUtil.getEntityInfo(entity.getId()), "", false, null);
}
@Override
protected void onPostExecute(Node newNode) {
protected void onPostExecute(Entity newEntity) {
if (mCallback != null) {
mCallback.onApplyMovedObject(newNode != null, objectInMotion);
mCallback.onApplyMovedObject(newEntity != null, objectInMotion);
}
}
}

View file

@ -3,6 +3,7 @@ package net.osmand.plus.osmedit;
import android.content.DialogInterface;
import android.os.AsyncTask;
import net.osmand.osm.edit.Entity;
import net.osmand.osm.edit.EntityInfo;
import net.osmand.osm.edit.Node;
import net.osmand.plus.dialogs.ProgressDialogFragment;
@ -53,9 +54,15 @@ public class UploadOpenstreetmapPointAsyncTask
OpenstreetmapPoint p = (OpenstreetmapPoint) point;
EntityInfo entityInfo = null;
if (OsmPoint.Action.CREATE != p.getAction()) {
entityInfo = remotepoi.loadNode(p.getEntity());
Entity entity = p.getEntity();
if (entity instanceof Node) {
entityInfo = remotepoi.loadNode((Node) entity);
} else {
loadErrorsMap.put(point, "Entity is not node");
return loadErrorsMap;
}
}
Node n = remotepoi.commitNodeImpl(p.getAction(), p.getEntity(), entityInfo,
Entity n = remotepoi.commitEntityImpl(p.getAction(), p.getEntity(), entityInfo,
p.getComment(), false, null);
if (n != null) {
uploaded = true;

View file

@ -32,6 +32,7 @@ import net.osmand.osm.AbstractPoiType;
import net.osmand.osm.MapPoiTypes;
import net.osmand.osm.PoiCategory;
import net.osmand.osm.PoiType;
import net.osmand.osm.edit.Entity;
import net.osmand.osm.edit.Node;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
@ -91,9 +92,9 @@ public class AddPOIAction extends QuickAction {
node.replaceTags(getTagsFromParams());
EditPoiData editPoiData = new EditPoiData(node, activity.getMyApplication());
if (Boolean.valueOf(getParams().get(KEY_DIALOG))) {
Node newNode = editPoiData.getEntity();
Entity newEntity = editPoiData.getEntity();
EditPoiDialogFragment editPoiDialogFragment =
EditPoiDialogFragment.createInstance(newNode, true, getTagsFromParams());
EditPoiDialogFragment.createInstance(newEntity, true, getTagsFromParams());
editPoiDialogFragment.show(activity.getSupportFragmentManager(),
EditPoiDialogFragment.TAG);
} else {
@ -129,11 +130,11 @@ public class AddPOIAction extends QuickAction {
newNode.putTagNoLC(tag.getKey(), tag.getValue());
}
}
EditPoiDialogFragment.commitNode(action, newNode, mOpenstreetmapUtil.getEntityInfo(newNode.getId()), "", false,
new CallbackWithObject<Node>() {
EditPoiDialogFragment.commitEntity(action, newNode, mOpenstreetmapUtil.getEntityInfo(newNode.getId()), "", false,
new CallbackWithObject<Entity>() {
@Override
public boolean processResult(Node result) {
public boolean processResult(Entity result) {
if (result != null) {
OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
if (plugin != null && offlineEdit) {