kopia lustrzana https://github.com/JOSM/MapWithAI
Improve matching for sources from arbitrary data locations
Signed-off-by: Taylor Smock <taylor.smock@kaart.com>pull/1/head v1.3.3
rodzic
cdf42b0a88
commit
7f8b79acb0
|
@ -4,6 +4,9 @@ package org.openstreetmap.josm.plugins.mapwithai.backend;
|
|||
import static org.openstreetmap.josm.tools.I18n.tr;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.openstreetmap.josm.data.Bounds;
|
||||
import org.openstreetmap.josm.data.osm.DataSet;
|
||||
|
@ -37,13 +40,29 @@ public class BoundingBoxMapWithAIDownloader extends BoundingBoxDownloader {
|
|||
@Override
|
||||
protected DataSet parseDataSet(InputStream source, ProgressMonitor progressMonitor) throws IllegalDataException {
|
||||
DataSet ds = OsmReaderCustom.parseDataSet(source, progressMonitor, true);
|
||||
GetDataRunnable.addMapWithAISourceTag(ds, MapWithAIPreferenceHelper.getMapWithAIUrl().stream()
|
||||
.filter(map -> map.getOrDefault("url", "no-url").equals(url))
|
||||
.map(map -> map.getOrDefault("source", MapWithAIPlugin.NAME)).findFirst().orElse(MapWithAIPlugin.NAME));
|
||||
if (url != null) {
|
||||
GetDataRunnable.addMapWithAISourceTag(ds, getSourceTag(url));
|
||||
}
|
||||
GetDataRunnable.cleanup(ds, downloadArea);
|
||||
return ds;
|
||||
}
|
||||
|
||||
private static String getSourceTag(String url) {
|
||||
List<Map<String, String>> possible = MapWithAIPreferenceHelper.getMapWithAIUrl().stream()
|
||||
.filter(map -> url.contains(map.getOrDefault("url", null))).collect(Collectors.toList());
|
||||
Map<String, String> probable = null;
|
||||
long max = 0;
|
||||
for (Map<String, String> check : possible) {
|
||||
List<String> parameters = MapWithAIDataUtils.parseParameters(check.get("parameters"));
|
||||
long count = parameters.parallelStream().filter(url::contains).count();
|
||||
if (count > max || probable == null) {
|
||||
max = count;
|
||||
probable = check;
|
||||
}
|
||||
}
|
||||
return probable == null ? MapWithAIPlugin.NAME : probable.getOrDefault("source", MapWithAIPlugin.NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the download task to be displayed in the
|
||||
* {@link ProgressMonitor}.
|
||||
|
|
|
@ -245,10 +245,7 @@ public final class MapWithAIDataUtils {
|
|||
if (urlInformation.containsKey("url")) {
|
||||
sb.append(urlInformation.get("url"));
|
||||
if (urlInformation.containsKey("parameters")) {
|
||||
List<String> parameters = DataUrl.readJsonStringArraySimple(urlInformation.get("parameters"))
|
||||
.parallelStream().filter(JsonObject.class::isInstance).map(JsonObject.class::cast)
|
||||
.filter(map -> map.getBoolean("enabled", false)).filter(map -> map.containsKey("parameter"))
|
||||
.map(map -> map.getString("parameter")).collect(Collectors.toList());
|
||||
List<String> parameters = parseParameters(urlInformation.get("parameters"));
|
||||
if (!parameters.isEmpty()) {
|
||||
sb.append('&').append(String.join("&", parameters));
|
||||
}
|
||||
|
@ -257,6 +254,19 @@ public final class MapWithAIDataUtils {
|
|||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a parameters string and return relevant parameters
|
||||
*
|
||||
* @param parameters A JSON string of parameters
|
||||
* @return Enabled parameters (list thereof)
|
||||
*/
|
||||
public static List<String> parseParameters(String parameters) {
|
||||
return DataUrl.readJsonStringArraySimple(parameters).parallelStream().filter(JsonObject.class::isInstance)
|
||||
.map(JsonObject.class::cast).filter(map -> map.getBoolean("enabled", false))
|
||||
.filter(map -> map.containsKey("parameter")).map(map -> map.getString("parameter"))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static Bounds bboxToBounds(BBox bbox) {
|
||||
Bounds bound = new Bounds(bbox.getBottomRight());
|
||||
bound.extend(bbox.getTopLeft());
|
||||
|
|
Ładowanie…
Reference in New Issue