Simpler tileLoadFunction for vector tiles
This commit is contained in:
@@ -105,9 +105,11 @@ class VectorTile extends Tile {
|
|||||||
if (this.state == TileState.IDLE) {
|
if (this.state == TileState.IDLE) {
|
||||||
this.setState(TileState.LOADING);
|
this.setState(TileState.LOADING);
|
||||||
this.tileLoadFunction_(this, this.url_);
|
this.tileLoadFunction_(this, this.url_);
|
||||||
|
if (this.loader_) {
|
||||||
this.loader_(this.extent, this.resolution, this.projection);
|
this.loader_(this.extent, this.resolution, this.projection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler for successful tile load.
|
* Handler for successful tile load.
|
||||||
|
|||||||
@@ -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 {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.
|
* @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
|
* A `{?-?}` template pattern, for example `subdomain{a-f}.domain.com`, may be
|
||||||
@@ -232,7 +243,7 @@ class VectorTile extends UrlTile {
|
|||||||
sourceTile.load();
|
sourceTile.load();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
covered = false;
|
covered = covered && sourceTile && sourceTile.getState() === TileState.LOADED;
|
||||||
if (!sourceTile) {
|
if (!sourceTile) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user