Ignore:
Timestamp:
2015-07-04T22:52:23+02:00 (10 years ago)
Author:
wiktorn
Message:

Basic WMTS support.

  • added information about units and to_meter to EPSG projection definitions (needed for WMTS)
  • added WMTSTileSource and WMTSLayer classes
  • a bit of cleanup of AbstractTileSourceLayer and align so it will work properly with WMTS tile definitions
  • added Imagery Preferences panel for WMTS and icon for button
  • added removal of wms: / tms: / wmts: prefix, if user will paste them into the field
  • CachedFile - added possibility to send custom headers with request
  • added support for unit and to_meter in CustomProjection
  • AbstractTMSTileSource cleanups (change of Coordinate to ICoordinate)
  • moved JCSCachedTileLoaderJob.read() to Utils

Addresses: #10623

Tested with Polish WMTS service proivders, Walonnie needs still some debugging, as it is not working right now.

Location:
trunk/src/org/openstreetmap/josm/data
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJob.java

    r8540 r8568  
    22package org.openstreetmap.josm.data.cache;
    33
    4 import java.io.ByteArrayOutputStream;
    54import java.io.FileNotFoundException;
    65import java.io.IOException;
    7 import java.io.InputStream;
    86import java.net.HttpURLConnection;
    97import java.net.URL;
     
    3028import org.openstreetmap.josm.data.cache.ICachedLoaderListener.LoadResult;
    3129import org.openstreetmap.josm.data.preferences.IntegerProperty;
     30import org.openstreetmap.josm.tools.Utils;
    3231
    3332/**
     
    350349
    351350                attributes.setResponseCode(responseCode(urlConn));
    352                 byte[] raw = read(urlConn);
     351                byte[] raw = Utils.readBytesFromStream(urlConn.getInputStream());
    353352
    354353                if (isResponseLoadable(urlConn.getHeaderFields(), responseCode(urlConn), raw)) {
     
    473472    }
    474473
    475     private static byte[] read(URLConnection urlConn) throws IOException {
    476         InputStream input = urlConn.getInputStream();
    477         try {
    478             ByteArrayOutputStream bout = new ByteArrayOutputStream(input.available());
    479             byte[] buffer = new byte[2048];
    480             boolean finished = false;
    481             do {
    482                 int read = input.read(buffer);
    483                 if (read >= 0) {
    484                     bout.write(buffer, 0, read);
    485                 } else {
    486                     finished = true;
    487                 }
    488             } while (!finished);
    489             if (bout.size() == 0)
    490                 return null;
    491             return bout.toByteArray();
    492         } finally {
    493             input.close();
    494         }
    495     }
    496 
    497474    /**
    498475     * TODO: move to JobFactory
  • trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java

    r8526 r8568  
    5656        SCANEX("scanex"),
    5757        /** A WMS endpoint entry only stores the WMS server info, without layer, which are chosen later by the user. **/
    58         WMS_ENDPOINT("wms_endpoint");
     58        WMS_ENDPOINT("wms_endpoint"),
     59        /** WMTS stores GetCapabilities URL. Does not store any information about the layer **/
     60        WMTS("wmts");
    5961
    6062
  • trunk/src/org/openstreetmap/josm/data/projection/CustomProjection.java

    r8533 r8568  
    88import java.util.List;
    99import java.util.Map;
     10import java.util.concurrent.ConcurrentHashMap;
    1011import java.util.regex.Matcher;
    1112import java.util.regex.Pattern;
     
    3536public class CustomProjection extends AbstractProjection {
    3637
     38    private final static Map<String, Double> UNITS_TO_METERS = getUnitsToMeters();
     39    private final static double METER_PER_UNIT_DEGREE = 2 * Math.PI * 6370997 / 360;
     40
    3741    /**
    3842     * pref String that defines the projection
     
    4549    protected String cacheDir;
    4650    protected Bounds bounds;
     51    private double metersPerUnit = METER_PER_UNIT_DEGREE; // default to degrees
    4752
    4853    /**
     
    8994        wktext("wktext", false),  // ignored
    9095        /** meters, US survey feet, etc. */
    91         units("units", true),     // ignored
     96        units("units", true),
    9297        /** Don't use the /usr/share/proj/proj_def.dat defaults file */
    9398        no_defs("no_defs", false),
    9499        init("init", true),
     100        to_meter("to_meter", true),
    95101        // JOSM extensions, not present in PROJ.4
    96102        wmssrs("wmssrs", true),
     
    103109
    104110        /** Map of all parameters by key */
    105         static final Map<String, Param> paramsByKey = new HashMap<>();
     111        static final Map<String, Param> paramsByKey = new ConcurrentHashMap<>();
    106112        static {
    107113            for (Param p : Param.values()) {
     
    198204            if (s != null) {
    199205                this.code = s;
     206            }
     207            s = parameters.get(Param.units.key);
     208            if (s != null) {
     209                this.metersPerUnit = UNITS_TO_METERS.get(s);
     210            }
     211            s = parameters.get(Param.to_meter.key);
     212            if (s != null) {
     213                this.metersPerUnit = parseDouble(s, Param.to_meter.key);
    200214            }
    201215        }
     
    528542        return name != null ? name : tr("Custom Projection");
    529543    }
     544
     545    @Override
     546    public double getMetersPerUnit() {
     547        return metersPerUnit;
     548    }
     549
     550    private static Map<String, Double> getUnitsToMeters() {
     551        Map<String, Double> ret = new ConcurrentHashMap<>();
     552        ret.put("km", 1000d);
     553        ret.put("m", 1d);
     554        ret.put("dm", 1d/10);
     555        ret.put("cm", 1d/100);
     556        ret.put("mm", 1d/1000);
     557        ret.put("kmi", 1852.0);
     558        ret.put("in", 0.0254);
     559        ret.put("ft", 0.3048);
     560        ret.put("yd", 0.9144);
     561        ret.put("mi", 1609.344);
     562        ret.put("fathom", 1.8288);
     563        ret.put("chain", 20.1168);
     564        ret.put("link", 0.201168);
     565        ret.put("us-in", 1d/39.37);
     566        ret.put("us-ft", 0.304800609601219);
     567        ret.put("us-yd", 0.914401828803658);
     568        ret.put("us-ch", 20.11684023368047);
     569        ret.put("us-mi", 1609.347218694437);
     570        ret.put("ind-yd", 0.91439523);
     571        ret.put("ind-ft", 0.30479841);
     572        ret.put("ind-ch", 20.11669506);
     573        ret.put("degree", METER_PER_UNIT_DEGREE);
     574        return ret;
     575    }
    530576}
  • trunk/src/org/openstreetmap/josm/data/projection/Projection.java

    r6069 r8568  
    6868     */
    6969    Bounds getWorldBoundsLatLon();
     70
     71    /**
     72     * Get the number of meters per unit of this projection. This more
     73     * defines the scale of the map, than real conversion of unit to meters
     74     * as this value is more less correct only along great circles.
     75     *
     76     * Used by WMTS to properly scale tiles
     77     * @return meters per unit of projection
     78     *
     79     */
     80    double getMetersPerUnit();
    7081}
  • trunk/src/org/openstreetmap/josm/data/projection/proj/Proj.java

    r7509 r8568  
    6464     */
    6565    double[] invproject(double east, double north);
    66 
    6766}
Note: See TracChangeset for help on using the changeset viewer.