-1

I have the following javascript code block, and is not very clear about it:

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);

What does the < in this.topTileFromX < mean?

3
  • 1
    "<" is the less than sign in the condition of a ternary operator. Beyond that, the question isn't very clear. Commented Mar 8, 2013 at 6:15
  • 1
    @TimMedora, I think he has difficulties in expressing in English. I have edited the question to make it more clear. Commented Mar 8, 2013 at 6:29
  • thanks. my language is not english Commented Mar 8, 2013 at 6:41

3 Answers 3

1

That's a JavaScript Ternary operator. See Details Here

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

is equivalent to the following expression

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);
}
Sign up to request clarification or add additional context in comments.

Comments

0

< means "lesser than", like in Mathematics.

Thus

  • 2 < 3 returns true
  • 2 < 2 is false
  • 3 < 2 is also false

Comments

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

It's a shorter if statement. It means:

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);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.