I am using OpenLayers5.
I'm working with Tile Layers in my project, but I need that when I move to the map, the layer will load with one second delay to no call many times to server.
My code is
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,
}),
});
},
]);
I saw in OpenLayers the following three functions:
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");
});
I need to wait a second while I move the map or zoom so as not to overload the server calls