0

我有以下 javascript 代码块,但不是很清楚:

var level = this.getLevelForResolution(this.map.getResolution());
var coef = 360 / Math.pow(2, level);

var x_num = this.topTileFromX < this.topTileToX ? Math.round((bounds.left - this.topTileFromX) / coef) : Math.round((this.topTileFromX - bounds.right) / coef);
var y_num = this.topTileFromY < this.topTileToY ? Math.round((bounds.bottom - this.topTileFromY) / coef) : Math.round((this.topTileFromY - bounds.top) / coef);

<in是什么this.topTileFromX <意思?

4

3 回答 3

1

那是一个 JavaScript 三元运算符。在此处查看详细信息

var x_num = this.topTileFromX < this.topTileToX ? Math.round((bounds.left - this.topTileFromX) / coef) : Math.round((this.topTileFromX - bounds.right) / coef);

等价于下面的表达式

var x_num;

if (this.topTileFromX < this.topTileToX )
{
    x_num= Math.round((bounds.left - this.topTileFromX) / coef);
}
else
{
    x_num= Math.round((this.topTileFromX - bounds.right) / coef);
}
于 2013-03-08T06:14:46.300 回答
0

<意思是“小于”,就像在数学中一样。

因此

  • 2 < 3返回true
  • 2 < 2false
  • 3 < 2也是false
于 2013-03-08T06:15:09.020 回答
0
var x_num = this.topTileFromX < this.topTileToX ? Math.round((bounds.left - this.topTileFromX) / coef) : Math.round((this.topTileFromX - bounds.right) / coef);

这是一个较短的 if 语句。它的意思是:

var x_num;

if(this.topTileFromX < this.topTileToX)
{
   x_num = Math.round((bounds.left - this.topTileFromX) / coef);
}
else
{
   x_num = Math.round((this.topTileFromX - bounds.right) / coef);
}
于 2013-03-08T06:17:03.967 回答