@@ -33,6 +33,9 @@ func init() {
33
33
34
34
func tileCoord (long , lat float64 , zoom int ) (float64 , float64 ) {
35
35
x , y := proj .WgsToMerc (long , lat )
36
+ if x < mercBbox [0 ] || x > mercBbox [2 ] || y < mercBbox [1 ] || y > mercBbox [3 ] {
37
+ return - 1 , - 1
38
+ }
36
39
res := mercRes [zoom ]
37
40
x = x - mercBbox [0 ]
38
41
y = mercBbox [3 ] - y
@@ -100,6 +103,9 @@ func (tl *TileList) addCoord(long, lat float64) {
100
103
const tilePadding = 0.2
101
104
tl .mu .Lock ()
102
105
tileX , tileY := tileCoord (long , lat , tl .maxZoom )
106
+ if tileX < 0 {
107
+ return
108
+ }
103
109
for x := uint32 (tileX - tilePadding ); x <= uint32 (tileX + tilePadding ); x ++ {
104
110
for y := uint32 (tileY - tilePadding ); y <= uint32 (tileY + tilePadding ); y ++ {
105
111
tl .tiles [tl .maxZoom ][tileKey {x , y }] = struct {}{}
@@ -124,6 +130,9 @@ func (tl *TileList) expireLine(nodes []osm.Node, zoom int) {
124
130
}
125
131
x1 , y1 := tileCoord (nodes [i ].Long , nodes [i ].Lat , zoom )
126
132
x2 , y2 := tileCoord (nodes [i + 1 ].Long , nodes [i + 1 ].Lat , zoom )
133
+ if x1 < 0 || x2 < 0 {
134
+ return
135
+ }
127
136
if int (x1 ) == int (x2 ) && int (y1 ) == int (y2 ) {
128
137
tl .tiles [zoom ][tileKey {X : uint32 (x1 ), Y : uint32 (y1 )}] = struct {}{}
129
138
} else {
@@ -140,6 +149,9 @@ func (tl *TileList) expireBox(b bbox, zoom int) {
140
149
defer tl .mu .Unlock ()
141
150
x1 , y1 := tileCoord (b .minx , b .maxy , zoom )
142
151
x2 , y2 := tileCoord (b .maxx , b .miny , zoom )
152
+ if x1 < 0 || x2 < 0 {
153
+ return
154
+ }
143
155
for x := uint32 (x1 ); x <= uint32 (x2 ); x ++ {
144
156
for y := uint32 (y1 ); y <= uint32 (y2 ); y ++ {
145
157
tl .tiles [zoom ][tileKey {x , y }] = struct {}{}
@@ -233,6 +245,9 @@ func nodesBbox(nodes []osm.Node) bbox {
233
245
func numBboxTiles (b bbox , zoom int ) int {
234
246
x1 , y1 := tileCoord (b .minx , b .maxy , zoom )
235
247
x2 , y2 := tileCoord (b .maxx , b .miny , zoom )
248
+ if x1 < 0 || x2 < 0 {
249
+ return 0
250
+ }
236
251
return int (math .Abs ((x2 - x1 + 1 ) * (y2 - y1 + 1 )))
237
252
}
238
253
0 commit comments