From f460198850470956ff3c1ffd224822ce934b3df6 Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Sun, 8 Dec 2019 17:21:56 +0100 Subject: [PATCH] Simpler tileLoadFunction for vector tiles --- src/ol/VectorTile.js | 4 +++- src/ol/source/VectorTile.js | 13 ++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/ol/VectorTile.js b/src/ol/VectorTile.js index 9d18626e1e..7c79cbc36f 100644 --- a/src/ol/VectorTile.js +++ b/src/ol/VectorTile.js @@ -105,7 +105,9 @@ class VectorTile extends Tile { if (this.state == TileState.IDLE) { this.setState(TileState.LOADING); this.tileLoadFunction_(this, this.url_); - this.loader_(this.extent, this.resolution, this.projection); + if (this.loader_) { + this.loader_(this.extent, this.resolution, this.projection); + } } } diff --git a/src/ol/source/VectorTile.js b/src/ol/source/VectorTile.js index 8fb5496cce..bda808a53c 100644 --- a/src/ol/source/VectorTile.js +++ b/src/ol/source/VectorTile.js @@ -52,6 +52,17 @@ import {listen, unlistenByKey} from '../events.js'; * }); * } * ``` + * If you do not need extent, resolution and projection to get the features for a tile (e.g. + * for GeoJSON tiles), your `tileLoadFunction` does not need a `setLoader()` call. Only make sure + * to call `setFeatures()` on the tile: + * ```js + * const format = new GeoJSON({featureProjection: map.getView().getProjection()}); + * async function tileLoadFunction(tile, url) { + * const response = await fetch(url); + * const data = await response.json(); + * tile.setFeatures(format.readFeatures(data)); + * } + * ``` * @property {import("../Tile.js").UrlFunction} [tileUrlFunction] Optional function to get tile URL given a tile coordinate and the projection. * @property {string} [url] URL template. Must include `{x}`, `{y}` or `{-y}`, and `{z}` placeholders. * A `{?-?}` template pattern, for example `subdomain{a-f}.domain.com`, may be @@ -232,7 +243,7 @@ class VectorTile extends UrlTile { sourceTile.load(); } } - covered = false; + covered = covered && sourceTile && sourceTile.getState() === TileState.LOADED; if (!sourceTile) { return; }