我有一个谷歌地图实现,其中我使用网上的地图块。但是,如果我走出瓷砖区域,它将引发错误,因为它无法找到图像..我如何使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'
};
}
您不能从异步调用返回。 – epascarello