kopia lustrzana https://github.com/JOSM/MapWithAI
ESRI branch
rodzic
50556cab86
commit
328f3b96b1
|
@ -3,12 +3,12 @@ package org.openstreetmap.josm.plugins.mapwithai.data.mapwithai;
|
|||
|
||||
import static org.openstreetmap.josm.tools.I18n.marktr;
|
||||
import static org.openstreetmap.josm.tools.I18n.tr;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -17,13 +17,11 @@ import java.util.Map;
|
|||
import java.util.Objects;
|
||||
import java.util.TreeSet;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonArray;
|
||||
import javax.json.JsonObject;
|
||||
import javax.json.stream.JsonParser;
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
import org.openstreetmap.gui.jmapviewer.interfaces.Attributed;
|
||||
import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate;
|
||||
import org.openstreetmap.gui.jmapviewer.tilesources.TileSourceInfo;
|
||||
|
@ -40,6 +38,7 @@ import org.openstreetmap.josm.tools.Logging;
|
|||
import org.openstreetmap.josm.tools.Utils;
|
||||
|
||||
public class MapWithAIInfo extends TileSourceInfo implements Comparable<MapWithAIInfo>, Attributed {
|
||||
|
||||
/**
|
||||
* Type of MapWithAI entry
|
||||
*/
|
||||
|
@ -66,7 +65,8 @@ public class MapWithAIInfo extends TileSourceInfo implements Comparable<MapWithA
|
|||
}
|
||||
}
|
||||
|
||||
public enum MapWithAICategory {
|
||||
public enum MapWithAICategory implements Comparable<MapWithAICategory> {
|
||||
|
||||
BUILDING("data/closedway", "buildings", marktr("Buildings")),
|
||||
HIGHWAY("presets/transport/way/way_road", "highways", marktr("Roads")),
|
||||
ADDRESS("presets/misc/housenumber_small", "addresses", marktr("Addresses")),
|
||||
|
@ -105,16 +105,26 @@ public class MapWithAIInfo extends TileSourceInfo implements Comparable<MapWithA
|
|||
return category;
|
||||
}
|
||||
}
|
||||
// Fuzzy match
|
||||
// fuzzy match
|
||||
if (s != null && !s.trim().isEmpty()) {
|
||||
s = s.toLowerCase();
|
||||
for (MapWithAICategory type : MapWithAICategory.values()) {
|
||||
if (s.contains(type.getCategoryString()) || type.getCategoryString().contains(s)) {
|
||||
if (s.contains(type.getDescription().toLowerCase())
|
||||
|| type.getDescription().toLowerCase().contains(s)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class DescriptionComparator implements Comparator<MapWithAICategory> {
|
||||
|
||||
@Override
|
||||
public int compare(MapWithAICategory o1, MapWithAICategory o2) {
|
||||
return (o1 == null || o2 == null) ? 1 : o1.getDescription().compareTo(o2.getDescription());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -191,6 +201,7 @@ public class MapWithAIInfo extends TileSourceInfo implements Comparable<MapWithA
|
|||
**/
|
||||
|
||||
public static class MapWithAIPreferenceEntry {
|
||||
|
||||
@StructEntry
|
||||
String name;
|
||||
@StructEntry
|
||||
|
@ -313,6 +324,16 @@ public class MapWithAIInfo extends TileSourceInfo implements Comparable<MapWithA
|
|||
}
|
||||
}
|
||||
|
||||
public static class MapWithAIInfoCategoryComparator implements Comparator<MapWithAIInfo> {
|
||||
|
||||
@Override
|
||||
public int compare(MapWithAIInfo o1, MapWithAIInfo o2) {
|
||||
return (Objects.nonNull(o1.getCategory()) || Objects.nonNull(o2.getCategory()) ? 1
|
||||
: Objects.compare(o1.getCategory(), o2.getCategory(),
|
||||
new MapWithAICategory.DescriptionComparator()));
|
||||
}
|
||||
}
|
||||
|
||||
public MapWithAIInfo() {
|
||||
this((String) null);
|
||||
}
|
||||
|
@ -529,6 +550,14 @@ public class MapWithAIInfo extends TileSourceInfo implements Comparable<MapWithA
|
|||
this.bounds = b;
|
||||
}
|
||||
|
||||
public void setCategory(MapWithAICategory category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the imagery polygonial bounds.
|
||||
*
|
||||
|
@ -876,5 +905,4 @@ public class MapWithAIInfo extends TileSourceInfo implements Comparable<MapWithA
|
|||
public void setConflationParameters(JsonArray parameters) {
|
||||
this.conflationParameters = parameters;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
@ -19,15 +20,14 @@ import java.util.TreeSet;
|
|||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonArray;
|
||||
import javax.json.JsonNumber;
|
||||
import javax.json.JsonObject;
|
||||
import javax.json.JsonReader;
|
||||
import javax.json.JsonString;
|
||||
import javax.json.JsonStructure;
|
||||
import javax.json.JsonValue;
|
||||
|
||||
import org.openstreetmap.josm.data.StructUtils;
|
||||
import org.openstreetmap.josm.data.imagery.ImageryInfo;
|
||||
import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryBounds;
|
||||
|
@ -36,6 +36,7 @@ import org.openstreetmap.josm.gui.util.GuiHelper;
|
|||
import org.openstreetmap.josm.io.CachedFile;
|
||||
import org.openstreetmap.josm.io.NetworkManager;
|
||||
import org.openstreetmap.josm.io.imagery.ImageryReader;
|
||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo.MapWithAICategory;
|
||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo.MapWithAIPreferenceEntry;
|
||||
import org.openstreetmap.josm.plugins.mapwithai.io.mapwithai.MapWithAISourceReader;
|
||||
import org.openstreetmap.josm.spi.preferences.Config;
|
||||
|
@ -216,8 +217,9 @@ public class MapWithAILayerInfo {
|
|||
}
|
||||
}
|
||||
defaultLayerIds.clear();
|
||||
Collections.sort(defaultLayers);
|
||||
Collections.sort(allDefaultLayers);
|
||||
|
||||
Collections.sort(defaultLayers, new MapWithAIInfo.MapWithAIInfoCategoryComparator());
|
||||
Collections.sort(allDefaultLayers, new MapWithAIInfo.MapWithAIInfoCategoryComparator());
|
||||
buildIdMap(allDefaultLayers, defaultLayerIds);
|
||||
updateEntriesFromDefaults(!loadError);
|
||||
buildIdMap(layers, layerIds);
|
||||
|
@ -282,8 +284,17 @@ public class MapWithAILayerInfo {
|
|||
newInfo.setAttributionImageURL(url + "content/items/" + newInfo.getId() + "/info/"
|
||||
+ feature.getString("thumbnail"));
|
||||
}
|
||||
// TODO groupCategories
|
||||
// TODO snippet/description
|
||||
// TODO: change this to streams
|
||||
MapWithAICategory category = null;
|
||||
for (JsonString elem : feature.getJsonArray("groupCategories").getValuesAs(JsonString.class)) {
|
||||
category = MapWithAICategory.fromString(elem.getString().replace("/Categories/", ""));
|
||||
if (category != null) {
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
newInfo.setCategory(category);
|
||||
newInfo.setDescription(feature.getString("snippet"));
|
||||
information.add(newInfo);
|
||||
}
|
||||
}
|
||||
|
@ -292,6 +303,16 @@ public class MapWithAILayerInfo {
|
|||
next = "-1";
|
||||
}
|
||||
}
|
||||
Comparator<MapWithAIInfo> comparator = new Comparator<MapWithAIInfo>() {
|
||||
|
||||
@Override
|
||||
public int compare(MapWithAIInfo o1, MapWithAIInfo o2) {
|
||||
return o1.getCategory().getDescription().compareTo(o2.getCategory().getDescription());
|
||||
}
|
||||
};
|
||||
if (information != null) {
|
||||
information = information.stream().sorted(comparator).collect(Collectors.toSet());
|
||||
}
|
||||
return information;
|
||||
}
|
||||
|
||||
|
@ -321,8 +342,8 @@ public class MapWithAILayerInfo {
|
|||
JsonReader reader = Json.createReader(br)) {
|
||||
JsonObject info = reader.readObject();
|
||||
|
||||
return info.getJsonArray("fields").getValuesAs(JsonObject.class).stream().collect(Collectors.toMap(
|
||||
o -> o.getString("name"), o -> o.getBoolean("editable", true) ? o.getString("alias", "") : ""));
|
||||
return info.getJsonArray("fields").getValuesAs(JsonObject.class).stream()
|
||||
.collect(Collectors.toMap(o -> o.getString("name"), o -> o.getString("alias", null)));
|
||||
} catch (IOException e) {
|
||||
Logging.error(e);
|
||||
}
|
||||
|
@ -569,6 +590,7 @@ public class MapWithAILayerInfo {
|
|||
}
|
||||
|
||||
public static interface FinishListener {
|
||||
|
||||
public void onFinish();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,10 +4,8 @@ package org.openstreetmap.josm.plugins.mapwithai.gui.download;
|
|||
import static org.openstreetmap.josm.tools.I18n.tr;
|
||||
|
||||
import java.awt.GridBagLayout;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import org.openstreetmap.josm.data.Bounds;
|
||||
import org.openstreetmap.josm.gui.bbox.JosmMapViewer;
|
||||
import org.openstreetmap.josm.gui.download.DownloadDialog;
|
||||
|
@ -29,7 +27,7 @@ public class MapWithAIDownloadOptions extends JPanel implements DownloadSelectio
|
|||
favorites.add(new JLabel("TODO: Favorites go here!")); // TODO
|
||||
optionPanel.add(favorites, GBC.eol().fill(GBC.HORIZONTAL).anchor(GBC.NORTH));
|
||||
mapwithaiProvidersPanel = new MapWithAIProvidersPanel(this, MapWithAILayerInfo.getInstance());
|
||||
optionPanel.add(mapwithaiProvidersPanel);
|
||||
optionPanel.add(mapwithaiProvidersPanel, GBC.eol().fill(GBC.HORIZONTAL).anchor(GBC.CENTER));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Ładowanie…
Reference in New Issue