【发布时间】:2021-02-25 23:03:01
【问题描述】:
我正在使用 OpenLayers5。
我在我的项目中使用 Tile Layers,但我需要当我移动到地图时,图层会延迟一秒加载,从而不会多次调用服务器。
我的代码是
app.controller("MainController", [
function () {
const map = new ol.Map({
target: "map",
layers: [
new ol.layer.Tile({
source: new ol.source.OSM(),
}),
new ol.layer.Tile({
id: "positions",
visible: true,
source: new ol.source.TileWMS({
refresh: {
force: true,
},
visible: true,
projections: ["EPSG:4326"],
url: "http://localhost:9000/getMap",
}),
}),
],
view: new ol.View({
center: [0, 0],
zoom: 0,
}),
});
},
]);
我在 OpenLayers 中看到了以下三个函数:
getSource().on("tileloadstart", function () {
// While loading the layer
console.log("tileloadstart");
});
getSource().on("tileloadend", function () {
// At the end of the layer loading
console.log("tileloadend");
});
getSource().on("tileloaderror", function () {
//If throw error while loading
console.log("tileloaderror");
});
移动地图或缩放时我需要稍等片刻,以免服务器调用超载
【问题讨论】: