Add support for editing MapObject
This commit is contained in:
parent
08085f1efb
commit
fed4db96e5
5 changed files with 101 additions and 43 deletions
|
@ -51,6 +51,7 @@ import net.osmand.CallbackWithObject;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.data.Amenity;
|
import net.osmand.data.Amenity;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
|
import net.osmand.data.MapObject;
|
||||||
import net.osmand.osm.PoiCategory;
|
import net.osmand.osm.PoiCategory;
|
||||||
import net.osmand.osm.PoiType;
|
import net.osmand.osm.PoiType;
|
||||||
import net.osmand.osm.edit.Entity;
|
import net.osmand.osm.edit.Entity;
|
||||||
|
@ -682,7 +683,7 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment {
|
||||||
return editPoiDialogFragment;
|
return editPoiDialogFragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showEditInstance(final Amenity amenity,
|
public static void showEditInstance(final MapObject mapObject,
|
||||||
final AppCompatActivity activity) {
|
final AppCompatActivity activity) {
|
||||||
final OsmandSettings settings = ((OsmandApplication) activity.getApplication())
|
final OsmandSettings settings = ((OsmandApplication) activity.getApplication())
|
||||||
.getSettings();
|
.getSettings();
|
||||||
|
@ -697,7 +698,7 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment {
|
||||||
new AsyncTask<Void, Void, Entity>() {
|
new AsyncTask<Void, Void, Entity>() {
|
||||||
@Override
|
@Override
|
||||||
protected Entity doInBackground(Void... params) {
|
protected Entity doInBackground(Void... params) {
|
||||||
return openstreetmapUtilToLoad.loadEntity(amenity);
|
return openstreetmapUtilToLoad.loadEntity(mapObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onPostExecute(Entity entity) {
|
protected void onPostExecute(Entity entity) {
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
package net.osmand.plus.osmedit;
|
package net.osmand.plus.osmedit;
|
||||||
|
|
||||||
|
import net.osmand.NativeLibrary;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.data.Amenity;
|
import net.osmand.data.Amenity;
|
||||||
|
import net.osmand.data.Building;
|
||||||
|
import net.osmand.data.LatLon;
|
||||||
|
import net.osmand.data.MapObject;
|
||||||
import net.osmand.osm.AbstractPoiType;
|
import net.osmand.osm.AbstractPoiType;
|
||||||
import net.osmand.osm.MapPoiTypes;
|
import net.osmand.osm.MapPoiTypes;
|
||||||
import net.osmand.osm.PoiType;
|
import net.osmand.osm.PoiType;
|
||||||
|
@ -77,46 +81,66 @@ public class OpenstreetmapLocalUtil implements OpenstreetmapUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Entity loadEntity(Amenity n) {
|
public Entity loadEntity(MapObject mapObject) {
|
||||||
PoiType poiType = n.getType().getPoiTypeByKeyName(n.getSubType());
|
boolean amenity = mapObject instanceof Amenity;
|
||||||
boolean isWay = n.getId() % 2 == 1; // check if amenity is a way
|
PoiType poiType = null;
|
||||||
if (poiType == null) {
|
if (amenity) {
|
||||||
|
poiType = ((Amenity) mapObject).getType().getPoiTypeByKeyName(((Amenity) mapObject).getSubType());
|
||||||
|
}
|
||||||
|
boolean isWay = mapObject.getId() % 2 == 1; // check if amenity is a way
|
||||||
|
if (poiType == null && amenity) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
long entityId = n.getId() >> 1;
|
long entityId;
|
||||||
|
if (mapObject instanceof Amenity) {
|
||||||
// EntityId id = new Entity.EntityId(EntityType.NODE, entityId);
|
entityId = mapObject.getId() >> 1;
|
||||||
Entity entity;
|
|
||||||
if (isWay) {
|
|
||||||
entity = new Way(entityId, null, n.getLocation().getLatitude(), n.getLocation().getLongitude());
|
|
||||||
} else {
|
} else {
|
||||||
entity = new Node(n.getLocation().getLatitude(),
|
entityId = mapObject.getId() >> 7;
|
||||||
n.getLocation().getLongitude(),
|
|
||||||
entityId);
|
|
||||||
}
|
|
||||||
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()) {
|
Entity entity;
|
||||||
AbstractPoiType abstractPoi = MapPoiTypes.getDefault().getAnyPoiAdditionalTypeByKey(entry.getKey());
|
LatLon loc = mapObject.getLocation();
|
||||||
if (abstractPoi != null && abstractPoi instanceof PoiType) {
|
if (loc == null) {
|
||||||
PoiType p = (PoiType) abstractPoi;
|
if (mapObject instanceof NativeLibrary.RenderedObject) {
|
||||||
if (!p.isNotEditableOsm() && !Algorithms.isEmpty(p.getEditOsmTag())) {
|
loc = ((NativeLibrary.RenderedObject) mapObject).getLabelLatLon();
|
||||||
entity.putTagNoLC(p.getEditOsmTag(), entry.getValue());
|
} else if (mapObject instanceof Building) {
|
||||||
|
loc = ((Building) mapObject).getLatLon2();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (loc == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (isWay) {
|
||||||
|
entity = new Way(entityId, null, loc.getLatitude(), loc.getLongitude());
|
||||||
|
} else {
|
||||||
|
entity = new Node(loc.getLatitude(), loc.getLongitude(), entityId);
|
||||||
|
}
|
||||||
|
if (poiType != null) {
|
||||||
|
entity.putTagNoLC(EditPoiData.POI_TYPE_TAG, poiType.getTranslation());
|
||||||
|
if (poiType.getOsmTag2() != null) {
|
||||||
|
entity.putTagNoLC(poiType.getOsmTag2(), poiType.getOsmValue2());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!Algorithms.isEmpty(mapObject.getName())) {
|
||||||
|
entity.putTagNoLC(OSMTagKey.NAME.getValue(), mapObject.getName());
|
||||||
|
}
|
||||||
|
if (amenity) {
|
||||||
|
if (!Algorithms.isEmpty(((Amenity) mapObject).getOpeningHours())) {
|
||||||
|
entity.putTagNoLC(OSMTagKey.OPENING_HOURS.getValue(), ((Amenity) mapObject).getOpeningHours());
|
||||||
|
}
|
||||||
|
for (Map.Entry<String, String> entry : ((Amenity) mapObject).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.getEditOsmTag())) {
|
||||||
|
entity.putTagNoLC(p.getEditOsmTag(), entry.getValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// check whether this is node (because id of node could be the same as relation)
|
// check whether this is node (because id of node could be the same as relation)
|
||||||
if (entity instanceof Node && MapUtils.getDistance(entity.getLatLon(), n.getLocation()) < 50) {
|
if (entity instanceof Node && MapUtils.getDistance(entity.getLatLon(), mapObject.getLocation()) < 50) {
|
||||||
return entity;
|
return entity;
|
||||||
} else if (entity instanceof Way) {
|
} else if (entity instanceof Way) {
|
||||||
return entity;
|
return entity;
|
||||||
|
|
|
@ -3,9 +3,12 @@ package net.osmand.plus.osmedit;
|
||||||
import android.util.Xml;
|
import android.util.Xml;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import net.osmand.NativeLibrary;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.data.Amenity;
|
import net.osmand.data.Amenity;
|
||||||
|
import net.osmand.data.Building;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
|
import net.osmand.data.MapObject;
|
||||||
import net.osmand.osm.PoiCategory;
|
import net.osmand.osm.PoiCategory;
|
||||||
import net.osmand.osm.PoiType;
|
import net.osmand.osm.PoiType;
|
||||||
import net.osmand.osm.edit.Entity;
|
import net.osmand.osm.edit.Entity;
|
||||||
|
@ -409,9 +412,15 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Entity loadEntity(Amenity n) {
|
public Entity loadEntity(MapObject object) {
|
||||||
boolean isWay = n.getId() % 2 == 1;// check if amenity is a way
|
long objectId = object.getId();
|
||||||
long entityId = n.getId() >> 1;
|
boolean isWay = objectId % 2 == 1;// check if mapObject is a way
|
||||||
|
long entityId;
|
||||||
|
if (object instanceof Amenity) {
|
||||||
|
entityId = objectId >> 1;
|
||||||
|
} else {
|
||||||
|
entityId = objectId >> 7;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
String api = isWay ? "api/0.6/way/" : "api/0.6/node/";
|
String api = isWay ? "api/0.6/way/" : "api/0.6/node/";
|
||||||
String res = sendRequest(getSiteApi() + api + entityId, "GET", null,
|
String res = sendRequest(getSiteApi() + api + entityId, "GET", null,
|
||||||
|
@ -427,14 +436,32 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
|
||||||
if (entity != null) {
|
if (entity != null) {
|
||||||
if (!isWay && entity instanceof Node) {
|
if (!isWay && entity instanceof Node) {
|
||||||
// check whether this is node (because id of node could be the same as relation)
|
// check whether this is node (because id of node could be the same as relation)
|
||||||
if (MapUtils.getDistance(entity.getLatLon(), n.getLocation()) < 50) {
|
if (MapUtils.getDistance(entity.getLatLon(), object.getLocation()) < 50) {
|
||||||
return replaceEditOsmTags(n, entity);
|
if (object instanceof Amenity) {
|
||||||
|
return replaceEditOsmTags((Amenity) object, entity);
|
||||||
|
} else {
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (isWay && entity instanceof Way) {
|
} else if (isWay && entity instanceof Way) {
|
||||||
LatLon loc = n.getLocation();
|
LatLon loc = object.getLocation();
|
||||||
|
if (loc == null) {
|
||||||
|
if (object instanceof NativeLibrary.RenderedObject) {
|
||||||
|
loc = ((NativeLibrary.RenderedObject) object).getLabelLatLon();
|
||||||
|
} else if (object instanceof Building) {
|
||||||
|
loc = ((Building) object).getLatLon2();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (loc == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
entity.setLatitude(loc.getLatitude());
|
entity.setLatitude(loc.getLatitude());
|
||||||
entity.setLongitude(loc.getLongitude());
|
entity.setLongitude(loc.getLongitude());
|
||||||
return replaceEditOsmTags(n, entity);
|
if (object instanceof Amenity) {
|
||||||
|
return replaceEditOsmTags((Amenity) object, entity);
|
||||||
|
} else {
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -2,7 +2,7 @@ package net.osmand.plus.osmedit;
|
||||||
|
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import net.osmand.data.Amenity;
|
import net.osmand.data.MapObject;
|
||||||
import net.osmand.osm.edit.Entity;
|
import net.osmand.osm.edit.Entity;
|
||||||
import net.osmand.osm.edit.EntityInfo;
|
import net.osmand.osm.edit.EntityInfo;
|
||||||
|
|
||||||
|
@ -16,5 +16,5 @@ public interface OpenstreetmapUtil {
|
||||||
|
|
||||||
void closeChangeSet();
|
void closeChangeSet();
|
||||||
|
|
||||||
Entity loadEntity(Amenity n);
|
Entity loadEntity(MapObject mapObject);
|
||||||
}
|
}
|
|
@ -19,6 +19,7 @@ import android.widget.Toast;
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.data.Amenity;
|
import net.osmand.data.Amenity;
|
||||||
|
import net.osmand.data.MapObject;
|
||||||
import net.osmand.data.TransportStop;
|
import net.osmand.data.TransportStop;
|
||||||
import net.osmand.osm.PoiType;
|
import net.osmand.osm.PoiType;
|
||||||
import net.osmand.osm.edit.Entity;
|
import net.osmand.osm.edit.Entity;
|
||||||
|
@ -197,8 +198,11 @@ public class OsmEditingPlugin extends OsmandPlugin {
|
||||||
} else if (resId == R.string.context_menu_item_modify_note) {
|
} else if (resId == R.string.context_menu_item_modify_note) {
|
||||||
modifyOsmNote(mapActivity, (OsmNotesPoint) selectedObj);
|
modifyOsmNote(mapActivity, (OsmNotesPoint) selectedObj);
|
||||||
} else if (resId == R.string.poi_context_menu_modify) {
|
} else if (resId == R.string.poi_context_menu_modify) {
|
||||||
EditPoiDialogFragment.showEditInstance(selectedObj instanceof TransportStop ?
|
if (selectedObj instanceof TransportStop) {
|
||||||
((TransportStop) selectedObj).getAmenity() : (Amenity) selectedObj, mapActivity);
|
EditPoiDialogFragment.showEditInstance(((TransportStop) selectedObj).getAmenity(), mapActivity);
|
||||||
|
} else if (selectedObj instanceof MapObject) {
|
||||||
|
EditPoiDialogFragment.showEditInstance((MapObject) selectedObj, mapActivity);
|
||||||
|
}
|
||||||
} else if (resId == R.string.poi_context_menu_modify_osm_change) {
|
} else if (resId == R.string.poi_context_menu_modify_osm_change) {
|
||||||
final Entity entity = ((OpenstreetmapPoint) selectedObj).getEntity();
|
final Entity entity = ((OpenstreetmapPoint) selectedObj).getEntity();
|
||||||
EditPoiDialogFragment.createInstance(entity, false)
|
EditPoiDialogFragment.createInstance(entity, false)
|
||||||
|
@ -217,6 +221,8 @@ public class OsmEditingPlugin extends OsmandPlugin {
|
||||||
}
|
}
|
||||||
final PoiType poiType = amenity.getType().getPoiTypeByKeyName(amenity.getSubType());
|
final PoiType poiType = amenity.getType().getPoiTypeByKeyName(amenity.getSubType());
|
||||||
isEditable = !amenity.getType().isWiki() && poiType !=null && !poiType.isNotEditableOsm();
|
isEditable = !amenity.getType().isWiki() && poiType !=null && !poiType.isNotEditableOsm();
|
||||||
|
} else if (selectedObj instanceof MapObject) {
|
||||||
|
isEditable = true;
|
||||||
}
|
}
|
||||||
if (isEditable) {
|
if (isEditable) {
|
||||||
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.poi_context_menu_modify, mapActivity)
|
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.poi_context_menu_modify, mapActivity)
|
||||||
|
|
Loading…
Reference in a new issue