Changeset 16589 in josm for trunk/src/org/openstreetmap/josm/io
- Timestamp:
- 2020-06-09T23:44:55+02:00 (4 years ago)
- 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 32 32 */ 33 33 static final int protocolMajorVersion = 1; 34 static final int protocolMinorVersion = 9;34 static final int protocolMinorVersion = 10; 35 35 36 36 /** -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/ImageryHandler.java
r16436 r16589 6 6 import java.util.Arrays; 7 7 8 import org.openstreetmap.josm.data.StructUtils; 8 9 import org.openstreetmap.josm.data.imagery.ImageryInfo; 10 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryPreferenceEntry; 9 11 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType; 10 import org.openstreetmap.josm.data.imagery.ImageryLayerInfo;11 12 import org.openstreetmap.josm.gui.MainApplication; 12 13 import org.openstreetmap.josm.gui.layer.ImageryLayer; 13 14 import org.openstreetmap.josm.gui.util.GuiHelper; 14 15 import org.openstreetmap.josm.io.remotecontrol.PermissionPrefWithDefault; 16 import org.openstreetmap.josm.tools.CheckParameterUtil; 15 17 import org.openstreetmap.josm.tools.Logging; 16 18 import org.openstreetmap.josm.tools.Utils; … … 40 42 @Override 41 43 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]); 43 47 } 44 48 … … 48 52 } 49 53 50 protected static ImageryInfo findBingEntry() {51 return ImageryLayerInfo.instance.getDefaultLayers().stream()52 .filter(i -> ImageryType.BING == i.getImageryType())53 .findFirst().orElse(null);54 }55 56 54 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); 89 59 } 90 60 … … 111 81 @Override 112 82 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;116 83 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()); 118 87 } catch (IllegalArgumentException e) { 119 88 throw new RequestHandlerBadRequestException(e.getMessage(), e);
Note:
See TracChangeset
for help on using the changeset viewer.