Tile.java

  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.mapviewer.javafx.impl;

  27. import jakarta.annotation.Nonnull;
  28. import java.net.URI;
  29. import javafx.scene.image.ImageView;
  30. import it.tidalwave.mapviewer.TileSource;
  31. import lombok.Getter;

  32. /***************************************************************************************************************************************************************
  33.  *
  34.  * This class represents a single tile for rendering a map. It basically wraps a bitmap that is available on the internet at a specific URL, and it has the
  35.  * capability of being loaded in background and rendering some temporary icons while the process has not terminated.
  36.  *
  37.  * @author  Fabrizio Giudici
  38.  *
  39.  **************************************************************************************************************************************************************/
  40. @Getter
  41. public class Tile extends ImageView
  42.   {
  43.     /** The source of tile bitmaps. */
  44.     @Nonnull
  45.     private final TileSource source;

  46.     /** The URL of this tile. */
  47.     private final URI uri;

  48.     /** The zoom level this tile belongs to. */
  49.     private final int zoom;

  50.     /***********************************************************************************************************************************************************
  51.      * Creates a new tile and submits it to the cache for downloading.
  52.      * @param   tileCache       the tile cache
  53.      * @param   source          the tile source
  54.      * @param   uri             the URL of the tile
  55.      * @param   size            the size of the tile
  56.      * @param   zoom            the zoom level of this tile
  57.      **********************************************************************************************************************************************************/
  58.     @SuppressWarnings("this-escape")
  59.     protected Tile (@Nonnull final TileCache tileCache, @Nonnull final TileSource source, @Nonnull final URI uri, final int size, final int zoom)
  60.       {
  61.         this.source = source;
  62.         this.uri = uri;
  63.         this.zoom = zoom;
  64.         setFitWidth(size);
  65.         setFitHeight(size);
  66.         tileCache.loadTileInBackground(this);
  67.       }
  68.   }