Changeset 36433 in osm


Ignore:
Timestamp:
2025-04-25T18:34:30+02:00 (4 weeks ago)
Author:
stoecker
Message:

see #24274 - support quadkey style TMS URLs

Location:
applications/viewer/jmapviewer
Files:
3 added
6 edited

Legend:

Unmodified
Added
Removed
  • applications/viewer/jmapviewer

    • Property ReleaseVersion changed from 2.24 to 2.25
  • applications/viewer/jmapviewer/bin

    • Property svn:ignore
      •  

        old new  
        11org
         2module-info.class
  • applications/viewer/jmapviewer/build.xml

    r36373 r36433  
    183183        <!-- resolver.repositories makes it global -->
    184184        <mvn:remoterepos id="resolver.repositories">
    185             <mvn:remoterepo id="JOSM-central" url="https://josm.openstreetmap.de/nexus/content/repositories/central/" />
     185            <mvn:remoterepo id="JOSM-central" url="https://josm.openstreetmap.de/repository/public/" />
    186186        </mvn:remoterepos>
    187187        <mvn:resolve>
  • applications/viewer/jmapviewer/pom.xml

    r36381 r36433  
    66    <groupId>org.openstreetmap.jmapviewer</groupId>
    77    <artifactId>jmapviewer</artifactId>
    8     <version>2.25-SNAPSHOT</version>
     8    <version>2.26-SNAPSHOT</version>
    99
    1010    <name>JMapViewer</name>
     
    7171            <id>josm-nexus-releases</id>
    7272            <name>JOSM Nexus (Releases)</name>
    73             <url>https://josm.openstreetmap.de/nexus/content/repositories/releases/</url>
     73            <url>https://josm.openstreetmap.de/repository/releases/</url>
    7474        </repository>
    7575        <snapshotRepository>
    7676            <id>josm-nexus-snapshot</id>
    7777            <name>JOSM Nexus (Snapshot)</name>
    78             <url>https://josm.openstreetmap.de/nexus/content/repositories/snapshots/</url>
     78            <url>https://josm.openstreetmap.de/repository/snapshots/</url>
    7979        </snapshotRepository>
    8080    </distributionManagement>
     
    8383        <repository>
    8484            <id>JOSM-central</id>
    85             <url>https://josm.openstreetmap.de/nexus/content/repositories/central/</url>
     85            <url>https://josm.openstreetmap.de/repository/public/</url>
    8686        </repository>
    8787    </repositories>
     
    8989        <pluginRepository>
    9090            <id>JOSM-central</id>
    91             <url>https://josm.openstreetmap.de/nexus/content/repositories/central/</url>
     91            <url>https://josm.openstreetmap.de/repository/public/</url>
    9292        </pluginRepository>
    9393    </pluginRepositories>
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/TemplatedTMSTileSource.java

    r36223 r36433  
    3030 * <li>{!y} - substituted with Yahoo Y tile number</li>
    3131 * <li>{-y} - substituted with reversed Y tile number</li>
     32 * <li>{quad} - Microsoft style quadkey</li>
    3233 * <li>{apikey} - substituted with API key retrieved for the imagery id</li>
    3334 * <li>{switch:VAL_A,VAL_B,VAL_C,...} - substituted with one of VAL_A, VAL_B, VAL_C. Usually
     
    4546    private static final Pattern PATTERN_Y_YAHOO = Pattern.compile("\\{!y}");
    4647    private static final Pattern PATTERN_NEG_Y   = Pattern.compile("\\{-y}");
     48    private static final Pattern PATTERN_QUAD    = Pattern.compile("\\{quad}");
    4749    private static final Pattern PATTERN_SWITCH  = Pattern.compile("\\{switch:([^}]+)}");
    4850    private static final Pattern PATTERN_HEADER  = Pattern.compile("\\{header\\(([^,]+),([^}]+)\\)}");
    4951    private static final Pattern PATTERN_API_KEY = Pattern.compile("\\{apikey}");
    50     private static final Pattern PATTERN_PARAM  = Pattern.compile("\\{((?:\\d+-)?z(?:oom)?(:?[+-]\\d+)?|x|y|!y|-y|switch:([^}]+))}");
     52    private static final Pattern PATTERN_PARAM  = Pattern.compile("\\{((?:\\d+-)?z(?:oom)?(:?[+-]\\d+)?|x|y|!y|-y|quad|switch:([^}]+))}");
    5153
    5254    // CHECKSTYLE.ON: SingleSpaceSeparator
    5355
    5456    private static final Pattern[] ALL_PATTERNS = {
    55             PATTERN_HEADER, PATTERN_ZOOM, PATTERN_X, PATTERN_Y, PATTERN_Y_YAHOO, PATTERN_NEG_Y, PATTERN_SWITCH, PATTERN_API_KEY
     57            PATTERN_HEADER, PATTERN_ZOOM, PATTERN_X, PATTERN_Y, PATTERN_Y_YAHOO, PATTERN_NEG_Y, PATTERN_SWITCH, PATTERN_API_KEY,
     58            PATTERN_QUAD
    5659    };
    5760
     
    156159                replacement = getRandomPart(randomParts);
    157160                break;
     161            case "quad": // PATTERN_QUAD
     162                replacement = xyzToQuadKey(tilex, tiley, zoom);
     163                break;
    158164            default:
    159165                // handle switch/zoom here, as group will contain parameters and switch will not work
     
    170176        matcher.appendTail(url);
    171177        return url.toString().replace(" ", "%20");
     178    }
     179
     180    /**
     181     * Convert an x y z coordinate to a quadkey
     182     * @param x The x coordinate
     183     * @param y The y coordinate
     184     * @param z The z coordinate
     185     * @return The quadkey
     186     */
     187    private static String xyzToQuadKey(int x, int y, int z) {
     188        final char[] string = new char[z];
     189        for (int i = z; i > 0; i--) {
     190            char digit = '0';
     191            final int mask = 1 << (i - 1);
     192            if ((x & mask) != 0) {
     193                digit++;
     194            }
     195            if ((y & mask) != 0) {
     196                digit += 2;
     197            }
     198            string[z - i] = digit;
     199        }
     200        return String.valueOf(string);
    172201    }
    173202
  • applications/viewer/jmapviewer/test/org/openstreetmap/gui/jmapviewer/tilesources/TemplatedTMSTileSourceTest.java

    r36223 r36433  
    3030     * triple of:
    3131     *  * baseUrl
    32      *  * expected tile url for zoom=1, x=2, y=3
     32     *  * expected tile url for zoom=4, x=5, y=6
    3333     *  * expected tile url for zoom=3, x=2, y=1
    3434     */
     
    3939        new String[] {
    4040                "http://imagico.de/map/osmim_tiles.php?layer=S2A_R136_N41_20150831T093006&z={zoom}&x={x}&y={-y}",
    41                 "http://imagico.de/map/osmim_tiles.php?layer=S2A_R136_N41_20150831T093006&z=1&x=2&y=-2",
     41                "http://imagico.de/map/osmim_tiles.php?layer=S2A_R136_N41_20150831T093006&z=4&x=5&y=9",
    4242                "http://imagico.de/map/osmim_tiles.php?layer=S2A_R136_N41_20150831T093006&z=3&x=2&y=6"
    4343                }
     
    5151        checkGetTileUrl(
    5252                "http://localhost/{z}/{x}/{y}",
    53                 "http://localhost/1/2/3",
     53                "http://localhost/4/5/6",
    5454                "http://localhost/3/1/2"
    5555                );
     
    6363        checkGetTileUrl(
    6464                "http://localhost/{zoom+5}/{x}/{y}",
    65                 "http://localhost/6/2/3",
     65                "http://localhost/9/5/6",
    6666                "http://localhost/8/1/2"
    6767                );
     
    7575        checkGetTileUrl(
    7676                "http://localhost/{zoom-5}/{x}/{y}",
    77                 "http://localhost/-4/2/3",
     77                "http://localhost/-1/5/6",
    7878                "http://localhost/-2/1/2"
    7979                );
     
    8787        checkGetTileUrl(
    8888                "http://localhost/{5-zoom}/{x}/{y}",
    89                 "http://localhost/4/2/3",
     89                "http://localhost/1/5/6",
    9090                "http://localhost/2/1/2"
    9191                );
     
    9999        checkGetTileUrl(
    100100                "http://localhost/{10-zoom-5}/{x}/{y}",
    101                 "http://localhost/4/2/3",
     101                "http://localhost/1/5/6",
    102102                "http://localhost/2/1/2"
    103103                );
     
    112112        TileSourceInfo testImageryTMS = new TileSourceInfo("test imagery", "http://localhost/{zoom}/{x}/{y}?token={apikey}&foo=bar", "id1");
    113113        TemplatedTMSTileSource ts = new TemplatedTMSTileSource(testImageryTMS);
    114         assertEquals("http://localhost/1/2/3?token=wololo&foo=bar", ts.getTileUrl(1, 2, 3));
     114        assertEquals("http://localhost/4/5/6?token=wololo&foo=bar", ts.getTileUrl(4, 5, 6));
    115115    }
    116116
     
    161161        checkGetTileUrl(
    162162                "http://localhost/{z}/{x}/{!y}",
    163                 "http://localhost/1/2/-3",
     163                "http://localhost/4/5/1",
    164164                "http://localhost/3/1/1"
    165165                );
     
    171171        checkGetTileUrl(
    172172                "http://localhost/{z}/{x}/{-y}",
    173                 "http://localhost/1/2/-2",
     173                "http://localhost/4/5/9",
    174174                "http://localhost/3/1/5"
     175                );
     176
     177    }
     178
     179    @Test
     180    void testGetTileUrl_quad() {
     181        checkGetTileUrl(
     182                "http://localhost/{quad}",
     183                "http://localhost/0321",
     184                "http://localhost/021"
    175185                );
    176186
     
    180190        TileSourceInfo testImageryTMS = new TileSourceInfo("test imagery", url, "id1");
    181191        TemplatedTMSTileSource ts = new TemplatedTMSTileSource(testImageryTMS);
    182         assertEquals(expected123, ts.getTileUrl(1, 2, 3));
     192        assertEquals(expected123, ts.getTileUrl(4, 5, 6));
    183193        assertEquals(expected312, ts.getTileUrl(3, 1, 2));
    184194    }
     
    192202            TileSourceInfo testImageryTMS = new TileSourceInfo("test imagery", test[0], "id1");
    193203            TemplatedTMSTileSource ts = new TemplatedTMSTileSource(testImageryTMS);
    194             assertEquals(test[1], ts.getTileUrl(1, 2, 3));
     204            assertEquals(test[1], ts.getTileUrl(4, 5, 6));
    195205            assertEquals(test[2], ts.getTileUrl(3, 2, 1));
    196206        }
     
    202212            TemplatedTMSTileSource ts = new TemplatedTMSTileSource(testImageryTMS);
    203213            System.out.println(MessageFormat.format("new String[]{\"{0}\", \"{1}\", \"{2}\"},",
    204                     url, ts.getTileUrl(1, 2, 3), ts.getTileUrl(3, 2, 1)));
     214                    url, ts.getTileUrl(4, 5, 6), ts.getTileUrl(3, 2, 1)));
    205215        }
    206216    }
Note: See TracChangeset for help on using the changeset viewer.