OpenLayers:实用程序 getSource().on 等待一秒钟加载或重新加载 TileLayer

问题描述

我使用的是 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,},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");
});

移动地图或缩放时我需要等待一秒钟,以免服务器调用过载

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)