Skip to content

Commit

Permalink
Merge branch '2023.08.30-map-tiling' of github.com:juliangiebel/space…
Browse files Browse the repository at this point in the history
…-station-14-map-viewer into 2023.08.30-map-tiling
  • Loading branch information
juliangiebel committed Feb 14, 2024
2 parents 842bae3 + f35557c commit 7c8df07
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
4 changes: 2 additions & 2 deletions js/AsyncImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AsyncImage {

/**
*
* @param {(image: Image, data: any) => void} callback A function that gets executed when the image is loaded
* @param {(image: HTMLImageElement, data: any) => void} callback A function that gets executed when the image is loaded
* @param {*} data additional data to pass to that function
*/
executeOnLoad(callback, data) {
Expand All @@ -34,4 +34,4 @@ class AsyncImage {
}
}

export default AsyncImage;
export default AsyncImage;
6 changes: 4 additions & 2 deletions js/MapLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Config from "./Config.js";
import TileLayer from "ol/layer/Tile.js";
import {XYZ} from "ol/source.js";
import TileGrid from "ol/tilegrid/TileGrid.js";
import TileImagePreloader from "./TileImagePreloader.js";

class MapLoader {
static async loadMap(mapName) {
Expand Down Expand Up @@ -66,6 +67,7 @@ class MapLoader {
const map = new Map({
layers: layers,
target: 'map',
maxTilesLoading: 20,
view: new View({
projection: projection,
center: getCenter([map0Extent.a.x, map0Extent.a.y, map0Extent.b.x, map0Extent.b.y]),
Expand Down Expand Up @@ -163,10 +165,10 @@ class MapLoader {
//console.log(gridLayer.url);

if (gridLayer.tiled) {
//TODO: Implement map tiling
mapLayer = new TileLayer({
//className: 'map',
extent: [extent.a.x, extent.a.y, extent.b.x, extent.b.y],
updateWhileInteracting: true,
updateWhileAnimating: true,
source: new XYZ({
attributions: data.attributions,
url: "https://" + gridLayer.url.replace(/https?:\/\//, "") + "/{x}/{y}/{z}",
Expand Down
26 changes: 26 additions & 0 deletions js/TileImagePreloader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import ImageTile from "ol/Tile";
import AsyncImage from "./AsyncImage.js";
import * as TileState from "ol/TileState.js";

class TileImagePreloader
{
/**
*
* @param tile { ImageTile }
* @param src { string }
*/
static load(tile, src)
{
new AsyncImage(src + "?preload=true").executeOnLoad((image, data, isAsync) => {
tile.setImage(image);
const fullImage = new AsyncImage(src);
fullImage.executeOnLoad((image, data, isAsync) => {
tile.setImage(image);
}, null);

fullImage.promise.catch(e => tile.setState(TileState.ERROR));
}, null);
}
}

export default TileImagePreloader;

0 comments on commit 7c8df07

Please sign in to comment.