Add constants for mapObjects

This commit is contained in:
Chumva 2018-09-06 15:19:39 +03:00
parent 08a4150101
commit df3397eb40
4 changed files with 20 additions and 11 deletions

View file

@ -18,6 +18,11 @@ import net.sf.junidecode.Junidecode;
public abstract class MapObject implements Comparable<MapObject> {
public static final MapObjectComparator BY_NAME_COMPARATOR = new MapObjectComparator();
public static final byte AMENITY_ID_RIGHT_SHIFT = 1;
public static final byte NON_AMENITY_ID_RIGHT_SHIFT = 7;
public static final byte WAY_MODULO_REMAINDER = 1;
protected String name = null;

View file

@ -4,6 +4,7 @@ import android.support.annotation.NonNull;
import net.osmand.NativeLibrary.RenderedObject;
import net.osmand.data.LatLon;
import net.osmand.data.MapObject;
import net.osmand.data.PointDescription;
import net.osmand.osm.AbstractPoiType;
import net.osmand.osm.MapPoiTypes;
@ -115,14 +116,15 @@ public class RenderedObjectMenuController extends MenuController {
boolean osmEditingEnabled = OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class) != null;
if (osmEditingEnabled && renderedObject.getId() != null
&& renderedObject.getId() > 0 &&
(renderedObject.getId() % 2 == 1 || (renderedObject.getId() >> 7) < Integer.MAX_VALUE)) {
(renderedObject.getId() % 2 == MapObject.AMENITY_ID_RIGHT_SHIFT
|| (renderedObject.getId() >> MapObject.NON_AMENITY_ID_RIGHT_SHIFT) < Integer.MAX_VALUE)) {
String link;
if ((renderedObject.getId() >> 6) % 2 == 1) {
if ((renderedObject.getId() >> 6) % 2 == MapObject.WAY_MODULO_REMAINDER) {
link = "https://www.openstreetmap.org/node/";
} else {
link = "https://www.openstreetmap.org/way/";
}
addPlainMenuItem(R.drawable.ic_action_info_dark, null, link + (renderedObject.getId() >> 7), true, true, null);
addPlainMenuItem(R.drawable.ic_action_info_dark, null, link + (renderedObject.getId() >> MapObject.NON_AMENITY_ID_RIGHT_SHIFT), true, true, null);
}
addMyLocationToPlainItems(latLon);
}

View file

@ -83,17 +83,18 @@ public class OpenstreetmapLocalUtil implements OpenstreetmapUtil {
@Override
public Entity loadEntity(MapObject mapObject) {
Long objectId = mapObject.getId();
if (!(objectId != null && objectId > 0 && (objectId % 2 == 1 || (objectId >> 7) < Integer.MAX_VALUE))) {
if (!(objectId != null && objectId > 0 && (objectId % 2 == MapObject.AMENITY_ID_RIGHT_SHIFT
|| (objectId >> MapObject.NON_AMENITY_ID_RIGHT_SHIFT) < Integer.MAX_VALUE))) {
return null;
}
Amenity amenity = null;
long entityId;
boolean isWay = objectId % 2 == 1; // check if mapObject is a way
boolean isWay = objectId % 2 == MapObject.WAY_MODULO_REMAINDER; // check if mapObject is a way
if (mapObject instanceof Amenity) {
amenity = (Amenity) mapObject;
entityId = mapObject.getId() >> 1;
entityId = mapObject.getId() >> MapObject.AMENITY_ID_RIGHT_SHIFT;
} else {
entityId = mapObject.getId() >> 7;
entityId = mapObject.getId() >> MapObject.NON_AMENITY_ID_RIGHT_SHIFT;
}
PoiType poiType = null;
if (amenity != null) {

View file

@ -414,15 +414,16 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
@Override
public Entity loadEntity(MapObject object) {
Long objectId = object.getId();
if (!(objectId != null && objectId > 0 && (objectId % 2 == 1 || (objectId >> 7) < Integer.MAX_VALUE))) {
if (!(objectId != null && objectId > 0 && (objectId % 2 == MapObject.AMENITY_ID_RIGHT_SHIFT
|| (objectId >> MapObject.NON_AMENITY_ID_RIGHT_SHIFT) < Integer.MAX_VALUE))) {
return null;
}
boolean isWay = objectId % 2 == 1;// check if mapObject is a way
boolean isWay = objectId % 2 == MapObject.WAY_MODULO_REMAINDER;// check if mapObject is a way
long entityId;
if (object instanceof Amenity) {
entityId = objectId >> 1;
entityId = objectId >> MapObject.AMENITY_ID_RIGHT_SHIFT;
} else {
entityId = objectId >> 7;
entityId = objectId >> MapObject.NON_AMENITY_ID_RIGHT_SHIFT;
}
try {
String api = isWay ? "api/0.6/way/" : "api/0.6/node/";