kopia lustrzana https://github.com/JOSM/MapWithAI
Split some classes into their own files and fix some sonarlint issues.
Signed-off-by: Taylor Smock <taylor.smock@kaart.com>pull/1/head
rodzic
eac9329a58
commit
cde1e3f60a
|
@ -21,6 +21,7 @@ import org.openstreetmap.josm.io.OsmApiException;
|
||||||
import org.openstreetmap.josm.io.OsmTransferException;
|
import org.openstreetmap.josm.io.OsmTransferException;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.MapWithAIPlugin;
|
import org.openstreetmap.josm.plugins.mapwithai.MapWithAIPlugin;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
|
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
|
||||||
|
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIType;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.io.mapwithai.OsmReaderCustom;
|
import org.openstreetmap.josm.plugins.mapwithai.io.mapwithai.OsmReaderCustom;
|
||||||
import org.openstreetmap.josm.tools.HttpClient;
|
import org.openstreetmap.josm.tools.HttpClient;
|
||||||
|
|
||||||
|
@ -96,7 +97,7 @@ class BoundingBoxMapWithAIDownloader extends BoundingBoxDownloader {
|
||||||
String contentType = this.activeConnection.getResponse().getHeaderField("Content-Type");
|
String contentType = this.activeConnection.getResponse().getHeaderField("Content-Type");
|
||||||
if (contentType.contains("text/xml")) {
|
if (contentType.contains("text/xml")) {
|
||||||
ds = OsmReaderCustom.parseDataSet(source, progressMonitor, true);
|
ds = OsmReaderCustom.parseDataSet(source, progressMonitor, true);
|
||||||
} else if (MapWithAIInfo.MapWithAIType.ESRI_FEATURE_SERVER.equals(this.info.getSourceType())) {
|
} else if (MapWithAIType.ESRI_FEATURE_SERVER == this.info.getSourceType()) {
|
||||||
ds = GeoJSONReader.parseDataSet(source, progressMonitor);
|
ds = GeoJSONReader.parseDataSet(source, progressMonitor);
|
||||||
if (info.getReplacementTags() != null) {
|
if (info.getReplacementTags() != null) {
|
||||||
GetDataRunnable.replaceKeys(ds, info.getReplacementTags());
|
GetDataRunnable.replaceKeys(ds, info.getReplacementTags());
|
||||||
|
|
|
@ -0,0 +1,104 @@
|
||||||
|
// License: GPL. For details, see LICENSE file.
|
||||||
|
package org.openstreetmap.josm.plugins.mapwithai.data.mapwithai;
|
||||||
|
|
||||||
|
import static org.openstreetmap.josm.tools.I18n.marktr;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.EnumMap;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.swing.ImageIcon;
|
||||||
|
|
||||||
|
import org.openstreetmap.josm.data.sources.ISourceCategory;
|
||||||
|
import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets;
|
||||||
|
import org.openstreetmap.josm.tools.ImageProvider;
|
||||||
|
import org.openstreetmap.josm.tools.ImageProvider.ImageSizes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The category for a MapWithAI source
|
||||||
|
*
|
||||||
|
* @author Taylor Smock
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public enum MapWithAICategory implements ISourceCategory<MapWithAICategory> {
|
||||||
|
|
||||||
|
BUILDING("data/closedway", "buildings", marktr("Buildings")),
|
||||||
|
HIGHWAY("presets/transport/way/way_road", "highways", marktr("Roads")),
|
||||||
|
ADDRESS("presets/misc/housenumber_small", "addresses", marktr("Addresses")),
|
||||||
|
POWER("presets/power/pole", "pole", marktr("Power")), PRESET("dialogs/search", "presets", marktr("Presets")),
|
||||||
|
FEATURED("presets/service/network-wireless.svg", "featured", marktr("Featured")),
|
||||||
|
OTHER(null, "other", marktr("Other"));
|
||||||
|
|
||||||
|
private static final Map<ImageSizes, Map<MapWithAICategory, ImageIcon>> iconCache = Collections
|
||||||
|
.synchronizedMap(new EnumMap<>(ImageSizes.class));
|
||||||
|
|
||||||
|
private final String category;
|
||||||
|
private final String description;
|
||||||
|
private final String icon;
|
||||||
|
|
||||||
|
MapWithAICategory(String icon, String category, String description) {
|
||||||
|
this.category = category;
|
||||||
|
this.icon = icon == null || icon.trim().isEmpty() ? "mapwithai" : icon;
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final String getCategoryString() {
|
||||||
|
return category;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final ImageIcon getIcon(ImageSizes size) {
|
||||||
|
return iconCache.computeIfAbsent(size, x -> Collections.synchronizedMap(new EnumMap<>(MapWithAICategory.class)))
|
||||||
|
.computeIfAbsent(this, x -> ImageProvider.get(x.icon, size));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MapWithAICategory fromString(String s) {
|
||||||
|
for (MapWithAICategory category : MapWithAICategory.values()) {
|
||||||
|
if (category.getCategoryString().equals(s)) {
|
||||||
|
return category;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (s != null && !s.trim().isEmpty()) {
|
||||||
|
// fuzzy match
|
||||||
|
String tmp = s.toLowerCase(Locale.ROOT);
|
||||||
|
for (MapWithAICategory type : MapWithAICategory.values()) {
|
||||||
|
if (tmp.contains(type.getDescription().toLowerCase(Locale.ROOT))
|
||||||
|
|| type.getDescription().toLowerCase(Locale.ROOT).contains(tmp)) {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Check if it matches a preset
|
||||||
|
if (TaggingPresets.getPresetKeys().stream().map(String::toLowerCase)
|
||||||
|
.anyMatch(m -> tmp.contains(m) || m.contains(tmp))) {
|
||||||
|
return PRESET;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return OTHER;
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MapWithAICategory getDefault() {
|
||||||
|
return OTHER;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MapWithAICategory getFromString(String s) {
|
||||||
|
return fromString(s);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,16 +1,14 @@
|
||||||
// License: GPL. For details, see LICENSE file.
|
// License: GPL. For details, see LICENSE file.
|
||||||
package org.openstreetmap.josm.plugins.mapwithai.data.mapwithai;
|
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 static org.openstreetmap.josm.tools.I18n.tr;
|
||||||
|
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.EnumMap;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
@ -20,145 +18,20 @@ import javax.json.Json;
|
||||||
import javax.json.JsonArray;
|
import javax.json.JsonArray;
|
||||||
import javax.json.JsonObject;
|
import javax.json.JsonObject;
|
||||||
import javax.json.stream.JsonParser;
|
import javax.json.stream.JsonParser;
|
||||||
import javax.swing.ImageIcon;
|
|
||||||
|
|
||||||
import org.openstreetmap.josm.data.StructUtils.StructEntry;
|
import org.openstreetmap.josm.data.StructUtils.StructEntry;
|
||||||
import org.openstreetmap.josm.data.imagery.ImageryInfo;
|
import org.openstreetmap.josm.data.imagery.ImageryInfo;
|
||||||
import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryBounds;
|
import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryBounds;
|
||||||
import org.openstreetmap.josm.data.imagery.Shape;
|
import org.openstreetmap.josm.data.imagery.Shape;
|
||||||
import org.openstreetmap.josm.data.sources.ISourceCategory;
|
|
||||||
import org.openstreetmap.josm.data.sources.ISourceType;
|
|
||||||
import org.openstreetmap.josm.data.sources.SourceInfo;
|
import org.openstreetmap.josm.data.sources.SourceInfo;
|
||||||
import org.openstreetmap.josm.data.sources.SourcePreferenceEntry;
|
import org.openstreetmap.josm.data.sources.SourcePreferenceEntry;
|
||||||
import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets;
|
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo.MapWithAIPreferenceEntry;
|
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo.MapWithAIPreferenceEntry;
|
||||||
import org.openstreetmap.josm.spi.preferences.Config;
|
import org.openstreetmap.josm.spi.preferences.Config;
|
||||||
import org.openstreetmap.josm.tools.CheckParameterUtil;
|
import org.openstreetmap.josm.tools.CheckParameterUtil;
|
||||||
import org.openstreetmap.josm.tools.ImageProvider;
|
|
||||||
import org.openstreetmap.josm.tools.ImageProvider.ImageSizes;
|
|
||||||
import org.openstreetmap.josm.tools.Logging;
|
import org.openstreetmap.josm.tools.Logging;
|
||||||
|
|
||||||
public class MapWithAIInfo extends
|
public class MapWithAIInfo extends
|
||||||
SourceInfo<MapWithAIInfo.MapWithAICategory, MapWithAIInfo.MapWithAIType, ImageryInfo.ImageryBounds, MapWithAIInfo.MapWithAIPreferenceEntry> {
|
SourceInfo<MapWithAICategory, MapWithAIType, ImageryInfo.ImageryBounds, MapWithAIInfo.MapWithAIPreferenceEntry> {
|
||||||
|
|
||||||
/**
|
|
||||||
* Type of MapWithAI entry
|
|
||||||
*/
|
|
||||||
public enum MapWithAIType implements ISourceType<MapWithAIType> {
|
|
||||||
FACEBOOK("facebook"), THIRD_PARTY("thirdParty"), ESRI("esri"), ESRI_FEATURE_SERVER("esriFeatureServer");
|
|
||||||
|
|
||||||
private final String typeString;
|
|
||||||
|
|
||||||
MapWithAIType(String typeString) {
|
|
||||||
this.typeString = typeString;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getTypeString() {
|
|
||||||
return typeString;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MapWithAIType fromString(String s) {
|
|
||||||
for (MapWithAIType type : MapWithAIType.values()) {
|
|
||||||
if (type.getTypeString().equals(s)) {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MapWithAIType getDefault() {
|
|
||||||
return THIRD_PARTY;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MapWithAIType getFromString(String s) {
|
|
||||||
return fromString(s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum MapWithAICategory implements ISourceCategory<MapWithAICategory> {
|
|
||||||
|
|
||||||
BUILDING("data/closedway", "buildings", marktr("Buildings")),
|
|
||||||
HIGHWAY("presets/transport/way/way_road", "highways", marktr("Roads")),
|
|
||||||
ADDRESS("presets/misc/housenumber_small", "addresses", marktr("Addresses")),
|
|
||||||
POWER("presets/power/pole", "pole", marktr("Power")), PRESET("dialogs/search", "presets", marktr("Presets")),
|
|
||||||
FEATURED("presets/service/network-wireless.svg", "featured", marktr("Featured")),
|
|
||||||
OTHER(null, "other", marktr("Other"));
|
|
||||||
|
|
||||||
private static final Map<ImageSizes, Map<MapWithAICategory, ImageIcon>> iconCache = Collections
|
|
||||||
.synchronizedMap(new EnumMap<>(ImageSizes.class));
|
|
||||||
|
|
||||||
private final String category;
|
|
||||||
private final String description;
|
|
||||||
private final String icon;
|
|
||||||
|
|
||||||
MapWithAICategory(String icon, String category, String description) {
|
|
||||||
this.category = category;
|
|
||||||
this.icon = icon == null || icon.trim().isEmpty() ? "mapwithai" : icon;
|
|
||||||
this.description = description;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final String getCategoryString() {
|
|
||||||
return category;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final String getDescription() {
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final ImageIcon getIcon(ImageSizes size) {
|
|
||||||
return iconCache
|
|
||||||
.computeIfAbsent(size, x -> Collections.synchronizedMap(new EnumMap<>(MapWithAICategory.class)))
|
|
||||||
.computeIfAbsent(this, x -> ImageProvider.get(x.icon, size));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MapWithAICategory fromString(String s) {
|
|
||||||
for (MapWithAICategory category : MapWithAICategory.values()) {
|
|
||||||
if (category.getCategoryString().equals(s)) {
|
|
||||||
return category;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (s != null && !s.trim().isEmpty()) {
|
|
||||||
// fuzzy match
|
|
||||||
String tmp = s.toLowerCase(Locale.ROOT);
|
|
||||||
for (MapWithAICategory type : MapWithAICategory.values()) {
|
|
||||||
if (tmp.contains(type.getDescription().toLowerCase(Locale.ROOT))
|
|
||||||
|| type.getDescription().toLowerCase(Locale.ROOT).contains(tmp)) {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Check if it matches a preset
|
|
||||||
if (TaggingPresets.getPresetKeys().stream().map(String::toLowerCase)
|
|
||||||
.anyMatch(m -> tmp.contains(m) || m.contains(tmp))) {
|
|
||||||
return PRESET;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return OTHER;
|
|
||||||
}
|
|
||||||
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MapWithAICategory getDefault() {
|
|
||||||
return OTHER;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MapWithAICategory getFromString(String s) {
|
|
||||||
return fromString(s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<MapWithAICategory> categories;
|
private List<MapWithAICategory> categories;
|
||||||
private JsonArray parameters;
|
private JsonArray parameters;
|
||||||
|
@ -176,7 +49,6 @@ public class MapWithAIInfo extends
|
||||||
* {@link #MapWithAIInfo(ImageryInfo) MapWithAIInfo constructor}
|
* {@link #MapWithAIInfo(ImageryInfo) MapWithAIInfo constructor}
|
||||||
* {@link #equalsPref(MapWithAIPreferenceEntry) equalsPref method}
|
* {@link #equalsPref(MapWithAIPreferenceEntry) equalsPref method}
|
||||||
**/
|
**/
|
||||||
|
|
||||||
public static class MapWithAIPreferenceEntry extends SourcePreferenceEntry<MapWithAIInfo> {
|
public static class MapWithAIPreferenceEntry extends SourcePreferenceEntry<MapWithAIInfo> {
|
||||||
@StructEntry
|
@StructEntry
|
||||||
String parameters;
|
String parameters;
|
||||||
|
@ -298,7 +170,7 @@ public class MapWithAIInfo extends
|
||||||
setEulaAcceptanceRequired(e.eula);
|
setEulaAcceptanceRequired(e.eula);
|
||||||
if (e.parameters != null) {
|
if (e.parameters != null) {
|
||||||
try (JsonParser parser = Json.createParser(new StringReader(e.parameters))) {
|
try (JsonParser parser = Json.createParser(new StringReader(e.parameters))) {
|
||||||
if (parser.hasNext() && JsonParser.Event.START_ARRAY.equals(parser.next())) {
|
if (parser.hasNext() && JsonParser.Event.START_ARRAY == parser.next()) {
|
||||||
setParameters(parser.getArray());
|
setParameters(parser.getArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -341,7 +213,7 @@ public class MapWithAIInfo extends
|
||||||
setConflationUrl(e.conflationUrl);
|
setConflationUrl(e.conflationUrl);
|
||||||
if (e.conflationParameters != null) {
|
if (e.conflationParameters != null) {
|
||||||
try (JsonParser parser = Json.createParser(new StringReader(e.conflationParameters))) {
|
try (JsonParser parser = Json.createParser(new StringReader(e.conflationParameters))) {
|
||||||
if (parser.hasNext() && JsonParser.Event.START_ARRAY.equals(parser.next())) {
|
if (parser.hasNext() && JsonParser.Event.START_ARRAY == parser.next()) {
|
||||||
setConflationParameters(parser.getArray());
|
setConflationParameters(parser.getArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -411,11 +283,11 @@ public class MapWithAIInfo extends
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setParameters(JsonArray parameters) {
|
public void setParameters(JsonArray parameters) {
|
||||||
this.parameters = parameters;
|
this.parameters = parameters != null ? Json.createArrayBuilder(parameters).build() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JsonArray getParameters() {
|
public JsonArray getParameters() {
|
||||||
return parameters;
|
return parameters != null ? Json.createArrayBuilder(parameters).build() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -472,7 +344,7 @@ public class MapWithAIInfo extends
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
if (url != null && !url.trim().isEmpty()) {
|
if (url != null && !url.trim().isEmpty()) {
|
||||||
sb.append(url);
|
sb.append(url);
|
||||||
if (MapWithAIType.ESRI_FEATURE_SERVER.equals(sourceType)) {
|
if (MapWithAIType.ESRI_FEATURE_SERVER == sourceType) {
|
||||||
if (!url.endsWith("/")) {
|
if (!url.endsWith("/")) {
|
||||||
sb.append('/');
|
sb.append('/');
|
||||||
}
|
}
|
||||||
|
@ -522,7 +394,7 @@ public class MapWithAIInfo extends
|
||||||
* @param parameters Set the conflation parameters
|
* @param parameters Set the conflation parameters
|
||||||
*/
|
*/
|
||||||
public void setConflationParameters(JsonArray parameters) {
|
public void setConflationParameters(JsonArray parameters) {
|
||||||
this.conflationParameters = parameters;
|
this.conflationParameters = parameters != null ? Json.createArrayBuilder(parameters).build() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -531,7 +403,7 @@ public class MapWithAIInfo extends
|
||||||
* @param categories The categories to set
|
* @param categories The categories to set
|
||||||
*/
|
*/
|
||||||
public void setAdditionalCategories(List<MapWithAICategory> categories) {
|
public void setAdditionalCategories(List<MapWithAICategory> categories) {
|
||||||
this.categories = categories;
|
this.categories = categories != null ? new ArrayList<>(categories) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -198,12 +198,8 @@ public class MapWithAILayerInfo {
|
||||||
allDefaultLayers.clear();
|
allDefaultLayers.clear();
|
||||||
defaultLayers.addAll(newLayers);
|
defaultLayers.addAll(newLayers);
|
||||||
for (MapWithAIInfo layer : newLayers) {
|
for (MapWithAIInfo layer : newLayers) {
|
||||||
if (MapWithAIInfo.MapWithAIType.ESRI.equals(layer.getSourceType())) {
|
if (MapWithAIType.ESRI == layer.getSourceType()) {
|
||||||
try (ESRISourceReader reader = new ESRISourceReader(layer)) {
|
allDefaultLayers.addAll(parseEsri(layer));
|
||||||
allDefaultLayers.addAll(reader.parse());
|
|
||||||
} catch (IOException e) {
|
|
||||||
Logging.error(e);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
allDefaultLayers.add(layer);
|
allDefaultLayers.add(layer);
|
||||||
}
|
}
|
||||||
|
@ -222,30 +218,45 @@ public class MapWithAILayerInfo {
|
||||||
listener.onFinish();
|
listener.onFinish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build the mapping of unique ids to {@link ImageryInfo}s.
|
* Parse an Esri layer
|
||||||
*
|
*
|
||||||
* @param lst input list
|
* @param layer The layer to parse
|
||||||
* @param idMap output map
|
* @return The Feature Servers for the ESRI layer
|
||||||
*/
|
*/
|
||||||
private static void buildIdMap(List<MapWithAIInfo> lst, Map<String, MapWithAIInfo> idMap) {
|
private Collection<MapWithAIInfo> parseEsri(MapWithAIInfo layer) {
|
||||||
idMap.clear();
|
try (ESRISourceReader esriReader = new ESRISourceReader(layer)) {
|
||||||
Set<String> notUnique = new HashSet<>();
|
return esriReader.parse();
|
||||||
for (MapWithAIInfo i : lst) {
|
} catch (IOException e) {
|
||||||
if (i.getId() != null) {
|
Logging.error(e);
|
||||||
if (idMap.containsKey(i.getId())) {
|
|
||||||
notUnique.add(i.getId());
|
|
||||||
Logging.error("Id ''{0}'' is not unique - used by ''{1}'' and ''{2}''!", i.getId(), i.getName(),
|
|
||||||
idMap.get(i.getId()).getName());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
idMap.put(i.getId(), i);
|
|
||||||
}
|
}
|
||||||
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
for (String i : notUnique) {
|
|
||||||
idMap.remove(i);
|
/**
|
||||||
|
* Build the mapping of unique ids to {@link ImageryInfo}s.
|
||||||
|
*
|
||||||
|
* @param lst input list
|
||||||
|
* @param idMap output map
|
||||||
|
*/
|
||||||
|
private void buildIdMap(List<MapWithAIInfo> lst, Map<String, MapWithAIInfo> idMap) {
|
||||||
|
idMap.clear();
|
||||||
|
Set<String> notUnique = new HashSet<>();
|
||||||
|
for (MapWithAIInfo i : lst) {
|
||||||
|
if (i.getId() != null) {
|
||||||
|
if (idMap.containsKey(i.getId())) {
|
||||||
|
notUnique.add(i.getId());
|
||||||
|
Logging.error("Id ''{0}'' is not unique - used by ''{1}'' and ''{2}''!", i.getId(), i.getName(),
|
||||||
|
idMap.get(i.getId()).getName());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
idMap.put(i.getId(), i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (String i : notUnique) {
|
||||||
|
idMap.remove(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
// License: GPL. For details, see LICENSE file.
|
||||||
|
package org.openstreetmap.josm.plugins.mapwithai.data.mapwithai;
|
||||||
|
|
||||||
|
import org.openstreetmap.josm.data.sources.ISourceType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type of MapWithAI entry
|
||||||
|
*
|
||||||
|
* @author Taylor Smock
|
||||||
|
*/
|
||||||
|
public enum MapWithAIType implements ISourceType<MapWithAIType> {
|
||||||
|
FACEBOOK("facebook"), THIRD_PARTY("thirdParty"), ESRI("esri"), ESRI_FEATURE_SERVER("esriFeatureServer");
|
||||||
|
|
||||||
|
private final String typeString;
|
||||||
|
|
||||||
|
MapWithAIType(String typeString) {
|
||||||
|
this.typeString = typeString;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTypeString() {
|
||||||
|
return typeString;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MapWithAIType fromString(String s) {
|
||||||
|
for (MapWithAIType type : MapWithAIType.values()) {
|
||||||
|
if (type.getTypeString().equals(s)) {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MapWithAIType getDefault() {
|
||||||
|
return THIRD_PARTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MapWithAIType getFromString(String s) {
|
||||||
|
return fromString(s);
|
||||||
|
}
|
||||||
|
}
|
|
@ -106,7 +106,7 @@ public class RoutingIslandsTest extends Test {
|
||||||
.message(tr("MapWithAI (experimental)"), marktr("Routable way not connected to other ways"))
|
.message(tr("MapWithAI (experimental)"), marktr("Routable way not connected to other ways"))
|
||||||
.build());
|
.build());
|
||||||
} else if ((ValidatorPrefHelper.PREF_OTHER.get() || ValidatorPrefHelper.PREF_OTHER_UPLOAD.get()
|
} else if ((ValidatorPrefHelper.PREF_OTHER.get() || ValidatorPrefHelper.PREF_OTHER_UPLOAD.get()
|
||||||
|| !Severity.OTHER.equals(SEVERITY_MAP.get(ROUTING_ISLAND))) && !isBeforeUpload) {
|
|| Severity.OTHER != SEVERITY_MAP.get(ROUTING_ISLAND)) && !isBeforeUpload) {
|
||||||
if (way.hasKey(HIGHWAY) && !IGNORE_TAGS_HIGHWAY.contains(way.get(HIGHWAY))) {
|
if (way.hasKey(HIGHWAY) && !IGNORE_TAGS_HIGHWAY.contains(way.get(HIGHWAY))) {
|
||||||
potentialHighways.add(way);
|
potentialHighways.add(way);
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ import org.openstreetmap.josm.gui.preferences.imagery.HeadersTable;
|
||||||
import org.openstreetmap.josm.gui.widgets.JosmTextArea;
|
import org.openstreetmap.josm.gui.widgets.JosmTextArea;
|
||||||
import org.openstreetmap.josm.gui.widgets.JosmTextField;
|
import org.openstreetmap.josm.gui.widgets.JosmTextField;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
|
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo.MapWithAIType;
|
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIType;
|
||||||
import org.openstreetmap.josm.tools.GBC;
|
import org.openstreetmap.josm.tools.GBC;
|
||||||
import org.openstreetmap.josm.tools.Logging;
|
import org.openstreetmap.josm.tools.Logging;
|
||||||
import org.openstreetmap.josm.tools.Pair;
|
import org.openstreetmap.josm.tools.Pair;
|
||||||
|
@ -59,10 +59,10 @@ class AddMapWithAIPanel extends JPanel {
|
||||||
private JSpinner minimumCacheExpiry;
|
private JSpinner minimumCacheExpiry;
|
||||||
private JComboBox<String> minimumCacheExpiryUnit;
|
private JComboBox<String> minimumCacheExpiryUnit;
|
||||||
private TimeUnit currentUnit;
|
private TimeUnit currentUnit;
|
||||||
private MapWithAIInfo.MapWithAIType type;
|
private MapWithAIType type;
|
||||||
|
|
||||||
private MapWithAIInfo info;
|
private MapWithAIInfo info;
|
||||||
private JComboBox<MapWithAIInfo.MapWithAIType> typeBox;
|
private JComboBox<MapWithAIType> typeBox;
|
||||||
|
|
||||||
protected AddMapWithAIPanel(LayoutManager layout) {
|
protected AddMapWithAIPanel(LayoutManager layout) {
|
||||||
super(layout);
|
super(layout);
|
||||||
|
@ -120,8 +120,8 @@ class AddMapWithAIPanel extends JPanel {
|
||||||
add(new JLabel(tr("{0} Enter name for this source", "3.")), GBC.eol());
|
add(new JLabel(tr("{0} Enter name for this source", "3.")), GBC.eol());
|
||||||
add(name, GBC.eol().fill(GBC.HORIZONTAL));
|
add(name, GBC.eol().fill(GBC.HORIZONTAL));
|
||||||
add(new JLabel(tr("{0} What is the type of this source?", "4.")), GBC.eol());
|
add(new JLabel(tr("{0} What is the type of this source?", "4.")), GBC.eol());
|
||||||
typeBox = new JComboBox<>(MapWithAIInfo.MapWithAIType.values());
|
typeBox = new JComboBox<>(MapWithAIType.values());
|
||||||
typeBox.setSelectedItem(MapWithAIInfo.MapWithAIType.THIRD_PARTY);
|
typeBox.setSelectedItem(MapWithAIType.THIRD_PARTY);
|
||||||
typeBox.addItemListener(l -> {
|
typeBox.addItemListener(l -> {
|
||||||
type = (MapWithAIType) typeBox.getSelectedItem();
|
type = (MapWithAIType) typeBox.getSelectedItem();
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
|
|
@ -14,8 +14,8 @@ import java.util.stream.Stream;
|
||||||
|
|
||||||
import javax.swing.table.DefaultTableModel;
|
import javax.swing.table.DefaultTableModel;
|
||||||
|
|
||||||
|
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAICategory;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
|
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo.MapWithAICategory;
|
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAILayerInfo;
|
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAILayerInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -58,9 +58,10 @@ import org.openstreetmap.josm.gui.preferences.imagery.ImageryProvidersPanel;
|
||||||
import org.openstreetmap.josm.gui.util.GuiHelper;
|
import org.openstreetmap.josm.gui.util.GuiHelper;
|
||||||
import org.openstreetmap.josm.gui.widgets.FilterField;
|
import org.openstreetmap.josm.gui.widgets.FilterField;
|
||||||
import org.openstreetmap.josm.gui.widgets.HtmlPanel;
|
import org.openstreetmap.josm.gui.widgets.HtmlPanel;
|
||||||
|
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAICategory;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
|
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo.MapWithAICategory;
|
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAILayerInfo;
|
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAILayerInfo;
|
||||||
|
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIType;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.io.mapwithai.ESRISourceReader;
|
import org.openstreetmap.josm.plugins.mapwithai.io.mapwithai.ESRISourceReader;
|
||||||
import org.openstreetmap.josm.tools.GBC;
|
import org.openstreetmap.josm.tools.GBC;
|
||||||
import org.openstreetmap.josm.tools.ImageProvider;
|
import org.openstreetmap.josm.tools.ImageProvider;
|
||||||
|
@ -392,7 +393,7 @@ public class MapWithAIProvidersPanel extends JPanel {
|
||||||
activeToolbar.setFloatable(false);
|
activeToolbar.setFloatable(false);
|
||||||
activeToolbar.setBorderPainted(false);
|
activeToolbar.setBorderPainted(false);
|
||||||
activeToolbar.setOpaque(false);
|
activeToolbar.setOpaque(false);
|
||||||
activeToolbar.add(new NewEntryAction(MapWithAIInfo.MapWithAIType.THIRD_PARTY));
|
activeToolbar.add(new NewEntryAction(MapWithAIType.THIRD_PARTY));
|
||||||
activeToolbar.add(edit);
|
activeToolbar.add(edit);
|
||||||
activeToolbar.add(remove);
|
activeToolbar.add(remove);
|
||||||
if (showActive) {
|
if (showActive) {
|
||||||
|
@ -556,7 +557,7 @@ public class MapWithAIProvidersPanel extends JPanel {
|
||||||
private class NewEntryAction extends AbstractAction {
|
private class NewEntryAction extends AbstractAction {
|
||||||
private static final long serialVersionUID = 7451336680150337942L;
|
private static final long serialVersionUID = 7451336680150337942L;
|
||||||
|
|
||||||
NewEntryAction(MapWithAIInfo.MapWithAIType type) {
|
NewEntryAction(MapWithAIType type) {
|
||||||
putValue(NAME, type.toString());
|
putValue(NAME, type.toString());
|
||||||
putValue(SHORT_DESCRIPTION, tr("Add a new {0} entry by entering the URL", type.toString()));
|
putValue(SHORT_DESCRIPTION, tr("Add a new {0} entry by entering the URL", type.toString()));
|
||||||
String icon = /* ICON(dialogs/) */ "add";
|
String icon = /* ICON(dialogs/) */ "add";
|
||||||
|
@ -572,7 +573,7 @@ public class MapWithAIProvidersPanel extends JPanel {
|
||||||
if (addDialog.getValue() == 1) {
|
if (addDialog.getValue() == 1) {
|
||||||
try {
|
try {
|
||||||
MapWithAIInfo info = p.getSourceInfo();
|
MapWithAIInfo info = p.getSourceInfo();
|
||||||
if (MapWithAIInfo.MapWithAIType.ESRI == info.getSourceType()) {
|
if (MapWithAIType.ESRI == info.getSourceType()) {
|
||||||
try (ESRISourceReader reader = new ESRISourceReader(info)) {
|
try (ESRISourceReader reader = new ESRISourceReader(info)) {
|
||||||
for (MapWithAIInfo i : reader.parse()) {
|
for (MapWithAIInfo i : reader.parse()) {
|
||||||
activeModel.addRow(i);
|
activeModel.addRow(i);
|
||||||
|
|
|
@ -24,8 +24,9 @@ import javax.json.JsonValue;
|
||||||
|
|
||||||
import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryBounds;
|
import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryBounds;
|
||||||
import org.openstreetmap.josm.io.CachedFile;
|
import org.openstreetmap.josm.io.CachedFile;
|
||||||
|
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAICategory;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
|
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo.MapWithAICategory;
|
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIType;
|
||||||
import org.openstreetmap.josm.tools.HttpClient;
|
import org.openstreetmap.josm.tools.HttpClient;
|
||||||
import org.openstreetmap.josm.tools.Logging;
|
import org.openstreetmap.josm.tools.Logging;
|
||||||
import org.openstreetmap.josm.tools.Utils;
|
import org.openstreetmap.josm.tools.Utils;
|
||||||
|
@ -86,7 +87,7 @@ public class ESRISourceReader implements Closeable {
|
||||||
JsonReader reader = Json.createReader(i)) {
|
JsonReader reader = Json.createReader(i)) {
|
||||||
layers.setFastFail(fastFail);
|
layers.setFastFail(fastFail);
|
||||||
JsonStructure parser = reader.read();
|
JsonStructure parser = reader.read();
|
||||||
if (parser.getValueType().equals(JsonValue.ValueType.OBJECT)) {
|
if (parser.getValueType() == JsonValue.ValueType.OBJECT) {
|
||||||
JsonObject obj = parser.asJsonObject();
|
JsonObject obj = parser.asJsonObject();
|
||||||
next = obj.getString("nextStart", "-1");
|
next = obj.getString("nextStart", "-1");
|
||||||
searchUrl = startReplace.matcher(search).replaceAll(next);
|
searchUrl = startReplace.matcher(search).replaceAll(next);
|
||||||
|
@ -124,7 +125,7 @@ public class ESRISourceReader implements Closeable {
|
||||||
ImageryBounds imageryBounds = new ImageryBounds(String.join(",", extent[1], extent[0], extent[3], extent[2]),
|
ImageryBounds imageryBounds = new ImageryBounds(String.join(",", extent[1], extent[0], extent[3], extent[2]),
|
||||||
",");
|
",");
|
||||||
newInfo.setBounds(imageryBounds);
|
newInfo.setBounds(imageryBounds);
|
||||||
newInfo.setSourceType(MapWithAIInfo.MapWithAIType.ESRI_FEATURE_SERVER);
|
newInfo.setSourceType(MapWithAIType.ESRI_FEATURE_SERVER);
|
||||||
newInfo.setTermsOfUseText(feature.getString("licenseInfo", null));
|
newInfo.setTermsOfUseText(feature.getString("licenseInfo", null));
|
||||||
if (feature.containsKey("thumbnail")) {
|
if (feature.containsKey("thumbnail")) {
|
||||||
newInfo.setAttributionImageURL(
|
newInfo.setAttributionImageURL(
|
||||||
|
@ -135,8 +136,8 @@ public class ESRISourceReader implements Closeable {
|
||||||
.stream().map(JsonString::getString).map(s -> s.replace("/Categories/", ""))
|
.stream().map(JsonString::getString).map(s -> s.replace("/Categories/", ""))
|
||||||
.map(MapWithAICategory::fromString).filter(Objects::nonNull)
|
.map(MapWithAICategory::fromString).filter(Objects::nonNull)
|
||||||
.collect(Collectors.toCollection(ArrayList::new));
|
.collect(Collectors.toCollection(ArrayList::new));
|
||||||
MapWithAICategory category = categories.stream().filter(c -> !MapWithAICategory.FEATURED.equals(c))
|
MapWithAICategory category = categories.stream().filter(c -> MapWithAICategory.FEATURED != c).findFirst()
|
||||||
.findFirst().orElse(MapWithAICategory.OTHER);
|
.orElse(MapWithAICategory.OTHER);
|
||||||
newInfo.setCategory(category);
|
newInfo.setCategory(category);
|
||||||
categories.remove(category);
|
categories.remove(category);
|
||||||
newInfo.setAdditionalCategories(categories);
|
newInfo.setAdditionalCategories(categories);
|
||||||
|
|
|
@ -28,6 +28,7 @@ import org.openstreetmap.josm.data.imagery.Shape;
|
||||||
import org.openstreetmap.josm.data.osm.BBox;
|
import org.openstreetmap.josm.data.osm.BBox;
|
||||||
import org.openstreetmap.josm.io.CachedFile;
|
import org.openstreetmap.josm.io.CachedFile;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
|
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
|
||||||
|
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIType;
|
||||||
import org.openstreetmap.josm.tools.DefaultGeoProperty;
|
import org.openstreetmap.josm.tools.DefaultGeoProperty;
|
||||||
import org.openstreetmap.josm.tools.GeoPropertyIndex;
|
import org.openstreetmap.josm.tools.GeoPropertyIndex;
|
||||||
import org.openstreetmap.josm.tools.HttpClient;
|
import org.openstreetmap.josm.tools.HttpClient;
|
||||||
|
@ -49,6 +50,9 @@ public class MapWithAISourceReader implements Closeable {
|
||||||
private CachedFile cachedFile;
|
private CachedFile cachedFile;
|
||||||
private boolean fastFail;
|
private boolean fastFail;
|
||||||
|
|
||||||
|
private static final int MIN_NODE_FOR_CLOSED_WAY = 2;
|
||||||
|
private static final int COORD_ARRAY_SIZE = 6;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a {@code ImageryReader} from a given filename, URL or internal
|
* Constructs a {@code ImageryReader} from a given filename, URL or internal
|
||||||
* resource.
|
* resource.
|
||||||
|
@ -93,7 +97,7 @@ public class MapWithAISourceReader implements Closeable {
|
||||||
try (JsonReader reader = Json.createReader(cachedFile.setMaxAge(CachedFile.DAYS)
|
try (JsonReader reader = Json.createReader(cachedFile.setMaxAge(CachedFile.DAYS)
|
||||||
.setCachingStrategy(CachedFile.CachingStrategy.IfModifiedSince).getContentReader())) {
|
.setCachingStrategy(CachedFile.CachingStrategy.IfModifiedSince).getContentReader())) {
|
||||||
JsonStructure struct = reader.read();
|
JsonStructure struct = reader.read();
|
||||||
if (JsonValue.ValueType.OBJECT.equals(struct.getValueType())) {
|
if (JsonValue.ValueType.OBJECT == struct.getValueType()) {
|
||||||
JsonObject jsonObject = struct.asJsonObject();
|
JsonObject jsonObject = struct.asJsonObject();
|
||||||
entries = parseJson(jsonObject);
|
entries = parseJson(jsonObject);
|
||||||
}
|
}
|
||||||
|
@ -103,17 +107,17 @@ public class MapWithAISourceReader implements Closeable {
|
||||||
|
|
||||||
private static MapWithAIInfo parse(Map.Entry<String, JsonValue> entry) {
|
private static MapWithAIInfo parse(Map.Entry<String, JsonValue> entry) {
|
||||||
String name = entry.getKey();
|
String name = entry.getKey();
|
||||||
if (JsonValue.ValueType.OBJECT.equals(entry.getValue().getValueType())) {
|
if (JsonValue.ValueType.OBJECT == entry.getValue().getValueType()) {
|
||||||
JsonObject values = entry.getValue().asJsonObject();
|
JsonObject values = entry.getValue().asJsonObject();
|
||||||
String url = values.getString("url", "");
|
String url = values.getString("url", "");
|
||||||
String type = values.getString("type", MapWithAIInfo.MapWithAIType.THIRD_PARTY.getTypeString());
|
String type = values.getString("type", MapWithAIType.THIRD_PARTY.getTypeString());
|
||||||
String eula = values.getString("eula", "");
|
String eula = values.getString("eula", "");
|
||||||
boolean conflation = values.getBoolean("conflate", false);
|
boolean conflation = values.getBoolean("conflate", false);
|
||||||
String conflationUrl = values.getString("conflationUrl", null);
|
String conflationUrl = values.getString("conflationUrl", null);
|
||||||
String id = values.getString("id", name.replace(" ", "_"));
|
String id = values.getString("id", name.replace(" ", "_"));
|
||||||
JsonValue countries = values.getOrDefault("countries", JsonValue.EMPTY_JSON_OBJECT);
|
JsonValue countries = values.getOrDefault("countries", JsonValue.EMPTY_JSON_OBJECT);
|
||||||
List<ImageryBounds> bounds = new ArrayList<>();
|
List<ImageryBounds> bounds = new ArrayList<>();
|
||||||
if (JsonValue.ValueType.OBJECT.equals(countries.getValueType())) {
|
if (JsonValue.ValueType.OBJECT == countries.getValueType()) {
|
||||||
Set<String> codes = Territories.getKnownIso3166Codes();
|
Set<String> codes = Territories.getKnownIso3166Codes();
|
||||||
for (Map.Entry<String, JsonValue> country : countries.asJsonObject().entrySet()) {
|
for (Map.Entry<String, JsonValue> country : countries.asJsonObject().entrySet()) {
|
||||||
if (codes.contains(country.getKey())) {
|
if (codes.contains(country.getKey())) {
|
||||||
|
@ -159,14 +163,14 @@ public class MapWithAISourceReader implements Closeable {
|
||||||
Collection<Shape> shapes = new ArrayList<>();
|
Collection<Shape> shapes = new ArrayList<>();
|
||||||
float[] moveTo = null;
|
float[] moveTo = null;
|
||||||
while (!iterator.isDone()) {
|
while (!iterator.isDone()) {
|
||||||
float[] coords = new float[6];
|
float[] coords = new float[COORD_ARRAY_SIZE];
|
||||||
int type = iterator.currentSegment(coords);
|
int type = iterator.currentSegment(coords);
|
||||||
if (type == PathIterator.SEG_MOVETO || type == PathIterator.SEG_LINETO) {
|
if (type == PathIterator.SEG_MOVETO || type == PathIterator.SEG_LINETO) {
|
||||||
if (type == PathIterator.SEG_MOVETO) {
|
if (type == PathIterator.SEG_MOVETO) {
|
||||||
moveTo = coords;
|
moveTo = coords;
|
||||||
}
|
}
|
||||||
defaultShape.addPoint(Float.toString(coords[1]), Float.toString(coords[0]));
|
defaultShape.addPoint(Float.toString(coords[1]), Float.toString(coords[0]));
|
||||||
} else if (type == PathIterator.SEG_CLOSE && moveTo != null && moveTo.length >= 2) {
|
} else if (type == PathIterator.SEG_CLOSE && moveTo != null && moveTo.length >= MIN_NODE_FOR_CLOSED_WAY) {
|
||||||
defaultShape.addPoint(Float.toString(moveTo[1]), Float.toString(moveTo[0]));
|
defaultShape.addPoint(Float.toString(moveTo[1]), Float.toString(moveTo[0]));
|
||||||
shapes.add(defaultShape);
|
shapes.add(defaultShape);
|
||||||
defaultShape = new Shape();
|
defaultShape = new Shape();
|
||||||
|
|
|
@ -13,7 +13,7 @@ import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.backend.DataAvailability;
|
import org.openstreetmap.josm.plugins.mapwithai.backend.DataAvailability;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
|
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo.MapWithAIType;
|
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIType;
|
||||||
import org.openstreetmap.josm.testutils.JOSMTestRules;
|
import org.openstreetmap.josm.testutils.JOSMTestRules;
|
||||||
|
|
||||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||||
|
@ -27,7 +27,7 @@ public class MapWithAISourceReaderTestIT {
|
||||||
public void testDefaultSourceIT() throws IOException {
|
public void testDefaultSourceIT() throws IOException {
|
||||||
try (MapWithAISourceReader source = new MapWithAISourceReader(DataAvailability.getReleaseUrl())) {
|
try (MapWithAISourceReader source = new MapWithAISourceReader(DataAvailability.getReleaseUrl())) {
|
||||||
List<MapWithAIInfo> infoList = source.parse();
|
List<MapWithAIInfo> infoList = source.parse();
|
||||||
assertFalse(infoList.isEmpty());
|
assertFalse(infoList.isEmpty(), "There should be viable sources");
|
||||||
for (MapWithAIType type : Arrays.asList(MapWithAIType.FACEBOOK, MapWithAIType.THIRD_PARTY)) {
|
for (MapWithAIType type : Arrays.asList(MapWithAIType.FACEBOOK, MapWithAIType.THIRD_PARTY)) {
|
||||||
assertTrue(infoList.stream().filter(i -> type.equals(i.getSourceType())).count() > 0,
|
assertTrue(infoList.stream().filter(i -> type.equals(i.getSourceType())).count() > 0,
|
||||||
tr("Type {0} should have more than 0 sources", type.getTypeString()));
|
tr("Type {0} should have more than 0 sources", type.getTypeString()));
|
||||||
|
|
|
@ -13,8 +13,7 @@ public class MapWithAIInfoTest {
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("provideMapWithAIInfoInitializers")
|
@MethodSource("provideMapWithAIInfoInitializers")
|
||||||
public void assertInitializersWorked(MapWithAIInfo i, String name, String url, String id,
|
public void assertInitializersWorked(MapWithAIInfo i, String name, String url, String id, MapWithAIType type) {
|
||||||
MapWithAIInfo.MapWithAIType type) {
|
|
||||||
assertEquals(name, i.getName());
|
assertEquals(name, i.getName());
|
||||||
assertEquals(id, i.getId());
|
assertEquals(id, i.getId());
|
||||||
assertEquals(url, i.getUrl());
|
assertEquals(url, i.getUrl());
|
||||||
|
@ -31,8 +30,8 @@ public class MapWithAIInfoTest {
|
||||||
String url = "https://test.url";
|
String url = "https://test.url";
|
||||||
String id = "a;lkdjfadl;ksfj";
|
String id = "a;lkdjfadl;ksfj";
|
||||||
String eula = "";
|
String eula = "";
|
||||||
MapWithAIInfo.MapWithAIType type = MapWithAIInfo.MapWithAIType.FACEBOOK;
|
MapWithAIType type = MapWithAIType.FACEBOOK;
|
||||||
MapWithAIInfo.MapWithAIType defaultType = MapWithAIInfo.MapWithAIType.THIRD_PARTY;
|
MapWithAIType defaultType = MapWithAIType.THIRD_PARTY;
|
||||||
MapWithAIInfo tempInfo = new MapWithAIInfo(name, url, id);
|
MapWithAIInfo tempInfo = new MapWithAIInfo(name, url, id);
|
||||||
return Stream.of(Arguments.of(new MapWithAIInfo(), null, null, null, defaultType),
|
return Stream.of(Arguments.of(new MapWithAIInfo(), null, null, null, defaultType),
|
||||||
Arguments.of(new MapWithAIInfo(name), name, null, null, defaultType),
|
Arguments.of(new MapWithAIInfo(name), name, null, null, defaultType),
|
||||||
|
|
|
@ -11,13 +11,19 @@ import java.util.Collection;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
|
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo.MapWithAIType;
|
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIType;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.testutils.MapWithAITestRules;
|
import org.openstreetmap.josm.plugins.mapwithai.testutils.MapWithAITestRules;
|
||||||
|
|
||||||
public class ESRISourceReaderTest {
|
public class ESRISourceReaderTest {
|
||||||
@Rule
|
@Rule
|
||||||
public MapWithAITestRules rule = (MapWithAITestRules) new MapWithAITestRules().wiremock().projection();
|
public MapWithAITestRules rule = (MapWithAITestRules) new MapWithAITestRules().wiremock().projection();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that ESRI servers are properly added
|
||||||
|
*
|
||||||
|
* @throws IOException If there is an issue with reading the network
|
||||||
|
* file/wiremocked file
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testAddEsriLayer() throws IOException {
|
public void testAddEsriLayer() throws IOException {
|
||||||
// TODO wiremock
|
// TODO wiremock
|
||||||
|
@ -28,9 +34,11 @@ public class ESRISourceReaderTest {
|
||||||
info.setUrl(url);
|
info.setUrl(url);
|
||||||
try (ESRISourceReader reader = new ESRISourceReader(info)) {
|
try (ESRISourceReader reader = new ESRISourceReader(info)) {
|
||||||
Collection<MapWithAIInfo> layers = reader.parse();
|
Collection<MapWithAIInfo> layers = reader.parse();
|
||||||
assertFalse(layers.isEmpty());
|
assertFalse(layers.isEmpty(), "There should be a MapWithAI layer");
|
||||||
assertTrue(layers.stream().noneMatch(i -> info.getUrl().equals(i.getUrl())));
|
assertTrue(layers.stream().noneMatch(i -> info.getUrl().equals(i.getUrl())),
|
||||||
assertTrue(layers.stream().allMatch(i -> MapWithAIType.ESRI_FEATURE_SERVER.equals(i.getSourceType())));
|
"The ESRI server should be expanded to feature servers");
|
||||||
|
assertTrue(layers.stream().allMatch(i -> MapWithAIType.ESRI_FEATURE_SERVER.equals(i.getSourceType())),
|
||||||
|
"There should only be ESRI feature servers");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue