Skip to content

Commit

Permalink
Merge branch 'pull/14'
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpoole committed Mar 10, 2021
2 parents debbbb6 + 2da762f commit dbeed27
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/main/java/dev/osm/mapsplit/MapSplit.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,14 @@ private double tile2lat(int y) {
* @return the tile X number
*/
private int lon2tileX(double lon) {
return (int) Math.floor((lon + 180.0) / 360.0 * Math.pow(2.0, zoom));
int xtile = (int) Math.floor((lon + 180) / 360 * (1 << zoom));
if (xtile < 0) {
xtile = 0;
}
if (xtile >= (1 << zoom)) {
xtile = ((1 << zoom) - 1);
}
return xtile;
}

/**
Expand All @@ -223,8 +230,14 @@ private int lon2tileX(double lon) {
* @return the tile y number
*/
private int lat2tileY(double lat) {
return (int) Math
.floor((1.0 - Math.log(Math.tan(lat * Math.PI / 180.0) + 1.0 / Math.cos(lat * Math.PI / 180.0)) / Math.PI) / 2.0 * Math.pow(2.0, zoom));
int ytile = (int) Math.floor((1 - Math.log(Math.tan(Math.toRadians(lat)) + 1 / Math.cos(Math.toRadians(lat))) / Math.PI) / 2 * (1 << zoom));
if (ytile < 0) {
ytile = 0;
}
if (ytile >= (1 << zoom)) {
ytile = ((1 << zoom) - 1);
}
return ytile;
}

/**
Expand Down

0 comments on commit dbeed27

Please sign in to comment.