我有一个使用在线地图瓦片的谷歌地图实现。但是,如果我超出了瓦片区域,它会抛出错误,因为它无法找到这些图像。如何编写if语句,在这些图像不存在时返回null?
我的想法是,因为我包括了jQuery:
$.get(url)
.done(function() {
// exists code
return `http://www.blablabla.com/grey-tiles/${zoom}/${coord.x}/${coord.y}.png`
}).fail(function() {
// not exists code
return null;
})
但是这对我并不起作用。这是我的组件构造函数:
constructor(){
this.imageMapOptions = {
getTileUrl: (coord: ImageMapTypeCoord, zoom: number) => {
return `http://www.blablabla.com/grey-tiles/${zoom}/${coord.x}/${coord.y}.png`
},
tileSize: { height: 256, width: 256 },
maxZoom: 18,
minZoom: 16,
radius: 1738000,
name: 'Beeksebergen'
};
}