Changeset 12469 in josm


Ignore:
Timestamp:
2017-07-12T21:41:19+02:00 (2 months ago)
Author:
Don-vip
Message:

fix #15012 - Support WMS endpoint in Imagery -> Rectified Image

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java

    r12279 r12469  
    9494            case WMS_ENDPOINT:
    9595                // convert to WMS type
    96                 return getWMSLayerInfo();
     96                return getWMSLayerInfo(info);
    9797            case WMTS:
    9898                // specify which layer to use
     
    152152    }
    153153
    154     protected ImageryInfo getWMSLayerInfo() throws IOException, WMSGetCapabilitiesException {
     154    /**
     155     * Asks user to choose a WMS layer from a WMS endpoint.
     156     * @param info the WMS endpoint.
     157     * @return chosen WMS layer, or null
     158     * @throws IOException if any I/O error occurs while contacting the WMS endpoint
     159     * @throws WMSGetCapabilitiesException if the WMS getCapabilities request fails
     160     */
     161    protected static ImageryInfo getWMSLayerInfo(ImageryInfo info) throws IOException, WMSGetCapabilitiesException {
    155162        CheckParameterUtil.ensureThat(ImageryType.WMS_ENDPOINT.equals(info.getImageryType()), "wms_endpoint imagery type expected");
    156163
  • trunk/src/org/openstreetmap/josm/actions/MapRectifierWMSmenuAction.java

    r12279 r12469  
    99import java.awt.event.ActionEvent;
    1010import java.awt.event.KeyEvent;
     11import java.io.IOException;
    1112import java.util.ArrayList;
    1213import java.util.List;
     
    2223import org.openstreetmap.josm.Main;
    2324import org.openstreetmap.josm.data.imagery.ImageryInfo;
     25import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;
    2426import org.openstreetmap.josm.gui.ExtendedDialog;
    2527import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils;
     
    2729import org.openstreetmap.josm.gui.widgets.JosmTextField;
    2830import org.openstreetmap.josm.gui.widgets.UrlLabel;
     31import org.openstreetmap.josm.io.imagery.WMSImagery.WMSGetCapabilitiesException;
    2932import org.openstreetmap.josm.tools.GBC;
    3033import org.openstreetmap.josm.tools.Shortcut;
     
    232235     */
    233236    private static void addWMSLayer(String title, String url) {
    234         WMSLayer layer = new WMSLayer(new ImageryInfo(title, url));
    235         Main.getLayerManager().addLayer(layer);
     237        ImageryInfo info = new ImageryInfo(title, url);
     238        if (info.getImageryType() == ImageryType.WMS_ENDPOINT) {
     239            try {
     240                info = AddImageryLayerAction.getWMSLayerInfo(info);
     241            } catch (IOException | WMSGetCapabilitiesException e) {
     242                Main.error(e);
     243                JOptionPane.showMessageDialog(Main.parent, e.getMessage(), tr("No valid WMS URL or id"), JOptionPane.ERROR_MESSAGE);
     244                return;
     245            }
     246        }
     247        Main.getLayerManager().addLayer(new WMSLayer(info));
    236248    }
    237249
  • trunk/src/org/openstreetmap/josm/io/imagery/WMSImagery.java

    r11747 r12469  
    345345            bboxElem = getChild(element, "LatLonBoundingBox");
    346346            if (bboxElem != null) {
    347                 double left = Double.parseDouble(bboxElem.getAttribute("minx"));
    348                 double top = Double.parseDouble(bboxElem.getAttribute("maxy"));
    349                 double right = Double.parseDouble(bboxElem.getAttribute("maxx"));
    350                 double bot = Double.parseDouble(bboxElem.getAttribute("miny"));
     347                double left = getDecimalDegree(bboxElem ,"minx");
     348                double top = getDecimalDegree(bboxElem, "maxy");
     349                double right = getDecimalDegree(bboxElem, "maxx");
     350                double bot = getDecimalDegree(bboxElem, "miny");
    351351                bounds = new Bounds(bot, left, top, right);
    352352            }
     
    357357
    358358        return new LayerDetails(name, ident, crsList, josmSupportsThisLayer, bounds, childLayers);
     359    }
     360
     361    private static double getDecimalDegree(Element elem, String attr) {
     362        // Some real-world WMS servers use a comma instead of a dot as decimal separator (seen in Polish WMS server)
     363        return Double.parseDouble(elem.getAttribute(attr).replace(',', '.'));
    359364    }
    360365
Note: See TracChangeset for help on using the changeset viewer.