Ignore:
Timestamp:
2020-06-09T23:44:55+02:00 (4 years ago)
Author:
simon04
Message:

fix #19364 - Remote control /imagery: support all imagery options

Location:
trunk/src/org/openstreetmap/josm/io/remotecontrol
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/RemoteControl.java

    r16324 r16589  
    3232     */
    3333    static final int protocolMajorVersion = 1;
    34     static final int protocolMinorVersion = 9;
     34    static final int protocolMinorVersion = 10;
    3535
    3636    /**
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/ImageryHandler.java

    r16436 r16589  
    66import java.util.Arrays;
    77
     8import org.openstreetmap.josm.data.StructUtils;
    89import org.openstreetmap.josm.data.imagery.ImageryInfo;
     10import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryPreferenceEntry;
    911import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;
    10 import org.openstreetmap.josm.data.imagery.ImageryLayerInfo;
    1112import org.openstreetmap.josm.gui.MainApplication;
    1213import org.openstreetmap.josm.gui.layer.ImageryLayer;
    1314import org.openstreetmap.josm.gui.util.GuiHelper;
    1415import org.openstreetmap.josm.io.remotecontrol.PermissionPrefWithDefault;
     16import org.openstreetmap.josm.tools.CheckParameterUtil;
    1517import org.openstreetmap.josm.tools.Logging;
    1618import org.openstreetmap.josm.tools.Utils;
     
    4042    @Override
    4143    public String[] getOptionalParams() {
    42         return new String[] {"title", "type", "cookies", "min_zoom", "max_zoom"};
     44        return StructUtils.serializeStruct(new ImageryPreferenceEntry(), ImageryPreferenceEntry.class,
     45                StructUtils.SerializeOptions.INCLUDE_NULL, StructUtils.SerializeOptions.INCLUDE_DEFAULT
     46        ).keySet().toArray(new String[0]);
    4347    }
    4448
     
    4852    }
    4953
    50     protected static ImageryInfo findBingEntry() {
    51         return ImageryLayerInfo.instance.getDefaultLayers().stream()
    52                 .filter(i -> ImageryType.BING == i.getImageryType())
    53                 .findFirst().orElse(null);
    54     }
    55 
    5654    protected ImageryInfo buildImageryInfo() {
    57         String url = args.get("url");
    58         String title = args.get("title");
    59         String type = args.get("type");
    60         final ImageryInfo bing = ImageryType.BING.getTypeString().equals(type) ? findBingEntry() : null;
    61         if ((title == null || title.isEmpty()) && bing != null) {
    62             title = bing.getName();
    63         }
    64         if (title == null || title.isEmpty()) {
    65             title = tr("Remote imagery");
    66         }
    67         String cookies = args.get("cookies");
    68         final ImageryInfo imgInfo = new ImageryInfo(title, url, type, null, cookies);
    69         if (bing != null) {
    70             imgInfo.setIcon(bing.getIcon());
    71         }
    72         String minZoom = args.get("min_zoom");
    73         if (minZoom != null && !minZoom.isEmpty()) {
    74             try {
    75                 imgInfo.setDefaultMinZoom(Integer.parseInt(minZoom));
    76             } catch (NumberFormatException e) {
    77                 Logging.error(e);
    78             }
    79         }
    80         String maxZoom = args.get("max_zoom");
    81         if (maxZoom != null && !maxZoom.isEmpty()) {
    82             try {
    83                 imgInfo.setDefaultMaxZoom(Integer.parseInt(maxZoom));
    84             } catch (NumberFormatException e) {
    85                 Logging.error(e);
    86             }
    87         }
    88         return imgInfo;
     55        args.computeIfAbsent("type", ignore -> ImageryType.WMS.getDefault().getTypeString());
     56        args.computeIfAbsent("name", ignore -> args.getOrDefault("title", tr("Remote imagery")));
     57        ImageryPreferenceEntry imageryPreferenceEntry = StructUtils.deserializeStruct(args, ImageryPreferenceEntry.class);
     58        return new ImageryInfo(imageryPreferenceEntry);
    8959    }
    9060
     
    11181    @Override
    11282    protected void validateRequest() throws RequestHandlerBadRequestException {
    113         String url = args != null ? args.get("url") : null;
    114         String type = args != null ? args.get("type") : null;
    115         String cookies = args != null ? args.get("cookies") : null;
    11683        try {
    117             ImageryLayer.create(new ImageryInfo(null, url, type, null, cookies));
     84            CheckParameterUtil.ensureParameterNotNull(args);
     85            CheckParameterUtil.ensureParameterNotNull(args.get("url"));
     86            ImageryLayer.create(buildImageryInfo());
    11887        } catch (IllegalArgumentException e) {
    11988            throw new RequestHandlerBadRequestException(e.getMessage(), e);
Note: See TracChangeset for help on using the changeset viewer.