Ignore:
Timestamp:
2015-06-24T20:57:43+02:00 (5 years ago)
Author:
wiktorn
Message:

Introduce WMS layer based on TMS. (closes: #11255)

HEADS UP: After this patch you need to manually remove JAX-B generated file/class: org/w3/_2001/xmlschema/Adapter1.java to compile the tree again.

  • create AbstractTileSourceLayer based on TMSLayer as a base for TMS, WMS and (future) WMTS layers, (addresses #11459)
  • WMS layer now uses JCS Caching (closes: #7363)
  • introduce new conversion methods in TileSource, that convert both X and Y (lat and lon) in one call. This is necessary for other than PseudoMercator projections
    • introduce TileXY class that represents X and Y indexes of tile in tile matrix/space
    • mark old conversion methods as deprecated
    • refactor JMapViewer and JOSM to new methods
    • change use of Coordinate class to ICoordinate where appropiate
  • extract CachedAttributionBingAerialTileSource to separate file
  • create TemplatedWMSTileSource that provides the WMS Layer with square (according to current projection) tiles (closes: #11572, closes: #7682, addresses: #5454)
  • implemented precaching imagery along GPX track for AbstractTileSourceLayer, so now it work for both - WMS and TMS (closes: #9154)
  • implemented common righ-click menu on map view, as well on layer list (closes #3591)
  • create separate build commands for JMapViewer classes to easily spot, when josm classes are used within JMapViewer
  • remove unnecessary classes of previous WMS implementation - GeorefImage, wms-cache.xsd (and JAXB task from build), WMSCache, WMSRequest, WMSGrabber, HTMLGrabber, WMSException
Location:
trunk/src/org/openstreetmap/josm/io
Files:
4 deleted
4 edited

Legend:

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

    r8510 r8526  
    77import java.io.ObjectOutputStream;
    88
     9import org.openstreetmap.josm.Main;
     10import org.openstreetmap.josm.data.Preferences;
     11import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryPreferenceEntry;
     12import org.openstreetmap.josm.gui.layer.AbstractTileSourceLayer;
    913import org.openstreetmap.josm.gui.layer.Layer;
    10 import org.openstreetmap.josm.gui.layer.WMSLayer;
    1114import org.openstreetmap.josm.tools.CheckParameterUtil;
    1215
     
    1720 */
    1821public class WMSLayerExporter extends FileExporter {
     22
     23    /** Which version of the file we export */
     24    public static final int CURRENT_FILE_VERSION = 6;
    1925
    2026    /**
     
    2935        CheckParameterUtil.ensureParameterNotNull(file, "file");
    3036        CheckParameterUtil.ensureParameterNotNull(layer, "layer");
    31         if (layer instanceof WMSLayer) {
     37
     38        if (layer instanceof AbstractTileSourceLayer) {
    3239            try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file))) {
    33                 ((WMSLayer) layer).writeExternal(oos);
     40                oos.writeInt(CURRENT_FILE_VERSION); // file version
     41                oos.writeObject(Main.map.mapView.getCenter());
     42                ImageryPreferenceEntry entry = new ImageryPreferenceEntry(((AbstractTileSourceLayer) layer).getInfo());
     43                oos.writeObject(Preferences.serializeStruct(entry, ImageryPreferenceEntry.class));
    3444            }
    3545        }
     46
    3647    }
    3748
    3849    @Override
    3950    public void activeLayerChange(Layer oldLayer, Layer newLayer) {
    40         setEnabled(newLayer instanceof WMSLayer);
     51        setEnabled(newLayer instanceof AbstractTileSourceLayer);
    4152    }
    4253}
  • trunk/src/org/openstreetmap/josm/io/WMSLayerImporter.java

    r7033 r8526  
    77import java.io.FileInputStream;
    88import java.io.IOException;
     9import java.io.InvalidClassException;
    910import java.io.ObjectInputStream;
     11import java.util.Map;
    1012
    1113import org.openstreetmap.josm.Main;
    1214import org.openstreetmap.josm.actions.ExtensionFileFilter;
    13 import org.openstreetmap.josm.gui.layer.WMSLayer;
     15import org.openstreetmap.josm.data.Preferences;
     16import org.openstreetmap.josm.data.coor.EastNorth;
     17import org.openstreetmap.josm.data.imagery.ImageryInfo;
     18import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryPreferenceEntry;
     19import org.openstreetmap.josm.gui.layer.ImageryLayer;
    1420import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    1521import org.openstreetmap.josm.gui.util.GuiHelper;
     
    2834            "wms", "wms", tr("WMS Files (*.wms)"));
    2935
    30     private final WMSLayer wmsLayer;
    31 
    3236    /**
    3337     * Constructs a new {@code WMSLayerImporter}.
    3438     */
    3539    public WMSLayerImporter() {
    36         this(new WMSLayer());
     40        super(FILE_FILTER);
    3741    }
    3842
    39     /**
    40      * Constructs a new {@code WMSLayerImporter} that will import data to the specified WMS layer.
    41      * @param wmsLayer The WMS layer.
    42      */
    43     public WMSLayerImporter(WMSLayer wmsLayer) {
    44         super(FILE_FILTER);
    45         this.wmsLayer = wmsLayer;
    46     }
    4743
    4844    @Override
    4945    public void importData(File file, ProgressMonitor progressMonitor) throws IOException, IllegalDataException {
    5046        CheckParameterUtil.ensureParameterNotNull(file, "file");
     47        final EastNorth zoomTo;
     48        ImageryInfo info = null;
     49        final ImageryLayer layer;
     50
    5151        try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file))) {
    52             wmsLayer.readExternal(ois);
     52            int sfv = ois.readInt();
     53            if (sfv < 5) {
     54                throw new InvalidClassException(tr("Unsupported WMS file version; found {0}, expected {1}", sfv, 5));
     55            } else if (sfv == 5) {
     56                ois.readInt(); // dax - not needed
     57                ois.readInt(); // day - not needed
     58                zoomTo = null;
     59
     60                int imageSize = ois.readInt();
     61                double pixelPerDegree = ois.readDouble();
     62
     63                String name = (String)ois.readObject();
     64                String extendedUrl = (String)ois.readObject();
     65
     66                info = new ImageryInfo(name);
     67                info.setExtendedUrl(extendedUrl);
     68                info.setPixelPerDegree(pixelPerDegree);
     69                info.setTileSize(imageSize);
     70            } else if (sfv == WMSLayerExporter.CURRENT_FILE_VERSION){
     71                zoomTo = (EastNorth) ois.readObject();
     72
     73                @SuppressWarnings("unchecked")
     74                ImageryPreferenceEntry entry = Preferences.deserializeStruct(
     75                        (Map<String, String>)ois.readObject(),
     76                        ImageryPreferenceEntry.class);
     77                info = new ImageryInfo(entry);
     78            } else {
     79                throw new InvalidClassException(tr("Unsupported WMS file version; found {0}, expected {1}", sfv, 6));
     80            }
    5381        } catch (ClassNotFoundException e) {
    5482            throw new IllegalDataException(e);
    5583        }
     84        layer = ImageryLayer.create(info);
     85
    5686
    5787        // FIXME: remove UI stuff from IO subsystem
     
    5989            @Override
    6090            public void run() {
    61                 Main.main.addLayer(wmsLayer);
    62                 wmsLayer.onPostLoadFromFile();
     91                Main.main.addLayer(layer);
     92                if (zoomTo != null) {
     93                    Main.map.mapView.zoomTo(zoomTo);
     94                }
    6395            }
    6496        });
    6597    }
    66 
    67     /**
    68      * Replies the imported WMS layer.
    69      * @return The imported WMS layer.
    70      * @see #importData(File, ProgressMonitor)
    71      */
    72     public final WMSLayer getWmsLayer() {
    73         return wmsLayer;
    74     }
    7598}
  • trunk/src/org/openstreetmap/josm/io/session/ImagerySessionExporter.java

    r8510 r8526  
    1717import org.openstreetmap.josm.data.Preferences;
    1818import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryPreferenceEntry;
     19import org.openstreetmap.josm.gui.layer.AbstractTileSourceLayer;
    1920import org.openstreetmap.josm.gui.layer.ImageryLayer;
    2021import org.openstreetmap.josm.gui.layer.Layer;
     
    8182        ImageryPreferenceEntry e = new ImageryPreferenceEntry(layer.getInfo());
    8283        Map<String, String> data = new LinkedHashMap<>(Preferences.serializeStruct(e, ImageryPreferenceEntry.class));
    83         if (layer instanceof WMSLayer) {
    84             WMSLayer wms = (WMSLayer) layer;
    85             data.put("automatic-downloading", Boolean.toString(wms.hasAutoDownload()));
    86             data.put("automatically-change-resolution", Boolean.toString(wms.isAutoResolution()));
     84        if (layer instanceof AbstractTileSourceLayer) {
     85            AbstractTileSourceLayer tsLayer = (AbstractTileSourceLayer) layer;
     86            data.put("automatic-downloading", Boolean.toString(tsLayer.autoLoad));
     87            data.put("automatically-change-resolution", Boolean.toString(tsLayer.autoZoom));
     88            data.put("show-errors", Boolean.toString(tsLayer.showErrors));
    8789        }
    8890        for (Map.Entry<String, String> entry : data.entrySet()) {
  • trunk/src/org/openstreetmap/josm/io/session/ImagerySessionImporter.java

    r8510 r8526  
    1111import org.openstreetmap.josm.data.imagery.ImageryInfo;
    1212import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryPreferenceEntry;
     13import org.openstreetmap.josm.gui.layer.AbstractTileSourceLayer;
    1314import org.openstreetmap.josm.gui.layer.ImageryLayer;
    1415import org.openstreetmap.josm.gui.layer.Layer;
    15 import org.openstreetmap.josm.gui.layer.WMSLayer;
    1616import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    1717import org.openstreetmap.josm.io.IllegalDataException;
     
    4646        ImageryInfo i = new ImageryInfo(prefEntry);
    4747        ImageryLayer layer = ImageryLayer.create(i);
    48         if (layer instanceof WMSLayer) {
    49             WMSLayer wms = (WMSLayer) layer;
    50             String autoDownload = attributes.get("automatic-downloading");
    51             if (autoDownload != null) {
    52                 wms.setAutoDownload(Boolean.parseBoolean(autoDownload));
     48        if (layer instanceof AbstractTileSourceLayer) {
     49            AbstractTileSourceLayer tsLayer = (AbstractTileSourceLayer) layer;
     50            if (attributes.containsKey("automatic-downloading")) {
     51                tsLayer.autoLoad = new Boolean(attributes.get("automatic-downloading")).booleanValue();
    5352            }
    54             String autoResolution = attributes.get("automatically-change-resolution");
    55             if (autoResolution != null) {
    56                 wms.setAutoResolution(Boolean.parseBoolean(autoResolution));
     53
     54            if (attributes.containsKey("automatically-change-resolution")) {
     55                tsLayer.autoZoom = new Boolean(attributes.get("automatically-change-resolution")).booleanValue();
     56            }
     57
     58            if (attributes.containsKey("show-errors")) {
     59                tsLayer.showErrors = new Boolean(attributes.get("show-errors")).booleanValue();
    5760            }
    5861        }
Note: See TracChangeset for help on using the changeset viewer.