maptalks / maptalks.js

A light and plugable JavaScript library for integrated 2D/3D maps.
https://maptalks.org
BSD 3-Clause "New" or "Revised" License
4.28k stars 499 forks source link

tianditu api was changed #853

Closed lifefriend closed 5 years ago

lifefriend commented 5 years ago

chrome71 , maptalks v0.42.2

tianditu api was changed, the example of epsg4326(http://maptalks.org/examples/en/tilelayer-projection/epsg4326/#tilelayer-projection_epsg4326) is blank

old: http://t{s}.tianditu.com/DataServer?T=vec_c&x={x}&y={y}&l={z} new: http://t{s}.tianditu.gov.cn/DataServer?T=vec_c&tk=YOUR_KEY&x={x}&y={y}&l={z}

in the new api,random white patches appear on the map

default

Here's the amendment I've tried.

_proto.loadTileImage = function loadTileImage(tileImage, url) {
        var crossOrigin = this.layer.options['crossOrigin'];
        tileImage.crossOrigin = crossOrigin !== null ? crossOrigin : '';

       // add  +++++
        tileImage.onerror = function(){
          tileImage.src = url;
          tileImage.onerrorTick = tileImage.onerrorTick || 0;
          tileImage.onerrorTick = tileImage.onerrorTick + 1;
          if(tileImage.onerrorTick > 9){
            tileImage.onerror = null;
          }
        };

        tileImage.src = url;
        return;
};

white patches disappear

gee1k commented 5 years ago

天地图现在已经全部服务需要申请 key 才可以使用,瓦片服务只需在 tileUrl 后加一个 tk 参数即可 image

image

gee1k commented 5 years ago

@lifefriend 你可以看看你的瓦片请求错误,状态码应该是 418

fuzhenn commented 5 years ago

@lifefriend adding a retry strategy to TileLayer is definitely a good idea. Could you submit a pull request to me?

Thanks!

lifefriend commented 5 years ago

@fuzhenn A pull request has been made in the hope that it does not break your code structure