Compare commits

...

6 Commits

Author SHA1 Message Date
Ivan
b874f5247e
Merge branch 'master' into issue_2393 2024-08-19 10:51:30 +03:00
ivanPyrohivskyi
7478370835 Refactoring 2024-08-15 21:48:11 +03:00
ivanPyrohivskyi
c3b96726a3 Refactoring 2024-08-15 21:44:58 +03:00
ivanPyrohivskyi
445d386037 Add id and test for demo 2024-08-09 21:07:48 +03:00
ivanPyrohivskyi
8a5cd9417d Fix crash, sort results 2024-08-09 14:48:34 +03:00
ivanPyrohivskyi
a392ec8aeb Show data for polygon 2024-08-08 22:49:00 +03:00
4 changed files with 120 additions and 0 deletions

View File

@ -690,5 +690,34 @@ public class NativeLibrary {
}
return null;
}
@Override
public String toString() {
String s = getClass().getSimpleName() + " " + name;
String link = getLink();
String tags = getPrintTags();
s += s.contains(link) ? "" : link;
s += s.contains(tags) ? "" : tags;
return s;
}
public String getLink() {
String s = "";
if (id != null && id > 0) {
if (x.size() > 1 && String.valueOf(id / 2).length() > 10) {
s += "OSM relation";
} else {
s += "https://osm.org/" + (x.size() > 1 ? "way/" : "node/") + (id / 2);
}
}
return s;
}
public String getPrintTags() {
String s = "";
for (Map.Entry<String, String> entry : tags.entrySet()) {
s += " " + entry.getKey() + ":" + entry.getValue();
}
return s;
}
}
}

View File

@ -13,6 +13,7 @@ import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import net.osmand.NativeLibrary;
import net.osmand.core.jni.ElevationConfiguration;
import net.osmand.core.jni.ElevationConfiguration.SlopeAlgorithm;
import net.osmand.core.jni.ElevationConfiguration.VisualizationStyle;
@ -21,6 +22,8 @@ import net.osmand.core.jni.IGeoTiffCollection.RasterType;
import net.osmand.core.jni.IMapTiledSymbolsProvider;
import net.osmand.core.jni.IObfsCollection;
import net.osmand.core.jni.IRasterMapLayerProvider;
import net.osmand.core.jni.MapObject;
import net.osmand.core.jni.MapObjectList;
import net.osmand.core.jni.MapObjectsSymbolsProvider;
import net.osmand.core.jni.MapPresentationEnvironment;
import net.osmand.core.jni.MapPresentationEnvironment.LanguagePreference;
@ -29,6 +32,7 @@ import net.osmand.core.jni.MapPrimitivesProvider.Mode;
import net.osmand.core.jni.MapPrimitiviser;
import net.osmand.core.jni.MapRasterLayerProvider_Software;
import net.osmand.core.jni.MapStylesCollection;
import net.osmand.core.jni.ObfMapObject;
import net.osmand.core.jni.ObfMapObjectsProvider;
import net.osmand.core.jni.ObfsCollection;
import net.osmand.core.jni.PointI;
@ -36,11 +40,14 @@ import net.osmand.core.jni.QListFloat;
import net.osmand.core.jni.QListPointI;
import net.osmand.core.jni.QStringList;
import net.osmand.core.jni.QStringStringHash;
import net.osmand.core.jni.QVectorPointI;
import net.osmand.core.jni.ResolvedMapStyle;
import net.osmand.core.jni.SqliteHeightmapTileProvider;
import net.osmand.core.jni.SwigUtilities;
import net.osmand.core.jni.ZoomLevel;
import net.osmand.data.LatLon;
import net.osmand.data.QuadRect;
import net.osmand.osm.MapPoiTypes;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.plugins.PluginsHelper;
import net.osmand.plus.plugins.srtm.SRTMPlugin;
@ -59,6 +66,7 @@ import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -660,4 +668,71 @@ public class MapRendererContext {
return vectorLayerEnabled ? MAIN : CONTOUR_LINES;
}
}
public List<NativeLibrary.RenderedObject> getPolygons(PointI point, ZoomLevel zoomLevel, boolean withPoints) {
MapObjectList polygons = mapPrimitivesProvider.retreivePolygons(point, zoomLevel);
List<NativeLibrary.RenderedObject> res = new ArrayList<>();
if (polygons.size() > 0) {
for (int i = 0; i < polygons.size(); i++) {
MapObject polygon = polygons.get(i);
NativeLibrary.RenderedObject renderedObject = convert(polygon, i);
res.add(renderedObject);
}
}
return res;
}
private NativeLibrary.RenderedObject convert(MapObject mapObject, int order) {
NativeLibrary.RenderedObject res = new NativeLibrary.RenderedObject();
QStringStringHash tags = mapObject.getResolvedAttributes();
QStringList tagsKeys = tags.keys();
for (int i = 0; i < tagsKeys.size(); i++) {
String key = tagsKeys.get(i);
String value = tags.get(key);
res.putTag(key, value);
}
String name = mapObject.getCaptionInNativeLanguage();
res.setName(name);
QStringStringHash names = mapObject.getCaptionsInAllLanguages();
QStringList namesKeys = names.keys();
for (int i = 0; i < namesKeys.size(); i++) {
String key = namesKeys.get(i);
String value = names.get(key);
res.setName(key, value);
}
QVectorPointI points31 = mapObject.getPoints31();
QuadRect rect = new QuadRect();
for (int i = 0; i < points31.size(); i++) {
PointI p = points31.get(i);
res.addLocation(p.getX(), p.getY());
rect.expand(p.getX(), p.getY(), p.getX(), p.getY());
}
res.setBbox((int)rect.left, (int)rect.top, (int)rect.right, (int)rect.bottom);
ObfMapObject obfMapObject;
try {
obfMapObject = ObfMapObject.dynamic_pointer_cast(mapObject);
} catch (Exception eObfMapObject) {
obfMapObject = null;
}
if (obfMapObject != null) {
res.setId(obfMapObject.getId().getOsmId());
}
res.setOrder(order);
/*For test only*/
if (res.getName().isEmpty()) {
MapPoiTypes mapPoiTypes = app.getPoiTypes();
for (Map.Entry<String, String> entry : res.getTags().entrySet()) {
String n = mapPoiTypes.getPoiTranslation(entry.getValue());
if (!Algorithms.isEmpty(n) && !n.toLowerCase().equals(entry.getValue())) {
name += n + ", ";
}
}
}
res.setName(name + " " + res.getLink() + " " + res.getPrintTags());
/*---*/
return res;
}
}

