Skip to content

Commit

Permalink
If a custom icon is specified include preset icons in search
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpoole committed Oct 7, 2023
1 parent 9e0c117 commit 0d4c0d9
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 14 deletions.
55 changes: 44 additions & 11 deletions src/main/java/de/blau/android/layer/data/MapOverlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,12 @@ public class MapOverlay<O extends OsmElement> extends MapViewLayer
private static final int ICON_SELECTED_BORDER = 2;
private static final int LABEL_EXTRA = 40;

private static final long AUTOPRUNE_MIN_INTERVAL = 10000; // milli-seconds between autoprunes
private static final long AUTOPRUNE_MIN_INTERVAL = 10000; // milli-seconds between
// autoprunes
public static final int DEFAULT_AUTOPRUNE_NODE_LIMIT = 5000;
public static final int PAN_AND_ZOOM_LIMIT = 17;
private static final int MP_SIZE_LIMIT = 1000; // max size of MP to render as MP
private static final int MP_SIZE_LIMIT = 1000; // max size of MP to render as
// MP

/** half the width/height of a node icon in px */
private final int iconRadius;
Expand Down Expand Up @@ -1209,15 +1211,7 @@ private void retrieveIcon(@NonNull OsmElement element, boolean isWay, @NonNull W
boolean usePresetIcon = style.usePresetIcon();

if (iconPath != null && !usePresetIcon) {
iconDrawable = customIconCache.get(iconPath);
if (iconDrawable == null && !customIconCache.containsKey(iconPath)) {
try (FileInputStream stream = new FileInputStream(iconPath)) {
iconDrawable = PresetIconManager.bitmapDrawableFromStream(context, ICON_SIZE_DP, stream, PresetIconManager.isSvg(iconPath));
customIconCache.put(iconPath, iconDrawable);
} catch (IOException e) {
Log.e(DEBUG_TAG, "Icon " + iconPath + " not found");
}
}
iconDrawable = retrieveCustomIcon(iconPath);
} else if (tmpPresets != null) {
SortedMap<String, String> tags = element.getTags();
PresetItem match = null;
Expand Down Expand Up @@ -1246,6 +1240,45 @@ private void retrieveIcon(@NonNull OsmElement element, boolean isWay, @NonNull W
map.postInvalidate();
}

/**
* Get a custom icon
*
* @param iconPath configured icon path
*/
@Nullable
public BitmapDrawable retrieveCustomIcon(String iconPath) {
BitmapDrawable iconDrawable = customIconCache.get(iconPath);
if (iconDrawable != null || customIconCache.containsKey(iconPath)) {
return iconDrawable;
}
String iconDirPath = DataStyle.getCurrent().getIconDirPath();
if (iconDirPath != null) {
try (FileInputStream stream = new FileInputStream(iconPath)) {
iconDrawable = PresetIconManager.bitmapDrawableFromStream(context, ICON_SIZE_DP, stream, PresetIconManager.isSvg(iconPath));
customIconCache.put(iconPath, iconDrawable);
return iconDrawable;
} catch (IOException e) {
Log.w(DEBUG_TAG, "Icon " + iconPath + " not found");
}
}
// search in all presets
for (Preset preset : App.getCurrentPresets(context)) {
if (preset != null) {
PresetIconManager iconManager = preset.getIconManager(context);
iconDrawable = iconManager.getDrawable(iconPath, ICON_SIZE_DP);
if (iconDrawable != null) {
customIconCache.put(iconPath, iconDrawable);
break;
}
}
}
if (iconDrawable == null) {
Log.w(DEBUG_TAG, "Icon " + iconPath + " not found");
customIconCache.put(iconPath, null);
}
return iconDrawable;
}

/**
* Remove everything from the iconCache
*/
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/de/blau/android/presets/Preset.java
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ public Preset(@NonNull List<PresetElement> elements) {
* @return the PresetIconManager instance
*/
@NonNull
PresetIconManager getIconManager(@NonNull Context ctx) {
public PresetIconManager getIconManager(@NonNull Context ctx) {
if (iconManager == null) {
if (directory != null) {
if (directory.getName().equals(AdvancedPrefDatabase.ID_DEFAULT)) {
Expand Down Expand Up @@ -1525,7 +1525,7 @@ public static boolean generateTaginfoJson(@NonNull Context ctx, @NonNull File ou

outputStream.println("\"tags\":[");
Collection<String> discardedKeys = new DiscardedTags(ctx).getKeys();
for (String key:discardedKeys) {
for (String key : discardedKeys) {
outputStream.println("{\"description\":\"Automatically discarded\",\"key\":\"" + key + "\"},");
}
int presetsCount = presets.length;
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/de/blau/android/resources/DataStyle.java
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ private void init() {
fp.getPaint().setStrokeCap(Cap.ROUND);
fp.getPaint().setStrokeJoin(Join.ROUND);
internalStyles.put(GPS_TRACK, fp);

fp = new FeatureStyle(MVT_DEFAULT, baseWayStyle);
fp.setColor(Color.BLUE);
fp.getPaint().setAlpha(0x7F);
Expand Down Expand Up @@ -2000,6 +2000,16 @@ public Path getXPath() {
return xPath;
}

/**
* If a directory is set for custom icons return it
*
* @return the directory path or null
*/
@Nullable
public String getIconDirPath() {
return iconDirPath;
}

/**
* @return the name
*/
Expand Down

0 comments on commit 0d4c0d9

Please sign in to comment.