Package: OpenStreetMapTileSource
OpenStreetMapTileSource
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
OpenStreetMapTileSource() |
|
|
|
|
|
||||||||||||||||||||
OpenStreetMapTileSource(int, String, String, String) |
|
|
|
|
|
||||||||||||||||||||
getTileUri(int, int, int) |
|
|
|
|
|
||||||||||||||||||||
static {...} |
|
|
|
|
|
||||||||||||||||||||
toString() |
|
|
|
|
|
Coverage
1: /*
2: * *************************************************************************************************************************************************************
3: *
4: * MapView: a JavaFX map renderer for tile-based servers
5: * http://tidalwave.it/projects/mapview
6: *
7: * Copyright (C) 2024 - 2025 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *************************************************************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
12: * You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
17: * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
18: *
19: * *************************************************************************************************************************************************************
20: *
21: * git clone https://bitbucket.org/tidalwave/mapview-src
22: * git clone https://github.com/tidalwave-it/mapview-src
23: *
24: * *************************************************************************************************************************************************************
25: */
26: package it.tidalwave.mapview;
27:
28: import jakarta.annotation.Nonnull;
29: import java.net.URI;
30: import java.net.URISyntaxException;
31: import it.tidalwave.mapview.spi.WGS84PseudoMercatorProjection;
32: import it.tidalwave.mapview.spi.TileSourceSupport;
33: import lombok.extern.slf4j.Slf4j;
34:
35: /***************************************************************************************************************************************************************
36: *
37: * The OpenStreetMap source of map tiles.
38: *
39: * @author Fabrizio Giudici
40: *
41: **************************************************************************************************************************************************************/
42: @Slf4j
43: public class OpenStreetMapTileSource extends TileSourceSupport
44: {
45: private static final int TILE_SIZE = 256;
46:
47: private static final int TOP_ZOOM_LEVEL = 19;
48:
49: private static final int DEFAULT_ZOOM_LEVEL = 9;
50:
51: /** The pattern, in {@link String#formatted(Object...)} syntax, of the URI. */
52: @Nonnull
53: protected final String pattern;
54:
55: /***********************************************************************************************************************************************************
56: * Creates a new instance.
57: **********************************************************************************************************************************************************/
58: public OpenStreetMapTileSource()
59: {
60: this(TOP_ZOOM_LEVEL, "https://tile.openstreetmap.org/%d/%d/%d.png", "OpenStreetMap", "OpenStreetMap");
61: }
62:
63: /***********************************************************************************************************************************************************
64: * Constructor for subclasses.
65: * @param maxZoom the maximum allowed zoom level
66: * @param pattern the URI pattern
67: * @param displayName the display name of the provider
68: * @param cachePrefix the prefix for the cache
69: **********************************************************************************************************************************************************/
70: protected OpenStreetMapTileSource (final int maxZoom,
71: @Nonnull final String pattern,
72: @Nonnull final String displayName,
73: @Nonnull final String cachePrefix)
74: {
75: super(new WGS84PseudoMercatorProjection(TILE_SIZE), 1, maxZoom, DEFAULT_ZOOM_LEVEL, TILE_SIZE, displayName, cachePrefix);
76: this.pattern = pattern;
77: }
78:
79: /***********************************************************************************************************************************************************
80: * {@inheritDoc}
81: **********************************************************************************************************************************************************/
82: @Override @Nonnull
83: public final URI getTileUri (final int column, final int row, final int zoom)
84: {
85: try
86: {
87: return new URI(pattern.formatted(zoom, column, row));
88: }
89: catch (URISyntaxException e)
90: {
91: throw new IllegalArgumentException(e);
92: }
93: }
94:
95: /***********************************************************************************************************************************************************
96: * {@inheritDoc}
97: **********************************************************************************************************************************************************/
98: @Override @Nonnull
99: public String toString()
100: {
101: return getClass().getSimpleName();
102: }
103: }