View File

@ -2,6 +2,7 @@ package net.osmand.plus.mapcontextmenu.other;
import androidx.annotation.Nullable;
import net.osmand.NativeLibrary;
import net.osmand.OnCompleteCallback;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
@ -29,6 +30,9 @@ public class MenuObject extends MenuTitleController {
this.pointDescription = pointDescription;
this.object = object;
this.mapActivity = mapActivity;
if (object instanceof NativeLibrary.RenderedObject) {
this.order = ((NativeLibrary.RenderedObject) object).getOrder();
}
init();
}

View File

@ -20,10 +20,12 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import net.osmand.IndexConstants;
import net.osmand.NativeLibrary;
import net.osmand.NativeLibrary.RenderedObject;
import net.osmand.PlatformUtil;
import net.osmand.RenderingContext;
import net.osmand.binary.BinaryMapIndexReader;
import net.osmand.core.android.MapRendererContext;
import net.osmand.core.android.MapRendererView;
import net.osmand.core.jni.AmenitySymbolsProvider.AmenitySymbolsGroup;
import net.osmand.core.jni.AreaI;
@ -65,6 +67,7 @@ import net.osmand.plus.settings.backend.preferences.CommonPreference;
import net.osmand.plus.utils.NativeUtilities;
import net.osmand.plus.views.MapLayers;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.corenative.NativeCoreContext;
import net.osmand.plus.views.layers.ContextMenuLayer.IContextMenuProvider;
import net.osmand.plus.views.layers.base.OsmandMapLayer;
import net.osmand.plus.wikivoyage.data.TravelGpx;
@ -278,6 +281,15 @@ public class MapSelectionHelper {
@NonNull PointF point) {
MapRendererView rendererView = view.getMapRenderer();
if (rendererView != null) {
MapRendererContext mapContext = NativeCoreContext.getMapRendererContext();
if (mapContext != null) {
List<NativeLibrary.RenderedObject> res = mapContext.getPolygons(NativeUtilities.get31FromElevatedPixel(rendererView, point.x, point.y), rendererView.getZoomLevel(), false);
for (RenderedObject polygon : res) {
System.out.println(polygon);
System.out.println("------------------------");
result.selectedObjects.put(polygon, mapLayers.getPoiMapLayer());
}
}
int delta = 20;
PointI tl = new PointI((int) point.x - delta, (int) point.y - delta);
PointI br = new PointI((int) point.x + delta, (int) point.y + delta);