Skip to content

Conversation

domoritz
Copy link
Contributor

@domoritz domoritz commented Sep 3, 2012

Implemented isValid() function for Bounds and LatLngBounds. Fixes issue #966. Added specification as well.

Example usage:

data = L.geoJson([]); // data may come from user input/ ajax
bounds = data.getBounds()
if (bounds.isValid()) {
  map.fitBounds(bounds);
}

@danzel
Copy link
Member

danzel commented Sep 3, 2012

Can you please revert/remove your rebuilt leaflet from the pull, it ruins trying to merging multiple pulls.
Thanks!

Could isValid just be
return this._southWest && this._northEast;
unless there is a case where they could be truthy but not valid?

@domoritz
Copy link
Contributor Author

domoritz commented Sep 3, 2012

Of course it can simply be this._southWest && this._northEast; but then it doesn't return true or false but object and undefined. However, in the end it has the same results.

@domoritz
Copy link
Contributor Author

domoritz commented Sep 5, 2012

Any comments?

@danzel
Copy link
Member

danzel commented Sep 5, 2012

Yep looks great to me!
@mourner will be the one to pull it, he'll be back in the next week I believe.

@domoritz
Copy link
Contributor Author

@danzel @mourner Is there anything left to do for me before this gets merged in?


isValid: function () {
return this.min && typeof this.max;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You forgot to remove typeof. Also, to cast everything to boolean, you can just do !!(this.min && this.max)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stupid me.

domoritz added a commit to domoritz/Leaflet that referenced this pull request Sep 11, 2012
@mourner
Copy link
Member

mourner commented Sep 11, 2012

Looks good to me!

mourner added a commit that referenced this pull request Sep 11, 2012
IsValid for Bounds and LatLngBounds
@mourner mourner merged commit 60444c2 into Leaflet:master Sep 11, 2012
mourner added a commit that referenced this pull request Sep 11, 2012
Added documentation for isValid from #972.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants